1
1
-- truths
2
2
3
3
local BGUtil = include (' bitgraves/common/bgutil' )
4
+ local BGMidi = include (' bitgraves/common/bgmidi' )
4
5
local Hexagon = include (' bitgraves/common/hexagon' )
5
6
6
7
engine .name = ' Truths'
7
8
mid = nil
8
9
9
10
local indexOffset = 2
11
+ local MPD218
10
12
11
13
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 ()
15
15
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
+ })
36
33
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
-
42
34
params :add_control (" monitor" , " monitor" , controlspec .new (0 , 1 , ' lin' , 0 , 0 , ' ' ))
43
35
params :set_action (" monitor" , function (x )
44
36
audio .level_monitor (x )
45
37
end )
46
38
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
+
47
49
mid = midi .connect ()
48
50
mid .event = midiEvent
49
51
redraw ()
50
52
end
51
53
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
-
98
54
function midiEvent (data )
99
55
-- tab.print(midi.to_msg(data))
100
56
local d = midi .to_msg (data )
@@ -105,14 +61,13 @@ function midiEvent(data)
105
61
local index = d .note - 36
106
62
engine .noteOff (index + indexOffset )
107
63
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
111
66
redraw (msg )
112
67
end
113
68
end
114
69
end
115
70
116
71
function redraw (msg )
117
- Hexagon :draw ( msg , ccAkaiMapping )
72
+ Hexagon :drawFancy ( MPD218 , msg )
118
73
end
0 commit comments