diff options
-rw-r--r-- | intervals.lua | 46 |
1 files changed, 39 insertions, 7 deletions
diff --git a/intervals.lua b/intervals.lua index 8c8538d..6096e1d 100644 --- a/intervals.lua +++ b/intervals.lua @@ -460,25 +460,36 @@ intervals_state = { engine.name = 'PolyPerc' -- TODO fix globals here --- TODO note_on vs note_off --- TODO parameters for velocity and for note_off delay -function play(note, once) +function play_start(note, vel) if intervals_state.play_audio then engine.hz(midi_to_hz(note)) end if intervals_state.play_midi then + intervals_state.midi_out:note_on(note, vel or intervals_state.note_vel) + end +end + +function play_stop(note, vel) + if intervals_state.play_midi then + intervals_state.midi_out:note_off(note, vel or intervals_state.note_vel) + end +end + + +function play(note, vel) + play_start(note, vel) + if intervals_state.play_midi then -- if state.timer then -- state.timer:stop() -- metro.free(state.timer.id) -- end local t = metro.init() - t.time = 0.15 + t.time = intervals_state.note_length t.event = function(time) t:stop() metro.free(t.id) - intervals_state.midi_out:note_off(note, 32) + play_stop(note, vel) end - intervals_state.midi_out:note_on(note, 80) t:start() end end @@ -491,7 +502,10 @@ function init() b = midi.to_msg(a) -- monitor if b.type == "note_on" then - play(b.note, b.vel) + play_start(b.note, b.vel) + end + if b.type == "note_off" or b.vel == 0 then + play_stop(b.note, b.vel) end state_call(intervals_state, "midi", {b}) end @@ -530,6 +544,24 @@ function init() intervals_state.timer.time = value end end}) + params:add({ + type = "control", + id = "note_length", + name = "Note length", + default=60, + controlspec = ControlSpec.new(0.0001, 3, 'lin', 0.05, 0.55, "secs"), + action = function(value) + intervals_state.note_length = value + end}) + params:add({ + type = "control", + id = "note_vel", + name = "Note velocity", + default=60, + controlspec = ControlSpec.new(1, 127, 'lin', 1.0, 20), + action = function(value) + intervals_state.note_vel = value + end}) params:bang() play(60) |