private static String filename, fileArg;
private static long position;
private static boolean makeGUI = true, isEdited;
+ private static Thread player;
+ public static final int RESOLUTION = 96, DEFAULT_TRACKS = 4;
/**
* Starts the application.
return channels;
}
+ /**
+ * Returns the MidiChannels of the selected synthesizer.
+ * @return the available MidiChannels
+ */
+ public static MidiChannel getChannel(int i) {
+ return channels[i];
+ }
+
/**
* Returns the currently active MidiChannel.
* @return the active MidiChannel
public static void clearSequence() {
// Creates a new sequence and sends it to the sequencer.
try {
- seq = new Sequence(Sequence.PPQ, 96, 3);
+ seq = new Sequence(Sequence.PPQ, RESOLUTION, DEFAULT_TRACKS);
sequencer.setSequence(seq);
} catch (InvalidMidiDataException e) {}
// Sends sequence to GUI.
*/
public static void play() {
sequencer.setTickPosition(position);
- sequencer.start();
+ resume();
}
/**
*/
public static void pause() {
sequencer.stop();
+ player.interrupt();
}
/**
*/
public static void resume() {
sequencer.start();
+
+ // Disables input to volatile components
+ // gui.disable();
+
+ // Creates the visualization thread and starts it.
+ player = new Thread () {
+ public void run() {
+ while(sequencer.isRunning()) gui.update(sequencer.getTickPosition());
+ Moosique.stop();
+ }
+ };
+ player.start();
}
/**
* Stops playback of the current sequence.
*/
public static void stop() {
- sequencer.stop();
- sequencer.setTickPosition(position);
+ if (sequencer.isRunning()) {
+ sequencer.stop();
+ sequencer.setTickPosition(position);
+ player.interrupt();
+ gui.update((long)0);
+ }
}
/**
* @return the tick position
*/
public static long getPosition() {
- return position;
+ return sequencer.getTickPosition();
}
/**
* @param ticks the tick position
*/
public static void setPosition(long ticks) {
- position = ticks;
+ sequencer.setTickPosition(ticks);
}
/**