diff options
| -rw-r--r-- | intervals.lua | 89 | 
1 files changed, 74 insertions, 15 deletions
| diff --git a/intervals.lua b/intervals.lua index e74a575..8c8538d 100644 --- a/intervals.lua +++ b/intervals.lua @@ -12,11 +12,9 @@  -- 3) select base tone  -- 4) key signatures  -- 5) play from input --- 6) midi out --- 7) parameters ---    - delay, ---    - midi out y/n ---    - amplitude + +local ControlSpec = require "controlspec" +-- TODO use MusicUtil  -- graphics and audio utilities  function midi_to_hz(note) @@ -253,10 +251,7 @@ end  -- end mode library -engine.name = 'PolyPerc' -function play(hz) -  engine.hz(hz) -end +  function message (msgs, tick_fn, midi_fn) @@ -352,7 +347,7 @@ end  function play_and_wait_2 (known, guess)    return {      init=function () -      play(midi_to_hz(guess)) +      play(guess)        return state_redraw      end,      redraw=function() @@ -387,7 +382,7 @@ function play_and_wait_1 (midi_note)    complete = nil    return {      init=function () -      play(midi_to_hz(midi_note)) +      play(midi_note)        return state_redraw      end,      redraw=function() @@ -463,18 +458,82 @@ 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) +  if intervals_state.play_audio then +    engine.hz(midi_to_hz(note)) +  end +  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.event = function(time) +      t:stop() +      metro.free(t.id) +      intervals_state.midi_out:note_off(note, 32) +    end +    intervals_state.midi_out:note_on(note, 80) +    t:start() +  end +end +  function init() -  play(midi_to_hz(60))    -- initialize midi -  m = midi.connect() -  m.event = function (a) +  -- TODO configure vport +  intervals_state.midi_in = midi.connect(1) +  intervals_state.midi_in.event = function (a)      b = midi.to_msg(a)      -- monitor      if b.type == "note_on" then -      play(midi_to_hz(b.note)) +      play(b.note, b.vel)      end      state_call(intervals_state, "midi", {b})    end +  intervals_state.midi_out = midi.connect(2) + +  -- TODO save +  params:add({ +    type = "option", +    id = "output", +    name = "Output", +    options = {"play + midi", "play", "midi"}, +    action = function(value) +      if value == 1 then +        intervals_state.play_midi = true +        intervals_state.play_audio = true +      end +      if value == 2 then +        intervals_state.play_midi = false +        intervals_state.play_audio = true +      end +      if value == 3 then +        intervals_state.play_midi = true +        intervals_state.play_audio = false +      end +    end +  }) +  params:add({ +    type = "control", +    id = "wait", +    name = "Wait Time", +    default=60, +    controlspec = ControlSpec.new(0.0001, 3, 'lin', 0.1, 1.0, "secs"), +    action = function(value) +      intervals_state.tick_interval = value +      if intervals_state.timer then +        intervals_state.timer.time = value +      end +  end}) +  params:bang() + +  play(60) +  end  function cleanup() | 
