]> ruin.nu Git - moosique.git/blob - MooViewCounter.java
hmm.. this doesn't want to work..
[moosique.git] / MooViewCounter.java
1 import javax.sound.midi.*;
2 import javax.swing.*;
3 import java.awt.*;
4
5 /**
6  * A graphical representation of the time signature of the current sequence.
7  * 
8  * @author  Andersson, Andreen, Lanneskog, Pehrson
9  * @version 1
10  */
11  
12 public class MooViewCounter extends JPanel {
13
14         private int measure, halfBeat, beat, halfNote;
15         private static final int CELL_HEIGHT = 10;
16         
17         /** 
18          * Creates an musical ruler depending on the timesignature
19          */
20
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));
25
26                 switch (timeSig2) {
27                         case  16: measure = timeSig1;           // 1/16
28                                 break;
29                         case  8: measure = timeSig1 * 2;        // 1/16
30                                  halfBeat = measure / timeSig1; // 1/8
31                                 break;
32                         case  4: measure = timeSig1 * 4;        // 1/16
33                                  halfBeat = beat / 2;           // 1/8          
34                                  beat = measure / timeSig1;     // 1/4  
35                                 break;
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
40                                 break;
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
45                                 break;
46                 }
47                 
48         }
49
50         /**
51          * Draws the ruler-like fields.
52          * @param g The Graphics object it operates on.
53          */
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
65                 }
66         }
67 }