summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorJulien "_FrnchFrgg_" RIVAUD <frnchfrgg@free.fr>2017-07-14 15:16:33 +0200
committerJulien "_FrnchFrgg_" RIVAUD <frnchfrgg@free.fr>2017-07-14 15:16:33 +0200
commit3b1a6a350e1377e56be0725bb2a9819d992e426c (patch)
tree19ae58ce217744f3c3d3a5540f005b3b30ae53e0 /scripts
parent812cbdaca9c8ced687e4dba11fb399535c96a5eb (diff)
Simplify _midifilter.lua example
Instead of and-ing the first byte to extract the event type, it is simpler and easier to understand to bitwise-shift it, so that we don't get the result as a multiple of 2^4, but as values corresponding to the MIDI specification. Currently, a guard is put against events with completely empty data, though maybe ardour discards those earlier on since that would not be valid MIDI.
Diffstat (limited to 'scripts')
-rw-r--r--scripts/_midifilter.lua7
1 files changed, 4 insertions, 3 deletions
diff --git a/scripts/_midifilter.lua b/scripts/_midifilter.lua
index 3ff61d3888..d6a1c1f567 100644
--- a/scripts/_midifilter.lua
+++ b/scripts/_midifilter.lua
@@ -27,11 +27,12 @@ function dsp_run (_, _, n_samples)
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
- if (#d == 3 and bit32.band (d[1], 240) == 144) then -- note on
+ if (#d == 3 and event_type == 9) then -- note on
tx_midi (t, d)
- end
- if (#d == 3 and bit32.band (d[1], 240) == 128) then -- note off
+ elseif (#d == 3 and event_type = 8) then -- note off
tx_midi (t, d)
end
end