From 296cc7c5ffd6ce0dc5992c7a2e1436e506cde8c8 Mon Sep 17 00:00:00 2001 From: Ben Date: Sun, 14 Feb 2021 07:40:15 +0700 Subject: [PATCH] migrate baaka --- baaka/baaka.lua | 102 +++++++++++++----------------------------------- 1 file changed, 28 insertions(+), 74 deletions(-) diff --git a/baaka/baaka.lua b/baaka/baaka.lua index 8fca8e6..3cb2d62 100644 --- a/baaka/baaka.lua +++ b/baaka/baaka.lua @@ -1,52 +1,45 @@ -- baaka local BGUtil = include('bitgraves/common/bgutil') +local BGMidi = include('bitgraves/common/bgmidi') local Hexagon = include('bitgraves/common/hexagon') engine.name = 'Baaka' local mix = 0 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 + BGUtil.configureSystemStuff() - params:add_control("amp", "amp", controlspec.new(0, 1, 'lin', 0, 0, '')) - params:set_action("amp", function(x) - engine.amp(x) - end) - - params:add_control("mix", "mix", controlspec.new(0, 1, 'lin', 0, 0, '')) - params:set_action("mix", function(x) - engine.mix(x) - end) - - params:add_control("noiseFreq", "noiseFreq", controlspec.new(0, 1, 'lin', 0, 1, '')) - params:set_action("noiseFreq", function(x) - engine.noiseFreq(util.linexp(0, 1, 1000, 18000, x)) - end) - - params:add_control("seqFreq", "seqFreq", controlspec.new(3, 51, 'lin', 0, 10, 'hz')) - params:set_action("seqFreq", function(x) - engine.seqFreq(x) - end) - - params:add_control("oscFreq", "oscFreq", controlspec.new(0, 1, 'lin', 0, 0, '')) - params:set_action("oscFreq", function(x) - engine.oscFreq(util.linexp(0, 1, 110, 440, x)) - end) - - params:add_control("bend", "bend", controlspec.new(0, 1, 'lin', 0, 0, '')) - params:set_action("bend", function(x) - engine.bend(x) - end) + BGUtil.addEngineControlParam(params, { id = "amp" }) + BGUtil.addEngineControlParam(params, { + id = "mix", + action = function(x) + mix = x + engine.mix(x) + end, + }) + BGUtil.addEngineControlParam(params, { id = "noiseFreq", min = 1000, max = 18000, warp = 'exp' }) + BGUtil.addEngineControlParam(params, { id = "seqFreq", min = 3, max = 51 }) + BGUtil.addEngineControlParam(params, { id = "oscFreq", min = 110, max = 440, warp = 'exp' }) + BGUtil.addEngineControlParam(params, { id = "bend" }) + BGUtil.addEngineControlParam(params, { id = "amp" }) params:add_control("monitor", "monitor", controlspec.new(0, 1, 'lin', 0, 0, '')) params:set_action("monitor", function(x) audio.level_monitor(x) end) + MPD218 = BGMidi.newInputMappingMPD218({ + [3] = 'bend', + [9] = 'oscFreq', + [12] = 'mix', + [13] = 'noiseFreq', + [14] = 'monitor', + [15] = 'amp', + }) + mid = midi.connect() mid.event = midiEvent redraw() @@ -65,44 +58,6 @@ function key(...) BGUtil.setlist_key('baaka/baaka', ...) end --- mapping from Akai MPD218 knobs to param handlers -local ccAkaiMapping = { - [3] = 'bend', - [9] = 'oscFreq', - [12] = 'mix', - [13] = 'noiseFreq', - [14] = 'monitor', - [15] = 'amp', -} - -local ccHandlers = { - ['bend'] = function(val) - params:set('bend', val) - return 'bend ' .. tostring(val) - end, - ['oscFreq'] = function(val) - params:set('oscFreq', val) - return 'mod freq ' .. val - end, - ['mix'] = function(val) - mix = val - params:set('mix', mix) - return 'mix ' .. mix - end, - ['noiseFreq'] = function(val) - params:set('noiseFreq', val) - return 'noise freq ' .. 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) -- tab.print(midi.to_msg(data)) local d = midi.to_msg(data) @@ -118,14 +73,13 @@ function midiEvent(data) redraw('seq ' .. newSeqFreq) 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