Changeset - 78973ed9e986
[Not reviewed]
default
0 2 0
Drew Perttula - 11 years ago 2014-06-15 15:47:47
drewp@bigasterisk.com
start to make inputquneo able to add effects to current song
Ignore-this: d56554a7a10411346e709007006bc4dd
2 files changed with 29 insertions and 3 deletions:
0 comments (0 inline, 0 general)
bin/inputquneo
Show inline comments
 
#!bin/python
 
"""
 
read Quneo midi events, write to curvecalc and maybe to effects
 
"""
 
from __future__ import division
 
from run_local import log
 
import logging
 
import cyclone.web, cyclone.httpclient
 
from rdflib import URIRef
 
from twisted.internet import reactor, task
 
from light9.curvecalc.client import sendLiveInputPoint
 
from light9.namespaces import L9, RDF, RDFS
 
from light9.rdfdb.syncedgraph import SyncedGraph
 
from light9 import networking
 

	
 
import sys
 
sys.path.append('/usr/lib/python2.7/dist-packages') # For pygame
 
import pygame.midi
 

	
 
curves = {
 
@@ -19,20 +23,31 @@ curves = {
 
    25: URIRef('http://light9.bigasterisk.com/show/dance2014/song1/curve/c-4'),
 
    6:URIRef('http://light9.bigasterisk.com/show/dance2014/song1/curve/c-5'),
 
    18: URIRef('http://light9.bigasterisk.com/show/dance2014/song1/curve/c-6'),
 
}
 

	
 
class WatchMidi(object):
 
    def __init__(self):
 
    def __init__(self, graph):
 
        self.graph = graph
 
        pygame.midi.init()
 

	
 
        dev = self.findQuneo()
 
        self.inp = pygame.midi.Input(dev)
 
        task.LoopingCall(self.step).start(.05)
 

	
 
        self.noteOn = {}
 

	
 
        self.effectMap = {} # note: effect class uri
 
        self.graph.addHandler(self.setupNotes)
 

	
 
    def setupNotes(self):
 
        for e in self.graph.subjects(RDF.type, L9['EffectClass']):
 
            qn = self.graph.value(e, L9['quneoNote'])
 
            if qn:
 
                self.effectMap[int(qn)] = e
 
        log.info("setup with %s effects", len(self.effectMap))
 
        
 
    def findQuneo(self):
 
        for dev in range(pygame.midi.get_count()):
 
            interf, name, isInput, isOutput, opened = pygame.midi.get_device_info(dev)
 
            if 'QUNEO' in name and isInput:
 
                return dev
 
@@ -42,24 +57,33 @@ class WatchMidi(object):
 
        if not self.inp.poll():
 
            return
 
        for ev in self.inp.read(999):
 
            (status, d1, d2, _), _ = ev
 
            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"
 

	
 
                        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
 

	
 
def main():
 
    log.setLevel(logging.DEBUG)
 
    graph = SyncedGraph(networking.rdfdb.url, "inputQuneo")
 
    wm = WatchMidi(graph)
 
    reactor.run()
 

	
 
wm = WatchMidi()
 
reactor.run()
 
main()
show/dance2014/effectClass.n3
Show inline comments
 
@@ -14,16 +14,18 @@
 
effect:cycFlash a :EffectClass;
 
  rdfs:label "cycFlash";
 
  :code "out = <http://light9.bigasterisk.com/show/dance2013/sub/cyc> * nsin(t*2)" .
 

	
 
  
 
effect:cycToMusic a :EffectClass; rdfs:label "cyc to music";
 
:quneoNote 26;
 
:code "out = <http://light9.bigasterisk.com/show/dance2013/sub/cyc> * music * env" .
 

	
 
effect:blacklight a :EffectClass;
 
  rdfs:label "blacklight";
 
  :quneoNote 23;
 
  :code 
 
    "env = <http://light9.bigasterisk.com/show/dance2014/song1/curve-1>",
 
    "out = [env * p1, env * p2, env * p3, env * p4]",
 
    "p1 = env * <http://light9.bigasterisk.com/show/dance2013/sub/blue> * .5",
 
    "p2 = Strip.solid('R', (0,0,1))",
 
    "p3 = Strip.solid('L', (0,0,1))",
0 comments (0 inline, 0 general)