/Users/lyon/j4p/src/sound/Scales.java

1    package sound; 
2     
3    /* 
4     * Open Source Software by http://www.Docjava.com 
5     * programmer: D. Lyon 
6     * e-mail: lyon@docjava.com 
7     * Date: Apr 29, 2002 
8     * Time: 12:39:06 PM 
9     */ 
10    
11   public class Scales { 
12       public static int CHROMATIC[] = { 
13           1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 
14    
15       }; 
16       public static int WHOLE_NOTES[] = {//major scale 
17           0, 2, 2, 1, 2, 2, 2, 1, 1 
18           // doe, re, me, fa, sol, la, ti, doe 
19           // 0,1,2,3,4,5,6,7,8,9,10,11 
20           // c, c#, D, D#, E, F, F#, G, G#, A, A#, B 
21           //whole notes are 
22           // C, D, E, F, G, A, B 
23           // 0, 2,4,5,7,9,11 <- note number 
24           // 0, 2,2,1,2,2,2 
25       }; 
26       public static int occidentals[] = {//sharps and flats 
27           1, 2, 3, 2, 2, 3 
28       }; 
29       public static int SILLY_SCALE[] = { 
30           1, 1, 3, 1, 1, 3, 1, 1, 3, 1, 1, 3, 
31           1, 1, 4, 1, 1, 4, 1, 1, 4, 1, 1, 4, 
32           1, 1, 5, 1, 1, 5, 1, 1, 5, 1, 1, 5 
33    
34       }; 
35       protected static int IONIAN[] = { 
36           2, 2, 1, 2, 2, 2, 1 
37       }; 
38       public static int HARMONIC_MINOR[] = { 
39           2, 1, 2, 2, 1, 3, 1 
40       }; 
41       protected static int GYPSY[] = { 
42           1, 3, 1, 1, 2, 1, 3, 1 
43       }; 
44    
45       public static void testWholeNotes() { 
46           int speed = 500; 
47           System.out.println("occidentals"); 
48           int[] scale = getScale(occidentals, 30); 
49           Utils.play(scale, speed); 
50           Utils.print(scale); 
51       } 
52    
53       public static void testPlayScale() { 
54           int speed = 50; 
55           System.out.println("SILLY_SCALE"); 
56           Utils.play(getScale(SILLY_SCALE, 35), speed); 
57    
58           System.out.println("gypsy"); 
59    
60           Utils.play(getScale(GYPSY, 35), speed); 
61           System.out.println("CHROMATIC"); 
62           Utils.play(getScale(CHROMATIC, 35), speed); 
63           System.out.println("HARMONIC_MINOR"); 
64           Utils.play(getScale(HARMONIC_MINOR, 32), speed); 
65       } 
66    
67       public static void main(String args[]) { 
68           testWholeNotes(); 
69       } 
70    
71       /** 
72        * get a scale starting at any note, 
73        * in a given progression. 
74        * The scale is as long as the progression. 
75        * for example: 
76        * 0,2,2,1,2,2,1, starting at 10 gives 
77        * 10,12,14,15,17,19,20 
78        */ 
79       public static int[] getScale( 
80               int progression[], int startNote) { 
81           //0,2, 2, 1, 2, 2, 2,1 
82           int scale[] = new int[progression.length]; 
83           for (int i = 0; i < progression.length; i++) { 
84               int octaveNumber = i / progression.length; 
85               scale[i] = startNote + progression[i % progression.length]; 
86               startNote = scale[i] * octaveNumber; 
87           } 
88           return scale; 
89       } 
90    
91       /** 
92        * start a prgression at any note and end and any note 
93        */ 
94       public static int[] getScale( 
95               int progression[], int startNote, int endNote) { 
96           int scale[] = new int[endNote - startNote]; 
97           for (int i = 0; i < scale.length; i++) { 
98               scale[i] = startNote + progression[i % progression.length]; 
99               startNote = scale[i % scale.length]; 
100          } 
101          return scale; 
102      } 
103  } 
104