if (noteOns.size() == 0) emptyTracks.add(tracks[i]);
// Sorts the note lists by tick position.
- Comparator c = new Comparator() {
- public int compare(Object o1, Object o2) {
- return (int)(((MidiEvent)o1).getTick() - ((MidiEvent)o2).getTick());
- }
- };
+ Comparator c = new NoteComparator();
Collections.sort(noteOns, c);
Collections.sort(noteOffs, c);
if (off != null) {
tracks[i].add(new MooNote(on, off));
} else {
- tracks[i].add(new MooNote(on));
+ tracks[i].add(new MooNote(on, new MidiEvent((ShortMessage)on.getMessage().clone(), on.getTick() + 48)));
}
iOn.remove();
}
return true;
}
+ /**
+ * Prompts the user .
+ */
+ public static boolean promptOnUnsavedChanges() {
+ if (!isEdited) return false;
+ int exitOption = JOptionPane.showConfirmDialog(gui,
+ "The current sequence has been edited, but not saved.\nDo you wish to continue anyway?",
+ "File not saved - continue?",
+ JOptionPane.OK_CANCEL_OPTION,
+ JOptionPane.WARNING_MESSAGE);
+ if (exitOption == JOptionPane.CANCEL_OPTION || exitOption == JOptionPane.CLOSED_OPTION) return true;
+ return false;
+ }
+
/**
* Saves the current sequence to the previously given filename.
*/
try {
MidiSystem.write(seq, 1, new File(file));
filename = file;
+ isEdited = false;
gui.setStatus("Saved " + file);
return true;
} catch (IOException e) {
* Releases all reserved devices and exits the program.
*/
public static void quit() {
- if (isEdited && gui != null) {
- int exitOption = JOptionPane.showConfirmDialog(gui,
- "The current sequence has been edited, but not saved.\nDo you wish to quit anyway?",
- "File not saved - really quit?",
- JOptionPane.OK_CANCEL_OPTION,
- JOptionPane.WARNING_MESSAGE);
- if (exitOption == JOptionPane.CANCEL_OPTION || exitOption == JOptionPane.CLOSED_OPTION) return;
+ if (gui != null) {
+ if (promptOnUnsavedChanges()) return;
}
if (sequencer.isOpen()) sequencer.close();
if (synthesizer.isOpen()) synthesizer.close();
System.exit(0);
}
+
+ /**
+ * A Comparator for sorting lists of MidiEvents.
+ */
+ public static class NoteComparator implements Comparator {
+ public int compare(Object o1, Object o2) {
+ return (int)(((MidiEvent)o1).getTick() - ((MidiEvent)o2).getTick());
+ }
+ }
}