I need a script to generate m midi file with some synthwave chords in progression using music21 python module
Sure! Here's an example script that uses the music21 python module to generate a MIDI file with synthwave chords in a specified progression:
from music21 import *
def generate_midi_with_synthwave_chords(progression, output_file):
# Create a new MIDI stream
stream = stream.Stream()
# Define the chords in the synthwave progression
chords = {'I': ['C4', 'E4', 'G4', 'B4'],
'ii': ['D4', 'F4', 'A4', 'C5'],
'iii': ['E4', 'G4', 'B4', 'D5'],
'IV': ['F4', 'A4', 'C5', 'E5'],
'V': ['G4', 'B4', 'D5', 'F5'],
'vi': ['A4', 'C5', 'E5', 'G5'],
'vii': ['B4', 'D5', 'F5', 'A5']}
# Iterate through the progression and add the corresponding chords to the stream
for chord_symbol in progression:
chord_notes = [note.Note(chord_note) for chord_note in chords[chord_symbol]]
chord = chord.Chord(chord_notes)
stream.append(chord)
# Add a piano instrument to the stream
piano = instrument.Piano()
stream.insert(0, piano)
# Write the stream to a MIDI file
stream.write('midi', fp=output_file)
print(f"MIDI file generated successfully: {output_file}")
# Specify the progression
progression = ['I', 'vi', 'IV', 'V']
# Specify the output file name
output_file = 'synthwave_chords.mid'
# Generate the MIDI file
generate_midi_with_synthwave_chords(progression, output_file)
In this example, the generate_midi_with_synthwave_chords function takes in a list of chord symbols representing a chord progression and an output file name. It then creates a new MIDI stream, adds the corresponding synthwave chords to the stream, inserts a piano instrument, and writes the stream to the specified MIDI file.
You can customize the chords dictionary to include different synthwave chord progressions or modify the script as per your requirements
原文地址: https://www.cveoy.top/t/topic/i0b8 著作权归作者所有。请勿转载和采集!