diff --git a/processing/lib/Engine_Processing.sc b/processing/lib/Engine_Processing.sc index 2a6bc20..bf8dc72 100644 --- a/processing/lib/Engine_Processing.sc +++ b/processing/lib/Engine_Processing.sc @@ -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]; diff --git a/processing/processing.lua b/processing/processing.lua index 5c7e371..c06582f 100644 --- a/processing/processing.lua +++ b/processing/processing.lua @@ -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 @@ -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 \ No newline at end of file