]> ruin.nu Git - moosique.git/commitdiff
Added some popup-menu items.
authorEinar Pehrson <einarp@itstud.chalmers.se>
Sat, 17 May 2003 00:10:51 +0000 (00:10 +0000)
committerEinar Pehrson <einarp@itstud.chalmers.se>
Sat, 17 May 2003 00:10:51 +0000 (00:10 +0000)
Fixed the popup loader.
Fixed the save function.

MooKeyboard.java
MooMenu.java
MooNoteElement.java
MooTrackView.java
Moosique.java
To Do.txt
midi/test3.mid

index 2a2bd9ead52f0797785de9e127154f2d6a965a11..35b2496ff0fa707a8b74bb0bdee285ab7d041cf2 100644 (file)
@@ -23,7 +23,6 @@ public class MooKeyboard extends KeyAdapter {
                        // If note is not already on and the key is mapped to a note, sends the NoteOn event.
                        if (!isOn[noteNumber] && noteNumber > 0) Moosique.getActiveChannel().noteOn(noteNumber, 127);
                        isOn[noteNumber] = true;
-                       System.out.println("NoteON");
                } catch (ArrayIndexOutOfBoundsException x) {
                        return;
                }
@@ -39,7 +38,6 @@ public class MooKeyboard extends KeyAdapter {
                        // Sends the NoteOff event.
                        Moosique.getActiveChannel().noteOff(noteNumber);
                        isOn[noteNumber] = false;
-                       System.out.println("NoteOFF");
                } catch (ArrayIndexOutOfBoundsException x) {
                        return;
                }
index d25ec0caa9a2cfd0a1fef8f0c74d65bdf44f19d8..053030b94e8746fd898f957df2620eee40f3711f 100644 (file)
@@ -161,23 +161,9 @@ public class MooMenu extends JMenuBar implements ActionListener {
                                Moosique.load(chooser.getSelectedFile().getAbsolutePath());
                        }
                } else if (command == "Save") {
-                       Moosique.save();
+                       if (!Moosique.save()) showSaveAsDialog();
                } else if (command == "Save as...") {
-                       // Shows a file chooser. If shown previously, starts in the current directory.
-                       if (directory != null) {
-                               chooser = new JFileChooser(directory);
-                       } else {
-                               chooser = new JFileChooser();
-                       }
-                       chooser.addChoosableFileFilter(new MidiFileFilter());
-                       int returnVal = chooser.showSaveDialog(this);
-
-                       // Stores the current directory and loads the selected file.
-                       File file = chooser.getSelectedFile();
-                       if(returnVal == JFileChooser.APPROVE_OPTION && isMidiFile(file)) {
-                               directory = file.getParentFile();
-                               Moosique.saveAs(file.getAbsolutePath());
-                       }
+                       showSaveAsDialog();
                } else if (command == "Exit") {
                        Moosique.quit();
                } else if (command == "Copy") {
@@ -240,6 +226,24 @@ public class MooMenu extends JMenuBar implements ActionListener {
                }
        }
 
