Fixed the popup loader.
Fixed the save function.
// 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;
}
// Sends the NoteOff event.
Moosique.getActiveChannel().noteOff(noteNumber);
isOn[noteNumber] = false;
- System.out.println("NoteOFF");
} catch (ArrayIndexOutOfBoundsException x) {
return;
}
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") {
}
}
+ 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) {
private String notePitch;
private String noteVelocity;
private JPopupMenu popup;
- private JMenuItem popupRemove, popupProp;
+ private JMenuItem popupRemove, popupProp, popupTransposeOctUp, popupTransposeOctDown;
/**
* Creates a new note element.
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);
}
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()) {
note.setPitch(note.getPitch() - 1);
}
calculateString();
+ repaint();
} else if (veloRect.contains(e.getPoint())) {
if (SwingUtilities.isRightMouseButton(e)) {
note.setVelocity(note.getVelocity() + 1);
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());
}
}
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);
}
-
}
* 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));
}
* The adapter used to listen on mouse actions
*/
class MAdapter extends MouseAdapter {
+
/**
* Adds a standard note if doubleclicked.
*/
}
}
+ 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());
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;
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];}
setActiveChannel(0);
} catch (MidiUnavailableException e) {
System.out.println("Failed, quitting.");
-// System.exit(1);
}
System.out.println("Done");
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");
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.
// 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());
* 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;
+ }
}
/**
\f
-Diverse
-
x Spara konfiguration?
Arbetskatalog
Fem senast öppnade filerna
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