Logo Search packages:      
Sourcecode: jokosher version File versions  Download package

def EventViewer::EventViewer::DrawWaveform (   self,
  exposeArea 
)

This function uses Cairo to draw the waveform level information
      onto a canvas in memory.

Definition at line 202 of file EventViewer.py.

00202                                         :
            """ This function uses Cairo to draw the waveform level information
                  onto a canvas in memory.
            """
            allocArea = self.get_allocation()
            
            rect = gtk.gdk.Rectangle(exposeArea.x - exposeArea.width, exposeArea.y,
                                    exposeArea.width*3, exposeArea.height)
            #Check if our area to cache is outside the allocated area
            if rect.x < 0:
                  rect.x = 0
            if rect.x + rect.width > allocArea.width:
                  rect.width = allocArea.width - rect.x
                  
            self.source = cairo.ImageSurface(cairo.FORMAT_ARGB32, rect.width, rect.height)

            context = cairo.Context(self.source)
            context.set_line_width(2)
            context.set_antialias(cairo.ANTIALIAS_SUBPIXEL)
            
            if self.event.isLoading:
                  # Draw a white background
                  context.rectangle(0, 0, rect.width, rect.height)
                  context.set_source_rgb(*self._BACKGROUND_RGB)
                  context.fill()
                  # and a border
                  context.set_line_width(2)
                  context.rectangle(0, 0, rect.width, rect.height)
                  context.set_source_rgb(*self._TEXT_RGB)
                  context.stroke()
                  # Write "Loading..."
                  context.move_to(5, 12)
                  if self.event.duration == 0:
                        displayLength = 0
                  else:
                        displayLength = int(100 * self.event.loadingLength / self.event.duration)
                  context.show_text("Loading (%d%%)..." % displayLength)
                  context.stroke()
                  # And exit here
                  return
            
            if len(self.event.levels) == 0:
                  raise "Trying to draw an event with no level data!"
            
            scale = (self.event.duration * self.project.viewScale) / float(len(self.event.levels))

            # Draw white background
            context.rectangle(0, 0, rect.width, rect.height)
            context.set_source_rgb(*self._BACKGROUND_RGB)
            context.fill()

            # draw the fade line
            context.set_source_rgb(*self._FADELINE_RGB)
            context.move_to(0,0) # FIXME: scale the Y!
            pixy = 0
            for sec,vol in self.event.audioFadePoints:
                  pixx = self.pixxFromSec(sec)
                  pixy = self.pixyFromVol(vol)
                  context.line_to(pixx,pixy)
            pixxEnd = self.pixxFromSec(self.event.duration)
            context.line_to(pixxEnd,pixy)
            
            context.stroke()

            # Draw volume curve
            x_pos = int(rect.x/scale)
            x = 0
            context.move_to(0,rect.height)
                        
            # calculate the fade curve
            fadecurve = self.getFadeCurve(self.event.duration, 
                        self.event.audioFadePoints, 
                        len(self.event.levels))
            # apply the fade curve to the volume curve to get new volumes
            levelsToUse = [x[0]*x[1] for x in zip(self.event.levels,fadecurve)]
            
            for peak in levelsToUse[x_pos:]:
                  x = (x_pos*scale) - rect.x
                  peakOnScreen = int(peak * rect.height)
                  context.line_to(x, rect.height - peakOnScreen)
                  
                  if x > rect.width:
                        break
                  x_pos += 1
            
            context.line_to(x, rect.height)
            
            #levels gradient fill
            gradient = cairo.LinearGradient(0.0, 0.0, 0, rect.height)
            gradient.add_color_stop_rgba(*self._OPAQUE_GRADIENT_STOP_ORGBA)
            gradient.add_color_stop_rgba(*self._TRANSPARENT_GRADIENT_STOP_ORGBA)
            context.set_source(gradient)
            context.fill_preserve()
            
            #levels path (on top of the fill)
            context.set_source_rgb(*self._BORDER_RGB)
            context.set_line_join(cairo.LINE_JOIN_ROUND)
            if scale < self._MAX_LINE_WIDTH:
                  context.set_line_width(scale)
            else:
                  context.set_line_width(self._MAX_LINE_WIDTH)
            context.stroke()
            
            # Reset the drawing scale
            context.identity_matrix()
            context.scale(1.0, 1.0)
            
            # Draw black border
            if (self.event.isSelected):
                  context.set_line_width(4)
            else:
                  context.set_line_width(2)
            context.rectangle(0, 0, rect.width, rect.height)
            context.set_source_rgb(*self._BORDER_RGB)
            context.stroke()
            context.set_line_width(2)
            
            #check if we are at the beginning
            if rect.x == 0:
                  #Draw event name
                  context.set_source_rgb(*self._TEXT_RGB)
                  context.move_to(5, 12)
                  context.show_text(self.event.name)
            
            #set area to record where the cached surface goes
            self.cachedDrawArea = rect
            self.redrawWaveform = False

      #_____________________________________________________________________

      def OnMouseMove(self,widget,mouse):


Generated by  Doxygen 1.6.0   Back to index