File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes problem in MIDI music file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "problem in MIDI music file " Watch "problem in MIDI music file " New topic

problem in MIDI music file

parthiban rajendran

Joined: Oct 05, 2005
Posts: 8
hello friends,
i created a program which is expected to play a MIDI song, continuously by continuous event handling. everytime the track is finished, the sequencer object will fire a event, which will be handled by a method called meta(). the problem is the event is fired so fast that the song is not being played at all from second time. the execution of the following program may explain better.

import javax.sound.midi.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

class Orchestra implements MetaEventListener

Sequencer player;// CD player
Sequence seq;// CD
Track track;// track in CD

int[] instruments = {35, 42, 46, 38, 49, 39, 50, 60, 70, 72, 64, 56, 58, 47, 67, 63};

public void buildTrackandStart()


//create the CD player and switch it on
player = MidiSystem.getSequencer();;

//registering for event handling

//create the CD
seq = new Sequence(Sequence.PPQ,4);

//create the track 'in the CD'
track = seq.createTrack();

//-------- SONG CREATION ----------------------
for(int i=0; i < 16;i++)
//-------- end of SONG CREATION ---------------

//making an event explicitly

//put the CD in the CD player

//push the play button in the CD player

catch(Exception ex)


public MidiEvent makeEvent(int command,int channel,int note,int velocity,int beat_timing)
MidiEvent event = null;
ShortMessage a = new ShortMessage();
event = new MidiEvent(a,beat_timing);
catch(Exception ex)

return event;

public void meta(MetaMessage message)


public class testMusicVer42a
public static void main(String args[])

Orchestra troop1 = new Orchestra();



when it runs, it is supposed to play the sequence continuously but it is not. what is the problem in this code? please help me friends. kindly reply at the earliest.
[ October 17, 2005: Message edited by: parthiban rajendran ]

i love 'drinking' java
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
It looks like there are many MetaMessage types. When messages come in try displaying the message type. Remove the start() call for now to reduce confusion. I haven't seen a description of what the types mean anywhere, but you may be able to figure out one of the last few is when the sequencer ends.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I agree. Here's the link:
subject: problem in MIDI music file
It's not a secret anymore!