Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import gst
- import gtk
- import cv
- import rb
- from struct import unpack
- from numpy import average,mean,sqrt,array,ndarray
- class SWave(rb.Plugin):
- def __init__(self):
- rb.Plugin.__init__(self)
- self.width,self.height = 800,30
- self.winWidth = 300
- self.player = None
- #self.img = cv.CreateImage((self.width,self.height), cv.IPL_DEPTH_8U,1)
- self.img = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, self.width, self.height)
- self.scaledimg = None
- self.gtkimage = gtk.Image()
- self.clearImage()
- self.fake = gst.element_factory_make("fakesink")
- self.fake.set_property("signal-handoffs", True)
- self.fake.connect("handoff", self.handler)
- self.m=0
- self.lastpos=None
- self.playingEntry=None
- def activate(self, shell):
- self.b=gtk.EventBox()
- self.b.set_events(gtk.gdk.BUTTON_PRESS_MASK)
- #self.gtkimage.set_from_pixbuf(self.img)
- self.clearImage()
- self.gtkimage.set_visible(True)
- self.b.add(self.gtkimage)
- self.b.set_visible(True)
- self.b.connect('button-press-event', self.imgPressed)
- shell.add_widget(self.b,rb.SHELL_UI_LOCATION_MAIN_TOP,False,True)
- self.player = shell.get_player()
- self.player.props.player.add_tee(self.fake)
- self.player.connect('playing-changed',self.playchanged)
- shell.props.window.connect('expose-event', self.resizeImage)
- print "added"
- def deactivate(self, shell):
- shell.get_player().props.player.remove_tee(self.fake)
- shell.remove_widget(self.b,rb.SHELL_UI_LOCATION_MAIN_TOP)
- def imgPressed(self, eventbox, event):
- pos = int(1e-9 * (event.x * self.duration / self.winWidth) + 0.5)
- self.player.set_playing_time(pos)
- def playchanged(self, RBSplayer, status):
- if status:
- if self.player.get_playing_entry() == self.playingEntry:
- return
- self.duration = 1e9*self.player.get_playing_song_duration()
- self.clearImage()
- def clearImage(self):
- #cv.Rectangle(self.img,(0,0),(self.width,self.height),cv.RGB(0,0,0),-1)
- self.img.pixel_array[:] *= 0
- self.gtkimage.set_from_pixbuf(self.img.scale_simple(self.winWidth, self.height, gtk.gdk.INTERP_BILINEAR))
- self.gtkimage.queue_draw()
- def drawLine(self, time, data):
- imgpos = int(self.width * time/self.duration)
- if self.lastpos == imgpos:
- return
- self.lastpos = imgpos
- avg = int(0.5+ self.height*sqrt(mean(pow(array(data),2))))
- avg = max(1,avg)
- #cv.Line(self.img,(imgpos, self.height/2-avg),(imgpos, self.height/2+avg), cv.RGB(255,255,255),1)
- self.img.pixel_array[self.height/2-avg:self.height/2+avg, imgpos:imgpos+1] = 254
- self.gtkimage.set_from_pixbuf(self.img.scale_simple(self.winWidth, self.height, gtk.gdk.INTERP_BILINEAR))
- self.gtkimage.queue_draw()
- def resizeImage(self,widget, event):
- if widget.allocation[2] == self.winWidth:
- return
- self.winWidth = widget.allocation[2]
- self.gtkimage.set_from_pixbuf(self.img.scale_simple(self.winWidth, self.height, gtk.gdk.INTERP_BILINEAR))
- #self.img.scale(self.scaledimg, 0, 0, self.winWidth, self.height, 0,0,self.width/self.winWidth,1, gtk.gdk.INTERP_BILINEAR)
- self.gtkimage.queue_draw()
- def handler(self, fakesink, gstbuffer, pad, *args):
- l = len(gstbuffer.data)/4
- self.drawLine(gstbuffer.timestamp, unpack('<%if'%l, gstbuffer.data))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement