} 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") {
* @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());
}
}
* 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();
}
/**
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) {
}
}
- 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);
}
public void mouseReleased(MouseEvent e) {}
- }
+*/ }
}
mtv.disableKeyboardRecording();
sequencer.stopRecording();
sequencer.recordDisable(track);
- Moosique.convertTrack(track, quantize);
- mtv.placeNoteElements();
+ java.util.List newNotes = Moosique.convertTrack(track, quantize);
+ mtv.placeNewNotes(newNotes);
}
}
}
this.track = track;
this.title = title;
insets = getInsets();
+ coords = new ArrayList(track.size() / 2);
+ selection = new TreeSet();
// Configures panel
setBackground(Color.white);
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();
}
/**
- * 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;
add(elem);
layoutElement(elem, false);
}
- setPreferredSize(new Dimension(VIEW_WIDTH, viewLength + extraHeight));
}
+ setPreferredSize(new Dimension(VIEW_WIDTH, viewLength + extraHeight));
}
/**
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];
}
}
}
-
// 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();
}
*/
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();
}
}
}
\f
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?