]> ruin.nu Git - moosique.git/blobdiff - Moosique.java
Fixed some bugs
[moosique.git] / Moosique.java
index c2006faff375c1c093596acc32fe5c2e5f988e2e..5d6ed9716b569d472141910edfb0e41358c21d74 100644 (file)
@@ -1,6 +1,6 @@
 import javax.sound.midi.*;
-import javax.swing.*;
 import java.io.*;
+import javax.swing.*;
 
 /**
  * Moosique - The MIDI Tracker
@@ -56,16 +56,23 @@ public class Moosique {
                //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 + "...");
-                       if (!load(fileArg)) clearSequence();
-                       System.out.println("Done");
+                       if (!load(fileArg)) {
+                               System.out.println("Failed");
+                               clearSequence();
+                       } else {
+                               System.out.println("Done");
+                       }
                } else {
                        // Otherwise creates a new empty one.
                        clearSequence();
                }
 
-               // If n-flag is set, plays song and then exits. Otherwise builds GUI.
+               // Builds GUI, unless n-flag is set.
                if (makeGUI) {
                        System.out.print("Building GUI...");
+                       try {
+                               UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+                       } catch (Exception e) {}
                        gui = new MooGUI(seq);
                        System.out.println("Done");
                } else {
@@ -78,7 +85,15 @@ public class Moosique {
        }
 
        /** 
-        * Returns a pointer to the current sequence.
+        * Returns the GUI.
+        * @return the GUI
+        */
+       public static MooGUI getGUI() {
+               return gui;
+       }
+
+       /** 
+        * Returns the current sequence.
         * @return the current sequence
         */
        public static Sequence getSequence() {
@@ -86,7 +101,15 @@ public class Moosique {
        }
 
        /** 
-        * Returns a pointer to the MidiChannels of the selected synthesizer.
+        * Returns the current sequencer.
+        * @return the current sequencer
+        */
+       public static Sequencer getSequencer() {
+               return sequencer;
+       }
+
+       /** 
+        * Returns the MidiChannels of the selected synthesizer.
         * @return the available MidiChannels
         */
        public static MidiChannel[] getChannels() {
@@ -94,7 +117,7 @@ public class Moosique {
        }
 
        /** 
-        * Returns a pointer to the currently active MidiChannel.
+        * Returns the currently active MidiChannel.
         * @return the active MidiChannel
         */
        public static MidiChannel getActiveChannel() {
@@ -173,7 +196,7 @@ public class Moosique {
         * @param measures      the number of measures to rewind
         */
        public static void rewind(long ticks) {
-               position -= ticks;
+               setPosition(position - ticks);
        }
 
        /** 
@@ -181,7 +204,7 @@ public class Moosique {
         * @param measures      the number of measures to fast forward
         */
        public static void forward(long ticks) {
-               position += ticks;
+               setPosition(position + ticks);
        }
 
        /** 
@@ -196,7 +219,6 @@ public class Moosique {
                } catch (InvalidMidiDataException e) {
                        return false;
                } catch (IOException e) {
-                       JOptionPane.showMessageDialog(null, "Error 404", "File Not Found", JOptionPane.ERROR_MESSAGE); 
                        return false;
                }
 
@@ -244,16 +266,19 @@ public class Moosique {
 
        /** 
         * Saves the current sequence to the given filename
-        * @param filename      the filename to use
+        * @param file  the filename to use
         */
-       public static void saveAs(String filename) throws IOException {
-               MidiSystem.write(seq, 1, new File(filename));
+       public static void saveAs(String file) {
+               try {
+                       MidiSystem.write(seq, 1, new File(filename));
+               } catch (IOException e) {}
+               filename = file;
        }
 
        /** 
         * Saves the current sequence to the previously given filename.
         */
-       public static void save() throws IOException {
+       public static void save() {
                saveAs(filename);
        }