if(command == "New") {
Moosique.clearSequence();
} else if (command == "Open...") {
+ // Shows a file chooser. If shown previously, starts in the current directory.
if (directory != null) {
chooser = new JFileChooser(directory);
} else {
}
chooser.addChoosableFileFilter(new MidiFileFilter());
int returnVal = chooser.showOpenDialog(this);
- if(returnVal == JFileChooser.APPROVE_OPTION && isMidiFile(chooser.getSelectedFile())) {
+
+ // Stores the current directory and loads the selected file.
+ File file = chooser.getSelectedFile();
+ if(returnVal == JFileChooser.APPROVE_OPTION && isMidiFile(file)) {
directory = chooser.getSelectedFile().getParentFile();
Moosique.load(chooser.getSelectedFile().getAbsolutePath());
}
} else if (command == "Save") {
Moosique.save();
} 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.addChoosableFileFilter(new MidiFileFilter());
int returnVal = chooser.showSaveDialog(this);
- if(returnVal == JFileChooser.APPROVE_OPTION && isMidiFile(chooser.getSelectedFile())) {
- directory = chooser.getSelectedFile().getParentFile();
- Moosique.saveAs(chooser.getSelectedFile().getAbsolutePath());
+
+ // 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());
}
} else if (command == "Exit") {
Moosique.quit();
* @return the note off MidiEvent
*/
public boolean hasNoteOffEvent() {
- return noteOffEvent == null;
+ return noteOffEvent != null;
}
}
\ No newline at end of file
measure = createLabel("Msr", 10);
beats = createLabel("Beat", 10);
ticks = createLabel("Tick", 10);
- measureValue = createLabel("1", 16);
- measureValue.setBorder(BorderFactory.createLineBorder(Color.black));
- beatsValue = createLabel("1", 16);
- beatsValue.setBorder(BorderFactory.createLineBorder(Color.black));
- ticksValue = createLabel("1", 16);
- ticksValue.setBorder(BorderFactory.createLineBorder(Color.black));
+ measureValue = formatProgInd(createLabel("1", 16));
+ beatsValue = formatProgInd(createLabel("1", 16));
+ ticksValue = formatProgInd(createLabel("1", 16));
JPanel spacenorth = new JPanel();
spacenorth.setBackground(bgColor);
JPanel spacesouth = new JPanel();
ticksValue.setText(Long.toString(ticks));
}
- /**
+ /*
* Creates a button with the specified image and tooltip.
- * @param imagelocation the imagelacation of the the image displayed in the button
- * @param tooltip the tooltip associated with this button
- * @return button the button to be attached to the toolbar
*/
private JButton createButton(String imagelocation, String tooltip) {
JButton button = new JButton (new ImageIcon(imagelocation));
return button;
}
- /**
+ /*
* Creates labels with the specified text and font size.
- * @param title the titel displayed on the label
- * @param fontsize the fontzise of the text displayed on the label
*/
private JLabel createLabel(String title, int fontSize){
JLabel label = new JLabel(title,JLabel.CENTER);
return label;
}
+ /*
+ * Formats the given label for the progress indicator.
+ */
+ private JLabel formatProgInd(JLabel label){
+ label.setBorder(BorderFactory.createLineBorder(Color.black));
+ label.setBackground(Color.white);
+ return label;
+ }
+
class MooMouseAdapter extends MouseAdapter {
public void mouseClicked(MouseEvent e) {
if (((JButton)e.getSource()).getToolTipText() == "Play") {
private int trackLength;
public NoteArea(Track track) {
- System.out.println("Creating track view...");
setLayout(null);
trackLength = 140;
setPreferredSize(new Dimension(200,140*NOTE_HEIGHT));
y = insets.top + (int)(mn.getTick() / 24) * NOTE_HEIGHT;
height = NOTE_HEIGHT;
// height = (mn.getDuration() / 24) * NOTE_HEIGHT;
- // System.out.println("Comp at: " + x + ", " + y + " is: " + findComponentAt(x + 10, y + 10));
while(findComponentAt(x, y) instanceof MooNoteElement ||
findComponentAt(x, y + height - 1) instanceof MooNoteElement) x += NOTE_WIDTH;
elem.setBounds(x, y, NOTE_WIDTH, height);
* @param tracks the tracks for which to add views
*/
public void setTracks(Track[] tracks) {
- trackPanel.removeAll();
- trackPanel.setLayout(new GridLayout(1,tracks.length));
- for (int i = 0; i < tracks.length; i++) {
- trackPanel.add(new MooTrackView(tracks[i]));
+ if (tracks.length == 1) {
+ // If MIDI file is of type 0, creates a view for the track.
+ trackPanel.add(new MooTrackView(tracks[0]));
+ } else {
+ // Creates dialog for progress bar.
+ JDialog progressDialog = new JDialog(Moosique.getGUI(), "Visualizing MIDI file...", false);
+ JProgressBar progressBar = new JProgressBar(0, tracks.length);
+ progressBar.setValue(0);
+ progressBar.setStringPainted(true);
+ progressDialog.getContentPane().add(progressBar);
+ progressDialog.pack();
+ progressDialog.setLocation((Toolkit.getDefaultToolkit().getScreenSize().width - progressDialog.getWidth()) / 2, (Toolkit.getDefaultToolkit().getScreenSize().height - progressDialog.getHeight()) / 2);
+ progressDialog.setVisible(true);
+
+ // Starts filling the track panel with track views, while updating the progress bar.
+ trackPanel.removeAll();
+ trackPanel.setLayout(new GridLayout(1,tracks.length));
+ for (int i = 1; i < tracks.length; i++) {
+ trackPanel.add(new MooTrackView(tracks[i]));
+ progressBar.setValue(i+1);
+ }
+ progressDialog.dispose();
}
trackPanel.validate();
}
private static String filename, fileArg;
private static long position;
- private static boolean makeGUI = true;
+ private static boolean makeGUI = true, isEdited;
/**
* Starts the application.
}
/**
- * Rewinds the current sequence the given number of measures.
- * @param measures the number of measures to rewind
+ * Returns the current tick position of the sequencer.
+ * @return the tick position
*/
public static long getPosition() {
return position;
}
/**
- * Rewinds the current sequence the given number of measures.
- * @param measures the number of measures to rewind
+ * Sets the current tick position of the sequencer.
+ * @param ticks the tick position
*/
public static void setPosition(long ticks) {
position = ticks;
}
+ /**
+ * Returns true if the current sequence has been edited.
+ * @return the tick position
+ */
+ public static boolean isEdited() {
+ return isEdited;
+ }
+
+ /**
+ * Sets the current sequence as edited, which implies prompts when loading a new sequence.
+ */
+ public static void setEdited() {
+ isEdited = true;
+ }
+
/**
* Rewinds the current sequence the given number of measures.
* @param measures the number of measures to rewind
} catch (IOException e) {
return false;
}
-
- // Sends sequence to GUI and sequencer
- if (gui != null) gui.setSequence(seq);
- try {
- sequencer.setSequence(seq);
- } catch (InvalidMidiDataException e) {}
-
+ isEdited = false;
+
// Searches the sequence for NoteOn events
Track[] tracks = seq.getTracks();
MidiEvent noteOn, noteOff = null, nextEvent;
}
}
}
+ // Sends sequence to GUI and sequencer, then returns
+ if (gui != null) gui.setSequence(seq);
+ try {
+ sequencer.setSequence(seq);
+ } catch (InvalidMidiDataException e) {}
return true;
}
Rolle: MooTrackView(16)
\f
-VIKTIGT! Implementera playfunktionens beteende. När play aktiveras ska följande loop köras:
-
- while(sequencer.isRunning()) {
- Moosique.getGUI().update();
- }
-
- i View:
-
- public void update() {
- // Calls on each track view to update itself.
- for (int i = 0; i < trackViews.length; i++) {
- trackViews[i].update();
- }
- }
-
- i GUI:
- public void update(){
- view.update();
- // Calls on the toolbar to update the progress indicator.
- toolbar.updateProgInd();
- }
-
+VIKTIGT! Implementera playfunktionens beteende.
När låten är slut återställes play-knappen.
-
Göra detta som en tråd?!?
\f
-x Fixa en progress indicator till filladdningen om den tänker ta så lång tid.
x Scrollningen?!? Horisontell behövs på både MooView och MooTrackView, men vertikal bara på MooView. Hur göra?
x Får Moosique vara statisk? Fult?
+x Spara konfiguration?
+ Arbetskatalog
+ Fem senast öppnade filerna
+ Valda MIDI-enheter
\f
MIDI Messages