changeset 1186:73e171c9d478

inputquneo sends effect creation on noteon Ignore-this: 2ce9027a2038daa02a65e788ca92e678
author drewp@bigasterisk.com
date Sun, 15 Jun 2014 17:31:13 +0000
parents a9a5243f8f89
children 102a456be7db
files bin/inputquneo
diffstat 1 files changed, 37 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/bin/inputquneo	Sun Jun 15 17:31:02 2014 +0000
+++ b/bin/inputquneo	Sun Jun 15 17:31:13 2014 +0000
@@ -4,7 +4,7 @@
 """
 from __future__ import division
 from run_local import log
-import logging
+import logging, urllib
 import cyclone.web, cyclone.httpclient
 from rdflib import URIRef
 from twisted.internet import reactor, task
@@ -34,7 +34,7 @@
         self.inp = pygame.midi.Input(dev)
         task.LoopingCall(self.step).start(.05)
 
-        self.noteOn = {}
+        self.noteIsOn = {}
 
         self.effectMap = {} # note: effect class uri
         self.graph.addHandler(self.setupNotes)
@@ -56,29 +56,48 @@
     def step(self):
         if not self.inp.poll():
             return
+        NOTEON, NOTEOFF = 144, 128
         for ev in self.inp.read(999):
             (status, d1, d2, _), _ = ev
-            print status, d1, d2
+            if status in [NOTEON, NOTEOFF]:
+                print status, d1, d2
 
 
-            # if noteOn and it's in effectMap,
-            # POST http://localhost:8070/songEffects drop=<effect>
-            
-            for group in [(23,24,25), (6, 18)]:
-                if d1 in group:
-                    if not self.noteOn.get(group):
-                        print "start zero"
+            if status == NOTEON:
+                if not self.noteIsOn.get(d1):
+                    self.noteIsOn[d1] = True
+                    try:
+                        e = self.effectMap[d1]
+                        cyclone.httpclient.fetch(
+                            url=networking.effectEval.path('songEffects'),
+                            method='POST',
+                            headers={'Content-Type': ['application/x-www-form-urlencoded']},
+                            postdata=urllib.urlencode([('drop', e)]),
+                        )
+                    except KeyError:
+                        pass
 
+            if status == NOTEOFF:
+                self.noteIsOn[d1] = False
+
+
+            if 0:
+                # curve editing mode, not done yet
+                for group in [(23,24,25), (6, 18)]:
+                    if d1 in group:
+                        if not self.noteIsOn.get(group):
+                            print "start zero"
+
+                            for d in group:
+                                sendLiveInputPoint(curves[d], 0)
+                            self.noteIsOn[group] = True
+                        else: # miss first update
+                            sendLiveInputPoint(curves[d1], d2 / 127)
+
+                    if status == 128: #noteoff
                         for d in group:
                             sendLiveInputPoint(curves[d], 0)
-                        self.noteOn[group] = True
-                    else: # miss first update
-                        sendLiveInputPoint(curves[d1], d2 / 127)
-                    
-                if status == 128: #noteoff
-                    for d in group:
-                        sendLiveInputPoint(curves[d], 0)
-                    self.noteOn[group] = False
+                        self.noteIsOn[group] = False
 
 def main():
     log.setLevel(logging.DEBUG)