diff options
author | Benjamin Berg <benjamin@sipsolutions.net> | 2009-10-05 11:37:09 (GMT) |
---|---|---|
committer | Benjamin Berg <benjamin@sipsolutions.net> | 2009-10-05 11:37:09 (GMT) |
commit | 5bcf3251c9cc4f5c3931b5e9cbda5d02decaccaf (patch) | |
tree | d70578462141b3b6c736a05d692025c3a97fb8e6 | |
parent | b3681e2696d414cce0b7320ca8ad3a0ecc1ae80e (diff) |
Redraw as fast as possible (using X11 properties)
-rw-r--r-- | config.py | 3 | ||||
-rw-r--r-- | drawwaveform.py | 54 | ||||
-rw-r--r-- | measure.py | 10 |
3 files changed, 46 insertions, 21 deletions
@@ -25,9 +25,6 @@ from sugar.activity import activity MEASURE_ROOT = activity.get_bundle_path() ICONS_DIR = MEASURE_ROOT + '/icons' -#In milliseconds, the delay interval after which the waveform draw function will be queued" -REFRESH_TIME = 30 - #Multiplied with width and height to set placement of text TEXT_X_M = 0.65 TEXT_Y_M = 0.70 diff --git a/drawwaveform.py b/drawwaveform.py index a3c13df..6d0a784 100644 --- a/drawwaveform.py +++ b/drawwaveform.py @@ -53,7 +53,8 @@ class DrawWaveform(gtk.DrawingArea): gtk.DrawingArea.__init__(self) - self.add_events(gtk.gdk.BUTTON_PRESS_MASK) + self.add_events(gtk.gdk.BUTTON_PRESS_MASK | \ + gtk.gdk.PROPERTY_CHANGE_MASK) self._input_freq = input_frequency self.stroke_color = None @@ -61,6 +62,9 @@ class DrawWaveform(gtk.DrawingArea): self.trigger_xpos = 0.0 self.trigger_ypos = 0.5 + self.active = False + self._redraw_atom = gtk.gdk.atom_intern('MeasureRedraw') + self.buffers = np.array([]) self.main_buffers = np.array([]) self.str_buffer='' @@ -208,11 +212,13 @@ class DrawWaveform(gtk.DrawingArea): if not self.context: self.handler_unblock(self.expose_event_id) self.context = True + self._indirect_queue_draw() def set_context_off(self): if self.context: self.handler_block(self.expose_event_id) self.context = False + self._indirect_queue_draw() def set_invert_state(self, invert_state): self.invert = invert_state @@ -229,6 +235,16 @@ class DrawWaveform(gtk.DrawingArea): gtk.DrawingArea.do_size_allocate(self, allocation) self._update_mode() + def _indirect_queue_draw(self): + if self.window == None: + return + self.window.property_change(self._redraw_atom, self._redraw_atom, + 32, gtk.gdk.PROP_MODE_REPLACE, []); + + def do_property_notify_event(self, event): + if event.atom == self._redraw_atom: + self.queue_draw() + def do_realize(self): gtk.DrawingArea.do_realize(self) @@ -300,8 +316,9 @@ class DrawWaveform(gtk.DrawingArea): def _expose(self, widget, event): """This function is the "expose" event handler and does all the drawing""" + #######################Real time drawing################################### - if self.context: + if self.context and self.active: #Iterate for each graph for graph_id in self.graph_id: @@ -310,6 +327,7 @@ class DrawWaveform(gtk.DrawingArea): samples = math.ceil(self.allocation.width/self.draw_interval) if len(buf) == 0: # We don't have enough data to plot. + self._indirect_queue_draw() return x_offset = 0 @@ -360,14 +378,20 @@ class DrawWaveform(gtk.DrawingArea): Fs = 48000 nfft = 65536 - # Multiply input with the window - np.multiply(buf, self.fft_window, buf) - - # Should be fast enough even without power of 2 stuff. - self.fftx = np.fft.rfft(buf) - self.fftx = abs(self.fftx) - data = np.multiply(self.fftx, 0.02, self.fftx) - ################################## + try: + # Multiply input with the window + np.multiply(buf, self.fft_window, buf) + + # Should be fast enough even without power of 2 stuff. + self.fftx = np.fft.rfft(buf) + self.fftx = abs(self.fftx) + data = np.multiply(self.fftx, 0.02, self.fftx) + ################################## + except ValueError: + # TODO: Figure out how this can happen. + # Shape mismatch between window and buf + self._indirect_queue_draw() + return True ################Scaling the values################### if config.CONTEXT == 2: @@ -402,7 +426,8 @@ class DrawWaveform(gtk.DrawingArea): else: self.window.draw_points(self._line_gc[graph_id], lines) ############################################################ - + + self._indirect_queue_draw() """ ## DISPLAYING FRAMERATE FOR DEBUGGGIN fr = 1.0/( time.time()-self.pr_time) @@ -486,6 +511,13 @@ class DrawWaveform(gtk.DrawingArea): self.fft_window = None + def set_active(self, active): + self.active = active + self._indirect_queue_draw() + + def get_active(self): + return self.active + def get_stroke_color_from_sugar(self): """Returns in (r,g,b) format the stroke color from the Sugar profile""" # Hitting gconf is a large overhead. @@ -97,7 +97,7 @@ class MeasureActivity(activity.Activity): self.first = True - gobject.timeout_add(config.REFRESH_TIME, self.waveform_refresh) + self.wave.set_active(True) def set_show_hide_windows(self, window_id=1): """Shows the appropriate window identified by the window_id @@ -127,10 +127,6 @@ class MeasureActivity(activity.Activity): If 1 is returned means camera context""" return self.active_context_status - def waveform_refresh(self): - self.wave.queue_draw() - return self.active_status - def on_quit(self,data=None): self.audiograb.on_activity_quit() self.ji.on_quit() @@ -145,9 +141,9 @@ class MeasureActivity(activity.Activity): elif (self.props.active and not self.ACTIVE): self.audiograb.resume_grabbing() self.active_status = True - gobject.timeout_add(config.REFRESH_TIME, \ - self.waveform_refresh) + self.ACTIVE = self.props.active + self.wave.set_active(self.ACTIVE) """ Write the project to the Journal |