X-Git-Url: https://ruin.nu/git/?p=moosique.git;a=blobdiff_plain;f=Moosique.java;h=09e8395707b175f41a9ab18e94b4a0858c8ef333;hp=5cf7af5b814f6c6eb07dcab4755d1bd894223f21;hb=6154ba318198471a2b94391df6aab6f2b6cd9b29;hpb=a8b0b5e27d120df964c5b6d8554a6207951b00d0 diff --git a/Moosique.java b/Moosique.java index 5cf7af5..09e8395 100644 --- a/Moosique.java +++ b/Moosique.java @@ -21,15 +21,15 @@ public class Moosique { private static MidiChannel[] channels; private static MidiChannel activeChannel; private static MidiEvent[] timeSignatures, tempoChanges; + private static ArrayList emptyTracks; private static Map trackMute = new HashMap(); private static Map trackSolo = new HashMap(); - + private static Thread player; private static String filename; private static long editPosition; - private static boolean makeGUI = true, initSound = true, isEdited = false, drawEmptyTracks = false; - private static Thread player; + private static boolean makeGUI = true, initSound = true, edited = false, drawEmptyTracks = false; public static final int DEFAULT_RESOLUTION = 96, DEFAULT_TRACKS = 4; /** @@ -236,7 +236,7 @@ public class Moosique { * @return the tick position */ public static boolean isEdited() { - return isEdited; + return edited; } /** @@ -302,7 +302,7 @@ public class Moosique { * Sets the current sequence as edited, which implies prompts when loading a new sequence. */ public static void setEdited() { - isEdited = true; + edited = true; } /** @@ -485,7 +485,7 @@ public class Moosique { } catch (IOException e) { return false; } - isEdited = false; + edited = false; Track[] tracks = seq.getTracks(); emptyTracks = new ArrayList(); @@ -527,11 +527,7 @@ public class Moosique { 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); @@ -559,7 +555,7 @@ public class Moosique { 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(); } @@ -572,6 +568,20 @@ public class Moosique { return true; } + /** + * Prompts the user . + */ + public static boolean promptOnUnsavedChanges() { + if (!edited) 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. */ @@ -591,6 +601,7 @@ public class Moosique { try { MidiSystem.write(seq, 1, new File(file)); filename = file; + edited = false; gui.setStatus("Saved " + file); return true; } catch (IOException e) { @@ -603,16 +614,20 @@ public class Moosique { * 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()); + } + } }