From ffc69c8cc2cc9cdfe3841c77c1e680dee2225c63 Mon Sep 17 00:00:00 2001 From: Einar Pehrson Date: Mon, 12 May 2003 22:33:01 +0000 Subject: [PATCH] no message --- MooMenu.java | 16 ++++++++++++---- MooNote.java | 2 +- MooToolbar.java | 27 ++++++++++++++------------- MooTrackView.java | 2 -- MooView.java | 26 ++++++++++++++++++++++---- Moosique.java | 39 +++++++++++++++++++++++++++------------ To Do.txt | 29 +++++------------------------ 7 files changed, 81 insertions(+), 60 deletions(-) diff --git a/MooMenu.java b/MooMenu.java index 892e765..ab055a9 100644 --- a/MooMenu.java +++ b/MooMenu.java @@ -139,6 +139,7 @@ public class MooMenu extends JMenuBar implements ActionListener { 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 { @@ -146,13 +147,17 @@ public class MooMenu extends JMenuBar implements ActionListener { } 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 { @@ -160,9 +165,12 @@ public class MooMenu extends JMenuBar implements ActionListener { } 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(); diff --git a/MooNote.java b/MooNote.java index 0449e86..3e66dab 100644 --- a/MooNote.java +++ b/MooNote.java @@ -142,6 +142,6 @@ public class MooNote extends MidiEvent { * @return the note off MidiEvent */ public boolean hasNoteOffEvent() { - return noteOffEvent == null; + return noteOffEvent != null; } } \ No newline at end of file diff --git a/MooToolbar.java b/MooToolbar.java index a9ec10b..eb8ca43 100644 --- a/MooToolbar.java +++ b/MooToolbar.java @@ -43,12 +43,9 @@ public class MooToolbar extends JToolBar { 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(); @@ -85,11 +82,8 @@ public class MooToolbar extends JToolBar { 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)); @@ -98,10 +92,8 @@ public class MooToolbar extends JToolBar { 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); @@ -109,6 +101,15 @@ public class MooToolbar extends JToolBar { 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") { diff --git a/MooTrackView.java b/MooTrackView.java index 0b4618d..16d396f 100644 --- a/MooTrackView.java +++ b/MooTrackView.java @@ -67,7 +67,6 @@ public class MooTrackView extends JPanel implements ActionListener { private int trackLength; public NoteArea(Track track) { - System.out.println("Creating track view..."); setLayout(null); trackLength = 140; setPreferredSize(new Dimension(200,140*NOTE_HEIGHT)); @@ -89,7 +88,6 @@ public class MooTrackView extends JPanel implements ActionListener { 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); diff --git a/MooView.java b/MooView.java index b21cf29..3f088bd 100644 --- a/MooView.java +++ b/MooView.java @@ -30,10 +30,28 @@ public class MooView extends JScrollPane { * @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(); } diff --git a/Moosique.java b/Moosique.java index 1c14a0f..bc821ba 100644 --- a/Moosique.java +++ b/Moosique.java @@ -22,7 +22,7 @@ public class Moosique { private static String filename, fileArg; private static long position; - private static boolean makeGUI = true; + private static boolean makeGUI = true, isEdited; /** * Starts the application. @@ -177,21 +177,36 @@ public class Moosique { } /** - * 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 @@ -222,13 +237,8 @@ public class Moosique { } 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; @@ -269,6 +279,11 @@ public class Moosique { } } } + // Sends sequence to GUI and sequencer, then returns + if (gui != null) gui.setSequence(seq); + try { + sequencer.setSequence(seq); + } catch (InvalidMidiDataException e) {} return true; } diff --git a/To Do.txt b/To Do.txt index 8d026dc..f13bcb3 100644 --- a/To Do.txt +++ b/To Do.txt @@ -8,36 +8,17 @@ Bj Rolle: MooTrackView(16) -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?!? -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 MIDI Messages -- 2.39.2