# HG changeset patch # User drewp@bigasterisk.com # Date 1277167696 0 # Node ID 721269c8dd70b458b96aca97bcc9875cf86b84c0 # Parent 11695f8ebbc056584dd68949e7447ce913d1debb gradient mode now draws as a smaller number of rectangles, not tons of lines Ignore-this: 55178e6e11709ccb02067bce8e8b01bc diff -r 11695f8ebbc0 -r 721269c8dd70 light9/curve.py --- a/light9/curve.py Tue Jun 22 04:32:19 2010 +0000 +++ b/light9/curve.py Tue Jun 22 00:48:16 2010 +0000 @@ -1,5 +1,5 @@ from __future__ import division -import math, glob, time +import math, glob, time, logging from bisect import bisect_left,bisect import Tix as tk try: @@ -13,6 +13,7 @@ from light9.zoomcontrol import RegionZoom from bcf2000 import BCF2000 +log = logging.getLogger() # todo: move to config, consolidate with ascoltami, musicPad, etc introPad = 4 postPad = 4 @@ -165,12 +166,13 @@ class Curveview(tk.Canvas): - def __init__(self, master, curve, knobEnabled=False, **kw): + def __init__(self, master, curve, knobEnabled=False, isMusic=False, **kw): """knobEnabled=True highlights the previous key and ties it to a hardware knob""" self.redrawsEnabled = False self.curve = curve self.knobEnabled = knobEnabled + self._isMusic = isMusic self._time = 0 self.last_mouse_world = None tk.Canvas.__init__(self,master,width=10,height=10, @@ -399,8 +401,16 @@ if len(visible_points)<50: self._draw_handle_points(visible_idxs,visible_points) + def is_music(self): + """are we one of the music curves (which might be drawn a bit + differently)""" + return self._isMusic + def _draw_gradient(self): - gradient_res = 3 + t1 = time.time() + gradient_res = 6 if self.is_music() else 3 + startX = startColor = None + rects = 0 for x in range(0, self.width, gradient_res): wx = self.world_from_screen(x,0)[0] mag = self.curve.eval(wx, allow_muting=False) @@ -410,9 +420,22 @@ else: low = (20, 10, 50) high = (255, 187, 255) - self.create_line(x,0, x,40, - fill=gradient(mag, low=low, high=high), - width=gradient_res, tags='curve') + color = gradient(mag, low=low, high=high) + if color != startColor: + if startColor is not None: + self._draw_gradient_slice(startX, x, startColor) + rects += 1 + startX = x + startColor = color + + if startColor is not None: + self._draw_gradient_slice(startX, self.width, startColor) + rects += 1 + log.debug("redraw %s rects in %.02f ms", rects, 1000 * (time.time()-t1)) + + def _draw_gradient_slice(self, x1, x2, color): + self.create_rectangle(x1, 0, x2, 40, + fill=color, width=0, tags='curve') def _draw_markers(self,visible_x): mark = self._draw_one_marker @@ -772,7 +795,8 @@ leftside = tk.Frame(self) leftside.pack(side='left') - self.curveView = Curveview(self, curve, knobEnabled=knobEnabled) + self.curveView = Curveview(self, curve, knobEnabled=knobEnabled, + isMusic=name in ['music', 'smooth_music']) self.curveView.pack(side='left', fill='both', expand=True) self.curveView.config(height=100)