1 import javax.sound.midi.*;
5 Killed superfluous exportMIDI method.
6 Added public static void quit()
7 Removed Sequence seq property.
8 Changed forward(int measures) and rewind(int measures) to forward(long ticks) and rewind(long ticks).
9 Added public static long getPosition()
10 Added public static void setPosition(long ticks)
11 Added public static void resume()
15 * Moosique - The MIDI Tracker
17 * Main class that handles initiation, IO and sound FX.
19 * @author Andersson, Andreen, Lanneskog, Pehrson
23 public class Moosique {
25 private static MooGUI gui;
26 private static MooSequence seq;
28 private static Sequencer sequencer = null;
29 private static Synthesizer synthesizer = null;
30 private static Receiver receiver = null;
31 private static MidiChannel[] channels;
33 private static String file;
34 private static long position;
37 * Starts the application.
39 public static void main (String[] args) {
40 seq = new MooSequence();
41 gui = new MooGUI(seq);
43 // Acquires MIDI devices and connects them.
45 sequencer = MidiSystem.getSequencer();
47 synthesizer = MidiSystem.getSynthesizer();
49 sequencer.getTransmitter().setReceiver(synthesizer.getReceiver());
50 } catch (MidiUnavailableException e) {
54 channels = synthesizer.getChannels();
58 * Returns a pointer to the current sequence.
59 * @return the current sequence
61 public static MooSequence getSequence() {
66 * Starts playback of the current sequence.
68 public static void play() {
69 sequencer.setSequence(seq.getSequence());
70 sequencer.setTickPosition(position);
75 * Pauses playback of the current sequence.
77 public static void pause() {
82 * Resumes playback of the current sequence.
84 public static void resume() {
89 * Stops playback of the current sequence.
91 public static void stop() {
93 sequencer.setTickPosition(position);
97 * Rewinds the current sequence the given number of measures.
98 * @param measures the number of measures to rewind
100 public static long getPosition() {
105 * Rewinds the current sequence the given number of measures.
106 * @param measures the number of measures to rewind
108 public static void setPosition(long ticks) {
113 * Rewinds the current sequence the given number of measures.
114 * @param measures the number of measures to rewind
116 public static void rewind(long ticks) {
121 * Fast forwards the current sequence the given number of measures.
122 * @param measures the number of measures to fast forward
124 public static void forward(long ticks) {
129 * Loads the MooSequence in the given file.
130 * @param filename the filename to use
132 public static void load(String filename) throws IOException {
134 seq = new MooSequence(MidiSystem.getSequence(new File(filename)));
138 * Saves the current sequence to the given filename
139 * @param filename the filename to use
141 public static void saveAs(String filename) throws IOException {
142 MidiSystem.write(seq.getSequence(), 1, new File(filename));
147 * Saves the current sequence to the previously given filename.
149 public static void save() throws IOException {
154 * Releases all reserved devices and exits the program.
156 public static void quit() {
157 if (sequencer.isOpen()) {
160 } catch (MidiUnavailableException e) {}