Skip to content

Commit

Permalink
migrate baaka
Browse files Browse the repository at this point in the history
  • Loading branch information
terribleben committed Feb 14, 2021
1 parent 2024c8e commit 296cc7c
Showing 1 changed file with 28 additions and 74 deletions.
102 changes: 28 additions & 74 deletions 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()
Expand All @@ -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)
Expand All @@ -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

0 comments on commit 296cc7c

Please sign in to comment.