Closed JithLord closed 2 years ago
This issue has been resolved! Use the GM 1 Sound Set!
can you please elaborate?? I have been having the same issue. I want to create music from different instruments but getting only piano in the output..
To anyone still wondering, you can add "output_notes.append(instrument.Violin())" immediately after "output_notes = [ ]" (at line 108 in predict.py) to have the output .mid use a violin. Change instrument to whatever you want at that point.
Side note: you can also get rid of the lines that have new_note.storedInstrument (lines 117 and 127). I didn't keep them when I changed instruments.
instrumentNo refers to the number from the GM1 Sound set, the values in the table are 1 indexed, make sure you subtract 1 from the table to get the exact instrument! GM1 Sound Set
def convert_to_midi(prediction_output):
offset = 0
output_notes = []
for pattern in prediction_output:
if ('.' in pattern) or pattern.isdigit():
notes_in_chord = pattern.split('.')
notes = []
for current_note in notes_in_chord:
new_note = note.Note(int(current_note))
new_note.storedInstrument = instrument.instrumentFromMidiProgram(instrumentNo)
notes.append(new_note)
new_chord = chord.Chord(notes)
new_chord.offset = offset
output_notes.append(new_chord)
else:
new_note = note.Note(pattern)
new_note.offset = offset
new_note.storedInstrument = instrument.instrumentFromMidiProgram(instrumentNo)
output_notes.append(new_note)
offset+ = 0.5
midi_stream = stream.Stream(output_notes)
midi_stream.write('midi', fp='music.mid')
Can music be generated for other instruments? I've tried using GM 1 sound set to replace the values in your program. ie Replace the value 0 which basically means Piano with a value 4 ie, Electric Piano but that doesn't seem to work.
notes_to_parse = s2.parts[4].recurse()
and the linenew_note.storedInstrument = instrument.instrumentFromMidiProgram(4)
But for some reason it always gives the default Piano. Any options, suggestions please do let me know