[Python] Python - data extraction from MIDI files

Discussão em 'Python' iniciado por Stack, Abril 19, 2025.

  1. Stack

    Stack Membro Participativo

    Looking to read in massive amount of MIDI files and extract their data into groups - tick(time), pitch(note) and velocity(volume). The extracted data will be applied to a Recurrent Neural Network for further music generation.

    I have been searching for libraries and located python-midi. Here's my code:

    import midi
    pattern = midi.read_midifile("pachelbel_canon.mid")

    #print out all events
    print pattern
    #print out all events at tick = 0
    print pattern[0]


    Interpretation of different event types can be found either on here or Granroth-Wilding's website. My target values (tick, pitch and velocity) are presented as midi.NOteOn/OffEvent(tick=0, channel=0, data=[pitch, velocity]).

    Question 1: Since there's no tutorial nor documentation available, after some testing I figured print pattern[0] returns all events happened at tick == 0. Of course all data can be retrieved by running a for-loop over all events, I'm just wondering is there any function to retrieve data by providing other parameters e.g. channel, pitch etc.

    Question 2: Apparently there are lots of midi / music libraries available out there. Not saying python-midi is not decent, yet if you have anything better in mind please do share! Preferably comes with some proper documentation or support, which doesn't exist for python-midi. I'm new to this area and would love some recommendations.

    Continue reading...

Compartilhe esta Página