From fe67e0acf0d44c09dcfbbfd1a02a91f43d2cf60e Mon Sep 17 00:00:00 2001 From: Einar Pehrson Date: Tue, 13 May 2003 15:17:42 +0000 Subject: [PATCH] *** empty log message *** --- MooNoteElement.java | 1 + MooToolbar.java | 9 +++++---- MooTrackView.java | 20 +++++++------------- MooView.java | 16 +++++++++++++--- Moosique.java | 9 +++++---- 5 files changed, 31 insertions(+), 24 deletions(-) diff --git a/MooNoteElement.java b/MooNoteElement.java index 3b08887..c502b4d 100644 --- a/MooNoteElement.java +++ b/MooNoteElement.java @@ -23,6 +23,7 @@ public class MooNoteElement extends JPanel { public MooNoteElement (MooNote mn) { note = mn; columns = mn.getDuration() / 24; + setBorder(BorderFactory.createLineBorder(Color.black)); } /** diff --git a/MooToolbar.java b/MooToolbar.java index 54b90db..92bf345 100644 --- a/MooToolbar.java +++ b/MooToolbar.java @@ -12,6 +12,7 @@ public class MooToolbar extends JToolBar { private JButton rewind, playpause, stop, fastforward; private JLabel measure, beats, ticks, measureValue, beatsValue, ticksValue; + private JPanel progIndPanel; private ImageIcon playIcon, pauseIcon; private MooMouseAdapter mouseAdapter; public static final Color bgColor = new Color(192, 224, 255); @@ -52,7 +53,7 @@ public class MooToolbar extends JToolBar { spacesouth.setBackground(bgColor); // Creates progress indicator panel and adds components - JPanel progIndPanel = new JPanel(); + progIndPanel = new JPanel(); progIndPanel.setMaximumSize(new Dimension(120,27)); progIndPanel.setLayout(new GridLayout(2,4)); progIndPanel.add(spacenorth); @@ -77,9 +78,9 @@ public class MooToolbar extends JToolBar { long measures = tickPosition / (beatsPerMeasure * ticksPerBeat); long beats = (tickPosition - measures * beatsPerMeasure * ticksPerBeat) / ticksPerBeat; long ticks = tickPosition - measures * beatsPerMeasure * ticksPerBeat - beats * ticksPerBeat; - measureValue.setText(Long.toString(measures)); - beatsValue.setText(Long.toString(beats)); - ticksValue.setText(Long.toString(ticks)); + measureValue.setText(Long.toString(1 + measures)); + beatsValue.setText(Long.toString(1 + beats)); + ticksValue.setText(Long.toString(1 + ticks)); } /* diff --git a/MooTrackView.java b/MooTrackView.java index cba9272..d33f3c1 100644 --- a/MooTrackView.java +++ b/MooTrackView.java @@ -21,14 +21,14 @@ public class MooTrackView extends JPanel implements ActionListener { private JPopupMenu notePopup; private JMenuItem menuItem; protected static int viewLength = 0; - + public static final int NOTE_HEIGHT = 10, NOTE_WIDTH = 40, VIEW_WIDTH = 200; public MooTrackView (Track track) { super(true); this.track = track; //setPreferredSize(new Dimension(200, 9000)); setLayout(new BorderLayout()); - this.setBorder(BorderFactory.createLineBorder(Color.black)); + // setBorder(BorderFactory.createLineBorder(Color.black)); //title = new MooTrackTitle(track); //title.setBorder(BorderFactory.createLineBorder(Color.black)); @@ -68,17 +68,14 @@ public class MooTrackView extends JPanel implements ActionListener { } class NoteArea extends JPanel { - public static final int NOTE_HEIGHT = 10; - public static final int NOTE_WIDTH = 40; - private int trackLength; + public static final int NOTE_HEIGHT = 10, NOTE_WIDTH = 40, VIEW_WIDTH = 200; private ArrayList rects; public NoteArea(Track track) { // Configuring panel super(true); setLayout(null); - trackLength = 140; - setPreferredSize(new Dimension(200, 140 * NOTE_HEIGHT)); + setPreferredSize(new Dimension(VIEW_WIDTH, 140 * NOTE_HEIGHT)); // Creating temporary variables MidiEvent note; @@ -106,11 +103,8 @@ public class MooTrackView extends JPanel implements ActionListener { elem.setBounds(r); rects.add(r); if (viewLength < (y + height)) viewLength = y + height; - - // while(findComponentAt(x, y) instanceof MooNoteElement || - // findComponentAt(x, y + height - 1) instanceof MooNoteElement) x += NOTE_WIDTH; } - setPreferredSize(new Dimension(200, viewLength)); + setPreferredSize(new Dimension(VIEW_WIDTH, viewLength)); } validate(); } @@ -126,8 +120,8 @@ public class MooTrackView extends JPanel implements ActionListener { public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; - for (int c = 0; c < viewLength ; c += NOTE_HEIGHT) { - for (int r = 0; r < (10*NOTE_WIDTH); r += NOTE_WIDTH) { + for (int c = 0; c < viewLength || c < getHeight(); c += NOTE_HEIGHT) { + for (int r = 0; r < (10 * NOTE_WIDTH); r += NOTE_WIDTH) { box = new Rectangle(r, c, NOTE_WIDTH, NOTE_HEIGHT); g2.setColor(Color.gray); g2.draw(box); diff --git a/MooView.java b/MooView.java index 3323540..ca9d68d 100644 --- a/MooView.java +++ b/MooView.java @@ -29,7 +29,6 @@ public class MooView extends JScrollPane { JViewport columnHeader = new JViewport(); columnHeader.setView(titlePanel); setColumnHeaderView(columnHeader); - numberOfTracks = tracks.length; setTracks(tracks); } @@ -38,7 +37,8 @@ public class MooView extends JScrollPane { * @param tracks the tracks for which to add views */ public void setTracks(Track[] tracks) { - if (tracks.length == 1) { + numberOfTracks = tracks.length; + if (numberOfTracks == 1) { // If MIDI file is of type 0, creates a view for the track. trackPanel.add(new MooTrackView(tracks[0])); titlePanel.add(new MooTrackTitle(tracks[0])); @@ -55,7 +55,7 @@ public class MooView extends JScrollPane { // Starts filling the track panel with track views, while updating the progress bar. trackPanel.removeAll(); - trackPanel.setLayout(new GridLayout(1,tracks.length)); + trackPanel.setLayout(new GridLayout(1,numberOfTracks)); for (int i = 1; i < tracks.length; i++) { trackPanel.add(new MooTrackView(tracks[i])); titlePanel.add(new MooTrackTitle(tracks[i])); @@ -63,6 +63,16 @@ public class MooView extends JScrollPane { } progressDialog.dispose(); } +/* JPanel filler = new JPanel(); + int totalViewLength = trackPanel.getComponents().length * MooTrackView.VIEW_WIDTH; + if (totalViewLength < getWidth()) { + System.out.println("Adding filler since width = " + getWidth() + " and tracks = " + totalViewLength); + ((GridLayout)trackPanel.getLayout()).setColumns(numberOfTracks + 1); + filler.setPreferredSize(new Dimension(getWidth() - totalViewLength, 140 * MooTrackView.NOTE_HEIGHT)); + trackPanel.add(filler); + setPreferredSize(new Dimension(getWidth(), getHeight())); + } +*/ trackPanel.validate(); setViewportView(trackPanel); } diff --git a/Moosique.java b/Moosique.java index b4c4259..531e4f5 100644 --- a/Moosique.java +++ b/Moosique.java @@ -24,6 +24,7 @@ public class Moosique { private static long position; private static boolean makeGUI = true, isEdited; private static Thread player; + public static final int RESOLUTION = 96, DEFAULT_TRACKS = 4; /** * Starts the application. @@ -140,7 +141,7 @@ public class Moosique { public static void clearSequence() { // Creates a new sequence and sends it to the sequencer. try { - seq = new Sequence(Sequence.PPQ, 96, 3); + seq = new Sequence(Sequence.PPQ, RESOLUTION, DEFAULT_TRACKS); sequencer.setSequence(seq); } catch (InvalidMidiDataException e) {} // Sends sequence to GUI. @@ -153,7 +154,6 @@ public class Moosique { public static void play() { sequencer.setTickPosition(position); resume(); - } /** @@ -176,7 +176,8 @@ public class Moosique { // Creates the visualization thread and starts it. player = new Thread () { public void run() { - gui.update(sequencer.getTickPosition()); + while(sequencer.isRunning()) gui.update(sequencer.getTickPosition()); + Moosique.stop(); } }; player.start(); @@ -188,7 +189,7 @@ public class Moosique { public static void stop() { sequencer.stop(); sequencer.setTickPosition(position); - player.destroy(); + player.interrupt(); gui.update((long)0); } -- 2.39.2