Esempio n. 1
0
    def __volume(self, value=None):
        player = self.__bla.player

        # Read value
        if value is None:
            return blacfg.getfloat("player", "volume")
        else:
            player.set_volume(value)
Esempio n. 2
0
    def __init__(self):
        super(VolumeControl, self).__init__(spacing=5)

        self.__volume = int(blacfg.getfloat("player", "volume") * 100)
        state = blacfg.getboolean("player", "muted")
        if not state:
            volume = self.__volume
        else:
            volume = 0.0

        # The mute button
        self.__image = gtk.Image()
        mute = gtk.ToggleButton()
        mute.add(self.__image)
        mute.set_relief(gtk.RELIEF_NONE)
        mute.set_active(state)
        mute.connect("toggled", self.__mute_toggled)

        # The volume scale
        self.__scale = gtk.HScale()
        self.__scale.set_range(0, 100)
        self.__scale.set_increments(-1, -10)
        self.__scale.set_size_request(120, 20)
        self.__scale.set_update_policy(gtk.UPDATE_CONTINUOUS)
        self.__scale.set_draw_value(False)
        self.__scale.set_value(volume)
        self.__scale.connect("value_changed", self.__volume_changed)
        self.__scale.connect("button_press_event", self.__button_press_event)
        self.__scale.connect(
            "button_release_event", self.__button_release_event)
        self.__scale.connect("scroll_event", self.__scroll_event)
        self.__scale.connect("key_press_event", lambda *x: True)
        self.__scale.connect("query_tooltip", self.__query_tooltip)
        self.__scale.set_has_tooltip(True)

        self.__update_icon(state)

        self.pack_start(mute, expand=False)
        self.pack_start(self.__scale, expand=True)
Esempio n. 3
0
    def __init_pipeline(self):
        if not gstreamer_is_working:
            self.stop()
            from blaplay.blagui import blaguiutils
            blaguiutils.error_dialog(
                "Error", "Failed to construct GStreamer pipeline. Make sure "
                "GStreamer 0.10, its Python bindings, and gst-plugins-base "
                "and gst-plugins-good are installed.")
            return False

        audio_sink = gst.Bin()

        filt = gst.element_factory_make("capsfilter")
        filt.set_property(
            "caps", gst.caps_from_string("audio/x-raw-float,"
                                         "rate=(int)44100,"
                                         "channels=(int)2,"
                                         "width=(int)32,"
                                         "depth=(int)32,"
                                         "endianness=(int)1234"))
        self.__equalizer = gst.element_factory_make("equalizer-10bands")
        tee = gst.element_factory_make("tee")
        queue = gst.element_factory_make("queue")
        queue.set_property("silent", True)

        def new_buffer(sink):
            self.emit("new_buffer", sink.emit("pull_buffer"))
        appsink = gst.element_factory_make("appsink")
        appsink.set_property("drop", True)
        appsink.set_property("sync", True)
        appsink.set_property("emit_signals", True)
        appsink.connect("new_buffer", new_buffer)

        sink = gst.element_factory_make("autoaudiosink")

        self.__volume = gst.element_factory_make("volume")
        elements = [filt, self.__equalizer, tee, queue, appsink,
                    self.__volume, sink]
        map(audio_sink.add, elements)

        pad = elements[0].get_static_pad("sink")
        audio_sink.add_pad(gst.GhostPad("sink", pad))

        gst.element_link_many(filt, self.__equalizer, tee)
        gst.element_link_many(tee, self.__volume, sink)
        gst.element_link_many(tee, queue, appsink)

        video_sink = gst.element_factory_make("xvimagesink")
        video_sink.set_property("force_aspect_ratio", True)

        self.__bin = gst.element_factory_make("playbin2")
        self.__bin.set_property("audio_sink", audio_sink)
        self.__bin.set_property("buffer_duration", 500 * gst.MSECOND)
        self.__bin.set_property("video_sink", video_sink)

        self.__bin.connect("about_to_finish", self.__about_to_finish)
        self.__bin.set_state(gst.STATE_READY)

        bus = self.__bin.get_bus()
        bus.add_signal_watch()
        bus.enable_sync_message_emission()
        self.__message_id = bus.connect("message", self.__message)
        self.__sync_message_id = bus.connect(
            "sync-message::element", self.__sync_message)

        if blacfg.getboolean("player", "muted"):
            volume = 0
        else:
            volume = blacfg.getfloat("player", "volume") * 100
        self.set_volume(volume)

        self.enable_equalizer(blacfg.getboolean("player", "use.equalizer"))

        return True
Esempio n. 4
0
 def __volume_scale_changed(self, checkbutton):
     blacfg.setboolean("player", "logarithmic.volume.scale",
                       checkbutton.get_active())
     player.set_volume(blacfg.getfloat("player", "volume") * 100)