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

1    package sound; 
2     
3     
4    public class SongReader { 
5     
6     
7        public static final int BLACK_ORPHEUS[] = { 
8            8, 4, 3, 1, 1, 12, 3, 8, 8, 4, 3, 1, 1, 11, 3, 
9            8, 8, 9, 11, 2, 6, 6, 6, 8, 9, 11, 4, 4, 4, 
10           6, 8, 9, 3, 3, 4, 6, 8, 8, 4, 3, 
11           1, 1, 12, 3, 8, 8, 2, 1, 11, 11, 9, 8, 1, 6, 6, 8, 9, 11, 4, 4, 6, 8, 1, 
12           12, 8, 8, 12, 3, 1, 8, 1, 1, 
13           3, 4, 6, 4, 3, 1, 3, 4, 6, 4, 3, 1, 3, 4, 6, 4, 3, 1, 11 
14       }; 
15    
16       public PetriNodes buildMarkov(int events[], int order) { 
17           PetriNodes pn = new PetriNodes(); 
18           for (int i = 0; i < events.length; i++) { 
19               StringBuffer sb = new StringBuffer(); 
20               for (int j = 0; j < order; j++) { 
21                   int eventIndex = i + j; 
22                   if (eventIndex >= events.length) continue; 
23                   sb.append(events[eventIndex] + ":"); 
24               } 
25               pn.add(new PetriNode(sb.toString())); 
26           } 
27           return pn; 
28       } 
29    
30       public static final int BLACK_ORPHEUS_NOTES[] = 
31               Utils.transpose(BLACK_ORPHEUS, 64); 
32       private static int i; 
33    
34       public static int getNextNote() { 
35           return BLACK_ORPHEUS_NOTES[i++ % BLACK_ORPHEUS_NOTES.length]; 
36       } 
37    
38       public static PetriNodes initMarkov(int order) { 
39           SongReader sr = new SongReader(); 
40           PetriNodes pn = sr.buildMarkov(sr.BLACK_ORPHEUS_NOTES, order); 
41           pn.init(); 
42           return pn; 
43       } 
44    
45       public static void main(String args[]) { 
46           PetriNodes pn = initMarkov(3); 
47           for (int i = 0; i < 9; i++) 
48               (pn.getNode(i)).play(); 
49       } 
50    
51    
52   }