#-- 100 bruits . 100 -> m1 m1 :play(n[tok]) -> m1 #-- 200 gamme Do mineur #-- claire . 200 -> m2 m2 2:play(36) -> m2 m2 5:play(31) -> m2 m2 6:play(38) -> m22 m2 1:play(37) -> m2 #-- security: goto start m22 2:play(39) -> m22 m22 5:play(34) -> m22 m22 6:play(38) -> m23 m22 1:play(37) -> m2 #-- security: goto start m23 2:play(36) -> m23 m23 5:play(31) -> m23 m23 6:play(37) -> m24 m23 1:play(37) -> m2 #-- security: goto start m24 2:play(38) -> m24 m24 5:play(31) -> m24 m24 6:play(37) -> m2 m24 1:play(37) -> m2 #-- security: goto start #-- 300 gamme Do mineur legato . 300 -> m3 #--m3 :play(n[tok]) -> m3 m3 3:{play(33,nil,nil,540);play(36,nil,nil,810);play(24)} -> m3 m3 6:{play(33,nil,nil,540);play(36,nil,nil,810);play(24)} -> m3 m3 9:play(nil) -> m3 #-- 400 gamme Re mineur . 400 -> m4 m4 :play(n[tok]) -> m4 m4 2:play(31) -> m4 m4 6:play(41) -> m4 #-- 500 Gamme Sol majeur . 500 -> m5 m5 :legato(n[tok]) -> m5 m5 2:legato({24,36,39,43} ) -> m5 m5 3:legato({27,36,39,43} ) -> m5 m5 1:legato({20,32,36,39,43} ) -> m5 m5 5:legato({23,35,39,43} ) -> m5 m5 6:legato({19,36,39} ) -> m5 m5 4:legato(nil ) -> m5 #-- 600 . 600 -> m6 m6 :play(n[tok]) -> m6 m6 1:play(31) -> m6 m6 2:play(33) -> m6 m6 3:play(34) -> m6 m6 4:play(36) -> m6 m6 5:play(37) -> m6 m6 6:play(38) -> m6 m6 7:play(41) -> m6 m6 8:play(42) -> m6 m6 9:play(nil) -> m6 #-- 700 accord Do mineur . 700 -> m7 m7 :legato(n[tok]) -> m7 m7 4:legato(nil) -> m7 #--m7 1:play({34,38,41,44}) -> m7 #--m7 2:play({31,34,39}) -> m7 #--m7 3:play({26,29,32}) -> m7 #--m7 4:play({32,35,38}) -> m7 #--m7 5:play({32,36,41}) -> m7 #--m7 6:play({24,27,31}) -> m7 #--m7 7:play({35,38,41}) -> m7 #--m7 8:play({32,36,39}) -> m7 #--m7 9:play({45,46}) -> m7 #-- 800 . 800 -> m8 m8 :play(n[tok]) -> m8 m8 1:play(31) -> m8 m8 2:play(33) -> m8 m8 3:play(34) -> m8 m8 4:play(36) -> m8 m8 5:play(37) -> m8 m8 6:play(38) -> m8 m8 7:play(41) -> m8 m8 8:play(42) -> m8 m8 9:play(nil) -> m8 #-- 900 batterie . 900 -> m9 m9 :play(n[tok]) -> m9 =begin lua -------------------- TUNING ------------- channel = 2 t = {} t[0] = -0.8 t[1] = 20 t[2] = 25 t[3] = 15 t[4] = 20 t[5] = 25 t[6] = 10 t[7] = 5 t[8] = 27 t[9] = 45 t[10] = 20 t[11] = 10 t[12] = 7 t[13] = 40 t[14] = 40 t[15] = 40 t[16] = 40 t[17] = 40 t[18] = 40 v = {} -- velocity range v[0] = 0 v[1] = {1.5,3.0} v[2] = {7.0,9.0} v[3] = {2.0,4.0} v[4] = {1.5,2.9} v[5] = {2.0,6.0} v[6] = {2.0,4.0} v[7] = {0.5,3.0} v[8] = {0.5,3.0} v[9] = {0.5,3.0} v[10] = {0.5,3.0} v[11] = {0.5,3.0} v[12] = {0.5,3.0} v[13] = {2.0, 4.5} v[14] = {2.0, 4.5} v[15] = {2.0, 4.5} v[16] = {2.0, 4.5} v[17] = {2.0, 4.5} v[18] = {2.0, 4.5} -------------------- END TUNING ------------- old = 0 wait = 0 token = {} token[46] = 0 token[49] = 1 token[50] = 2 token[51] = 3 token[52] = 4 token[53] = 5 token[54] = 6 token[55] = 7 token[56] = 8 token[57] = 9 token[97] = 10 -- a token[98] = 11 -- b token[99] = 12 -- c token[120] = 10 -- x token[121] = 11 -- y token[122] = 12 -- z token[100] = 13 -- d token[101] = 14 -- e token[102] = 15 -- f token[103] = 16 -- g token[104] = 17 -- h token[105] = 18 -- i n = {} n[0] = 0 --notes !! n[1] = 24 --notes !! n[2] = 26 --notes !! n[3] = 27 --notes !! n[4] = 29 --notes !! n[5] = 31 --notes !! n[6] = 32 --notes !! n[7] = 34 --notes !! n[8] = 35 --notes !! n[9] = 36 --notes !! n[10] = 120 --notes !! n[11] = 122 --notes !! n[12] = 124 --notes !! n[13] = 38 --notes !! n[14] = 39 --notes !! n[15] = 41 --notes !! n[16] = 43 --notes !! n[17] = 44 --notes !! n[18] = 46 --notes !! wait2 = 0 wait3 = 0 mode = 0 -- in1 = {} -- raw in2 = {} -- diff in3 = 0 -- energy in4 = 46 -- label in5 = 0 -- distance ctr_mode = nil wawa = nil ctrl_leg = 3 wawa_max = 6.0 last_time = 0 -- when the last note occured ct_last = {} ct_wait = {} function bang() -- get token id from class 'char' tok = token[in4] -- special 'legato', 'control change' mode if (ctr_mode) then ctrl(19, (0 + in1[ctrl_leg] - ct_min) * 127 / (ct_max - ct_min)) end -- special 'wawa' mode (modulation when change) if (wawa) then ctrl(20, in3 * 127 / wawa_max) end -- low pass // threshold filter if (tok == nil or (tok == old and wait < 50) or in5 > t[tok]) then wait = wait + 1 return nil end --print('tok', tok, 'change', mode_change) wait = 0 old = tok -- mode change if (tok ~= nil and tok > 9 and tok < 13) then bell(n[tok]) if (mode_change == nil) then mode_change = tok return nil else if (mode_change == 10 and tok == 10) then clear_mode() mode = -24 return 100 -- claire end if (mode_change == 10 and tok == 11) then clear_mode() mode = 0 return 200 -- paul end if (mode_change == 10 and tok == 12) then clear_mode() mode = 0 channel = 8 return 300 -- ... end if (mode_change == 11 and tok == 10) then clear_mode() mode = 0 channel = 8 return 400 -- ... end if (mode_change == 11 and tok == 11) then clear_mode() mode = 0 return 500 -- ... end if (mode_change == 11 and tok == 12) then clear_mode() mode = 24 return 600 -- ... end if (mode_change == 12 and tok == 10) then clear_mode() mode = 48 wawa = true return 700 -- ... end if (mode_change == 12 and tok == 11) then clear_mode() mode = 0 channel = 8 return 800 -- ... end if (mode_change == 12 and tok == 12) then clear_mode() mode = 72 return 900 -- ... end mode_change = nil bell(n[13]) return nil end end mode_change = nil -- compute velocity -- velocity range from 30 to 130 velo = 30 + (in3 - v[tok][1]) * 100 / (v[tok][2]-v[tok][1]) -- clip to [20,127] if (velo > 127) then velo = 127 end if (velo < 20) then velo = 20 end -- debug print(tok, 'dist', in5, 'energy', in3, velo) -- normal operation in the turing machine return tok end -- play a note or chord, scaling with 'mode' value to have proper sound function play(note, duration, when_relative, when_abs) duration = duration or 300 when_abs = when_abs or 0 -- note off last note if (old_note) then note_off(old_note) end -- will play until note off if (duration == 0) then old_note = note end if (note == nil) then return end -- when to start note if (when_relative) then when = (current_time - last_time) * when_relative if (when > 2000) then return -- ignore end else last_time = current_time when = when_abs end if (type(note) == 'table') then -- chord for k,v in ipairs(note) do send_note(1, v + mode, velo, duration, channel, when) -- port, note, velo, length, channel, time end else -- note send_note(1, note+mode, velo, duration, channel, when) -- port, note, velo, length, channel, time end end -- stop playing note(s) function note_off(note) if (type(note) == 'table') then -- chord for k,v in ipairs(note) do send_note(1, v + mode, 0, 0, channel, 0) -- port, note, velo, length, channel, time end else -- note send_note(1, note+mode, 0, 0, channel, 0) -- port, note, velo, length, channel, time end old_note = nil end -- play a mode change bell function bell(note) send_note(1, note, 100, 300, channel, 0) -- port, note, velo, length, channel, time end -- play until next note function legato(note, when) play(note, 0, when) end function ctrl(id, ct) ct = math.floor(ct) ct_last[id] = ct_last[id] or 0 ct_wait[id] = ct_wait[id] or 0 if (ct < 1) then ct = 1 end if (ct > 127) then ct = 127 end if (ct ~= ct_last[id] and (ct_wait[id] > 5 and (ct_wait[id] > 30 or math.abs(ct - ct_last[id]) > 5))) then ct_wait[id] = 0 --print('wawa', ct, in3) send_ctrl(1, id, ct, channel, 0 ) -- port, ctrl, value, channel, time ct_last[id] = ct else ct_wait[id] = ct_wait[id] + 1 end end -- clear function clear_mode() send_ctrl(1, 19, 64, channel, 0 ) -- port, ctrl, value, channel, time send_ctrl(1, 20, 64, channel, 0 ) -- port, ctrl, value, channel, time mode_change = nil ctr_mode = nil wawa = nil ctrl_leg = 3 ct_min = -1.0 ct_max = 1.0 wawa_max = 6.0 legato(nil) channel = 2 end =end