From 7b42837e329f030f7af07f59f44bc438cb603f39 Mon Sep 17 00:00:00 2001 From: onyx-and-iris <75868496+onyx-and-iris@users.noreply.github.com> Date: Thu, 4 Aug 2022 13:21:21 +0100 Subject: [PATCH] fix bug in midi example. now check for full velocity (button pressed) disable updates other than midi, in midi example. add docstring --- examples/midi/__main__.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/examples/midi/__main__.py b/examples/midi/__main__.py index d52b053..046243f 100644 --- a/examples/midi/__main__.py +++ b/examples/midi/__main__.py @@ -11,6 +11,11 @@ class Observer: self.vm.subject.add(self) def on_update(self, subject): + """ + We expect to only receive midi updates. + + We could skip subject check but check anyway, in case an event is added later. + """ if subject == "midi": self.get_info() self.on_midi_press() @@ -20,9 +25,14 @@ class Observer: print(f"Value of midi button {current} is {self.vm.midi.get(current)}") def on_midi_press(self): + """ + checks if strip 3 level prefader mode is greater than -40 + + checks if midi button 48 velcity is 127 (full velocity for button press). + """ if ( max(self.vm.strip[3].levels.postfader) > -40 - and self.vm.midi.get(self.midi_btn) != 0 + and self.vm.midi.get(self.midi_btn) == 127 ): print( f"Strip 3 level is greater than -40 and midi button {self.midi_btn} is pressed" @@ -34,7 +44,9 @@ class Observer: def main(): - with voicemeeterlib.api(kind_id) as vm: + # we only care about midi events here. + subs = {ev: False for ev in ["pdirty", "mdirty", "ldirty"]} + with voicemeeterlib.api(kind_id, subs=subs) as vm: obs = Observer(vm, midi_btn, macrobutton) obs.register()