]> ruin.nu Git - moosique.git/blobdiff - MooViewCounter.java
no message
[moosique.git] / MooViewCounter.java
index bb06eac5720a4e80d849e11c4984c9ea9619d932..de1dac2db6e25c53bde2e2ded1d9c49791d24c60 100644 (file)
@@ -1,8 +1,9 @@
+import javax.sound.midi.*;
 import javax.swing.*;
 import java.awt.*;
 
 /**
- * 
+ * A graphical representation of the time signature of the current sequence.
  * 
  * @author  Andersson, Andreen, Lanneskog, Pehrson
  * @version 1
@@ -10,53 +11,73 @@ import java.awt.*;
  
 public class MooViewCounter extends JPanel {
 
-       private int timeSig1, timeSig2, measure, halfBeat, beat, halfNote;
-
+       private int measure, halfBeat, beat, halfNote;
+       private static final int CELL_HEIGHT = 10;
+       
        /** 
-        * Creates 
+        * Creates an musical ruler depending on the timesignature
         */
-       public MooViewCounter (int ts1, int ts2) {
-               timeSig1 = ts1;
-               timeSig2 = ts2;
-               setBackground(Color.black);
-               setPreferredSize(new Dimension(35,200*10));
-               
-               switch (timeSig2) {
-                       case  16: measure = timeSig1;  
-                       break;
-                       case  8: measure = timeSig1 * 2;
-                                        halfBeat = measure/timeSig1;
-                       break;
-                       case  4: measure = timeSig1 * (int)Math.pow(2,2);
-                                        beat = measure/timeSig1;
-                                        halfBeat = beat/2;       
-                       break;
-                       case  2: measure = timeSig1 * (int)Math.pow(2,3); 
-                                        halfNote = measure/timeSig1;
-                                        beat = halfNote/2;
-                                        halfBeat = beat/2;
-                       break;
-                       case  1: measure = timeSig1 * (int)Math.pow(2,4);
-                                    halfNote = measure/2;
-                                        beat = halfNote/2;
-                                        halfBeat = beat/2;
-                       break;
+       public MooViewCounter (MetaMessage[] timeSigs) {
+               // ...for now
+               int timeSig1 = 4, timeSig2 = 4;
+               calculateLineSpecs(timeSig1, timeSig2);
+               setBackground(Moosique.getGUI().bgColor);
+               setPreferredSize(new Dimension(35, 200 * CELL_HEIGHT));
+       }
+
+       private void calculateLineSpecs(int ts1, int ts2) {
+               switch (ts2) {
+                       case 16: measure = ts1;                 // 1/16
+                                break;
+                       case  8: measure = ts1 * 2;     // 1/16
+                                halfBeat = measure / ts1;      // 1/8
+                                break;
+                       case  2: measure = ts1 * 8;     // 1/16
+                                halfBeat = beat / 2;           // 1/8
+                                beat = halfNote / 2;           // 1/4
+                                halfNote = measure / ts1;      // 1/2
+                                break;
+                       case  1: measure = ts1 * 16;    // 1/16
+                                halfBeat = beat / 2;           // 1/8
+                                beat = halfNote / 2;           // 1/4
+                                halfNote = measure / 2;        // 1/2
+                                break;
+                       default: measure = ts1 * 4;     // 1/16
+                                halfBeat = beat / 2;           // 1/8          
+                                beat = measure / ts1;  // 1/4  
+                                break;
                }
-               
        }
 
+       /**
+        * Draws the ruler-like fields.
+        * @param g The Graphics object it operates on.
+        */
        public void paintComponent(Graphics g) {
                super.paintComponent(g);
                if (!(g instanceof Graphics2D)) return;
                Graphics2D g2 = (Graphics2D)g;
-               g2.setColor(Color.white);
+               g2.setColor(Color.black);
+
+
+               /* Using time signature...
+               for (int i = 0, tick = getTicksForPosition(i, 0, 0); tick < Moosique.getSequence().getTickLength(); i++) {
+                       int[] ts = getTimeSig(tick);
+                       calculateLineSpecs(ts[0], ts[1]);
+                       g2.drawLine(0, c * CELL_HEIGHT, 5, c * CELL_HEIGHT);                                    // 1/16
+                       g2.drawLine(0, c * CELL_HEIGHT * halfBeat, 10, c * CELL_HEIGHT * halfBeat);             // 1/8
+                       g2.drawLine(0, c * CELL_HEIGHT * beat, 15, c * CELL_HEIGHT * beat);                     // 1/4
+                       g2.drawLine(0, c * CELL_HEIGHT * halfNote, 20, c * CELL_HEIGHT * halfNote);             // 1/2
+                       g2.drawLine(0, c * CELL_HEIGHT * measure, 30, c * CELL_HEIGHT * measure);               // 1/1
+               }
+               */
+
                for (int c = 0; c < 200; c++) {
-                       g2.drawLine(0,c*10,5,c*10);                                                     // 1/16
-                       g2.drawLine(0,c*10*halfBeat,10,c*10*halfBeat);                  // 1/8
-                       g2.drawLine(0,c*10*beat,15,c*10*beat);                                  // 1/4
-                       g2.drawLine(0,c*10*halfNote,20,c*10*halfNote);                  // 1/2
-                       g2.drawLine(0,c*10*measure,30,c*10*measure);                    // 1/1
-                       
+                       g2.drawLine(0, c * CELL_HEIGHT, 5, c * CELL_HEIGHT);                                    // 1/16
+                       g2.drawLine(0, c * CELL_HEIGHT * halfBeat, 10, c * CELL_HEIGHT * halfBeat);             // 1/8
+                       g2.drawLine(0, c * CELL_HEIGHT * beat, 15, c * CELL_HEIGHT * beat);                     // 1/4
+                       g2.drawLine(0, c * CELL_HEIGHT * halfNote, 20, c * CELL_HEIGHT * halfNote);             // 1/2
+                       g2.drawLine(0, c * CELL_HEIGHT * measure, 30, c * CELL_HEIGHT * measure);               // 1/1
                }
        }
-}
\ No newline at end of file
+}