while this is both a cool idea & possible, the model “use cheat codes on the grid, play passersby with a midi controller” would be about 1000% times easier and a totally approachable starting point for a beginner
essentially, midi and grid are handled by separate blocks of code called functions. so combining midi and grid (which live in separate functions) would be much more cut and paste, whereas your original idea would require a rewritten grid function(s) that handles both passersby and cheat codes
for starters, here’s a block of code from passersby (on GitHub) that handles midi (+ shares it w the engine)
-- Engine functions
local function note_on(note_num, vel)
engine.noteOn(note_num, MusicUtil.note_num_to_freq(note_num), vel)
table.insert(active_notes, note_num)
input_indicator_active = true
screen_dirty = true
end
local function note_off(note_num)
engine.noteOff(note_num)
for i = #active_notes, 1, -1 do
if active_notes[i] == note_num then
table.remove(active_notes, i)
end
end
if #active_notes == 0 then
input_indicator_active = false
screen_dirty = true
end
end
local function set_pitch_bend(bend_st)
engine.pitchBendAll(MusicUtil.interval_to_ratio(bend_st))
end
local function set_channel_pressure(pressure)
engine.pressureAll(pressure)
end
-- MIDI input
local function midi_event(data)
local msg = midi.to_msg(data)
local channel_param = params:get("midi_channel")
if channel_param == 1 or (channel_param > 1 and msg.ch == channel_param - 1) then
-- Note on
if msg.type == "note_on" then
note_on(msg.note, msg.vel / 127)
-- Note off
elseif msg.type == "note_off" then
note_off(msg.note)
-- Pitch bend
elseif msg.type == "pitchbend" then
local bend_st = (util.round(msg.val / 2)) / 8192 * 2 -1 -- Convert to -1 to 1
set_pitch_bend(bend_st * params:get("bend_range"))
-- Pressure
elseif msg.type == "channel_pressure" or msg.type == "key_pressure" then
set_channel_pressure(msg.val / 127)
end
end
end
not too bad to read over !
this, plus another line which orders up the passersby engine from supercollider
local Passersby = require "passersby/lib/passersby_engine"
is pretty much the “meat” of that task I laid out. I’m probably (definitely (edited to add engine functions a few lines up)) missing a few bits and bobs, but pasting those two chunks (+ determining how you want to change the sound, maybe params) will be close to all you need to add a simple midi synth to any softcut script