Skip to content

Commit

Permalink
Added midi continue support
Browse files Browse the repository at this point in the history
I really think this should be handled by `clock.transport`. It already handles start and stop messages from midi devices. I'm not really happy about splitting transport responsibilities between `clock` and handling them manually in my script. Because of this, I'm implementing this in the least invasive way I can think of.

Added new params for midi continue device and mode
Device is the midi device to listen for "continue" messages from
Mode is whether a "continue" message always plays or toggles playback (like a play/pause button)
Updated readme with release notes
  • Loading branch information
Jake Carter committed Dec 28, 2022
1 parent 7d1df89 commit eb3fd33
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ The size determines how long the sound will last. Larger circles will sound out

There are also a few parameters to adjust under the _KEY 1_ parameters page. Play around with those.

### v1.6.1

Minor update to add midi continue support.

- Added two new params; midi continue device and midi continue mode
- Midi continue device lets you choose which device to listen for "continue" messages from; This allows you to choose a different midi device for "continue" messages than the device you're sending midi out messages to
- Midi continue mode lets you choose if new "continue" messages always start playback or toggle so you can use it as a play/pause button
- Grouped new params in "midi continue" group

### v1.6

This is a pretty major update under the hood. Because of that I took this as an opportunity to update some of the param IDs. This means that existing PSETs will probably result in unexpected behavior.
Expand Down
31 changes: 30 additions & 1 deletion circles.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- oO ( circles ) Oo
-- v1.6 @jakecarter
-- v1.6.1 @jakecarter
-- llllllll.co/t/22951
--
-- ENC 2 & 3 move cursor
Expand Down Expand Up @@ -34,10 +34,13 @@ local isRunning = true
-- enums
local outputs = { audio = 1, midi = 2, crow = 3, crow_jf = 4 }
local radius_affects = { release = 1, amp = 2 }
local midi_continue_modes = { always_play = 1, toggle= 2 }

local midi_devices
local midi_out_device
local midi_out_channel
local midi_continue_device
local midi_continue_mode
function build_midi_device_list()
midi_devices = {}
for i = 1,#midi.vports do
Expand Down Expand Up @@ -100,6 +103,19 @@ function setupParams()
action = function() build_scale_notes() end
})

-- midi continue
params:add_group("midi continue", 2)
params:add({type = "option", id = "midi_continue_device", name = "device",
options = midi_devices, default = 1,
action = function(value)
midi_continue_device = midi.connect(value)
end
})
params:add_option("midi_continue_mode", "mode", { "always play", "toggle" })
params:set_action("midi_continue_mode", function(value)
midi_continue_mode = value
end)

-- libCircles
params:add_option("keep_on_screen", "keep on screen", { "no", "yes" })
params:set_action("keep_on_screen", function(value)
Expand Down Expand Up @@ -134,6 +150,7 @@ function init()
build_midi_device_list()

setupParams()
midi_continue_device.event = midi_continue_device_event

clock.run(step)
end
Expand Down Expand Up @@ -169,6 +186,18 @@ function clock.transport.stop()
isRunning = false
end

function midi_continue_device_event(data)
msg = midi.to_msg(data)

if msg.type == "continue" then
if midi_continue_mode == midi_continue_modes.always_play then
isRunning = true
elseif midi_continue_mode == midi_continue_modes.toggle then
isRunning = not isRunning
end
end
end

function noteForCircle(circle)
local noteIndex = math.floor(math_helpers.scale(circle.x, 0, 128, 1, #scale_notes))
local note = scale_notes[noteIndex]
Expand Down

0 comments on commit eb3fd33

Please sign in to comment.