-
Notifications
You must be signed in to change notification settings - Fork 0
/
roland_mtpdkit.lua
175 lines (146 loc) · 4.79 KB
/
roland_mtpdkit.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
ardour {
["type"] = "dsp",
name = "Roland TD4 to MTPowerDrumKit",
category = "Utility",
license = "MIT",
author = "Ardour Lua Task Force",
description = [[A plugin that allows using a Roland TD4 drum kit with the MT Power Drum Kit plugin.
It uses MIDI CC messages to determine the required MIDI note to play instead.
Default plugin settings are based on Roland TD4 and MT Power Drum Kit default values.
Pedal thresholds define the following ranges :
- [0, open threshold] => Open Hihat range
- ]open threshold, closed threshold] => Half Closed Hihat range
- ]closed threshold, 127] => Closed Hihat range]]
}
-- Here are all default values for the plugin
ROLAND_TD4_DEFAULT_HIHAT_NOTE = 26
ROLAND_TD4_HIHAT_PEDAL_CC_ID = 4
DEFAULT_HIHAT_OPEN_THRESHOLD = 0
DEFAULT_HIHAT_CLOSED_THRESHOLD = 120
MT_DEFAULT_HIHAT_CLOSED_NOTE = 42
MT_DEFAULT_HIHAT_HALF_CLOSED_NOTE = 83
MT_DEFAULT_HIHAT_OPEN_NOTE = 46
-- This is to store the current hihat note. The value is based on the last CC message we had.
local cur_hihat_note = HIHAT_OPEN_NOTE;
-- Parameter index enumeration
P_ROLAND_H_NOTE = 1
P_H_OPEN = 4
P_H_H_CLOSED = 5
P_H_CLOSED = 6
P_H_OPEN_THRESH = 2
P_H_CLOSED_THRESH = 3
function dsp_ioconfig ()
return { { midi_in = 1, midi_out = 1, audio_in = 0, audio_out = 0}, }
end
function dsp_params ()
local map_scalepoints = {}
for note=0,127 do
local name = ARDOUR.ParameterDescriptor.midi_note_name(note)
map_scalepoints[string.format("%03d (%s)", note, name)] = note
end
local map_params = {}
map_params[P_ROLAND_H_NOTE] = {
["type"] = "input",
name = "Roland TD4 Hihat note",
min = 0,
max = 127,
default = ROLAND_TD4_DEFAULT_HIHAT_NOTE,
integer = true,
enum = true,
scalepoints = map_scalepoints
}
map_params[P_H_OPEN] = {
["type"] = "input",
name = "MT Power Drum kit open Hihat note",
min = 0,
max = 127,
default = MT_DEFAULT_HIHAT_OPEN_NOTE,
integer = true,
enum = true,
scalepoints = map_scalepoints
}
map_params[P_H_H_CLOSED] = {
["type"] = "input",
name = "MT Power Drum kit half closed Hihat note",
min = 0,
max = 127,
default = MT_DEFAULT_HIHAT_HALF_CLOSED_NOTE,
integer = true,
enum = true,
scalepoints = map_scalepoints
}
map_params[P_H_CLOSED] = {
["type"] = "input",
name = "MT Power Drum kit closed Hihat note",
min = 0,
max = 127,
default = MT_DEFAULT_HIHAT_CLOSED_NOTE,
integer = true,
enum = true,
scalepoints = map_scalepoints
}
map_params[P_H_OPEN_THRESH] = {
["type"] = "input",
name = "Roland TD4 Hihat pedal open threshold",
min = 0,
max = 127,
default = DEFAULT_HIHAT_OPEN_THRESHOLD,
integer = true,
}
map_params[P_H_CLOSED_THRESH] = {
["type"] = "input",
name = "Roland TD4 Hihat pedal closed threshold",
min = 0,
max = 127,
default = DEFAULT_HIHAT_CLOSED_THRESHOLD,
integer = true,
}
return map_params
end
function dsp_run (_, _, n_samples)
assert (type(midiin) == "table")
assert (type(midiout) == "table")
local cnt = 1;
function tx_midi (time, data)
midiout[cnt] = {}
midiout[cnt]["time"] = time;
midiout[cnt]["data"] = data;
cnt = cnt + 1;
end
local ctrl = CtrlPorts:array()
-- for each incoming midi event
for _,b in pairs (midiin) do
local t = b["time"] -- t = [ 1 .. n_samples ]
local d = b["data"] -- get midi-event
local event_type
if #d == 0 then event_type = -1 else event_type = d[1] >> 4 end
local roland_hihat = ctrl[P_ROLAND_H_NOTE]
if (#d == 3 and event_type == 9) then -- note on
if (d[2] == ctrl[P_ROLAND_H_NOTE]) then
d[2] = cur_hihat_note
end
tx_midi (t, d)
elseif (#d == 3 and event_type == 8) then -- note off
if (d[2] == ctrl[P_ROLAND_H_NOTE]) then
d[2] = cur_hihat_note
end
tx_midi (t, d)
end
if (#d == 3 and (d[1] & 240) == 176) then -- CC
-- if (d[2] == 120 or d[2] == 123) then -- panic
--
-- end
-- If the CC message is about the Roland TD4 hihat pedal
if (d[2] == ROLAND_TD4_HIHAT_PEDAL_CC_ID) then
-- Look at the value representing the pedal "angle" and check them against the defined thresholds
if (d[3] <= ctrl[P_H_OPEN_THRESH]) then
cur_hihat_note = ctrl[P_H_OPEN] -- Hihat note is now Hihat Open
elseif (d[3] > ctrl[P_H_OPEN_THRESH] and d[3] <= ctrl[P_H_CLOSED_THRESH]) then
cur_hihat_note = ctrl[P_H_H_CLOSED] -- Hihat note is now Hihat Half Closed
else
cur_hihat_note = ctrl[P_H_CLOSED] -- Otherwise Hihat note is Hihat Closed
end
end
end
end
end