Skip to content

Commit 31b0b64

Browse files
committed
migrate truths
1 parent 296cc7c commit 31b0b64

File tree

1 file changed

+33
-78
lines changed

1 file changed

+33
-78
lines changed

truths/truths.lua

Lines changed: 33 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,56 @@
11
-- truths
22

33
local BGUtil = include('bitgraves/common/bgutil')
4+
local BGMidi = include('bitgraves/common/bgmidi')
45
local Hexagon = include('bitgraves/common/hexagon')
56

67
engine.name = 'Truths'
78
mid = nil
89

910
local indexOffset = 2
11+
local MPD218
1012

1113
function init()
12-
audio:rev_off() -- no system reverb
13-
audio:pitch_off() -- no system pitch analysis
14-
audio:monitor_mono() -- expect only channel 1 input
14+
BGUtil.configureSystemStuff()
1515

16-
params:add_control("bend", "bend", controlspec.new(0, 1, 'lin', 0, 0, ''))
17-
params:set_action("bend", function(x)
18-
engine.bend(util.linlin(0, 1, 0, -2, x))
19-
end)
20-
21-
params:add_control("carrierSource", "carrierSource", controlspec.new(0, 1, 'lin', 0, 0, ''))
22-
params:set_action("carrierSource", function(x)
23-
engine.carrierInAmp(util.linlin(0, 1, 1, 0, x))
24-
engine.carrierNoiseAmp(util.linlin(0, 1, 0.2, 1, x))
25-
end)
26-
27-
params:add_control("modulatorSource", "modulatorSource", controlspec.new(0, 1, 'lin', 0, 0, ''))
28-
params:set_action("modulatorSource", function(x)
29-
engine.modSource(x)
30-
end)
31-
32-
params:add_control("sustain", "sustain", controlspec.new(0, 1, 'lin', 0, 0, ''))
33-
params:set_action("sustain", function(x)
34-
engine.sustain(x)
35-
end)
16+
BGUtil.addEngineControlParam(params, { id = "amp" })
17+
BGUtil.addEngineControlParam(params, {
18+
id = "bend",
19+
max = 2,
20+
action = function(x)
21+
engine.bend(x * -1) -- max < 1 fails for some reason
22+
end,
23+
})
24+
BGUtil.addEngineControlParam(params, { id = "modSource" })
25+
BGUtil.addEngineControlParam(params, { id = "sustain" })
26+
BGUtil.addEngineControlParam(params, {
27+
id = "carrierSource",
28+
action = function(x)
29+
engine.carrierInAmp(util.linlin(0, 1, 1, 0, x))
30+
engine.carrierNoiseAmp(util.linlin(0, 1, 0.2, 1, x))
31+
end,
32+
})
3633

37-
params:add_control("amp", "amp", controlspec.new(0, 1, 'lin', 0, 0, ''))
38-
params:set_action("amp", function(x)
39-
engine.amp(x)
40-
end)
41-
4234
params:add_control("monitor", "monitor", controlspec.new(0, 1, 'lin', 0, 0, ''))
4335
params:set_action("monitor", function(x)
4436
audio.level_monitor(x)
4537
end)
4638

39+
MPD218 = BGMidi.newInputMappingMPD218({
40+
[3] = 'bend',
41+
[9] = 'carrierSource',
42+
[12] = 'modSource',
43+
[13] = 'sustain',
44+
[14] = 'monitor',
45+
[15] = 'amp',
46+
-- [16] = 'padOffset',
47+
})
48+
4749
mid = midi.connect()
4850
mid.event = midiEvent
4951
redraw()
5052
end
5153

52-
function enc(nEnc, delta)
53-
54-
end
55-
56-
-- mapping from Akai MPD218 knobs to param handlers
57-
local ccAkaiMapping = {
58-
[3] = 'bend',
59-
[9] = 'carrierSource',
60-
[12] = 'modulatorSource',
61-
[13] = 'sustain',
62-
[14] = 'monitor',
63-
[15] = 'amp',
64-
[16] = 'padOffset',
65-
}
66-
67-
local ccHandlers = {
68-
['bend'] = function(val)
69-
params:set('bend', val)
70-
return 'bend ' .. val
71-
end,
72-
['carrierSource'] = function(val)
73-
params:set('carrierSource', val)
74-
return 'carrier noise ' .. val
75-
end,
76-
['modulatorSource'] = function(val)
77-
params:set('modulatorSource', val)
78-
return 'in mod ' .. val
79-
end,
80-
['sustain'] = function(val)
81-
params:set('sustain', val)
82-
return 'sustain ' .. val
83-
end,
84-
['monitor'] = function(val)
85-
params:set('monitor', val)
86-
return 'monitor ' .. val
87-
end,
88-
['amp'] = function(val)
89-
params:set('amp', val)
90-
return 'amp ' .. val
91-
end,
92-
['padOffset'] = function(val)
93-
indexOffset = math.floor(util.linlin(0, 1, 0, 12, val))
94-
return 'pad offset ' .. indexOffset
95-
end,
96-
}
97-
9854
function midiEvent(data)
9955
-- tab.print(midi.to_msg(data))
10056
local d = midi.to_msg(data)
@@ -105,14 +61,13 @@ function midiEvent(data)
10561
local index = d.note - 36
10662
engine.noteOff(index + indexOffset)
10763
elseif d.type == 'cc' then
108-
local handler = ccAkaiMapping[d.cc]
109-
if handler ~= nil and ccHandlers[handler] ~= nil then
110-
local msg = ccHandlers[handler](d.val / 127)
64+
local handled, msg = BGMidi.handleCCMPD218(MPD218, params, d.cc, d.val)
65+
if handled then
11166
redraw(msg)
11267
end
11368
end
11469
end
11570

11671
function redraw(msg)
117-
Hexagon:draw(msg, ccAkaiMapping)
72+
Hexagon:drawFancy(MPD218, msg)
11873
end

0 commit comments

Comments
 (0)