diff options
author | Benjamin Berg <benjamin@sipsolutions.net> | 2009-10-05 11:36:26 (GMT) |
---|---|---|
committer | Benjamin Berg <benjamin@sipsolutions.net> | 2009-10-05 11:36:26 (GMT) |
commit | b3681e2696d414cce0b7320ca8ad3a0ecc1ae80e (patch) | |
tree | 1a94c7d062d50f0f4a513c038749b0102d2d8027 /drawwaveform.py | |
parent | 6bf7fb222e51f039575ee8fb528bdfdb54353d3f (diff) |
Add possibility to change trigger configuration.
Diffstat (limited to 'drawwaveform.py')
-rw-r--r-- | drawwaveform.py | 95 |
1 files changed, 81 insertions, 14 deletions
diff --git a/drawwaveform.py b/drawwaveform.py index bc0a788..a3c13df 100644 --- a/drawwaveform.py +++ b/drawwaveform.py @@ -45,13 +45,21 @@ class DrawWaveform(gtk.DrawingArea): __gtype_name__ = "MeasureDrawWaveform" + TRIGGER_NONE = 0 + TRIGGER_POS = 1 + TRIGGER_NEG = 2 + def __init__(self, input_frequency=48000): gtk.DrawingArea.__init__(self) + self.add_events(gtk.gdk.BUTTON_PRESS_MASK) + self._input_freq = input_frequency self.stroke_color = None - self.triggering = True + self.triggering = self.TRIGGER_NONE + self.trigger_xpos = 0.0 + self.trigger_ypos = 0.5 self.buffers = np.array([]) self.main_buffers = np.array([]) @@ -88,6 +96,7 @@ class DrawWaveform(gtk.DrawingArea): self.log_param5 = "" self._BACKGROUND_LINE_THICKNESS = 0.8 + self._TRIGGER_LINE_THICKNESS = 3 self._FOREGROUND_LINE_THICKNESS = 6 self.logging_status = False @@ -196,12 +205,14 @@ class DrawWaveform(gtk.DrawingArea): return True def set_context_on(self): - self.handler_unblock(self.expose_event_id) + if not self.context: + self.handler_unblock(self.expose_event_id) self.context = True def set_context_off(self): + if self.context: + self.handler_block(self.expose_event_id) self.context = False - self.handler_block(self.expose_event_id) def set_invert_state(self, invert_state): self.invert = invert_state @@ -235,6 +246,17 @@ class DrawWaveform(gtk.DrawingArea): self._line_gc[graph_id].set_foreground(clr) + r, g, b = self.get_stroke_color_from_sugar() + clr = colormap.alloc_color(r, g, b, False, False) + + self._trigger_line_gc = self.window.new_gc(foreground=clr) + self._trigger_line_gc.set_line_attributes( \ + self._TRIGGER_LINE_THICKNESS, gdk.LINE_SOLID, \ + gdk.CAP_ROUND, gdk.JOIN_BEVEL) + + self._trigger_line_gc.set_foreground(clr) + + # Background pixmap clr = colormap.alloc_color(0, 65535, 0, False, False) @@ -271,6 +293,11 @@ class DrawWaveform(gtk.DrawingArea): del cr self.window.set_back_pixmap(back_surf, False) + def do_button_press_event(self, event): + self.trigger_xpos = event.x / float(self.allocation.width) + self.trigger_ypos = event.y / float(self.allocation.height) + return True + def _expose(self, widget, event): """This function is the "expose" event handler and does all the drawing""" #######################Real time drawing################################### @@ -288,18 +315,43 @@ class DrawWaveform(gtk.DrawingArea): x_offset = 0 if (self.fft_show==False): - if self.triggering == True: - ints = buf[:-samples-3] <= 0 - ints &= buf[1:-samples-2] > 0 + if self.triggering != self.TRIGGER_NONE: + xpos = self.trigger_xpos + ypos = self.trigger_ypos + samples_to_end = int(samples*(1-xpos)) - ints = np.where(ints)[0] - if len(ints) == 0: - ints = len(buf) - samples + ypos -= 0.5 + ypos *= -32767.0 / self.y_mag + + x_offset = + self.allocation.width * xpos - (samples - samples_to_end) * self.draw_interval + + position = -1 + if self.triggering & self.TRIGGER_POS: + ints = buf[samples-samples_to_end:-samples_to_end-3] <= ypos + ints &= buf[samples-samples_to_end+1:-samples_to_end-2] > ypos + + ints = np.where(ints)[0] + if len(ints) > 0: + position = max(position, ints[-1]) + + if self.triggering & self.TRIGGER_NEG: + ints = buf[samples-samples_to_end:-samples_to_end-3] >= ypos + ints &= buf[samples-samples_to_end+1:-samples_to_end-2] < ypos + + ints = np.where(ints)[0] + if len(ints) > 0: + position = max(position, ints[-1]) + + if position == -1: + position = len(buf) - samples_to_end - 2 else: - ints = ints[-1] - x_offset = int((float(-buf[ints])/(buf[ints+1]-buf[ints]))*self.draw_interval+0.5) + position = position+samples-samples_to_end + try: + x_offset -= int((float(-buf[position]+ypos)/(buf[position+1]-buf[position]))*self.draw_interval+0.5) + except: + pass - data = buf[ints:ints+samples+2].astype(np.float64) + data = buf[position-samples+samples_to_end:position+samples_to_end+2].astype(np.float64) else: data = buf[-samples:].astype(np.float64) @@ -331,17 +383,26 @@ class DrawWaveform(gtk.DrawingArea): ##########The actual drawing of the graph################## - lines = (np.arange(len(data), dtype='float32') * self.draw_interval) - x_offset + lines = (np.arange(len(data), dtype='float32') * self.draw_interval) + x_offset # We must make sure its int, or draw_lines will throw warnings # and these warnings are slow (even though they are filtered)! lines = zip(lines.astype('int'), data.astype('int')) - if self.type[graph_id] ==0: + if (self.fft_show==False): + if self.triggering != self.TRIGGER_NONE: + x = int(self.trigger_xpos * self.allocation.width) + y = int(self.trigger_ypos * self.allocation.height) + length = int(self._TRIGGER_LINE_THICKNESS * 3.5) + self.window.draw_line(self._trigger_line_gc, x - length, y, x + length, y) + self.window.draw_line(self._trigger_line_gc, x, y - length, x, y + length) + + if self.type[graph_id] == 0: self.window.draw_lines(self._line_gc[graph_id], lines) else: self.window.draw_points(self._line_gc[graph_id], lines) ############################################################ + """ ## DISPLAYING FRAMERATE FOR DEBUGGGIN fr = 1.0/( time.time()-self.pr_time) @@ -373,6 +434,12 @@ class DrawWaveform(gtk.DrawingArea): self._update_mode() + def get_trigger(self): + return self.triggering + + def set_trigger(self, trigger): + self.triggering = trigger + def get_ticks(self): return self.allocation.width/float(self._tick_size) |