예제 #1
0
 def on_message(self, bus, message):
     t = message.type
     if t == gst.MESSAGE_EOS:
         self.eos()
     elif t == gst.MESSAGE_ERROR:
         mygtk.show_error("gstreamer error: %s - %s" %
                          message.parse_error())
예제 #2
0
    def __init__(self, sink):
        gst.Pipeline.__init__(self)
        try:
            self.playbin = gst.element_factory_make("playbin2")
        except gst.ElementNotFoundError:
            self.playbin = gst.element_factory_make("playbin")
        self.add(self.playbin)

        bin = gst.Bin("speed-bin")
        try:
            self.speedchanger = gst.element_factory_make("pitch")
        except gst.ElementNotFoundError:
            mygtk.show_error(
                _(u"You need to install the gstreamer soundtouch elements for "
                  "play it slowly to. They are part of gstreamer-plugins-bad. Consult the "
                  "README if you need more information.")).run()
            raise SystemExit()

        bin.add(self.speedchanger)

        self.audiosink = sink

        bin.add(self.audiosink)
        convert = gst.element_factory_make("audioconvert")
        bin.add(convert)
        gst.element_link_many(self.speedchanger, convert)
        gst.element_link_many(convert, self.audiosink)
        sink_pad = gst.GhostPad("sink", self.speedchanger.get_pad("sink"))
        bin.add_pad(sink_pad)
        self.playbin.set_property("audio-sink", bin)
        bus = self.playbin.get_bus()
        bus.add_signal_watch()
        bus.connect("message", self.on_message)

        self.eos = lambda: None
예제 #3
0
    def __init__(self, sink):
        gst.Pipeline.__init__(self)
        self.playbin = gst.element_factory_make("playbin")
        self.add(self.playbin)

        bin = gst.Bin("speed-bin")
        try:
            self.speedchanger = gst.element_factory_make("pitch")
        except gst.ElementNotFoundError:
            mygtk.show_error(_(u"You need to install the gstreamer soundtouch elements for "
                    "play it slowly to. They are part of gstreamer-plugins-bad. Consult the "
                    "README if you need more information.")).run()
            raise SystemExit()

        bin.add(self.speedchanger)

        self.audiosink = sink

        bin.add(self.audiosink)
        convert = gst.element_factory_make("audioconvert")
        bin.add(convert)
        gst.element_link_many(self.speedchanger, convert)
        gst.element_link_many(convert, self.audiosink)
        sink_pad = gst.GhostPad("sink", self.speedchanger.get_pad("sink"))
        bin.add_pad(sink_pad)
        self.playbin.set_property("audio-sink", bin)
        bus = self.playbin.get_bus()
        bus.add_signal_watch()
        bus.connect("message", self.on_message)

        self.eos = lambda: None
예제 #4
0
 def on_message(self, bus, message):
     t = message.type
     if t == gst.MESSAGE_EOS:
         self.eos()
     elif t == gst.MESSAGE_ERROR:
         mygtk.show_error("gstreamer error: %s - %s" % message.parse_error())
