{
   "labels" : [],
   "is_private" : null,
   "id" : "1-4WB",
   "code" : "//PLACE MOUSE CURSOR ON EACH OF THE NUMBERS IN ORDER AND HIT CMD-RETURN\r\n\r\n(\r\n// 1):\r\n// Initialize\r\nvar currMidiNum, noteNames, octaves, screenRes, yres;\r\n~pitchLo = \\a0;\r\n~pitchHi = \\c8;\r\n\r\n//MIDI NOTE DICTIONARY\r\n////Allows you to input a symbol and get out the midi note number\r\n////Use only these symbols:\r\n//// \\c, \\cs, \\d, \\eb, \\e, \\f, \\fs, \\g, \\gs, \\a, \\bb, \\b\r\n\r\n~mnd = ();\r\ncurrMidiNum = 0;\r\nnoteNames = [\\c, \\cs, \\d, \\eb, \\e, \\f, \\fs, \\g, \\gs, \\a, \\bb, \\b];\r\noctaves = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];\r\noctaves.do{ |it ix|\r\n\tnoteNames.do{ |it2 ix2|\r\n\t\t~mnd.put((it2 ++ it).asSymbol, currMidiNum);\r\n\t\tcurrMidiNum = currMidiNum+1;\r\n\t}\r\n};\r\n\r\n//FUNCTION TO LOOK UP Y-LOCATION FOR A PITCH\r\n\r\nscreenRes = \"system_profiler SPDisplaysDataType | grep Resolution\".unixCmdGetStdOut.findRegexp(\"(?<!@ )[0-9]{3,}\").collect({|item| item[1].asInteger}).clump(2);\r\n~yres = screenRes[0][1];\r\n\r\n~midiToY = {\r\n\targ midinote;\r\n\t~mnd[midinote].linlin(~mnd[~pitchLo].asFloat, ~mnd[~pitchHi].asFloat, ~yres, 0.0).round;\r\n};\r\n\r\n//SYNTHDEF\r\nSynthDef(\\mouseTheremin, {\r\n\targ pitchLo = 30, pitchHi = 80, pitchres=1.0;\r\n\tvar osc, freq, env, envgate, pitch, amp;\r\n\tamp = MouseX.kr(-40, 10).dbamp;\r\n\tpitch = MouseY.kr(minval:pitchHi, maxval:pitchLo, lag:0.0001).round(pitchres);\r\n\tenvgate = MouseButton.kr(lag:0.0001);\r\n\tenv = EnvGen.ar( envelope:Env.asr(releaseTime:0.05), gate:envgate );\r\n\tfreq = pitch.midicps;\r\n\tosc = SinOsc.ar( freq );\r\n\tOut.ar(0, osc*env*amp);\r\n}).add;\r\n\r\n) ///////////////////////////////////////////////////////////\r\n\r\n(\r\n// 2):\r\n// Boot Server\r\ns.boot;\r\n)\r\n\r\n(\r\n// 3):\r\n// Start Synth\r\n~mt = Synth(\\mouseTheremin, [\\pitchLo, ~mnd[~pitchLo], \\pitchHi, ~mnd[~pitchHi]]);\r\n)\r\n\r\n\r\n// TO STOP SYNTH OR USE CMD-.\r\n~mt.free;\r\n\r\n\r\n\r\n//UTILITIES\r\n\r\n//EXAMPLE OF MIDI NOTE TO Y COORDINATE TO LOOK UP VALUES FOR YOUR PROCESSING PATCH:\r\n////Use only these symbols:\r\n//// \\c, \\cs, \\d, \\eb, \\e, \\f, \\fs, \\g, \\gs, \\a, \\bb, \\b\r\n~midiToY.value(\\g5);\r\n~midiToY.value(\\fs4);\r\n//Look @ Post Window\r\n\r\n\r\n//USE THESE TO 'PLAY ALONG' AND THEN FIND MIDI PITCH\r\n~mspoll = {MouseY.kr(~mnd[~pitchHi], ~mnd[~pitchLo]).round.poll}.play;\r\n~mnd.findKeyForValue(66);\r\n\r\n\r\n~mspoll.free;",
   "name" : "mousetheremin",
   "author" : "justinwenloyang",
   "ancestor_list" : [],
   "description" : "Simple mouse theremin for Designing Digital Music and Interaction"
}
