From e7289eb46e09ee6ed3bc5bb4a814f59902d885cb Mon Sep 17 00:00:00 2001 From: Einar Pehrson Date: Thu, 22 May 2003 12:39:32 +0000 Subject: [PATCH] no message --- MooMenu.java | 3 --- MooNote.java | 4 +++- MooToolbar.java | 40 ++++++++++++++++++++----------------- MooTrackTitle.java | 4 ++-- MooTrackView.java | 35 ++++++++++++++++++++++---------- Moosique.java | 50 +++++++++++++++++++++++++--------------------- To Do.txt | 1 + 7 files changed, 79 insertions(+), 58 deletions(-) diff --git a/MooMenu.java b/MooMenu.java index d30d181..7c6be00 100644 --- a/MooMenu.java +++ b/MooMenu.java @@ -221,13 +221,10 @@ public class MooMenu extends JMenuBar implements ActionListener { } else if (command == "Set tempo...") { MooDialog newDialog = new MooDialog(MooDialog.SET_TEMPO); - } else if (command == "Scale velocity...") { MooDialog newDialog = new MooDialog(MooDialog.SCALE_VELOCITY); - } else if (command == "Transpose...") { MooDialog newDialog = new MooDialog(MooDialog.TRANSPOSE); - } else if (command == "User manual") { MooDialog manual = new MooDialog(MooDialog.MANUAL); } else if (command == "About") { diff --git a/MooNote.java b/MooNote.java index 57cf86c..34b0f2f 100644 --- a/MooNote.java +++ b/MooNote.java @@ -175,6 +175,8 @@ public class MooNote extends MidiEvent implements Cloneable, Comparable { * @return a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object */ public int compareTo(Object o) { - return (int)(getTick() - ((MidiEvent)o).getTick()); + int diff = (int)(getTick() - ((MidiEvent)o).getTick()); + if (diff != 0) return diff; + return (noteOnMsg.getData1() - ((ShortMessage)((MidiEvent)o).getMessage()).getData1()); } } diff --git a/MooToolbar.java b/MooToolbar.java index 1ea47ab..5be8fdb 100644 --- a/MooToolbar.java +++ b/MooToolbar.java @@ -93,12 +93,11 @@ public class MooToolbar extends JToolBar { * Resets the progress indicator. */ public void resetProgInd() { - measuresValue.setText("1"); - beatsValue.setText("1"); - ticksValue.setText("1"); - playpause.setIcon(playIcon); - playpause.setToolTipText("Play"); - ticksPerBeat = Moosique.getSequence().getResolution(); + measuresValue.setText("1"); + beatsValue.setText("1"); + ticksValue.setText("1"); + updatePlayButton("Play", playIcon); + ticksPerBeat = Moosique.getSequence().getResolution(); } /** @@ -131,32 +130,37 @@ public class MooToolbar extends JToolBar { return label; } + /** + * Updates the play button with the given command and icon. + */ + private void updatePlayButton(String command, Icon icon) { + playpause.setIcon(icon); + playpause.setActionCommand(command); + playpause.setToolTipText(command); + } + class MAdapter extends MouseAdapter { public void mouseClicked(MouseEvent e) { if (e.getSource() instanceof JButton) { String command = ((JButton)e.getSource()).getActionCommand(); if (command == "Play") { - playpause.setIcon(pauseIcon); - playpause.setActionCommand("Pause"); - playpause.setToolTipText("Pause"); + updatePlayButton("Pause", pauseIcon); Moosique.play(); } else if (command == "Pause") { - playpause.setIcon(playIcon); - playpause.setActionCommand("Resume"); - playpause.setToolTipText("Resume"); + updatePlayButton("Resume", playIcon); Moosique.pause(); } else if (command == "Resume") { - playpause.setIcon(pauseIcon); - playpause.setActionCommand("Pause"); - playpause.setToolTipText("Pause"); + updatePlayButton("Pause", pauseIcon); Moosique.resume(); } else if (command == "Rewind") { + System.out.println("Rewound!"); // Different implementation, perhaps? + updatePlayButton("Play", playIcon); Moosique.setEditPosition(0); Moosique.stop(); } else if (command == "Fast forward") { - } else if (command == "Stop") { + updatePlayButton("Play", playIcon); Moosique.stop(); } } else if (e.getSource() instanceof JLabel) { @@ -185,7 +189,7 @@ public class MooToolbar extends JToolBar { } } - public void mousePressed(MouseEvent e) { +/* public void mousePressed(MouseEvent e) { if (e.getSource() instanceof JButton) { if (((JButton)e.getSource()).getToolTipText() == "Rewind") { Moosique.rewind(beatsPerMeasure * ticksPerBeat); @@ -196,5 +200,5 @@ public class MooToolbar extends JToolBar { } public void mouseReleased(MouseEvent e) {} - } +*/ } } diff --git a/MooTrackTitle.java b/MooTrackTitle.java index 8bec94b..4079e45 100644 --- a/MooTrackTitle.java +++ b/MooTrackTitle.java @@ -194,8 +194,8 @@ public class MooTrackTitle extends JPanel { mtv.disableKeyboardRecording(); sequencer.stopRecording(); sequencer.recordDisable(track); - Moosique.convertTrack(track, quantize); - mtv.placeNoteElements(); + java.util.List newNotes = Moosique.convertTrack(track, quantize); + mtv.placeNewNotes(newNotes); } } } diff --git a/MooTrackView.java b/MooTrackView.java index 2f96085..126ee63 100644 --- a/MooTrackView.java +++ b/MooTrackView.java @@ -46,6 +46,8 @@ public class MooTrackView extends JPanel { this.track = track; this.title = title; insets = getInsets(); + coords = new ArrayList(track.size() / 2); + selection = new TreeSet(); // Configures panel setBackground(Color.white); @@ -53,7 +55,23 @@ public class MooTrackView extends JPanel { setLayout(null); setPreferredSize(new Dimension(VIEW_WIDTH, 140 * NOTE_HEIGHT)); - placeNoteElements(); + // Creates temporary variables + MidiEvent note; + MooNoteElement elem; + extraHeight = Toolkit.getDefaultToolkit().getScreenSize().height - 150; + + // Places note elements + for (int i = 0; i < track.size(); i++) { + note = track.get(i); + if (note instanceof MooNote) { + // Adds the note element to the note area and moves it to the appropriate place. + MooNote mn = (MooNote)note; + elem = new MooNoteElement(this, mn); + add(elem); + layoutElement(elem, false); + } + } + setPreferredSize(new Dimension(VIEW_WIDTH, viewLength + extraHeight)); // Creates panel pop-up menu. popup = new JPopupMenu(); @@ -77,22 +95,17 @@ public class MooTrackView extends JPanel { } /** - * Creates note elements for all MooNotes in the track, and places them in the appropriate place. + * Creates note elements for all MooNotes in the given list, and places them in the appropriate place. */ - public void placeNoteElements() { - // Empties the container - removeAll(); - coords = new ArrayList(track.size() / 2); - selection = new TreeSet(); - + public void placeNewNotes(java.util.List notes) { // Creates temporary variables MidiEvent note; MooNoteElement elem; extraHeight = Toolkit.getDefaultToolkit().getScreenSize().height - 150; // Places note elements - for (int i = 0; i < track.size(); i++) { - note = track.get(i); + for (int i = 0; i < notes.size(); i++) { + note = (MidiEvent)notes.get(i); if (note instanceof MooNote) { // Adds the note element to the note area and moves it to the appropriate place. MooNote mn = (MooNote)note; @@ -100,8 +113,8 @@ public class MooTrackView extends JPanel { add(elem); layoutElement(elem, false); } - setPreferredSize(new Dimension(VIEW_WIDTH, viewLength + extraHeight)); } + setPreferredSize(new Dimension(VIEW_WIDTH, viewLength + extraHeight)); } /** diff --git a/Moosique.java b/Moosique.java index 90ad9a0..8da5285 100644 --- a/Moosique.java +++ b/Moosique.java @@ -46,7 +46,6 @@ public class Moosique { String fileArg = null; for (int i = 0; i < args.length; i++) { if (args[i].equals("-n")) makeGUI = false; - else if (args[i].equals("-m")) initSound = false; else if (fileArg == null) fileArg = args[i]; } @@ -432,29 +431,11 @@ public class Moosique { } } - // Disables input to volatile components // gui.disable(); // Creates the visualisation thread and starts it. - player = new Thread () { - public void run() { - while(sequencer.isRunning()) { - // Updates the GUI with the current tick position. - gui.update(sequencer.getTickPosition()); - - // Puts the thread to sleep for as long as it takes - // the sequencer to reach the next sixteenth. - try { - //sleep((long)((15000 / getTempo()) * (tickDiff / ticksPerSixteenth))); - sleep (10); - } catch (InterruptedException e) { - Moosique.stop(); - } - } - Moosique.stop(); - } - }; + player = new PlayThread(); player.start(); } @@ -713,16 +694,39 @@ public class Moosique { */ public static class MidiEventComparator implements Comparator { public int compare(Object o1, Object o2) { - return (int)(((MidiEvent)o1).getTick() - ((MidiEvent)o2).getTick()); + int diff = (int)(((MidiEvent)o1).getTick() - ((MidiEvent)o2).getTick()); + if (diff != 0 || !(((MidiEvent)o1).getMessage() instanceof ShortMessage) || !(((MidiEvent)o2).getMessage() instanceof ShortMessage)) return diff; + return (((ShortMessage)((MidiEvent)o1).getMessage()).getData1() - ((ShortMessage)((MidiEvent)o2).getMessage()).getData1()); + } + } + + /** + * The thread that updates the GUI during playback. + */ + public static class PlayThread extends Thread { + public void run() { + // Updates the GUI with the current tick position. + gui.update(sequencer.getTickPosition()); + + // Puts the thread to sleep for as long as it takes + // the sequencer to reach the next sixteenth. + try { + //sleep((long)((15000 / getTempo()) * (tickDiff / ticksPerSixteenth))); + sleep (10); + } catch (InterruptedException e) { + Moosique.stop(); + } } } /** * A listener for detecting the end of the sequence. */ - public static void class SongEndListener implements MetaEventListener { + public static class SongEndListener implements MetaEventListener { public void meta(MetaMessage event) { - if (event.getType() == 47 ) sequencer.stop(); // End of stream + if (event.getType() == 47) + // End of sequence + stop(); } } } diff --git a/To Do.txt b/To Do.txt index 137caaf..47f6068 100644 --- a/To Do.txt +++ b/To Do.txt @@ -11,6 +11,7 @@ Rolle Spara konfiguration BUGGAR +x Play-knappen ändras inte till Pause. x Varför ritar den ut de tomma spåren i en ny fil? Rätt, men hur? x Varför hänger sig Play om man ändrar duration på en not? x Kopiera/flytta spår, möjligt? -- 2.39.2