Thanxx for showing the concern to go through once my code..
The problem was that the in a.setMessage(* , , , ) & b.setMessage(*, , , ) first arguement(*) is set to 128 & that's why no sound was coming...
correct one:
a.setMessage(144,1,27,100)
But now I'm facing another problem with the same code which i edited some what (as given HFJ) to make it work through command line
Getting compiled but no sound coming..
package com.BB.getPlayer;
import javax.sound.midi.*;
public class MiniMusicAppCmd {
/**
* @param args
*/
public static void main(
String[] args) {
// TODO Auto-generated method stub
MiniMusicAppCmd mcd=new MiniMusicAppCmd();
if(args.length<2)
{
System.out.println("Hey you have to enter only the instrument & node You want To Play");
}
else
{
int instrument=Integer.parseInt(args[0]);
int note=Integer.parseInt(args[1]);
System.out.println(instrument+ " "+ note);
mcd.play(instrument,note);
}
}
public void play(int instru,int note)
{
try {
Sequencer player =MidiSystem.getSequencer();
player.open();
Sequence seq=new Sequence(Sequence.PPQ,4);
Track track=seq.createTrack();
//MidiEvent midi=null;
ShortMessage first=new ShortMessage();
first.setMessage(192,1,instru,0);
MidiEvent chngInstru=new MidiEvent(first, 1);
track.add(chngInstru);
ShortMessage a=new ShortMessage();
a.setMessage(144,1,note,100);
MidiEvent noteOn=new MidiEvent(a,1);
track.add(noteOn);
ShortMessage b=new ShortMessage();
b.setMessage(128,1,note,100);
MidiEvent noteOff=new MidiEvent(b,1);
track.add(noteOff);
player.setSequence(seq);
player.start();
} catch (MidiUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidMidiDataException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
please help i'm running this code on eclipse.