X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=MooToolbar.java;h=54b90db40f83a871e82fc4b3a666436fa2900ee9;hb=5380690b9fc56b683d15765382669d79c50d3414;hp=a2f55712fac336c7e0df85fbc0ae85e190b9f55d;hpb=da1367e949d97032452cec6117f2aec79fd11c83;p=moosique.git diff --git a/MooToolbar.java b/MooToolbar.java index a2f5571..54b90db 100644 --- a/MooToolbar.java +++ b/MooToolbar.java @@ -11,7 +11,7 @@ import javax.sound.midi.*; public class MooToolbar extends JToolBar { private JButton rewind, playpause, stop, fastforward; - private JLabel measure, beats, ticks, measurevalue, beatsvalue, ticksvalue; + private JLabel measure, beats, ticks, measureValue, beatsValue, ticksValue; private ImageIcon playIcon, pauseIcon; private MooMouseAdapter mouseAdapter; public static final Color bgColor = new Color(192, 224, 255); @@ -21,55 +21,69 @@ public class MooToolbar extends JToolBar { */ public MooToolbar() { + // setAlignmentX(LEFT_ALIGNMENT); setFloatable(false); mouseAdapter = new MooMouseAdapter(); // Creates playback buttons rewind = createButton("images/rewind.gif", "Rewind"); - add(rewind); playpause = createButton("images/play.gif", "Play"); - add(playpause); + stop = createButton("images/stop.gif", "Stop"); + fastforward = createButton("images/forward.gif", "Fast forward"); playIcon = new ImageIcon("images/play.gif"); pauseIcon = new ImageIcon("images/pause.gif"); - stop = createButton("images/stop.gif", "Stop"); + + // Adds playback buttons + add(rewind); + add(playpause); add(stop); - fastforward = createButton("images/forward.gif", "Fast forward"); add(fastforward); // Creates progress indicator + measure = createLabel("Msr", 10); + beats = createLabel("Beat", 10); + ticks = createLabel("Tick", 10); + 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(); + spacesouth.setBackground(bgColor); + + // Creates progress indicator panel and adds components JPanel progIndPanel = new JPanel(); progIndPanel.setMaximumSize(new Dimension(120,27)); progIndPanel.setLayout(new GridLayout(2,4)); - measure = createLabel("Mrs",10); - beats = createLabel("Beat",10); - ticks = createLabel("Tick",10); - measurevalue = createLabel("1", 16); - beatsvalue = createLabel("1",16); - ticksvalue = createLabel("1",16); - - JPanel spacenorth = new JPanel(); - spacenorth.setBackground(bgColor); progIndPanel.add(spacenorth); - progIndPanel.add(measure); progIndPanel.add(beats); progIndPanel.add(ticks); - - JPanel spacesouth = new JPanel(); - spacesouth.setBackground(bgColor); progIndPanel.add(spacesouth); - - progIndPanel.add(measurevalue); - progIndPanel.add(beatsvalue); - progIndPanel.add(ticksvalue); + progIndPanel.add(measureValue); + progIndPanel.add(beatsValue); + progIndPanel.add(ticksValue); add(progIndPanel); + } - + /** + * Updates the progress indicator. + * @param tickPosition the tick position to visualize + */ + public void updateProgInd(long tickPosition) { + int ticksPerBeat = Moosique.getSequence().getResolution(); + int beatsPerMeasure = 4; + 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)); + } + + /* * 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)); @@ -78,41 +92,42 @@ 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 value = new JLabel(title,JLabel.CENTER); - value.setFont(new Font("Times New Roman", Font.PLAIN, fontSize)); - value.setBorder(BorderFactory.createLineBorder(Color.black)); - return value; + JLabel label = new JLabel(title,JLabel.CENTER); + label.setFont(new Font("Times New Roman", Font.PLAIN, fontSize)); + return label; } - - // int pos = Moosique.getSequencer().getTickPosition(); - // int measures = pos / (4 * Moosique.getSequence.get) - // int beats = (pos - measures * 4 * 96) / 96; - // int ticks = (pos - measures*4*96 - beats*96); - + + /* + * 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") { - Moosique.play(); playpause.setIcon(pauseIcon); playpause.setToolTipText("Pause"); + Moosique.play(); } else if (((JButton)e.getSource()).getToolTipText() == "Pause") { - Moosique.pause(); playpause.setIcon(playIcon); playpause.setToolTipText("Resume"); + Moosique.pause(); } else if (((JButton)e.getSource()).getToolTipText() == "Resume") { - Moosique.resume(); playpause.setIcon(pauseIcon); playpause.setToolTipText("Pause"); + Moosique.resume(); } else if (((JButton)e.getSource()).getToolTipText() == "Stop") { - Moosique.stop(); playpause.setIcon(playIcon); playpause.setToolTipText("Play"); + Moosique.stop(); } } @@ -126,4 +141,4 @@ public class MooToolbar extends JToolBar { public void mouseReleased(MouseEvent e) {} } -} +} \ No newline at end of file