~ubuntu-branches/ubuntu/edgy/jokosher/edgy

« back to all changes in this revision

Viewing changes to InstrumentConnectionsDialog.py

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2006-07-19 18:49:10 UTC
  • Revision ID: james.westby@ubuntu.com-20060719184910-0av4ghk8vsjvcij3
Tags: upstream-0.1
ImportĀ upstreamĀ versionĀ 0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
import gtk
 
3
import gtk.glade
 
4
import gobject
 
5
import pygst
 
6
pygst.require("0.10")
 
7
import gst
 
8
import os
 
9
import sys
 
10
import Globals
 
11
import Project
 
12
import AlsaDevices
 
13
 
 
14
#=========================================================================
 
15
 
 
16
class InstrumentConnectionsDialog:
 
17
        """ This class handles all of the processing associated with the
 
18
                Instrument Connections dialog.
 
19
        """     
 
20
        #_____________________________________________________________________
 
21
 
 
22
        def __init__(self, project, parent):
 
23
                                
 
24
                if project:
 
25
                        self.project = project
 
26
                else:
 
27
                        return
 
28
                
 
29
                self.res = gtk.glade.XML(parent.GLADE_PATH, "InstrumentConnectionsDialog")
 
30
 
 
31
                self.signals = {
 
32
                        "on_close_clicked" : self.OnClose,
 
33
                }
 
34
                
 
35
                self.res.signal_autoconnect(self.signals)
 
36
 
 
37
                self.window = self.res.get_widget("InstrumentConnectionsDialog")
 
38
                self.vbox = self.res.get_widget("vbox")
 
39
                
 
40
                if len(self.project.instruments) > 0:
 
41
                        self.Populate()
 
42
                else:
 
43
                        self.res.get_widget("explainLabel").set_text("There are no instruments to connect")
 
44
 
 
45
                self.parent = parent
 
46
                self.window.set_icon(self.parent.icon)
 
47
                self.window.show_all()
 
48
 
 
49
        #_____________________________________________________________________
 
50
 
 
51
        def OnClose(self, button):
 
52
                self.window.destroy()
 
53
 
 
54
        def Populate(self):
 
55
                self.mixers = {}
 
56
        
 
57
                for device in AlsaDevices.GetAlsaList("capture").values():
 
58
 
 
59
                        #Don't want the default device twice (once as 'default' and once as its actual hw ref)
 
60
                        if device == "default":
 
61
                                continue
 
62
 
 
63
                        mixer = gst.element_factory_make('alsamixer')
 
64
                        mixer.set_property("device", device)
 
65
                        mixer.set_state(gst.STATE_READY)
 
66
 
 
67
                        if not mixer.implements_interface(gst.interfaces.Mixer):
 
68
                                print 'Cannot get mixer tracks from the device. Check permissions on the mixer device.'
 
69
                        else:
 
70
                                self.mixers[device] = mixer.list_tracks()
 
71
                        
 
72
                        mixer.set_state(gst.STATE_NULL)
 
73
                
 
74
                for instr in self.project.instruments:                  
 
75
                        instrument = instr
 
76
                        row = gtk.HBox()
 
77
                        row.set_spacing(10)
 
78
                        image = gtk.Image()
 
79
                        image.set_from_pixbuf(instrument.pixbuf)
 
80
                        label = gtk.Label(instrument.name)
 
81
                        
 
82
                        liststore = gtk.ListStore(gobject.TYPE_STRING)
 
83
                        combobox = gtk.ComboBox(liststore)
 
84
                        cell = gtk.CellRendererText()
 
85
                        combobox.pack_start(cell, True)
 
86
                        combobox.add_attribute(cell, 'text', 0)
 
87
 
 
88
                        self.AlsaID = []
 
89
 
 
90
                        currentItem = 0
 
91
                        for device in self.mixers:
 
92
                                mixertracks = self.mixers[device]
 
93
                                for t in mixertracks:
 
94
                                        if t.flags & gst.interfaces.MIXER_TRACK_INPUT:
 
95
                                                combobox.append_text(t.label)
 
96
                                                if instr.inTrack and instr.input == device and t.label == instr.inTrack:
 
97
                                                        combobox.set_active(currentItem)
 
98
                                                self.AlsaID.append(device)
 
99
                                                currentItem += 1
 
100
                        
 
101
                        combobox.connect("changed", self.OnSelected, instr)
 
102
                        row.pack_start(combobox, False, False)
 
103
                        row.pack_start(image, False, False)
 
104
                        row.pack_start(label, False, False)
 
105
                        
 
106
                        self.vbox.add(row)
 
107
                        
 
108
        def OnSelected(self, widget, instr):
 
109
                '''Set the instrument's input'''
 
110
                device = self.AlsaID[widget.get_active()]
 
111
                mixertracks = self.mixers[device]
 
112
                for track in mixertracks:
 
113
                        if track.label == widget.get_active_text():
 
114
                                inTrack = track.label
 
115
                print inTrack
 
116
                if device != instr.input or inTrack != instr.inTrack:
 
117
                        instr.input = device
 
118
                        instr.inTrack = inTrack
 
119
                        self.project.unsavedChanges = True