2 Commits 552820a9e4 ... 3a8547707b

Author SHA1 Message Date
  Kuba Winnicki 3a8547707b Initial proof of concept 3 months ago
  Kuba Winnicki 552820a9e4 Initial proof of concept 3 months ago
1 changed files with 19 additions and 19 deletions
  1. 19 19
      midiloop.py

+ 19 - 19
midiloop.py

@@ -1,10 +1,10 @@
 #!/usr/bin/env python3
 
 import mido
-from sys import stdout
+from sys import stderr, stdout
 from pythonosc import udp_client
 
-# will spit exception when server unavaliable
+# WARNING: will spit exception when server unavaliable
 atem = udp_client.SimpleUDPClient("spass.local", 3333)
 amp = udp_client.SimpleUDPClient("pig.local", 9137)
 ovly = udp_client.SimpleUDPClient("xuj.local", 9137)
@@ -12,7 +12,7 @@ ovly = udp_client.SimpleUDPClient("xuj.local", 9137)
 msg_matrix = {
     # OVERLAY
     0o00:  (atem, "/atem/mini/preview", 1),
-    0o30: (ovly, "/party/screen/bar/t/reset", 0),
+    0o30: (ovly, "/party/bar/t/reset", 0),
 
     # RETROTINK
     0o01:  (atem, "/atem/mini/preview", 2),
@@ -74,8 +74,9 @@ def get_controller(device_name):
             return (mido.open_input(device), mido.open_output(device))
     return None
 
-def get_float(v):
-    return v * 258.01574 / 32768
+def floatize(v):
+    """Convert to float and normalize"""
+    return min(v * 258.01574 / 32767, 1.0)
 
 def event_loop(apc_in, apc_out): 
     last = 0
@@ -87,29 +88,28 @@ def event_loop(apc_in, apc_out):
             osc.send_message(addr, value)
             print(msg, 'sent', value, 'to:', addr)
 
-            # turn on led of pressed button and clear previous one for a feedback
+            # Turn on the led of pressed button and clear previous one for a feedback
             apc_out.send(mido.Message('note_on', channel=6, note=last, velocity=0))
             apc_out.send(mido.Message('note_on', channel=6, note=msg.note, velocity=5))
             last = msg.note
         if msg.type == "control_change" and msg.control == 56:
-            # full range
-            v = get_float(msg.value) * direction
-            atem.send_message("/atem/mini/transition/position", abs(v))
-            # atem.send_message("/atem/mini/transition/bar", 0.9999-v)
-            if msg.value == 0:
-                #direction *= -1
-                atem.send_message("/atem/mini/transition/position", 0.9999999999)
-                atem.send_message("/atem/mini/transition/cut", abs(v))
-            print("fade", msg.value)
+            v = abs(floatize(msg.value) * direction)
+            if direction == -1:
+                v = 1.0 - v
+            atem.send_message("/atem/mini/transition/position", v)
+            if v == 1.0:
+                direction *= -1
+            # print("fade", msg.value, v)
         if msg.type == "control_change" and msg.control == 55:
-            # full range
-            ovly.send_message("/party/media/volume", get_float(msg.value))
+            # Full range
+            ovly.send_message("/party/media/volume", floatize(msg.value))
         elif msg.type == "control_change" and msg.control in audio_controls:
-            # full range
+            # Full range
             atem.send_message(f"/atem/mini/{audio_controls[msg.control]}/gain",
-                              get_float(msg.value) * 110. - 100.)
+                              floatize(msg.value) * 110. - 100.)
         else:
             print(msg)
+
         stdout.flush()
 
 if __name__ == "__main__":