Mercurial > code > home > repos > light9
annotate bin/inputquneo @ 1431:f85cc11b3e8c
checkpoint show data
Ignore-this: 7dc477a7921f92dc9cc8115c6cc2b9cf
author | drewp@bigasterisk.com |
---|---|
date | Sat, 11 Jun 2016 17:15:30 +0000 |
parents | 73e171c9d478 |
children | 6fa4288da8a6 |
rev | line source |
---|---|
1069
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
1 #!bin/python |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
2 """ |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
3 read Quneo midi events, write to curvecalc and maybe to effects |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
4 """ |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
5 from __future__ import division |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
6 from run_local import log |
1186
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
7 import logging, urllib |
1069
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
8 import cyclone.web, cyclone.httpclient |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
9 from rdflib import URIRef |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
10 from twisted.internet import reactor, task |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
11 from light9.curvecalc.client import sendLiveInputPoint |
1182
78973ed9e986
start to make inputquneo able to add effects to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1069
diff
changeset
|
12 from light9.namespaces import L9, RDF, RDFS |
78973ed9e986
start to make inputquneo able to add effects to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1069
diff
changeset
|
13 from light9.rdfdb.syncedgraph import SyncedGraph |
78973ed9e986
start to make inputquneo able to add effects to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1069
diff
changeset
|
14 from light9 import networking |
1069
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
15 |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
16 import sys |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
17 sys.path.append('/usr/lib/python2.7/dist-packages') # For pygame |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
18 import pygame.midi |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
19 |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
20 curves = { |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
21 23: URIRef('http://light9.bigasterisk.com/show/dance2014/song1/curve/c-2'), |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
22 24: URIRef('http://light9.bigasterisk.com/show/dance2014/song1/curve/c-3'), |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
23 25: URIRef('http://light9.bigasterisk.com/show/dance2014/song1/curve/c-4'), |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
24 6:URIRef('http://light9.bigasterisk.com/show/dance2014/song1/curve/c-5'), |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
25 18: URIRef('http://light9.bigasterisk.com/show/dance2014/song1/curve/c-6'), |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
26 } |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
27 |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
28 class WatchMidi(object): |
1182
78973ed9e986
start to make inputquneo able to add effects to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1069
diff
changeset
|
29 def __init__(self, graph): |
78973ed9e986
start to make inputquneo able to add effects to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1069
diff
changeset
|
30 self.graph = graph |
1069
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
31 pygame.midi.init() |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
32 |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
33 dev = self.findQuneo() |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
34 self.inp = pygame.midi.Input(dev) |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
35 task.LoopingCall(self.step).start(.05) |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
36 |
1186
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
37 self.noteIsOn = {} |
1182
78973ed9e986
start to make inputquneo able to add effects to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1069
diff
changeset
|
38 |
78973ed9e986
start to make inputquneo able to add effects to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1069
diff
changeset
|
39 self.effectMap = {} # note: effect class uri |
78973ed9e986
start to make inputquneo able to add effects to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1069
diff
changeset
|
40 self.graph.addHandler(self.setupNotes) |
78973ed9e986
start to make inputquneo able to add effects to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1069
diff
changeset
|
41 |
78973ed9e986
start to make inputquneo able to add effects to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1069
diff
changeset
|
42 def setupNotes(self): |
78973ed9e986
start to make inputquneo able to add effects to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1069
diff
changeset
|
43 for e in self.graph.subjects(RDF.type, L9['EffectClass']): |
78973ed9e986
start to make inputquneo able to add effects to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1069
diff
changeset
|
44 qn = self.graph.value(e, L9['quneoNote']) |
78973ed9e986
start to make inputquneo able to add effects to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1069
diff
changeset
|
45 if qn: |
78973ed9e986
start to make inputquneo able to add effects to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1069
diff
changeset
|
46 self.effectMap[int(qn)] = e |
78973ed9e986
start to make inputquneo able to add effects to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1069
diff
changeset
|
47 log.info("setup with %s effects", len(self.effectMap)) |
1069
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
48 |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
49 def findQuneo(self): |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
50 for dev in range(pygame.midi.get_count()): |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
51 interf, name, isInput, isOutput, opened = pygame.midi.get_device_info(dev) |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
52 if 'QUNEO' in name and isInput: |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
53 return dev |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
54 raise ValueError("didn't find quneo input device") |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
55 |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
56 def step(self): |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
57 if not self.inp.poll(): |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
58 return |
1186
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
59 NOTEON, NOTEOFF = 144, 128 |
1069
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
60 for ev in self.inp.read(999): |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
61 (status, d1, d2, _), _ = ev |
1186
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
62 if status in [NOTEON, NOTEOFF]: |
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
63 print status, d1, d2 |
1069
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
64 |
1182
78973ed9e986
start to make inputquneo able to add effects to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1069
diff
changeset
|
65 |
1186
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
66 if status == NOTEON: |
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
67 if not self.noteIsOn.get(d1): |
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
68 self.noteIsOn[d1] = True |
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
69 try: |
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
70 e = self.effectMap[d1] |
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
71 cyclone.httpclient.fetch( |
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
72 url=networking.effectEval.path('songEffects'), |
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
73 method='POST', |
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
74 headers={'Content-Type': ['application/x-www-form-urlencoded']}, |
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
75 postdata=urllib.urlencode([('drop', e)]), |
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
76 ) |
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
77 except KeyError: |
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
78 pass |
1182
78973ed9e986
start to make inputquneo able to add effects to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1069
diff
changeset
|
79 |
1186
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
80 if status == NOTEOFF: |
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
81 self.noteIsOn[d1] = False |
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
82 |
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
83 |
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
84 if 0: |
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
85 # curve editing mode, not done yet |
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
86 for group in [(23,24,25), (6, 18)]: |
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
87 if d1 in group: |
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
88 if not self.noteIsOn.get(group): |
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
89 print "start zero" |
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
90 |
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
91 for d in group: |
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
92 sendLiveInputPoint(curves[d], 0) |
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
93 self.noteIsOn[group] = True |
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
94 else: # miss first update |
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
95 sendLiveInputPoint(curves[d1], d2 / 127) |
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
96 |
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
97 if status == 128: #noteoff |
1069
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
98 for d in group: |
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
99 sendLiveInputPoint(curves[d], 0) |
1186
73e171c9d478
inputquneo sends effect creation on noteon
drewp@bigasterisk.com
parents:
1182
diff
changeset
|
100 self.noteIsOn[group] = False |
1069
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
101 |
1182
78973ed9e986
start to make inputquneo able to add effects to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1069
diff
changeset
|
102 def main(): |
78973ed9e986
start to make inputquneo able to add effects to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1069
diff
changeset
|
103 log.setLevel(logging.DEBUG) |
78973ed9e986
start to make inputquneo able to add effects to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1069
diff
changeset
|
104 graph = SyncedGraph(networking.rdfdb.url, "inputQuneo") |
78973ed9e986
start to make inputquneo able to add effects to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1069
diff
changeset
|
105 wm = WatchMidi(graph) |
78973ed9e986
start to make inputquneo able to add effects to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1069
diff
changeset
|
106 reactor.run() |
1069
c756638275d6
quneo input demo. optimize curve display a little.
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
107 |
1182
78973ed9e986
start to make inputquneo able to add effects to current song
Drew Perttula <drewp@bigasterisk.com>
parents:
1069
diff
changeset
|
108 main() |