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

1    package sound; 
2     
3    import java.util.StringTokenizer; 
4    import java.util.Vector; 
5     
6    public class PetriNode { 
7     
8        private String identifier; 
9        private Vector nextNodes = new Vector(); 
10    
11       public void addNext(int i) { 
12           nextNodes.addElement(new Integer(i)); 
13       } 
14    
15       public static String[] 
16               getTokens(String s) { 
17    
18           StringTokenizer 
19                   st = new StringTokenizer( 
20                           s, ",: \t\n\r\f\\"); 
21           int n = st.countTokens(); 
22           String t[] = new String[n]; 
23           for (int i = 0; i < n; i++) 
24               t[i] = st.nextToken(); 
25           return t; 
26       } 
27    
28       public static int[] getNotes(String s[]) { 
29           int ia[] = new int[s.length]; 
30           for (int i = 0; i < ia.length; i++) 
31               ia[i] = Integer.parseInt(s[i]); 
32           return ia; 
33       } 
34    
35       public void play() { 
36           int ia[] = getNotes(getTokens(identifier)); 
37           Utils.playThread(ia, 127, 1000); 
38       } 
39    
40       public int getNext() { 
41           if (nextNodes.size() == 0) return 0; 
42           int r = (int) (nextNodes.size() * Math.random()); 
43           Object o = nextNodes.elementAt(r); 
44           return ((Integer) o).intValue(); 
45       } 
46    
47    
48       public PetriNode(String _identifier) { 
49           identifier = _identifier; 
50       } 
51    
52       public String getIdentifier() { 
53           return identifier; 
54       } 
55    
56       public boolean equals(PetriNode p2) { 
57           return this.getIdentifier().equals(p2.getIdentifier()); 
58       } 
59    
60       public String toString() { 
61           return 
62                   "id=" + identifier 
63                   + "\nNextNodes:" + nextNodes.toString(); 
64       } 
65    
66    
67   }