# -*- Mode: Python -*-
# vi:si:et:sw=4:sts=4:ts=4

import sys

import pygtk
pygtk.require ("2.0")
import gtk
import gobject
gobject.threads_init ()

import pygst
pygst.require ("0.10")
import gst
import gst.interfaces

def on_sync_message (bus, message):
    print "got message: %s" % (repr (message))

pipeline = "alsamixer"
if sys.argv[1:]:
    pipeline = " ".join(sys.argv[1:])
a = gst.element_factory_make(pipeline)

bus = gst.Bus()
a.set_bus (bus)

res = a.set_state(gst.STATE_READY)
if res != gst.STATE_CHANGE_SUCCESS:
    print "Could not set pipeline %s to PAUSED" % pipeline

print "Initial states: "
for t in a.list_tracks():
    sys.stdout.write(t.label)
    if t.flags & gst.interfaces.MIXER_TRACK_INPUT:
      sys.stdout.write(" (I)")
    elif t.flags & gst.interfaces.MIXER_TRACK_OUTPUT:
      sys.stdout.write(" (O)")

    sys.stdout.write(': %d - %d' % (t.min_volume, t.max_volume))
    volumes = a.get_volume(t)
    sys.stdout.write(': %r' % (volumes, ))
    if t.props.num_channels > 0:
        a.set_volume(t, volumes=volumes)
    if t.flags & gst.interfaces.MIXER_TRACK_RECORD:
        sys.stdout.write(' (selected)')
    sys.stdout.write('\n')

bus.enable_sync_message_emission()
bus.connect('sync-message::element', on_sync_message)

gtk.main()
