package pitches; //import java.io.IOException; import maxlink.MaxLink; /* Daniel Shiffman */ /* Programming from A to Z */ /* Spring 2007 */ /* http://www.shiffman.net */ /* daniel.shiffman@nyu.edu */ public class pitchClass { final MaxLink link = new MaxLink(this, "pitchClass"); public void init(){ //final MaxLink link = new MaxLink(this, "pitchClass"); int noteplace = 0; int scaleplace = 0; char[] notes = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L'}; char note = notes[noteplace]; boolean transpose = false; String song = ""; song += note; //try { //A2ZFileReader file = new A2ZFileReader("bah.txt"); //String stuff = file.getContent(); for (int i = 0; i < 100; i++) { // input = get input from max transpose = transposeur(transpose); if (transpose == true){ //noteplace = pickNextNote(noteplace, input); noteplace = pickNextNote(noteplace); //song += notes[noteplace]; } scaleplace = scaledegree(scaleplace); } //System.out.println(song); // print out string of characters. //link.output(song); //}catch (IOException e) { //e.printStackTrace(); //} }//main public static void main(String[] args) { pitchClass pc = new pitchClass(); pc.init(); } //function to pick notes public int pickNextNote(int noteplace) { boolean foundone = false; //final MaxLink link = new MaxLink(this, "pitchClass"); //int[] chromatic = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; //int j = 0; // chromatic place-holder int hack = 0; // let's count just so we don't get stuck in an infinite loop by accident double[] probs = new double[12];//{0.5,0.20,0.17,0.03,0.4,0.1,0.5,0.3,0.01,0.1,0.1,0.2,0.4}; for (int i = 0; i < probs.length; i++) { probs[i] = i/10.0; } while (!foundone && hack < 10000) { double location = Math.random() * probs.length; // pick a number 0 - 11 int location2 = (int)location; double r2 = Math.random(); // pick a number to compare r1 to // If the second random number is less than the probability in the array // ...Then we've found an OK answer if (r2 < probs[location2]) { // check r2 against location foundone = true; // 12 RULES: // 1 - move up a 5th if (location2 == 0) { noteplace = (noteplace + 1)%12; System.out.println("noteplace = " + noteplace); link.output(0, noteplace); return (noteplace); } // 2 - move up a 5th if (location2 == 1) { noteplace = (noteplace + 2)%12; System.out.println("noteplace = " + noteplace); link.output(0, noteplace); return (noteplace); } // 3 - move up a 5th if (location2 == 2) { noteplace = (noteplace + 3)%12; System.out.println("noteplace = " + noteplace); link.output(0, noteplace); return (noteplace); } // 4 - move up a 5th if (location2 == 3) { noteplace = (noteplace + 4)%12; System.out.println("noteplace = " + noteplace); link.output(0, noteplace); return (noteplace); } // 5 - move up a 5th if (location2 == 4) { noteplace = (noteplace + 5)%12; System.out.println("noteplace = " + noteplace); link.output(0, noteplace); return (noteplace); } // 6 - move up a 5th if (location2 == 5) { noteplace = (noteplace + 6)%12; System.out.println("noteplace = " + noteplace); link.output(0, noteplace); return (noteplace); } // 7 - move up a 5th if (location2 == 6) { noteplace = (noteplace + 7)%12; System.out.println("noteplace = " + noteplace); link.output(0, noteplace); return (noteplace); } // 8 - move up a 5th if (location2 == 7) { noteplace = (noteplace + 8)%12; System.out.println("noteplace = " + noteplace); link.output(0, noteplace); return (noteplace); } // 9 - move up a 5th if (location2 == 8) { noteplace = (noteplace + 9)%12; System.out.println("noteplace = " + noteplace); link.output(0, noteplace); return (noteplace); } // 10 - move up a 5th if (location2 == 9) { noteplace = (noteplace + 10)%12; System.out.println("noteplace = " + noteplace); link.output(0, noteplace); return (noteplace); } // 11 - move up a 5th if (location2 == 10) { noteplace = (noteplace + 11)%12; System.out.println("noteplace = " + noteplace); link.output(0, noteplace); return (noteplace); } // 12 - move up a 5th if (location2 == 11) { noteplace = (noteplace + 12)%12; System.out.println("noteplace = " + noteplace); link.output(0, noteplace); return (noteplace); } else { return 0; } } // for hack++; foundone = false; } // while return 0; } // function //function to pick notes public int scaledegree(int scaleplace) { boolean foundone = false; //final MaxLink link = new MaxLink(this, "pitchClass"); //int[] chromatic = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; //int j = 0; // chromatic place-holder int hack = 0; // let's count just so we don't get stuck in an infinite loop by accident double[] probs = {0.5,0.5,0.5,0.5,0.5,0.5,0.5}; while (!foundone && hack < 10000) { double location = Math.random() * probs.length; // pick a number 0 - 11 int location2 = (int)location; double r2 = Math.random(); // pick a number to compare r1 to // If the second random number is less than the probability in the array // ...Then we've found an OK answer if (r2 < probs[location2]) { // check r2 against location foundone = true; // 12 RULES: // 1 - move up a 5th if (location2 == 0) { scaleplace = (scaleplace + 1)%7; System.out.println("scaleplace = " + scaleplace); link.output(1, scaleplace); return (scaleplace); } // 2 - move up a 5th if (location2 == 1) { scaleplace = (scaleplace + 2)%7; System.out.println("scaleplace = " + scaleplace); link.output(1, scaleplace); return (scaleplace); } // 3 - move up a 5th if (location2 == 2) { scaleplace = (scaleplace + 3)%7; System.out.println("scaleplace = " + scaleplace); link.output(1, scaleplace); return (scaleplace); } // 4 - move up a 5th if (location2 == 3) { scaleplace = (scaleplace + 4)%7; System.out.println("scaleplace = " + scaleplace); link.output(1, scaleplace); return (scaleplace); } // 5 - move up a 5th if (location2 == 4) { scaleplace = (scaleplace + 5)%7; System.out.println("scaleplace = " + scaleplace); link.output(1, scaleplace); return (scaleplace); } // 6 - move up a 5th if (location2 == 5) { scaleplace = (scaleplace + 6)%7; System.out.println("scaleplace = " + scaleplace); link.output(1, scaleplace); return (scaleplace); } // 7 - move up a 5th if (location2 == 6) { scaleplace = (scaleplace + 7)%7; System.out.println("scaleplace = " + scaleplace); link.output(1, scaleplace); return (scaleplace); } else { return 0; } } // for hack++; foundone = false; } // while return 0; } // function public boolean transposeur(boolean transpose){ boolean foundone = false; double threshold = 0.25; double chance = 0; while (!foundone) { chance = Math.random(); // pick a number 0.0 - 1.0 if (chance < threshold) { foundone = true; return true; }else{ foundone = true; return false; } } // while return true; // still unsure about this.... } } //class