Skip to content

Commit

Permalink
migrate linda
Browse files Browse the repository at this point in the history
  • Loading branch information
terribleben committed Feb 14, 2021
1 parent 16d6e8e commit 2024c8e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 68 deletions.
2 changes: 1 addition & 1 deletion linda/lib/Engine_Linda.sc
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ Engine_Linda : CroneEngine {
sEffects.set(\amp, msg[1]);
});
this.addCommand("noteOffset", "f", {|msg|
bNoteOffset.set(msg[1].linlin(0, 1, -4, -24).round);
bNoteOffset.set(msg[1].round);
});
this.addCommand("filterCreep", "f", {|msg|
bFilterCreep.set(msg[1]);
Expand Down
91 changes: 24 additions & 67 deletions linda/linda.lua
Original file line number Diff line number Diff line change
@@ -1,104 +1,61 @@
-- linda - WIP
-- linda

local BGUtil = include('bitgraves/common/bgutil')
local BGMidi = include('bitgraves/common/bgmidi')
local Hexagon = include('bitgraves/common/hexagon')

engine.name = 'Linda'
mid = nil
local MPD218

function init()
audio:rev_off() -- no system reverb
audio:pitch_off() -- no system pitch analysis
audio:monitor_mono() -- expect only channel 1 input

params:add_control('amp', 'amp', controlspec.new(0, 1, 'lin', 0, 0.5, ''))
params:set_action('amp', function(x)
engine.amp(x)
end)

params:add_control('noteOffset', 'noteOffset', controlspec.new(0, 1, 'lin', 0, 0, ''))
params:set_action('noteOffset', function(x)
engine.noteOffset(x)
end)
BGUtil.configureSystemStuff()

BGUtil.addEngineControlParam(params, { id = "amp" })
BGUtil.addEngineControlParam(params, {
id = "noteOffset",
min = 4,
max = 24,
action = function(x) engine.noteOffset(x * -1) end, -- param won't work when max is -24 for some reason
})
BGUtil.addEngineControlParam(params, { id = "filterCreep" })
BGUtil.addEngineControlParam(params, { id = "shudderDuration" })

params:add_control('monitor', 'monitor', controlspec.new(0, 1, 'lin', 0, 0, ''))
params:set_action('monitor', function(x)
audio.level_monitor(x)
end)

params:add_control('filterCreep', 'filterCreep', controlspec.new(0, 1, 'lin', 0, 0, ''))
params:set_action('filterCreep', function(x)
engine.filterCreep(x)
end)

params:add_control('shudderDuration', 'shudderDuration', controlspec.new(0, 1, 'lin', 0, 0, ''))
params:set_action('shudderDuration', function(x)
engine.shudderDuration(x)
end)
MPD218 = BGMidi.newInputMappingMPD218({
[9] = 'noteOffset',
[12] = 'filterCreep',
[13] = 'shudderDuration',
[14] = 'monitor',
[15] = 'amp',
})

mid = midi.connect()
mid.event = midiEvent
redraw()
end

-- expose a couple params via enc for debugging
function enc(nEnc, delta)
if nEnc == 2 then
params:delta('mix', delta)
end
end

-- mapping from Akai MPD218 knobs to param handlers
local ccAkaiMapping = {
[9] = 'noteOffset',
[12] = 'filterCreep',
[13] = 'shudderDuration',
[14] = 'monitor',
[15] = 'amp',
}

function key(...)
BGUtil.setlist_key('processing/linda', ...)
end

local ccHandlers = {
['noteOffset'] = function(val)
params:set('noteOffset', val)
local printVal = math.floor(util.linlin(0, 1, -4, -24, val))
return 'pad offset ' .. tostring(printVal)
end,
['filterCreep'] = function(val)
params:set('filterCreep', val)
return 'filter creep ' .. tostring(val)
end,
['shudderDuration'] = function(val)
params:set('shudderDuration', val)
return 'rhythm ' .. tostring(val)
end,
['monitor'] = function(val)
params:set('monitor', val)
return 'monitor ' .. val
end,
['amp'] = function(val)
params:set('amp', val)
return 'amp ' .. val
end,
}

function midiEvent(data)
local d = midi.to_msg(data)
if d.type == 'note_on' then
local note = d.note - 36
engine.noteOn(note)
elseif d.type == 'cc' then
local handler = ccAkaiMapping[d.cc]
if handler ~= nil and ccHandlers[handler] ~= nil then
local msg = ccHandlers[handler](d.val / 127)
local handled, msg = BGMidi.handleCCMPD218(MPD218, params, d.cc, d.val)
if handled then
redraw(msg)
end
end
end

function redraw(msg)
Hexagon:draw(msg, ccAkaiMapping)
Hexagon:drawFancy(MPD218, msg)
end

0 comments on commit 2024c8e

Please sign in to comment.