1 import javax.sound.midi.*;
6 * A graphical representation of the time signature of the current sequence.
8 * @author Andersson, Andreen, Lanneskog, Pehrson
12 public class MooViewCounter extends JPanel {
14 private int measure, halfBeat, beat, halfNote;
15 private static final int CELL_HEIGHT = 10;
18 * Creates an musical ruler depending on the timesignature
21 public MooViewCounter (MetaMessage[] timeSigs) {
22 int timeSig1 = 4, timeSig2 = 4; // ...for now
23 setBackground(Moosique.getGUI().bgColor);
24 setPreferredSize(new Dimension(35, 200 * CELL_HEIGHT));
27 case 16: measure = timeSig1; // 1/16
29 case 8: measure = timeSig1 * 2; // 1/16
30 halfBeat = measure / timeSig1; // 1/8
32 case 4: measure = timeSig1 * 4; // 1/16
33 halfBeat = beat / 2; // 1/8
34 beat = measure / timeSig1; // 1/4
36 case 2: measure = timeSig1 * 8; // 1/16
37 halfBeat = beat / 2; // 1/8
38 beat = halfNote / 2; // 1/4
39 halfNote = measure / timeSig1; // 1/2
41 case 1: measure = timeSig1 * 16; // 1/16
42 halfBeat = beat / 2; // 1/8
43 beat = halfNote / 2; // 1/4
44 halfNote = measure / 2; // 1/2
51 * Draws the ruler-like fields.
52 * @param g The Graphics object it operates on.
54 public void paintComponent(Graphics g) {
55 super.paintComponent(g);
56 if (!(g instanceof Graphics2D)) return;
57 Graphics2D g2 = (Graphics2D)g;
58 g2.setColor(Color.black);
59 for (int c = 0; c < 200; c++) {
60 g2.drawLine(0, c * CELL_HEIGHT, 5, c * CELL_HEIGHT); // 1/16
61 g2.drawLine(0, c * CELL_HEIGHT * halfBeat, 10, c * CELL_HEIGHT * halfBeat); // 1/8
62 g2.drawLine(0, c * CELL_HEIGHT * beat, 15, c * CELL_HEIGHT * beat); // 1/4
63 g2.drawLine(0, c * CELL_HEIGHT * halfNote, 20, c * CELL_HEIGHT * halfNote); // 1/2
64 g2.drawLine(0, c * CELL_HEIGHT * measure, 30, c * CELL_HEIGHT * measure); // 1/1