+ // Creates a new sequence.
+ seq = new Sequence(Sequence.PPQ, DEFAULT_RESOLUTION, DEFAULT_TRACKS);
+ Track[] tracks = seq.getTracks();
+
+ // Creates messages for default tempo (120) and time signature (4/4).
+ MetaMessage timeSigMsg = new MetaMessage();
+ MetaMessage tempoMsg = new MetaMessage();
+ try {
+ timeSigMsg.setMessage(88, encodeTimeSig(4, 4), 4);
+ tempoMsg.setMessage(81, encodeTempo(120), 3);
+ } catch (InvalidMidiDataException e) {}
+
+ // Adds them to track 0.
+ tracks[0].add(new MidiEvent(timeSigMsg, (long)0));
+ tracks[0].add(new MidiEvent(tempoMsg, (long)0));
+
+ // Sets program and title for the tracks.
+ initializeTrack(tracks[1], 0, 24, "Guitar");
+ initializeTrack(tracks[2], 1, 33, "Bass");
+ initializeTrack(tracks[3], 9, 0, "Drums");
+
+ file = null;
+ emptyTracks = new ArrayList();
+ timeSignatures = new ArrayList();
+ tempoChanges = new ArrayList();
+ trackSolo = new HashMap();
+ trackMute = new HashMap();
+ copyBuffer = new ArrayList();
+ } catch (InvalidMidiDataException e) {}
+ // Sends the sequence to the GUI.
+ if (gui != null) gui.setSequence(seq);
+ }
+
+ /**
+ * Creates event in the given track for program change and title.
+ */
+ private static void initializeTrack(Track track, int channel, int program, String title) {
+ // Creates program change and title message.
+ ShortMessage programMsg = new ShortMessage();
+ MetaMessage titleMsg = new MetaMessage();
+
+ // Sets the data of the messages.
+ try {
+ programMsg.setMessage(ShortMessage.PROGRAM_CHANGE, channel, program, 0);
+ titleMsg.setMessage(3, title.getBytes(), title.length());
+ } catch (InvalidMidiDataException e) {}
+
+ // Adds them to the track.
+ track.add(new MidiEvent(programMsg, (long)0));
+ track.add(new MidiEvent(titleMsg, (long)0));
+ }
+
+ /**
+ * Wraps each NoteOn event in the track with its NoteOff event in a MooNote.
+ * @param track the track to convert
+ * @param quantize whether to round locations and durations in the track to nearest 16th
+ * @return a list of the created MooNotes
+ */
+ public static List convertTrack(Track track, boolean quantize) {
+ // Searches the track for NoteOn and NoteOff events
+ ArrayList noteOns = new ArrayList(track.size() / 2);
+ ArrayList noteOffs = new ArrayList(track.size() / 2);
+ ArrayList newMooNotes = new ArrayList();
+ MidiEvent event;
+ for (int j = 0; j < track.size(); j++) {
+ event = track.get(j);
+ if (event.getMessage().getStatus() >= 144 &&
+ event.getMessage().getStatus() < 160) noteOns.add(event);
+ if (event.getMessage().getStatus() >= 128 &&
+ event.getMessage().getStatus() < 144) noteOffs.add(event);