Question

I'm new to JAVA MIDI and i have come across a problem .I want to load a MIDI file then set a couple of labels with the name of each instrument that was used for each track.For example if the MIDI file has 5 tracks(each track has only one instrument ) then i will get 5 labels each one having the name of the instrument used on each track.

Is there any way to see what instrument was used for each track in a MIDI file(function,method...)?

Was it helpful?

Solution

Once you have isolated each track in the arrangement, there are a two different ways to determine the instrument which should play it.

One is that a MIDI meta message with ID 0x04 will appear with the instrument name as a string. See this great page detailing the MIDI file format for details.

The second way is that a MIDI program change message will appear at the beginning of the track. Assuming that the MIDI files are set to use GM (general MIDI) instruments, you can associate data of the program change message to a GM instrument.

Note that program changes are allowed to appear anywhere in a MIDI track, and the sequencer should deal with them accordingly. Although most MIDI files you'll see in the wild won't use program changes in the middle of tracks, keep in mind that it is allowed by the standard and may occur.

OTHER TIPS

  1. Get a Sequence for the MIDI file.
  2. Get the Track objects of the sequence.
  3. Get the MidiEvent objects of the track.
  4. Get the MidiMessage of the event. That will contain the information on (among other things) an instrument change.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top