3

I would like to know about open source libraries that could be used to perform some simple tasks on MIDI files:

  1. reading a file one note - or chord - at a time;
  2. extracting a given instrument to re-encode it separately in a new file;
  3. allow to produce a "customizable" score -- by that I mean that I should be able to alter the way the sheet music is produced from the midi using the libraries ... I assume this will require an interaction with Lilypond or Musixtex.

I don't really have a preferred language, as long as it is not too painful to make the app cross-platform. Other advice is welcome -- better to learn it now rather than when I've already written a lot of code. So far, I've been trying to dig in MuseScore's (C++) source code, but it seems that GUI code permeates most files and although spotting relevant files was easy, it is difficult for me to extract just what I need (I'm only aiming for a command line application right now, I'll see about interfaces later).

Any ideas?

Thanks!

Anthony Labarre
  • 2,745
  • 1
  • 28
  • 39
  • I investigated this briefly about 6 years ago. The MIDI file spec isn't that hard (there are 3 flavors, if I remember), but I never could quite understand the compression scheme they used, which involved reading the high-order bit and understanding how many bytes were going to be in that chunk. I guess that's why I'm a front-end coder. :) – Robusto Mar 03 '10 at 01:13
  • see this question: http://stackoverflow.com/questions/3231/c-c-library-for-reading-midi-signals-from-a-usb-midi-device – sean e Apr 15 '10 at 16:09

2 Answers2

2

If you're still working on the project and language isn't a problem, you might try Python's cross-platform music21 which can parse midi files into Note, Chord, Instrument, etc., objects, lets you manipulate the scores, and then R/T back to MIDI or output to Lilypond, etc. (full disclosure, I'm the author of the toolkit; but I don't know of many others in any language that will take MIDI in and put Lilypond out while giving you a chance to treat the MIDI elements as objects to manipulate in the meantime.).

Sample code to screw up all the instrument sounds in a MIDI file and then play it and make a lilypond.pdf from it:

 import music21
 mf = music21.converter.parse('pathToMidiFile.mid')
 for x in mf.recurse():
     if 'Instrument' in x.classes:
         x.midiProgram = (x.midiProgram * 2) % 128
 mf.show('midi')
 mf.show('lily.pdf')

Hope that helps.

  • Thanks for the heads up. I finished the software I wanted to build, but it's good to know that your toolkit exists, I might need it for another app some day. – Anthony Labarre Oct 05 '12 at 06:18
2

Well, I'm just getting started, but this (in Python) seems promising.

Anthony Labarre
  • 2,745
  • 1
  • 28
  • 39