Skip to content

Commit b7d1d63

Browse files
committed
Input stuff
1 parent 2a06084 commit b7d1d63

1 file changed

Lines changed: 91 additions & 15 deletions

File tree

Tools/audiopy/audiopy

Lines changed: 91 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,42 +73,97 @@ class MainWindow:
7373
# device
7474
self.__devctl = sunaudiodev.open('control')
7575
info = self.__devctl.getinfo()
76-
7776
#
78-
# create the speaker/headphone radio button
79-
label = Label(root, text='Output to:')
77+
# where does input come from?
78+
frame = Frame(root, bd=1, relief=RAISED)
79+
frame.grid(row=0, column=0)
80+
label = Label(frame, text='Input From:')
81+
label.grid(row=0, column=0, sticky=E)
82+
self.__micvar = IntVar()
83+
btn = Checkbutton(frame,
84+
text='Microphone',
85+
variable=self.__micvar,
86+
onvalue=MICROPHONE,
87+
command=self.__pushtodev,
88+
underline=0)
89+
btn.grid(row=0, column=1, sticky=W)
90+
root.bind('<Alt-m>', self.__mic)
91+
root.bind('<Alt-M>', self.__mic)
92+
self.__lineinvar = IntVar()
93+
btn = Checkbutton(frame,
94+
text='Line In',
95+
variable=self.__lineinvar,
96+
onvalue=LINE_IN,
97+
command=self.__pushtodev,
98+
underline=5)
99+
btn.grid(row=1, column=1, sticky=W)
100+
root.bind('<Alt-i>', self.__linein)
101+
root.bind('<Alt-I>', self.__linein)
102+
self.__cdvar = IntVar()
103+
btn = Checkbutton(frame,
104+
text='CD',
105+
variable=self.__cdvar,
106+
onvalue=CD,
107+
command=self.__pushtodev,
108+
underline=0)
109+
btn.grid(row=2, column=1, sticky=W)
110+
root.bind('<Alt-c>', self.__cd)
111+
root.bind('<Alt-C>', self.__cd)
112+
#
113+
# where does output go to?
114+
frame = Frame(root, bd=1, relief=RAISED)
115+
frame.grid(row=1, column=0)
116+
label = Label(frame, text='Output To:')
80117
label.grid(row=0, column=0, sticky=E)
81118
self.__spkvar = IntVar()
82-
btn = Checkbutton(root,
119+
btn = Checkbutton(frame,
83120
text='Speaker',
84121
variable=self.__spkvar,
85122
onvalue=SPEAKER,
86-
command=self.__outputto,
123+
command=self.__pushtodev,
87124
underline=0)
88125
btn.grid(row=0, column=1, sticky=W)
89126
root.bind('<Alt-s>', self.__speaker)
90127
root.bind('<Alt-S>', self.__speaker)
91128
self.__headvar = IntVar()
92-
btn = Checkbutton(root,
129+
btn = Checkbutton(frame,
93130
text='Headphones',
94131
variable=self.__headvar,
95132
onvalue=HEADPHONE,
96-
command=self.__outputto,
133+
command=self.__pushtodev,
97134
underline=0)
98135
btn.grid(row=1, column=1, sticky=W)
99136
root.bind('<Alt-h>', self.__headphones)
100137
root.bind('<Alt-H>', self.__headphones)
101138
self.__linevar = IntVar()
102-
btn = Checkbutton(root,
139+
btn = Checkbutton(frame,
103140
variable=self.__linevar,
104141
onvalue=LINE_OUT,
105-
text='Line out',
106-
command=self.__outputto,
142+
text='Line Out',
143+
command=self.__pushtodev,
107144
underline=0)
108145
btn.grid(row=2, column=1, sticky=W)
109146
root.bind('<Alt-l>', self.__lineout)
110147
root.bind('<Alt-L>', self.__lineout)
111-
148+
#
149+
# do we need to poll for changes?
150+
self.__needtopoll = 1
151+
try:
152+
fd = self.__devctl.fileno()
153+
self.__needtopoll = 0
154+
except AttributeError:
155+
pass
156+
else:
157+
import struct
158+
import fcntl
159+
import signal
160+
import FCNTL
161+
import STROPTS
162+
# set up the signal handler
163+
signal.signal(signal.SIGPOLL, self.__update)
164+
fcntl.ioctl(fd, STROPTS.I_SETSIG, STROPTS.S_MSG)
165+
self.__update()
166+
112167
def __quit(self, event=None):
113168
self.__devctl.close()
114169
self.__root.quit()
@@ -117,28 +172,46 @@ class MainWindow:
117172
# Exercise the Python interpreter regularly so keyboard interrupts get
118173
# through.
119174
self.__tkroot.tk.createtimerhandler(KEEPALIVE_TIMER, self.__keepalive)
120-
#
175+
if self.__needtopoll:
176+
self.__update()
177+
178+
def __update(self, num=None, frame=None):
121179
# We have to poll because the device could have changed state and the
122180
# underlying module does not support the SIGPOLL notification
123181
# interface.
124182
info = self.__devctl.getinfo()
125183
self.__spkvar.set(info.o_port & SPEAKER)
126184
self.__headvar.set(info.o_port & HEADPHONE)
127185
self.__linevar.set(info.o_port & LINE_OUT)
186+
self.__micvar.set(info.i_port & MICROPHONE)
187+
self.__lineinvar.set(info.i_port & LINE_IN)
188+
self.__cdvar.set(info.i_port & CD)
128189

129-
def __outputto(self, event=None):
190+
def __pushtodev(self, event=None):
130191
info = self.__devctl.getinfo()
131192
info.o_port = self.__spkvar.get() + \
132193
self.__headvar.get() + \
133194
self.__linevar.get()
195+
info.i_port = self.__micvar.get() + \
196+
self.__lineinvar.get() + \
197+
self.__cdvar.get()
134198
self.__devctl.setinfo(info)
135199

136200
def __getset(self, var, onvalue):
137201
if var.get():
138202
var.set(0)
139203
else:
140204
var.set(onvalue)
141-
self.__outputto()
205+
self.__pushtodev()
206+
207+
def __mic(self, event=None):
208+
self.__getset(self.__micvar, MICROPHONE)
209+
210+
def __linein(self, event=None):
211+
self.__getset(self.__lineinvar, LINE_IN)
212+
213+
def __cd(self, event=None):
214+
self.__getset(self.__cdvar, CD)
142215

143216
def __speaker(self, event=None):
144217
self.__getset(self.__spkvar, SPEAKER)
@@ -165,7 +238,10 @@ def main():
165238
if len(sys.argv) == 1:
166239
# GUI
167240
w = MainWindow()
168-
w.start()
241+
try:
242+
w.start()
243+
except KeyboardInterrupt:
244+
pass
169245
return
170246

171247
# command line

0 commit comments

Comments
 (0)