/*Self notes*/ //An //45 keys used import ddf.minim.signals.*; import ddf.minim.*; import ddf.minim.analysis.*; import ddf.minim.effects.*; Minim minim = new Minim(this); SineWave [] [] notes; AudioOutput out; float midi = 48; int a = 45; int b = 5; PFont font; String s = "TYPE SOMETHING; hit enter to clear."; boolean [] playing = new boolean [45]; //float baseFrequency = 110; /* Sam Pluta's midi to freq function */ public float midiToFreq (float midi) { float freq = (8.1758 * pow(2,midi/12.0)); //println("freq: "+freq); return freq; } void prepNotes () { //Sets up a two dimensional array of SineWaves to be added/removed from out (the AudioOutput object). notes = new SineWave [a] [b]; for (int i = 0; i < a; i++) { //This should be the base value of the note. So... float frequency = midiToFreq (midi + i); //System.out.println (frequency); for (int j = 1; j < b+1; j++) { //Odd overtones only for the organ timbre. notes [i] [j-1] = new SineWave (frequency * (j*2-1), random (0.015,0.025), out.sampleRate ()); //Overtones: f, 3f, 5f, 7f, 9f, 11f //System.out.println (frequency * (j*2-1)); } //System.out.println ("\n"); } } void playNote (int n) { for (int i = 0; i < b; i ++) { out.addSignal (notes [n] [i]); } } void silenceNote (int n) { for (int i = 0; i < b; i ++) { out.removeSignal (notes [n] [i]); } } void resetValues () { for (int i = 0; i < a; i ++) { playing [i] = false; } } void setup () { size (1500,50); // minim.start (); out = minim.getLineOut (Minim.STEREO); for (int i = 0; i < 45; i++) { playing [i] = false; } prepNotes (); fill(0, 102, 153, 51); font = loadFont ("Garamond-48.vlw"); textFont (font, 36); text (s, 0, 42); } void draw () { text ("t", 0, 0); } void keyPressed () { switch (key) { case 'z': if (! playing [0]) { playing [0] = true; playNote (0); } else { playing [0] = false; silenceNote (0); } break; case 's': if (! playing [1]) { playing [1] = true; playNote (1); } else { playing [1] = false; silenceNote (1); } break; case 'x': if (! playing [2]) { playing [2] = true; playNote (2); } else { playing [2] = false; silenceNote (2); } break; case 'd': if (! playing [3]) { playing [3] = true; playNote (3); } else { playing [3] = false; silenceNote (3); } break; case 'c': if (! playing [4]) { playing [4] = true; playNote (4); } else { playing [4] = false; silenceNote (4); } break; case 'v': if (! playing [5]) { playing [5] = true; playNote (5); } else { playing [5] = false; silenceNote (5); } break; case 'g': if (! playing [6]) { playing [6] = true; playNote (6); } else { playing [6] = false; silenceNote (6); } break; case 'b': if (! playing [7]) { playing [7] = true; playNote (7); } else { playing [7] = false; silenceNote (7); } break; case 'h': if (! playing [8]) { playing [8] = true; playNote (8); } else { playing [8] = false; silenceNote (8); } break; case 'n': if (! playing [9]) { playing [9] = true; playNote (9); } else { playing [9] = false; silenceNote (9); } break; case 'j': if (! playing [10]) { playing [10] = true; playNote (10); } else { playing [10] = false; silenceNote (10); } break; case 'm': if (! playing [11]) { playing [11] = true; playNote (11); } else { playing [11] = false; silenceNote (11); } break; case ',': if (! playing [12]) { playing [12] = true; playNote (12); } else { playing [12] = false; silenceNote (12); } break; case 'l': if (! playing [13]) { playing [13] = true; playNote (13); } else { playing [13] = false; silenceNote (13); } break; case '.': if (! playing [14]) { playing [14] = true; playNote (14); } else { playing [14] = false; silenceNote (14); } break; case ';': if (! playing [15]) { playing [15] = true; playNote (15); } else { playing [15] = false; silenceNote (15); } break; case '/': if (! playing [16]) { playing [16] = true; playNote (16); } else { playing [16] = false; silenceNote (16); } break; case 'q': if (! playing [17]) { playing [17] = true; playNote (17); } else { playing [17] = false; silenceNote (17); } break; case '2': if (! playing [18]) { playing [18] = true; playNote (18); } else { playing [18] = false; silenceNote (18); } break; case 'w': if (! playing [19]) { playing [19] = true; playNote (19); } else { playing [19] = false; silenceNote (19); } break; case '3': if (! playing [20]) { playing [20] = true; playNote (20); } else { playing [20] = false; silenceNote (20); } break; case 'e': if (! playing [21]) { playing [21] = true; playNote (21); } else { playing [21] = false; silenceNote (21); } break; case '4': if (! playing [22]) { playing [22] = true; playNote (22); } else { playing [22] = false; silenceNote (22); } break; case 'r': if (! playing [23]) { playing [23] = true; playNote (23); } else { playing [23] = false; silenceNote (23); } break; case 't': if (! playing [24]) { playing [24] = true; playNote (24); } else { playing [24] = false; silenceNote (24); } break; case '6': if (! playing [25]) { playing [25] = true; playNote (25); } else { playing [25] = false; silenceNote (25); } break; case 'y': if (! playing [26]) { playing [26] = true; playNote (26); } else { playing [26] = false; silenceNote (26); } break; case '7': if (! playing [27]) { playing [27] = true; playNote (27); } else { playing [27] = false; silenceNote (27); } break; case 'u': if (! playing [28]) { playing [28] = true; playNote (28); } else { playing [28] = false; silenceNote (28); } break; case 'i': if (! playing [29]) { playing [29] = true; playNote (29); } else { playing [29] = false; silenceNote (29); } break; case '9': if (! playing [30]) { playing [30] = true; playNote (30); } else { playing [30] = false; silenceNote (30); } break; case 'o': if (! playing [31]) { playing [31] = true; playNote (31); } else { playing [31] = false; silenceNote (31); } break; case '0': if (! playing [32]) { playing [32] = true; playNote (32); } else { playing [32] = false; silenceNote (32); } break; case 'p': if (! playing [33]) { playing [33] = true; playNote (33); } else { playing [33] = false; silenceNote (33); } break; case '-': if (! playing [34]) { playing [34] = true; playNote (34); } else { playing [34] = false; silenceNote (34); } break; case '[': if (! playing [35]) { playing [35] = true; playNote (35); } else { playing [35] = false; silenceNote (35); } break; case ']': if (! playing [36]) { playing [36] = true; playNote (36); } else { playing [36] = false; silenceNote (36); } break; case ' ': out.clearSignals (); resetValues (); break; } //ENTER s += key; text (s, 0, 42); if (key == ENTER) { background (255); s = ""; } }