aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2023-09-03 15:35:40 +0300
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2023-09-05 23:39:23 +0300
commit03ca9c8010702337a06c8b0ca9ca1e90c301d47e (patch)
tree1844d390c63fa1dab5e5a83962644ee6ce422a5c
parent973fa97138a82e98ffded5bd92e0268b2364aa15 (diff)
downloadapplause2-03ca9c8010702337a06c8b0ca9ca1e90c301d47e.tar.gz
MIDIStream is now an ordinary class that caches internally
-rw-r--r--applause.lua36
1 files changed, 15 insertions, 21 deletions
diff --git a/applause.lua b/applause.lua
index 8a4b07f..ff4bde5 100644
--- a/applause.lua
+++ b/applause.lua
@@ -1732,10 +1732,23 @@ end
--
-- MIDI Support
--- NOTE: The MIDIStream is defined at the very end, since
--- we need to use primitives not yet defined
--
+MIDIStream = DeriveClass(Stream)
+
+function MIDIStream:gtick()
+ return function()
+ -- This is always cached since there is only one MIDI event queue
+ -- and it must not be pulled more than once per tick.
+ local sample = sampleCache[self]
+ if not sample then
+ sample = C.applause_pull_midi_sample()
+ sampleCache[self] = sample
+ end
+ return sample
+ end
+end
+
-- Last value of a specific control channel
function Stream:CC(control, channel)
channel = channel or 0
@@ -2372,22 +2385,3 @@ Client.__gc = Client.kill
--
dofile "dssi.lua"
dofile "evdev.lua"
-
---
--- See above, MIDIStream depends on tostream() and other
--- primitives.
---
-do
- local class = DeriveClass(Stream)
-
- function class:gtick()
- return C.applause_pull_midi_sample
- end
-
- -- FIXME: Since a sample must only be pulled once
- -- per tick, so MIDIStream can be reused, it must
- -- always be cached.
- -- FIXME: This could be done directly in gtick(),
- -- so this definition can be moved upwards to the rest of the MIDI stuff.
- MIDIStream = class:cache()
-end