X-Git-Url: https://ruin.nu/git/?p=moosique.git;a=blobdiff_plain;f=MooToolbar.java;h=de416699065e7ba60b327b2c7dddc292f483bfc6;hp=9852c6a4fe72cba4667aeaa5e9c6c2cb38d43357;hb=HEAD;hpb=31f81450a303d52bf37ec8bcbb12e0f3b3b8b833 diff --git a/MooToolbar.java b/MooToolbar.java index 9852c6a..de41669 100644 --- a/MooToolbar.java +++ b/MooToolbar.java @@ -1,7 +1,7 @@ +import javax.sound.midi.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; -import javax.sound.midi.*; /** * The application's toolbar, with the most frequently used commands. @@ -10,7 +10,7 @@ import javax.sound.midi.*; */ public class MooToolbar extends JToolBar { - private JButton rewind, playpause, stop, fastforward; + private JButton rewind, playpause, stop, fastforward, record; private JLabel measure, beats, ticks, measuresValue, beatsValue, ticksValue; private JPanel progIndPanel; private ImageIcon playIcon, pauseIcon; @@ -24,12 +24,14 @@ public class MooToolbar extends JToolBar { */ public MooToolbar() { + setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); // setAlignmentX(LEFT_ALIGNMENT); setFloatable(false); mouseAdapter = new MAdapter(); // Creates playback buttons rewind = createButton("images/rewind.gif", "Rewind"); + record = createButton("images/record.gif", "Record"); playpause = createButton("images/play.gif", "Play"); stop = createButton("images/stop.gif", "Stop"); fastforward = createButton("images/forward.gif", "Fast forward"); @@ -38,6 +40,7 @@ public class MooToolbar extends JToolBar { // Adds playback buttons add(rewind); + add(record); add(playpause); add(stop); add(fastforward); @@ -74,17 +77,16 @@ public class MooToolbar extends JToolBar { * @param tickPosition the tick position to visualize */ public void updateProgInd(long tickPosition) { - ticksPerBeat = Moosique.getSequence().getResolution(); + System.out.print("Updating to " + tickPosition + " = "); if (tickPosition == 0) { resetProgInd(); + System.out.println("1:1:1"); } else { - // Otherwise, calculates the current song position in measures, beats and ticks. - long measures = tickPosition / (beatsPerMeasure * ticksPerBeat); - long beats = (tickPosition - measures * beatsPerMeasure * ticksPerBeat) / ticksPerBeat; - long ticks = tickPosition - measures * beatsPerMeasure * ticksPerBeat - beats * ticksPerBeat; - measuresValue.setText(Long.toString(1 + measures)); - beatsValue.setText(Long.toString(1 + beats)); - ticksValue.setText(Long.toString(1 + ticks)); + int[] position = Moosique.getPositionForTicks(tickPosition); + System.out.println("" + (position[0] + 1) + ":" + (position[1] + 1) + ":" + (position[2] + 1)); + measuresValue.setText(Integer.toString(position[0] + 1)); + beatsValue.setText(Long.toString(position[1] + 1)); + ticksValue.setText(Long.toString(position[2] + 1)); } } @@ -92,25 +94,25 @@ public class MooToolbar extends JToolBar { * 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(); } - /* - * Creates a button with the specified image and tooltip. + /** + * Creates a button with the specified image and action command / tooltip. */ - private JButton createButton(String imagelocation, String tooltip) { + private JButton createButton(String imagelocation, String command) { JButton button = new JButton (new ImageIcon(imagelocation)); - button.setToolTipText(tooltip); + button.setToolTipText(command); + button.setActionCommand(command); button.addMouseListener(mouseAdapter); return button; } - /* + /** * Creates labels with the specified text and font size. */ private JLabel createLabel(String title, int fontSize){ @@ -119,7 +121,7 @@ public class MooToolbar extends JToolBar { return label; } - /* + /** * Formats the given label for the progress indicator. */ private JLabel formatProgInd(JLabel label){ @@ -129,27 +131,42 @@ public class MooToolbar extends JToolBar { 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 toolTip = ((JButton)e.getSource()).getToolTipText(); - if (toolTip == "Play") { - playpause.setIcon(pauseIcon); - playpause.setToolTipText("Pause"); + String command = ((JButton)e.getSource()).getActionCommand(); + if (command == "Play") { + updatePlayButton("Pause", pauseIcon); Moosique.play(); - } else if (toolTip == "Pause") { - playpause.setIcon(playIcon); - playpause.setToolTipText("Resume"); + } else if (command == "Pause") { + updatePlayButton("Resume", playIcon); Moosique.pause(); - } else if (toolTip == "Resume") { - playpause.setIcon(pauseIcon); - playpause.setToolTipText("Pause"); + } else if (command == "Resume") { + updatePlayButton("Pause", pauseIcon); Moosique.resume(); - } else if (toolTip == "Stop") { + } else if (command == "Stop") { + updatePlayButton("Play", playIcon); Moosique.stop(); + } else if (command == "Record") { + MooDialog recordDialog = new MooDialog(MooDialog.RECORD); + } else if (command == "Rewind") { + updatePlayButton("Play", playIcon); + Moosique.setEditPosition(0); + Moosique.stop(); + } else if (command == "Fast forward") { + } } else if (e.getSource() instanceof JLabel) { - long position = Moosique.getPosition(); + long position = Moosique.getEditPosition(); if (e.getSource().equals(measuresValue)) { if (SwingUtilities.isRightMouseButton(e)) { position += beatsPerMeasure * ticksPerBeat; @@ -169,12 +186,12 @@ public class MooToolbar extends JToolBar { position -= 1; } } - Moosique.setPosition(position); + Moosique.setEditPosition(position); Moosique.getGUI().update(position); } } - 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); @@ -185,5 +202,5 @@ public class MooToolbar extends JToolBar { } public void mouseReleased(MouseEvent e) {} - } +*/ } }