Midi2Scilab

About

Midi2Scilab parses Standard Midi files and generates Scilab/Octave/Matlab code for Midi events. Instrument models are usually simulated in these environments and playing a Midi file is a common task.

The project uses similar ideas to Matlab and MIDI project, but is written in standard C++ and doesn't require any additional tools.

Example

Let's create a C-Major scale from the middle C and above.





You can download the produced Midi file here.

Now, let's convert the Midi file to Scilab code:

$ ./midi2scilab –music-pitch scale.mid
music_notes = [ 'C4' 'CIS4' 'D4' 'DIS4' 'E4' 'F4' 'FIS4' 'G4' 'GIS4' 'A4' 'AIS4' 'B4' 'C5' ];


music_notes_freq = [ 261.626 277.183 293.665 311.127 329.628 349.228 369.994 391.995 415.305 440 466.164 493.883 523.251 ];


channel_program = [ 71 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ];


channel = list();


channel(1) = list();
channel(1)(1) = list( 'C4', 0, 813 );
channel(1)(2) = list( 'D4', 813, 813 );
channel(1)(3) = list( 'E4', 1626, 814 );
channel(1)(4) = list( 'F4', 2440, 813 );
channel(1)(5) = list( 'G4', 3253, 814 );
channel(1)(6) = list( 'A4', 4067, 813 );
channel(1)(7) = list( 'B4', 4880, 814 );
channel(1)(8) = list( 'C5', 5694, 813 );
channel(1)(9) = list( 'C5', 6507, 814 );
channel(1)(10) = list( 'B4', 7321, 813 );
channel(1)(11) = list( 'A4', 8134, 814 );
channel(1)(12) = list( 'G4', 8948, 813 );
channel(1)(13) = list( 'F4', 9761, 814 );
channel(1)(14) = list( 'E4', 10575, 813 );
channel(1)(15) = list( 'D4', 11388, 814 );
channel(1)(16) = list( 'C4', 12202, 813 );


channel(2) = list();


channel(3) = list();


channel(4) = list();


channel(5) = list();


channel(6) = list();


channel(7) = list();


channel(8) = list();


channel(9) = list();


channel(10) = list();


channel(11) = list();


channel(12) = list();


channel(13) = list();


channel(14) = list();


channel(15) = list();


channel(16) = list();

Midi2Scilab produces triplets for each NOTE_ON Midi event for each channel (instrument). In our case, Midi channel 1 has a program number 71 (clarinet). Each note starts right after another and is ~800 miliseconds long. The first element in channel() list is a note name. Usually you need a note frequency to simulate instrument playing the note - music_notes and music_notes_freq are used to map between the note name and the frequency.

Midi2Scilab also offers two other modes. Switch –freq-pitch (default) is used to directly produce frequencies inside the channel() list as the first argument and –midi-pitch puts Midi pitch (0..127) for the first argument respectively.

The generated file can be opened by Scilab and (as they use the same syntax) GNU Octave/Matlab.

Download

Source and Win32 executable are available for download. Use Sourceforge download site.

You can browse the SVN tree here.

Author

Midi2Scilab and examples were written by Matevž Jekovec <matevz at jekovec dot net> as a seminar at Digital Signal Processing subject at Faculty of computer and information science in Ljubljana, Slovenia.

License

Midi2Scilab is free software licensed under the GNU GPL v3.

Get Midi2Scilab at SourceForge.net. Fast, secure and Free Open Source software downloads