We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSound,  Music Libraries › themidibus reading midi file
Page Index Toggle Pages: 1
themidibus reading midi file? (Read 2007 times)
themidibus reading midi file?
Apr 23rd, 2009, 11:50pm
 
I just finished my first Processing sketch, which accepts input from MIDI sources, and displays a real-time visualization.  I used themidibus for the midi interface.

Now after I've done this, I realize one other use of this (so it's easier to show a demo on the web) is to have it load a midi file and visualize from it.  Is there a way to connect a java sequencer as transmitter and setup themidibus as receiver, or something like that, using only Processing, to achieve the result?
Re: themidibus reading midi file?
Reply #1 - Apr 26th, 2009, 1:57pm
 
I need such a thing too... reading from a midi file. I'm studying the javax.sound.midi javadoc at the moment...

If someone has done this before, please help!
Re: themidibus reading midi file?
Reply #2 - Apr 27th, 2009, 12:07am
 
I finally could get it to load a midi file and extract tracks information :

Code:
import javax.sound.midi.*;
import java.io.File;

String filename = "D:/mypath/data/test.mid";
File f = new File(filename);
try {
 Sequence s = MidiSystem.getSequence(f);
 println("Division type: " + s.getDivisionType());
 println("Duration (microsec): " + s.getMicrosecondLength());
 println("Resolution: " + s.getResolution());
 println("Duration (ticks): " + s.getTickLength());
 Track[] tracks = s.getTracks();
 println("Tracks: " + tracks.length);
 for(int i = 0; i < tracks.length; i++) {
   Track t = tracks[i];
   println("  Track " + (i+1));
   println("    Events: " + t.size());
   println("    Duration (ticks): " + t.ticks());
 }
}
catch(Exception e) {}


Next step : extract all note-on, note-off and control change events, put them in an array, and play them back on tempo.
Re: themidibus reading midi file?
Reply #3 - May 10th, 2009, 8:03pm
 
Hey,

The MidiBus doesn't currently support reading midi files, although I was considering adding it in if there's interest. You're got the right method, the javax.sound.midi package has everything you need to read midi. I think maybe proMidi has implemented midi file reading but I'm not sure.

Sparky
Re: themidibus reading midi file?
Reply #4 - May 27th, 2009, 10:06am
 
Yes, it'd be great if MIDI file read is supported.  When I write code to respond to MIDI messages, it'd be nice if I don't have to consider where it comes from, whether it comes from MIDI file or from an actual instrument, or both at the same time...  Having a common interface makes things easier to be re-useable.  MIDIbus would be a great abstraction to build this, as theBUS supports multiple inputs all going to the same input bus.  So is this possible?
Page Index Toggle Pages: 1