Changeset - c756638275d6
[Not reviewed]
default
0 5 2
Drew Perttula - 11 years ago 2014-06-02 07:04:40
drewp@bigasterisk.com
quneo input demo. optimize curve display a little.
Ignore-this: 4cf5b4b5853a94842c9fa8e2916bc6f4
7 files changed with 100 insertions and 23 deletions:
0 comments (0 inline, 0 general)
bin/inputdemo
Show inline comments
 
@@ -9,12 +9,13 @@ import optparse, logging, urllib, time
 
from gi.repository import Gtk
 
from run_local import log
 
from light9 import showconfig, networking
 
from light9.rdfdb import clientsession
 
from light9.rdfdb.syncedgraph import SyncedGraph
 
import cyclone.httpclient
 
from light9.curvecalc.client import sendLiveInputPoint
 

	
 
class App(object):
 
    def __init__(self):
 
        parser = optparse.OptionParser()
 
        parser.set_usage("%prog [opts] [curve uri]")
 
        parser.add_option("--debug", action="store_true",
 
@@ -46,23 +47,13 @@ class App(object):
 
        win.parse_geometry('50x250')
 
        win.connect("delete-event", lambda *a: reactor.crash())
 
        win.connect("destroy", lambda *a: reactor.crash())
 
        win.show_all()
 

	
 
    def onChanged(self, scale):
 
        f = cyclone.httpclient.fetch(
 
            networking.curveCalc.path('liveInputPoint'),
 
            method='POST', timeout=1,
 
            postdata=urllib.urlencode({
 
                'curve': self.curve,
 
                'value': str(scale.get_value()),
 
            }))
 
        @f.addCallback
 
        def cb(result):
 
            if result.code // 100 != 2:
 
                log.error("curveCalc said %s: %s", result.code, result.body)
 
        t1 = time.time()
 
        d = sendLiveInputPoint(self.curve, scale.get_value())
 
        @d.addCallback
 
        def done(result):
 
            print "posted in %.1f ms" % (1000 * (time.time() - t1))
 
        @f.addErrback
 
        def eb(err):
 
            print "err", err
 

	
 
App()
bin/inputquneo
Show inline comments
 
new file 100644
 
#!bin/python
 
"""
 
read Quneo midi events, write to curvecalc and maybe to effects
 
"""
 
from __future__ import division
 
from run_local import log
 
import cyclone.web, cyclone.httpclient
 
from rdflib import URIRef
 
from twisted.internet import reactor, task
 
from light9.curvecalc.client import sendLiveInputPoint
 

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

	
 
curves = {
 
    23: URIRef('http://light9.bigasterisk.com/show/dance2014/song1/curve/c-2'),
 
    24: URIRef('http://light9.bigasterisk.com/show/dance2014/song1/curve/c-3'),
 
    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):
 
        pygame.midi.init()
 

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

	
 
        self.noteOn = {}
 
        
 
    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
 
        raise ValueError("didn't find quneo input device")
 
        
 
    def step(self):
 
        if not self.inp.poll():
 
            return
 
        for ev in self.inp.read(999):
 
            (status, d1, d2, _), _ = ev
 
            print status, d1, d2
 

	
 
            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
 

	
 

	
 
wm = WatchMidi()
 
reactor.run()
light9/curvecalc/client.py
Show inline comments
 
new file 100644
 
"""
 
client code for talking to curvecalc
 
"""
 
import cyclone.httpclient
 
from light9 import networking
 
import urllib
 
from run_local import log
 

	
 
def sendLiveInputPoint(curve, value):
 
    f = cyclone.httpclient.fetch(
 
        networking.curveCalc.path('liveInputPoint'),
 
        method='POST', timeout=1,
 
        postdata=urllib.urlencode({
 
            'curve': curve,
 
            'value': str(value),
 
        }))
 
    @f.addCallback
 
    def cb(result):
 
        if result.code // 100 != 2:
 
            raise ValueError("curveCalc said %s: %s", result.code, result.body)
 
    return f
light9/curvecalc/curve.py
Show inline comments
 
@@ -97,15 +97,15 @@ class Curve(object):
 
        """returns index of new point"""
 
        i = bisect(self.points, (new_pt[0],None))
 
        self.points.insert(i,new_pt)
 
        # missing a check that this isn't the same X as the neighbor point
 
        return i
 

	
 
    def live_input_point(self, new_pt):
 
    def live_input_point(self, new_pt, clear_ahead_secs=.01):
 
        x, y = new_pt
 
        exist = self.points_between(x, x + .01)
 
        exist = self.points_between(x, x + clear_ahead_secs)
 
        for pt in exist:
 
            self.remove_point(pt)
 
        self.insert_pt(new_pt)
 
        dispatcher.send("points changed", sender=self)
 
        # now simplify to the left
 
        
light9/curvecalc/curveedit.py
Show inline comments
 
@@ -41,8 +41,8 @@ class CurveEdit(object):
 
        
 
    def inputTime(self, val):
 
        self.currentTime = val
 
        
 
    def liveInputPoint(self, curveUri, value):
 
        curve = self.curveset.curveFromUri(curveUri)
 
        curve.live_input_point((self.currentTime, value))
 
        curve.live_input_point((self.currentTime, value), clear_ahead_secs=.5)
 
        
light9/curvecalc/curveview.py
Show inline comments
 
@@ -732,20 +732,18 @@ class Curveview(object):
 
        self.curveGroup = GooCanvas.CanvasGroup(parent=self.canvas.get_root_item())
 

	
 
        self.canvas.set_property("background-color",
 
                                 "gray20" if self.curve.muted else "black")
 

	
 
        self.update_time_bar(self._time)
 
        if self.canvas.props.y2 < 40:
 
            self._draw_line(visible_points, area=True)
 
        else:
 
            self._draw_time_tics(visible_x)
 
            self._draw_line(visible_points)
 
            self._draw_markers(
 
                self.markers.points[i] for i in
 
                self.markers.indices_between(visible_x[0], visible_x[1]))
 
        if self.canvas.props.y2 > 80:
 
            self._draw_time_tics(visible_x)
 

	
 
            self.dots = {} # idx : canvas rectangle
 

	
 
            if len(visible_points) < 50 and not self.curve.muted:
 
                self._draw_handle_points(visible_idxs,visible_points)
 

	
 
@@ -1068,13 +1066,13 @@ class CurveRow(object):
 
        self.box.set_border_width(1)
 

	
 
        self.cols = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0)
 
        self.box.add(self.cols)
 
        
 
        controls = Gtk.Frame()
 
        controls.set_size_request(115, -1)
 
        controls.set_size_request(160, -1)
 
        controls.set_shadow_type(Gtk.ShadowType.OUT)
 
        self.cols.pack_start(controls, expand=False, fill=True, padding=0)
 
        self.setupControls(controls, name, curve, slider)
 

	
 
        self.curveView = Curveview(curve, markers, knobEnabled=knobEnabled,
 
                                   isMusic=name in ['music', 'smooth_music'],
 
@@ -1101,12 +1099,14 @@ class CurveRow(object):
 
        self.curveView.widget.show()
 
        self.setHeight(100)
 
        self.cols.pack_start(self.curveView.widget, expand=True, fill=True, padding=0)       
 

	
 
    def setHeight(self, h):
 
        self.curveView.widget.set_size_request(-1, h)
 
        # the event watcher wasn't catching these
 
        reactor.callLater(.5, self.curveView.update_curve)
 
        
 
    def setupControls(self, controls, name, curve, slider):
 
        box = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0)
 
        controls.add(box)
 

	
 
        curve_name_label = Gtk.LinkButton()
makefile
Show inline comments
 
@@ -49,7 +49,7 @@ tkdnd_build:
 
bin/ascoltami2: gst_packages link_to_sys_packages
 

	
 
gst_packages:
 
	sudo aptitude install python-gi gir1.2-gst-plugins-base-1.0 libgirepository-1.0-1 gir1.2-gstreamer-1.0 gstreamer1.0-tools gstreamer1.0-plugins-good gstreamer1.0-pulseaudio gir1.2-goocanvas-2.0-9
 

	
 
packages:
 
	sudo aptitude install coffeescript freemind normalize-audio audacity python-pygoocanvas
 
	sudo aptitude install coffeescript freemind normalize-audio audacity python-pygoocanvas python-pygame
0 comments (0 inline, 0 general)