diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2015-12-31 14:29:30 +0100 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2015-12-31 14:29:30 +0100 |
commit | 3b409db5f23a6f4f39467e05f9edf0963721d3ed (patch) | |
tree | eaebd904cfc49eb45b144019403c6b69da77b038 /applause.lua | |
parent | fc9c4746a21226723875cebfbf310065038141bf (diff) | |
download | applause2-3b409db5f23a6f4f39467e05f9edf0963721d3ed.tar.gz |
fixed potential segfaults in MIDI processing & 1-based channels
* there are at most 128 different MIDI notes; mtof() will now also work
for all of them
* channels have origin 1 now in the public APIs.
This is what most applications seem to use, so in order to avoid
confusion it's probably a good idea to use it as well.
Diffstat (limited to 'applause.lua')
-rw-r--r-- | applause.lua | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/applause.lua b/applause.lua index a76fb41..c701bc3 100644 --- a/applause.lua +++ b/applause.lua @@ -903,10 +903,14 @@ function NoiseStream:tick() end end +-- +-- MIDI Support +-- + -- Velocity of NOTE ON for a specific note on a channel MIDIVelocityStream = DeriveClass(Stream, function(self, note, channel) self.note = note - self.channel = channel or 0 + self.channel = channel or 1 end) -- implemented in applause.c, private! @@ -930,7 +934,7 @@ end -- The MIDI note is the lower byte and the velocity the -- upper byte of the word. MIDINoteStream = DeriveClass(Stream, function(self, channel) - self.channel = channel or 0 + self.channel = channel or 1 end) -- implemented in applause.c, private! @@ -949,7 +953,7 @@ end MIDICCStream = DeriveClass(Stream, function(self, control, channel) self.control = control - self.channel = channel or 0 + self.channel = channel or 1 end) -- implemented in applause.c, private! @@ -969,12 +973,12 @@ end -- MIDI primitives --- There are only 120 different MIDI notes, +-- There are only 128 possible MIDI notes, -- so their frequencies can and should be cached. -- We do this once instead of on-demand, so the lookup -- table consists of consecutive numbers. -local mtof_cache = table.new(120, 0) -for note = 0, 119 do +local mtof_cache = table.new(128, 0) +for note = 0, 127 do -- MIDI NOTE 69 corresponds to 440 Hz mtof_cache[note] = 440*math.pow(2, (note - 69)/12) end |