Skip to content

Commit

Permalink
migrate processing
Browse files Browse the repository at this point in the history
  • Loading branch information
terribleben committed Feb 14, 2021
1 parent fe5b65e commit 16d6e8e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 74 deletions.
2 changes: 1 addition & 1 deletion processing/lib/Engine_Processing.sc
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Engine_Processing : CroneEngine {
sEffects.set(\amp, msg[1]);
});
this.addCommand("noteOffset", "f", {|msg|
bNoteOffset.set(msg[1].linlin(0, 1, 0, -24).round);
bNoteOffset.set(msg[1].round);
});
this.addCommand("pShudder", "f", {|msg|
gPShudder = msg[1];
Expand Down
96 changes: 23 additions & 73 deletions processing/processing.lua
Original file line number Diff line number Diff line change
@@ -1,100 +1,51 @@
-- processing chamber

local BGUtil = dofile(_path.code .. 'bitgraves/common/bgutil.lua')
local BGMidi = include('bitgraves/common/bgmidi')
local Hexagon = BGUtil.dofile_norns('common/hexagon.lua')

engine.name = 'Processing'
mid = nil

local triad = 0
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
BGUtil.configureSystemStuff()

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.addEngineControlParam(params, { id = "amp" })
BGUtil.addEngineControlParam(params, {
id = "noteOffset",
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 = "pShudder" })
BGUtil.addEngineControlParam(params, { id = "detune" })
BGUtil.addEngineControlParam(params, { id = "triad", action = function(x) triad = x end })

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('pShudder', 'pShudder', controlspec.new(0, 1, 'lin', 0, 0, ''))
params:set_action('pShudder', function(x)
engine.pShudder(x)
end)

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

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

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


function enc(nEnc, delta)

end

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

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

local ccHandlers = {
['triad'] = function(val)
params:set('triad', val)
return 'triad ' .. tostring(val)
end,
['noteOffset'] = function(val)
params:set('noteOffset', val)
local printVal = math.floor(util.linlin(0, 1, -4, -24, val))
return 'pad offset ' .. tostring(printVal)
end,
['detune'] = function(val)
params:set('detune', val)
return 'detune ' .. tostring(val)
end,
['pShudder'] = function(val)
params:set('pShudder', val)
return 'shudder ' .. 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
Expand All @@ -116,14 +67,13 @@ function midiEvent(data)
engine.monotonic(0)
end
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 16d6e8e

Please sign in to comment.