+       private void showSaveAsDialog() {
+                       // Shows a file chooser. If shown previously, starts in the current directory.
+                       if (directory != null) {
+                               chooser = new JFileChooser(directory);
+                       } else {
+                               chooser = new JFileChooser();
+                       }
+                       chooser.addChoosableFileFilter(new MidiFileFilter());
+                       int returnVal = chooser.showSaveDialog(this);
+
+                       // Stores the current directory and loads the selected file.
+                       File file = chooser.getSelectedFile();
+                       if(returnVal == JFileChooser.APPROVE_OPTION && isMidiFile(file)) {
+                               directory = file.getParentFile();
+                               Moosique.saveAs(file.getAbsolutePath());
+                       }
+       }
+
        class MidiFileFilter extends javax.swing.filechooser.FileFilter {
                public boolean accept(File f) {
                        if(f != null) {
index 8d8778d369e57a18b778f39734a9158644b50385..3a068cd67908b13456b1ae0bf014401ff7f0cd7c 100644 (file)
@@ -19,7 +19,7 @@ public class MooNoteElement extends JPanel {
        private String notePitch;
        private String noteVelocity;
        private JPopupMenu popup;
-       private JMenuItem popupRemove, popupProp;
+       private JMenuItem popupRemove, popupProp, popupTransposeOctUp, popupTransposeOctDown;
 
        /** 
         * Creates a new note element.
@@ -44,10 +44,15 @@ public class MooNoteElement extends JPanel {
                popupProp = new JMenuItem("Preferences...");
                popupProp.addActionListener(pList);
                popup.add(popupProp);
-
                popupRemove = new JMenuItem("Remove");
                popupRemove.addActionListener(pList);
                popup.add(popupRemove);
+               popupTransposeOctUp = new JMenuItem("Transpose one octave up");
+               popupTransposeOctUp.addActionListener(pList);
+               popup.add(popupTransposeOctUp);
+               popupTransposeOctDown = new JMenuItem("Transpose one octave down");
+               popupTransposeOctDown.addActionListener(pList);
+               popup.add(popupTransposeOctDown);
 
        }
 
@@ -131,15 +136,14 @@ public class MooNoteElement extends JPanel {
        class MAdapter extends MouseAdapter {
        
                public void mouseClicked(MouseEvent e) {
-                       
+                       // Play the note
                }
 
                /**
                 * Checks if the mouse is pressed.
-                * Pops up the menu if right mousebutton is used.
                 * Increases the pitch or velocity if the right mousebutton is pressed while holding ctrl down.
                 * Decreases the pitch or velocity if the left mousebutton is pressed while holding ctrl down.
-                * @param e The events recieved.
+                * @param e the event recieved.
                 */
                public void mousePressed(MouseEvent e) {
                        if (e.isControlDown()) {
@@ -150,6 +154,7 @@ public class MooNoteElement extends JPanel {
                                                note.setPitch(note.getPitch() - 1);
                                        }
                                        calculateString();
+                                       repaint();
                                } else if (veloRect.contains(e.getPoint())) {
                                        if (SwingUtilities.isRightMouseButton(e)) {
                                                note.setVelocity(note.getVelocity() + 1);
@@ -157,11 +162,20 @@ public class MooNoteElement extends JPanel {
                                                note.setVelocity(note.getVelocity() - 1);
                                        }
                                        calculateString();
+                                       repaint();
                                }
-                               e.getComponent().repaint();
-                       } else if (e.isPopupTrigger()) {
-                               popup.show(e.getComponent(), e.getX(), e.getY());
-                       }
+                       } else maybeShowPopup(e);
+               }
+
+               public void mouseReleased(MouseEvent e) {
+                       maybeShowPopup(e);
+               }
+
+               /**
+                * Shows the menu if an OS-specific popup-trigger was activated.
+                */
+               private void maybeShowPopup(MouseEvent e) {
+                       if (e.isPopupTrigger() && !e.isControlDown()) popup.show(e.getComponent(), e.getX(), e.getY());
                }
        }
 
@@ -171,19 +185,29 @@ public class MooNoteElement extends JPanel {
        class PopupListener implements ActionListener {
                public void actionPerformed(ActionEvent e) {
                        Object source = e.getSource();
-                       if  (source == popupProp) {
+                       if (source == popupProp) {
                                new MooDialog(note);
-                       } else if  (source == popupRemove) {
+                       } else if (source == popupRemove) {
                                remove();
+                       } else if (source == popupTransposeOctUp) {
+                               note.setPitch(note.getPitch() + 12);
+                               update();
+                       } else if (source == popupTransposeOctDown) {
+                               note.setPitch(note.getPitch() - 12);
+                               update();
                        }
                }
+
+               private void update() {
+                       calculateString();
+                       repaint();
+               }
        }
 
        /**
-        * Asks the MooTrackView that it's painted on to remove this element and the note.
+        * Asks the MooTrackView that the note element is painted on to remove this element and the note.
         */
        protected void remove(){
                mtv.removeNote(this);
        }
-
 }
index 4d58e1d2ddac24fd1e83141c7f153538c807af8b..bac8cbc59fa4d8c75cd09c0078ac5be21a22a1ac 100644 (file)
@@ -172,7 +172,8 @@ public class MooTrackView extends JPanel {
         * Adds a standard note to this track.
         */
        private void addStandardNote() {
-               long timestamp = (long)(ticksPerSixteenth * (popupY - insets.top) / NOTE_HEIGHT);
+               int row =  (popupY - insets.top) / NOTE_HEIGHT;
+               long timestamp = (long)(ticksPerSixteenth * row);
                addNote(new MooNote(title.getChannel(), 60, 100, timestamp, Moosique.getSequence().getResolution() / 4));
        }
 
@@ -196,6 +197,7 @@ public class MooTrackView extends JPanel {
         * The adapter used to listen on mouse actions
         */
        class MAdapter extends MouseAdapter {
+
                /**
                 * Adds a standard note if doubleclicked.
                 */
@@ -206,10 +208,18 @@ public class MooTrackView extends JPanel {
                        }
                }
        
+               public void mousePressed(MouseEvent e) {
+                       maybeShowPopup(e);
+               }
+
+               public void mouseReleased(MouseEvent e) {
+                       maybeShowPopup(e);
+               }
+
                /**
-                * Shows the menu if on standard poptriggers.
+                * Shows the menu if an OS-specific popup-trigger was activated.
                 */
-               public void mousePressed(MouseEvent e) {
+               private void maybeShowPopup(MouseEvent e) {
                        if (e.isPopupTrigger()) {
                                popupY = e.getY();
                                popup.show(e.getComponent(), e.getX(), e.getY());
index 9b4349c9acbb9db040a1f8bd0d1b1c6d75225853..e03cca0749a08b9396c7e760c722bb62f698c36a 100644 (file)
@@ -22,7 +22,7 @@ public class Moosique {
        private static MidiEvent[] timeSignatures, tempoChanges;
        private static ArrayList emptyTracks;
 
-       private static String filename, fileArg;
+       private static String filename;
        private static long editPosition;
        private static boolean makeGUI = true, isEdited = false, drawEmptyTracks = false;
        private static Thread player;
@@ -35,6 +35,7 @@ public class Moosique {
                System.out.println("\nMoosique version 1.0\n");
 
                // Parses command-line arguments.
+               String fileArg = null;
                for (int i = 0; i < args.length; i++) {
                        if (args[i].equals("-n")) {makeGUI = false;}
                        else if (fileArg == null) {fileArg = args[i];}
@@ -54,7 +55,6 @@ public class Moosique {
                        setActiveChannel(0);
                } catch (MidiUnavailableException e) {
                        System.out.println("Failed, quitting.");
-//                     System.exit(1);
                }
                System.out.println("Done");
 
@@ -62,7 +62,7 @@ public class Moosique {
                if (fileArg != null) {
                        System.out.print("Loading MIDI sequence from " + fileArg + "...");
                        if (!load(fileArg)) {
-                               System.out.println("Failed");
+                               System.out.println("Failed, creating new sequence");
                                clearSequence();
                        } else {
                                System.out.println("Done");
@@ -153,6 +153,7 @@ public class Moosique {
                try {
                        seq = new Sequence(Sequence.PPQ, DEFAULT_RESOLUTION, DEFAULT_TRACKS);
                        sequencer.setSequence(seq);
+                       filename = null;
                        emptyTracks = new ArrayList();
                } catch (InvalidMidiDataException e) {}
                // Sends sequence to GUI.
@@ -193,15 +194,7 @@ public class Moosique {
                // Creates the visualisation thread and starts it.
                player = new Thread () {
                        public void run() {
-                               long ticksPerSixteenth = seq.getResolution()/4;
-                               System.out.println("Ticks/16: " + ticksPerSixteenth);
-                               long position = sequencer.getTickPosition();
                                while(sequencer.isRunning()) {
-                                       long pos = sequencer.getTickPosition();
-                                       long tickDiff = pos - position;
-                                       System.out.print(" ... " + tickDiff);
-                                       position = pos;
-
                                        // Updates the GUI with the current tick position.
                                        gui.update(sequencer.getTickPosition());
 
@@ -435,19 +428,27 @@ public class Moosique {
         * Saves the current sequence to the given filename
         * @param file  the filename to use
         */
-       public static void saveAs(String file) {
+       public static boolean saveAs(String file) {
                try {
-                       MidiSystem.write(seq, 1, new File(filename));
-               } catch (IOException e) {}
-               filename = file;
-               gui.setStatus("Saved " + file);
+                       MidiSystem.write(seq, 1, new File(file));
+                       filename = file;
+                       gui.setStatus("Saved " + file);
+                       return true;
+               } catch (IOException e) {
+                       gui.setStatus("Failed in saving " + file);
+                       return false;
+               }
        }
 
        /** 
         * Saves the current sequence to the previously given filename.
         */
-       public static void save() {
-               saveAs(filename);
+       public static boolean save() {
+               if (filename == null) return false;
+               else {
+                       saveAs(filename);
+                       return true;
+               }
        }
 
        /** 
index 93b5d1365159829369080550d64db7c7997adf75..2fb00c41a7d65175dfad50007e24f5bc91b05868 100644 (file)
--- a/To Do.txt
+++ b/To Do.txt
@@ -1,7 +1,5 @@
 
 \f
-Diverse
-
 x Spara konfiguration?
        Arbetskatalog
        Fem senast öppnade filerna
@@ -24,11 +22,8 @@ x G
 x Gör en ruta för taktarten i MooViews övre vänstra hörn.
 x Implementera klart menyn, med alla dialoger.
 x Lägg till en tom panel i MooGUI för att fylla ut skärmen. Använd setBounds()
-
+x Fixa markera, kopiera, klipp ut och klistra in.
 x Highlighta noter som spelas? (Enligt kravspec.)
-
-\f
-MooNoteProp
-       * Textfält som gör att man bara kan skriva in siffror?
+x Textfält som gör att man bara kan skriva in siffror? (MooNoteProp)
 
 \f
\ No newline at end of file
index 5893970efde08226b61448a245ee923430912e5f..2e2aa18bc16b9621ac39cd273e3b5baa93ade7ec 100644 (file)
Binary files a/midi/test3.mid and b/midi/test3.mid differ