diff options
author | gretchen <gretchen@gnar.cool> | 2019-11-16 15:34:50 -0800 |
---|---|---|
committer | gretchen <gretchen@gnar.cool> | 2019-11-16 15:35:04 -0800 |
commit | 8fcdea3150dd9442170ef8604a17430f445d7c23 (patch) | |
tree | a2edf48a336a75b6ddc1ff912aa400f951d7e72e | |
parent | 6233537417149704c252e77cd80e992539feb97b (diff) | |
download | intervals-8fcdea3150dd9442170ef8604a17430f445d7c23.tar.gz intervals-8fcdea3150dd9442170ef8604a17430f445d7c23.zip |
first stab at parameters and midi out.
-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() |