package hf;
import javax.sound.midi.*;
public class BeatBox1
{
public static void main(String[] args)
{
BeatBox1 boom = new BeatBox1();
boom.go();
}
public void go()
{
try
{
Sequencer player = MidiSystem.getSequencer();
player.open();
Sequence seq = new Sequence(Sequence.PPQ,4);
Track track = seq.createTrack();
for(int i = 5;i<125;i+=5)
{
track.add(makeEvent(144,i,i));
track.add(makeEvent(128,i,i+2));
}
player.setSequence(seq);
player.start();
}
catch(Exception e)
{
System.out.println("Problem starting the BeatBox");
}
}
public static MidiEvent makeEvent(int onOff,int note,int time)
{
MidiEvent event = null;
try
{
ShortMessage a = new ShortMessage();
a.setMessage(onOff,1,note,100);
event = new MidiEvent(a,time);
return event;
}
catch(Exception e)
{
System.out.println("Error in creating Event.");
}
return event;
}
}
I found the above example code in a book. They recommend making the makeEvent method static. What is the reason?
The program runs correctly when makeEvent() is made non-static as well. Is there any performance gain or any advantage that can be obtained by making the method static?