예제 #5
0
    def __init__(self, sink, config):
        gtk.Window.__init__(self,gtk.WINDOW_TOPLEVEL)

        self.set_title(NAME)

        try:
            self.set_icon(mygtk.iconfactory.get_icon("playitslowly", 128))
        except gobject.GError:
            print "could not load playitslowly icon"

        self.set_default_size(500, 200)
        self.set_border_width(5)

        self.vbox = gtk.VBox()
        self.accel_group = gtk.AccelGroup()
        self.add_accel_group(self.accel_group)

        try:
            self.pipeline = Pipeline(sink)
        except gst.ElementNotFoundError:
            #TODO Need better error handling because other gstreamer elements could also be missing.
            mygtk.show_error(_(u"You need to install the gstreamer soundtouch elements for "
                    "play it slowly to. They are part of gstreamer-plugins-bad. Consult the "
                    "README if you need more information.")).run()
            raise SystemExit()
        self.pipeline.set_on_error_cb(self.on_error_cb)

        self.filedialog = mygtk.FileChooserDialog(None, self, gtk.FILE_CHOOSER_ACTION_OPEN)
        self.filedialog.connect("response", self.filechanged)
        filechooserhbox = gtk.HBox()
        self.filechooser = gtk.FileChooserButton(self.filedialog)
        filechooserhbox.pack_start(self.filechooser, True, True)
        self.recentbutton = gtk.Button(_("Recent"))
        self.recentbutton.connect("clicked", self.show_recent)
        filechooserhbox.pack_end(self.recentbutton, False, False)

        self.speedchooser = mygtk.TextScaleReset(gtk.Adjustment(1.00, 0.10, 4.0, 0.05, 0.05))
        self.speedchooser.scale.connect("value-changed", self.speedchanged)
        self.speedchooser.scale.connect("button-press-event", self.speedpress)
        self.speedchooser.scale.connect("button-release-event", self.speedrelease)
        self.speedchangeing = False

        self.pitchchooser = mygtk.TextScaleReset(gtk.Adjustment(0.0, -24.0, 24.0, 1.0, 1.0, 1.0))
        self.pitchchooser.scale.connect("value-changed", self.pitchchanged)

        self.pitchchooser_fine = mygtk.TextScaleReset(gtk.Adjustment(0.0, -50, 50, 1.0, 1.0, 1.0))
        self.pitchchooser_fine.scale.connect("value-changed", self.pitchchanged)

        self.positionchooser = mygtk.ClockScale(gtk.Adjustment(0.0, 0.0, 100.0))
        self.positionchooser.scale.connect("button-press-event", self.start_seeking)
        self.positionchooser.scale.connect("button-release-event", self.positionchanged)
        self.seeking = False

        self.startchooser = mygtk.TextScaleWithCurPos(self.positionchooser, gtk.Adjustment(0.0, 0, 100.0))
        self.startchooser.scale.connect("button-press-event", self.start_seeking)
        self.startchooser.scale.connect("button-release-event", self.seeked)
        self.startchooser.add_accelerator("clicked", self.accel_group, ord('['), gtk.gdk.CONTROL_MASK, ())
        self.startchooser.add_accelerator("clicked", self.accel_group, ord('['), 0, ())

        self.endchooser = mygtk.TextScaleWithCurPos(self.positionchooser, gtk.Adjustment(1.0, 0, 100.0, 0.01, 0.01))
        self.endchooser.scale.connect("button-press-event", self.start_seeking)
        self.endchooser.scale.connect("button-release-event", self.seeked)
        self.endchooser.add_accelerator("clicked", self.accel_group, ord(']'), gtk.gdk.CONTROL_MASK, ())
        self.endchooser.add_accelerator("clicked", self.accel_group, ord(']'), 0, ())

        self.vbox.pack_start(filechooserhbox)
        self.vbox.pack_start(self.positionchooser)
        self.vbox.pack_start(mygtk.form([(_(u"Speed (times)"), self.speedchooser),
            (_(u"Pitch (semitones)"), self.pitchchooser),
            (_(u"Fine Pitch (cents)"), self.pitchchooser_fine),
            (_(u"Start Position (seconds)"), self.startchooser),
            (_(u"End Position (seconds)"), self.endchooser)
        ]), False, False)

        buttonbox = gtk.HButtonBox()
        self.vbox.pack_end(buttonbox, False, False)

        self.play_button = gtk.ToggleButton(gtk.STOCK_MEDIA_PLAY)
        self.play_button.connect("toggled", self.play)
        self.play_button.set_use_stock(True)
        self.play_button.set_sensitive(False)
        buttonbox.pack_start(self.play_button)
        # make SPACE a shortcut for play/pause (CTRL-SPC would be better?)
        self.play_button.add_accelerator("clicked", self.accel_group, ord(' '), 0, ())

        self.back_button = gtk.Button(gtk.STOCK_MEDIA_REWIND)
        self.back_button.connect("clicked", self.back)
        self.back_button.set_use_stock(True)
        self.back_button.set_sensitive(False)
        buttonbox.pack_start(self.back_button)

        self.volume_button = gtk.VolumeButton()
        self.volume_button.set_value(1.0)
        self.volume_button.set_relief(gtk.RELIEF_NORMAL)
        self.volume_button.connect("value-changed", self.volumechanged)
        buttonbox.pack_start(self.volume_button)

        self.save_as_button = gtk.Button(stock=gtk.STOCK_SAVE_AS)
        self.save_as_button.connect("clicked", self.save)
        self.save_as_button.set_sensitive(False)
        buttonbox.pack_start(self.save_as_button)

        button_about = gtk.Button(stock=gtk.STOCK_ABOUT)
        button_about.connect("clicked", self.about)
        buttonbox.pack_end(button_about)

        self.connect("key-release-event", self.key_release)

        self.add(self.vbox)
        self.connect("destroy", gtk.main_quit)

        self.config = config
        self.config_saving = False
        self.load_config()
예제 #6
0
 def on_error_cb(self, error):
     mygtk.show_error(error)