+ /**
+ * Sets whether empty tracks should be drawn
+ * @param state true if empty tracks should be drawn
+ */
+ public static void setDrawEmptyTracks(boolean state) {
+ drawEmptyTracks = state;
+ }
+
+ /**
+ * Sets the current sequence as edited, which implies prompts when loading a new sequence.
+ */
+ public static void setEdited() {
+ edited = true;
+ }
+
+ /**
+ * Sets the current editing position of the sequencer.
+ * @param ticks the tick position
+ */
+ public static void setEditPosition(long ticks) {
+ editPosition = ticks;
+ }
+
+ /**
+ * Sets the current editing position of the sequencer.
+ * @param ticks the tick position
+ */
+ public static void setTempo(int bpm) {
+ // tempoMsg
+ }
+
+ /**
+ * Sets the current editing position of the sequencer.
+ * @param ticks the tick position
+ */
+ public static void setTimeSig(int bpm) {
+ // timeSigMsg
+ }
+
+ public static void setTrackSolo(Track track, boolean on){
+ trackSolo.put(track, new Boolean(on));
+ }
+
+ public static void setTrackMute(Track track, boolean on){
+ trackMute.put(track, new Boolean(on));
+ }
+
+
+
+
+
+
+
+
+ /* ***
+ ** PLAYBACK METHODS **
+ *** */
+
+
+
+
+
+
+
+
+ /**
+ * Starts playback of the current sequence.
+ */
+ public static void play() {
+ sequencer.setTickPosition(editPosition);
+ resume();
+ }
+
+ /**
+ * Resumes playback of the current sequence.
+ */
+ public static void resume() {
+ gui.update(0);
+ try {
+ sequencer.setSequence(seq);
+ } catch (InvalidMidiDataException e) {}
+ Track[] tracks = seq.getTracks();
+
+ sequencer.start();
+
+ for (int i = 0; i < tracks.length; i++) {
+
+ Object ob = trackSolo.get(tracks[i]);
+ if(ob instanceof Boolean){
+ sequencer.setTrackSolo(i,((Boolean)ob).booleanValue());
+ }
+
+ ob = trackMute.get(tracks[i]);
+ if(ob instanceof Boolean){
+ sequencer.setTrackMute(i,((Boolean)ob).booleanValue());
+ }
+ }
+
+
+ // Disables input to volatile components
+ // gui.disable();
+
+ // Creates the visualisation thread and starts it.
+ player = new Thread () {
+ public void run() {
+ while(sequencer.isRunning()) {
+ // Updates the GUI with the current tick position.
+ gui.update(sequencer.getTickPosition());
+
+ // Puts the thread to sleep for as long as it takes
+ // the sequencer to reach the next sixteenth.
+ try {
+ //sleep((long)((15000 / getTempo()) * (tickDiff / ticksPerSixteenth)));
+ sleep (10);
+ } catch (InterruptedException e) {
+ Moosique.stop();
+ }
+ }
+ Moosique.stop();
+ }
+ };
+ player.start();
+ }
+
+ /**
+ * Pauses playback of the current sequence.
+ */
+ public static void pause() {
+ if (sequencer.isRunning()) {
+ sequencer.stop();
+ }
+ if (player != null) player.interrupt();
+ }
+
+ /**
+ * Stops playback of the current sequence.
+ */
+ public static void stop() {
+ if (sequencer.isRunning()) {
+ sequencer.stop();
+ }
+ sequencer.setTickPosition(editPosition);
+ if (player != null) player.interrupt();
+ gui.update((long)0);
+ }
+
+
+
+
+
+
+
+
+ /* ***
+ ** SYSTEM & IO METHODS **
+ *** */
+
+
+
+
+
+
+
+
+ /**
+ * Replaces the current sequence with a new one, holding three empty tracks.
+ */
+ public static void clearSequence() {
+ // Creates a new sequence and sends it to the sequencer.
+ try {
+ seq = new Sequence(Sequence.PPQ, DEFAULT_RESOLUTION, DEFAULT_TRACKS);
+ sequencer.setSequence(seq);
+ filename = null;
+ emptyTracks = new ArrayList();
+ trackSolo = new HashMap();
+ trackMute = new HashMap();
+ } catch (InvalidMidiDataException e) {}
+ // Sends sequence to GUI.
+ if (gui != null) gui.setSequence(seq);
+ }
+
+ /**
+ * Loads a MIDI sequence from the given file.