from music21 import converter, instrument, note, stream from music21 import chord fic=open("tabla.abc") ficabc=fic.read() fic.close() # ABC notation abc_notation = ficabc def abc_to_midi(abc_notation, output_filename): # Convert ABC notation to music21 stream object stream_obj = converter.parse(abc_notation) # Create MIDI file midi_stream = stream.Stream() # Set instrument to piano midi_stream.append(instrument.Piano()) # Iterate over each element in the music21 stream for element in stream_obj.flat: # Check if element is a note if isinstance(element, note.Note): # Add note to MIDI stream midi_stream.append(element) # Check if element is a chord elif isinstance(element, chord.Chord): # Add chord to MIDI stream midi_stream.append(element) # Write MIDI stream to file midi_stream.write('midi', fp=output_filename) # Usage example output_filename = 'tabla.mid' abc_to_midi(abc_notation, output_filename) print(f"MIDI file '{output_filename}' generated successfully!")