/* Example of a generalized diatonic (or extended mentone) key map. Transposition takes place by keyboard translation, so each scale and chord need only one fingering pattern. The keyboard layout is altering pitches as follows: ^ # / . -> M / \ b v v m where M (resp. m) is the major (resp. minor) second, and the the sharp # (resp. flat b) raises (resp lower) with the interval M - m, that is, the difference between the major and minor seconds. Resulting key pattern: C# D# E# C D E F# G# A# B# Cb Db Eb F G A B Fb Gb Ab Bb C' M is set to 2^(5/31) and m = 2^(3/31), the E31 approximation of Renaissance meantone. Middle A = 440 Hz, and is in US keyboard layout on key "J". */ // The device number to open 0 => int deviceNum; // keyboard Hid kb; // hid message HidMsg msg; // Open keyboard. if(!kb.openKeyboard(deviceNum)) me.exit(); // Successful! Print name of device. <<< "Keyboard '", kb.name(), "' ready." >>>; // Key x-axis coordinate int x[256]; 0 => x[100] => x[53]; 1 => x[41] => x[49] => x[30] => x[20] => x[4] => x[29]; 2 => x[58] => x[31] => x[26] => x[22] => x[27]; 3 => x[59] => x[32] => x[8] => x[7] => x[6]; 4 => x[60] => x[33] => x[21] => x[9] => x[25]; 5 => x[61] => x[34] => x[23] => x[10] => x[5]; 6 => x[62] => x[35] => x[28] => x[11] => x[17]; 7 => x[63] => x[36] => x[24] => x[13] => x[16]; 8 => x[64] => x[37] => x[12] => x[14] => x[54]; 9 => x[65] => x[38] => x[18] => x[15] => x[55]; 10 => x[66] => x[39] => x[19] => x[51] => x[56]; 11 => x[67] => x[45] => x[47] => x[52] => x[229]; 12 => x[68] => x[46] => x[48] => x[49]; // Key y-axis coordinate int y[256]; 0 => y[49] => y[58] => y[59] => y[60] => y[61] => y[62] => y[63] => y[64] => y[65] => y[66] => y[67] => y[68] => y[69]; 1 => y[100] => y[30] => y[31] => y[32] => y[33] => y[34] => y[35] => y[36] => y[37] => y[38] => y[39] => y[45] => y[46]; 2 => y[20] => y[26] => y[8] => y[21] => y[23] => y[28] => y[24] => y[12] => y[18] => y[19] => y[47] => y[48]; 3 => y[4] => y[22] => y[7] => y[9] => y[10] => y[11] => y[13] => y[14] => y[15] => y[51] => y[52] => y[49]; 4 => y[53] => y[29] => y[27] => y[6] => y[25] => y[5] => y[17] => y[16] => y[54] => y[55] => y[56] => y[229]; // Key serving as origin 7 => int x0; 3 => int y0; int init[256]; // Tuning frequency 440.0 => float f0; Gain g; .1 => g.gain; BeeThree s[256]; JCRev r => dac; r => Echo e => Echo e2 => dac; // set delays 240::ms => e.max => e.delay; 480::ms => e2.max => e2.delay; // set gains .6 => e.gain; .3 => e2.gain; .05 => r.mix; // Infinite event loop. while(true) { // Wait on event. kb => now; // get one or more messages while(kb.recv(msg)) { // Print. if(msg.isButtonDown()) <<< " key", msg.which, "down (", x[msg.which], ",", y[msg.which], ")" >>>; else <<< " key", msg.which, "down (", x[msg.which], ",", y[msg.which], ")" >>>; // Play a note. if (!((x[msg.which] == 0) && (y[msg.which] == 0))) if(msg.isButtonDown()) { if (init[msg.which] == 0) { 1 => init[msg.which]; s[msg.which] => r; } f0 * Math.pow(2, (5*(x[msg.which] - x0) + 3*(y[msg.which] - y0))/31.0) => s[msg.which].freq; 1 => s[msg.which].noteOn; } else { if (init[msg.which] == 1) { 0 => init[msg.which]; s[msg.which] =< r; } 1 => s[msg.which].noteOff; } } }