//The public class for generating the Variations in a 2-column array for playback. //An array is generated for the treble line and another for the bass line. //variations are named but called by numbers. //TODO implement key selection (make it "more tonal") public class varius { //instance variables int numT; int numB; int notesT[5000][2]; int notesB[5000][2]; int nomin; int beat; int chords[][]; int numChords; 12 * 3 => int tConst; 12 * 1 => int bConst; 12 => int octave; //Constructs the notes tables fun void Varius(int var[], int numVar, int table[][], int num, int nom, int denom) { table @=> chords; num => numChords; nom => nomin; for(0 => int i; i < numVar; i++) { if(var[i] == 1) { var1Treble(); var1Bass(); } if(var[i] == 2) { var2Treble(); var2Bass(); } } } //returns the desired treble line notes fun int[][] getTrebleTable() { return notesT; } //returns the desired bass line notes fun int[][] getBassTable() { return notesB; } //returns the number of notes for each line fun int getNumTreble() { return numT; } //returns the number of notes for each line fun int getNumBass() { return numB; } fun int chordLength(int rawLength) { if (rawLength == 3) { return 3; } else { return 4/rawLength; } } /* The Variations Begin Here */ //Variation 1: The "Allemande" (but not really because 3/4 is allowed too) fun void var1Treble() { //initialize beat count nomin => beat; //marks start of variation and set tempo -1 => notesT[numT][0]; 80 => notesT[numT][1]; numT++; //walking rhythm for(0 => int i; i < numChords-1; i++) { for(0 => int j; j < chordLength(chords[i][0]); j++) { if(beat == 1) { chords[i][3]+tConst => notesT[numT][0]; 8 => notesT[numT][1]; numT++; (chords[i][3]+ Math.random2(-1, 1)*2)+ tConst => notesT[numT][0]; 8 => notesT[numT][1]; numT++; nomin=>beat; //"replenish" the beat; } else { int rand; while(true) { Math.random2(3, 5) => rand; if(chords[i][rand] != 0) break; } chords[i][rand]+tConst => notesT[numT][0]; 4 => notesT[numT][1]; numT++; beat--; } } } //end on a long final note pattern chords[numChords-1][3]+tConst => notesT[numT][0]; chords[numChords-1][0] => notesT[numT][1]; numT++; } fun void var1Bass() { //initialize beat count nomin => beat; //marks start of variation and set tempo -1 => notesB[numB][0]; 80 => notesB[numB][1]; numB++; for(0 => int i; i < numChords; i++) { chords[i][1] + bConst => notesB[numB][0]; chords[i][0] => notesB[numB][1]; numB++; } } //Variation 2: The Crazy Arppegios fun void var2Treble() { //marks start of variation and set tempo -1 => notesT[numT][0]; 120 => notesT[numT][1]; numT++; //walking rhythm for(0 => int i; i < numChords-1; i++) { for(0 => int j; j < chordLength(chords[i][0]); j++) { chords[i][2]+ tConst => notesT[numT][0]; 16 => notesT[numT][1]; numT++; chords[i][3]+ tConst => notesT[numT][0]; 16 => notesT[numT][1]; numT++; chords[i][4]+ tConst => notesT[numT][0]; 16 => notesT[numT][1]; numT++; chords[i][3]+ tConst => notesT[numT][0]; 16 => notesT[numT][1]; numT++; } } //end with a flourish~ chords[numChords-1][2]+ tConst + octave => notesT[numT][0]; 16 => notesT[numT][1]; numT++; chords[numChords-1][4]+ tConst => notesT[numT][0]; 16 => notesT[numT][1]; numT++; chords[numChords-1][3]+ tConst => notesT[numT][0]; 16 => notesT[numT][1]; numT++; chords[numChords-1][2]+tConst => notesT[numT][0]; chords[numChords-1][0] -1 => notesT[numT][1]; numT++; } fun void var2Bass() { //marks start of variation and set tempo -1 => notesB[numB][0]; 120 => notesB[numB][1]; numB++; for(0 => int i; i < numChords -1 ; i++) { chords[i][1] + bConst => notesB[numB][0]; 4 => notesB[numB][1]; numB++; for(0 => int j; j < chordLength(chords[i][0])-1; j++) { 0 => notesB[numB][0]; 4 => notesB[numB][1]; numB++; } } //end on a long final note pattern chords[numChords-1][1]+ bConst => notesB[numB][0]; chords[numChords-1][0] => notesB[numB][1]; numB++; } }