]> ruin.nu Git - moosique.git/blobdiff - Moosique.java
no message
[moosique.git] / Moosique.java
index 860f561a3d720e50dcf333554824f65f6fd18a0c..298c045ff30523290cc1ee234668f9355119ed9b 100644 (file)
@@ -68,6 +68,9 @@ public class Moosique {
                }
                System.out.println("Done");
 
+               // Loads user preferences (work directory, last opened files etc).
+               loadPreferences();
+
                //If a filename is given as the command-line argument, attempts to load a sequence from the file.
                if (fileArg != null) {
                        System.out.print("Loading MIDI sequence from " + fileArg + "...");
@@ -509,10 +512,11 @@ public class Moosique {
        /** 
         * Wraps each NoteOn event in the track with its NoteOff event in a MooNote.
         */
-       public static void convertTrack(Track track) {
+       public static List convertTrack(Track track) {
                // Searches the track for NoteOn and NoteOff events
                ArrayList noteOns = new ArrayList(track.size() / 2);
                ArrayList noteOffs = new ArrayList(track.size() / 2);
+               ArrayList mooNotes = new ArrayList();
                MidiEvent event;
                for (int j = 0; j < track.size(); j++) {
                        event = track.get(j);
@@ -536,28 +540,34 @@ public class Moosique {
                ShortMessage onMsg, nextOffMsg;
                while(iOn.hasNext()) {
                        on = (MidiEvent)iOn.next();
-                       onMsg = (ShortMessage)on.getMessage();
-                       iOff = noteOffs.iterator();
-                       while(iOff.hasNext()) {
-                               nextOff = (MidiEvent)iOff.next();
-                               nextOffMsg = (ShortMessage)nextOff.getMessage();
-                               if(onMsg.getChannel() == nextOffMsg.getChannel() &&
-                                  onMsg.getData1() == nextOffMsg.getData1() &&
-                                  c.compare(nextOff, on) > 0) {
-                                       off = nextOff;
-                                       iOff.remove();
-                                       break;
+                       if (!(on instanceof MooNote)) {
+                               onMsg = (ShortMessage)on.getMessage();
+                               iOff = noteOffs.iterator();
+                               while(iOff.hasNext()) {
+                                       nextOff = (MidiEvent)iOff.next();
+                                       nextOffMsg = (ShortMessage)nextOff.getMessage();
+                                       if(onMsg.getChannel() == nextOffMsg.getChannel() &&
+                                          onMsg.getData1() == nextOffMsg.getData1() &&
+                                          c.compare(nextOff, on) > 0) {
+                                               off = nextOff;
+                                               iOff.remove();
+                                               break;
+                                       }
+                                               
                                }
-                                       
-                       }
-                       track.remove(on);
-                       if (off != null) {
-                               track.add(new MooNote(on, off));
-                       } else {
-                               track.add(new MooNote(on, new MidiEvent((ShortMessage)on.getMessage().clone(), on.getTick() + 48)));
+                               track.remove(on);
+                               MooNote mn;
+                               if (off != null) {
+                                       mn = new MooNote(on, off);
+                               } else {
+                                       mn = new MooNote(on, new MidiEvent((ShortMessage)on.getMessage().clone(), on.getTick() + 48));
+                               }
+                               track.add(mn);
+                               mooNotes.add(mn);
+                               iOn.remove();
                        }
-                       iOn.remove();
                }
+               return mooNotes;
        }
 
        /** 
@@ -612,6 +622,20 @@ public class Moosique {
                return true;
        }
 
+       /** 
+        * Loads the user preferences.
+        */
+       public static void loadPreferences() {
+               
+       }
+
+       /** 
+        * Saves the user preferences.
+        */
+       public static void savePreferences() {
+               
+       }
+
        /** 
         * Prompts the user .
         */
@@ -661,6 +685,7 @@ public class Moosique {
                if (gui != null) {
                        if (promptOnUnsavedChanges()) return;
                }
+               savePreferences();
                if (sequencer.isOpen()) sequencer.close();
                if (synthesizer.isOpen()) synthesizer.close();
                System.exit(0);