Kaydet (Commit) a4b055ff authored tarafından Barry Warsaw's avatar Barry Warsaw

Add a scale widget and command line options to set the output volume.

Bump version number 1.0
üst c7c9a648
...@@ -7,9 +7,9 @@ Version: 0.1 ...@@ -7,9 +7,9 @@ Version: 0.1
Introduction Introduction
Audiopy is a program to control the Solaris audio device, allowing Audiopy is a program to control the Solaris audio device, allowing
you to set both the input and output devices. It can be run you to choose both the input and output devices, and to set the
either as a standalone command-line script, or as a Tkinter based output volume. It can be run either as a standalone command-line
GUI application. script, or as a Tkinter based GUI application.
Note that your version of Python must have been built with the Note that your version of Python must have been built with the
sunaudiodev module enabled. It is not enabled by default however! sunaudiodev module enabled. It is not enabled by default however!
...@@ -26,6 +26,8 @@ Introduction ...@@ -26,6 +26,8 @@ Introduction
devices: the headphone jack, the speakers, or the line-out jack. devices: the headphone jack, the speakers, or the line-out jack.
You can enable any combination of these three devices. You can enable any combination of these three devices.
You can also set the output gain (volume) level.
Running as a GUI Running as a GUI
Simply start audiopy with no arguments to start it as a Tkinter Simply start audiopy with no arguments to start it as a Tkinter
...@@ -43,10 +45,10 @@ Running as a GUI ...@@ -43,10 +45,10 @@ Running as a GUI
Alt-q is also an accelerator for selecting Quit from the File Alt-q is also an accelerator for selecting Quit from the File
menu. menu.
No unsupported devices will appear in the GUI. When run as a GUI, Unsupported devices will appear dimmed out in the GUI. When run
audiopy monitors the audio device and automatically updates its as a GUI, audiopy monitors the audio device and automatically
display if the state of the device is changed by some other updates its display if the state of the device is changed by some
means. In pre-Python 1.5.2 this is done by occasionally polling other means. In Python 1.5.2 this is done by occasionally polling
the device, but in Python 1.5.2 no polling is necessary (you don't the device, but in Python 1.5.2 no polling is necessary (you don't
really need to know this, but I thought I'd plug 1.5.2 :-). really need to know this, but I thought I'd plug 1.5.2 :-).
...@@ -85,7 +87,13 @@ Running as a Command Line Program ...@@ -85,7 +87,13 @@ Running as a Command Line Program
% ./audiopy -s=0 -p=1 -c % ./audiopy -s=0 -p=1 -c
Audiopy understands two other command line options: Audiopy understands these other command line options:
--gain volume
-g volume
Sets the output volume to the specified gain level. This must
be an integer between MIN_GAIN and MAX_GAIN (usually [0..255],
but use the -h option to find the exact values).
--version --version
-v -v
......
...@@ -7,10 +7,10 @@ Email: bwarsaw@python.org ...@@ -7,10 +7,10 @@ Email: bwarsaw@python.org
Version: %(__version__)s Version: %(__version__)s
When no arguments are given, this pops up a graphical window which lets you When no arguments are given, this pops up a graphical window which lets you
choose the audio input and output devices. choose the audio input and output devices, and set the output volume.
This program can be driven via the command line, and when done so, no window This program can be driven via the command line, and when done so, no window
pops up. Options have the general form: pops up. Most options have the general form:
--device[={0,1}] --device[={0,1}]
-d[={0,1}] -d[={0,1}]
...@@ -31,6 +31,11 @@ The list of devices and their short options are: ...@@ -31,6 +31,11 @@ The list of devices and their short options are:
Other options are: Other options are:
--gain volume
-g volume
Sets the output gain to the specified volume, which must be an integer
in the range [%(MIN_GAIN)s..%(MAX_GAIN)s]
--version --version
-v -v
Print the version number and exit. Print the version number and exit.
...@@ -49,7 +54,7 @@ from SUNAUDIODEV import * ...@@ -49,7 +54,7 @@ from SUNAUDIODEV import *
# Milliseconds between interrupt checks # Milliseconds between interrupt checks
KEEPALIVE_TIMER = 500 KEEPALIVE_TIMER = 500
__version__ = '0.1' __version__ = '1.0'
...@@ -213,6 +218,21 @@ class MainWindow: ...@@ -213,6 +218,21 @@ class MainWindow:
root.bind('<Alt-q>', self.__quit) root.bind('<Alt-q>', self.__quit)
root.bind('<Alt-Q>', self.__quit) root.bind('<Alt-Q>', self.__quit)
# #
# Volume
frame = Frame(root, bd=1, relief=RAISED)
frame.grid(row=3, column=0, sticky='NSEW')
label = Label(frame, text='Output Volume:')
label.grid(row=0, column=0, sticky=W)
self.__scalevar = IntVar()
self.__scale = Scale(frame,
orient=HORIZONTAL,
from_=MIN_GAIN,
to=MAX_GAIN,
length=200,
variable=self.__scalevar,
command=self.__volume)
self.__scale.grid(row=1, column=0, sticky=EW)
#
# do we need to poll for changes? # do we need to poll for changes?
self.__needtopoll = 1 self.__needtopoll = 1
try: try:
...@@ -268,6 +288,8 @@ Email: bwarsaw@python.org''' % __version__) ...@@ -268,6 +288,8 @@ Email: bwarsaw@python.org''' % __version__)
self.__spkvar.set(info.o_port & SPEAKER) self.__spkvar.set(info.o_port & SPEAKER)
self.__headvar.set(info.o_port & HEADPHONE) self.__headvar.set(info.o_port & HEADPHONE)
self.__linevar.set(info.o_port & LINE_OUT) self.__linevar.set(info.o_port & LINE_OUT)
# volume
self.__scalevar.set(info.o_gain)
def __pushtodev(self, event=None): def __pushtodev(self, event=None):
info = self.__devctl.getinfo() info = self.__devctl.getinfo()
...@@ -275,6 +297,7 @@ Email: bwarsaw@python.org''' % __version__) ...@@ -275,6 +297,7 @@ Email: bwarsaw@python.org''' % __version__)
self.__headvar.get() + \ self.__headvar.get() + \
self.__linevar.get() self.__linevar.get()
info.i_port = self.__inputvar.get() info.i_port = self.__inputvar.get()
info.o_gain = self.__scalevar.get()
self.__devctl.setinfo(info) self.__devctl.setinfo(info)
def __getset(self, var, onvalue): def __getset(self, var, onvalue):
...@@ -306,6 +329,9 @@ Email: bwarsaw@python.org''' % __version__) ...@@ -306,6 +329,9 @@ Email: bwarsaw@python.org''' % __version__)
def __lineout(self, event=None): def __lineout(self, event=None):
self.__getset(self.__linevar, LINE_OUT) self.__getset(self.__linevar, LINE_OUT)
def __volume(self, event=None):
self.__pushtodev()
def start(self): def start(self):
self.__keepalive() self.__keepalive()
self.__tkroot.mainloop() self.__tkroot.mainloop()
...@@ -361,7 +387,7 @@ class Helpwin: ...@@ -361,7 +387,7 @@ class Helpwin:
def usage(msg='', code=1): def usage(code, msg=''):
print __doc__ % globals() print __doc__ % globals()
if msg: if msg:
print msg print msg
...@@ -398,10 +424,23 @@ def main(): ...@@ -398,10 +424,23 @@ def main():
info = device.getinfo() info = device.getinfo()
# first get the existing values # first get the existing values
for arg in sys.argv[1:]: i = 0
while i < len(sys.argv)-1:
i = i + 1
arg = sys.argv[i]
if arg in ('-h', '--help'): if arg in ('-h', '--help'):
usage(code=0) usage(0)
# does not return # does not return
elif arg in ('-g', '--gain'):
gainspec = '<missing>'
try:
gainspec = sys.argv[i+1]
gain = int(gainspec)
except (ValueError, IndexError):
usage(1, 'Bad gain specification: ' + gainspec)
info.o_gain = gain
i = i + 1
continue
elif arg in ('-v', '--version'): elif arg in ('-v', '--version'):
print '''\ print '''\
audiopy -- a program to control the Solaris audio device. audiopy -- a program to control the Solaris audio device.
...@@ -424,7 +463,7 @@ Version: %s''' % __version__ ...@@ -424,7 +463,7 @@ Version: %s''' % __version__
elif arg[:len(short)+1] == short+'=': elif arg[:len(short)+1] == short+'=':
val = int(arg[len(short)+1:]) val = int(arg[len(short)+1:])
except ValueError: except ValueError:
usage(msg='Invalid option: ' + arg) usage(1, msg='Invalid option: ' + arg)
# does not return # does not return
if val == 0: if val == 0:
if io == 0: if io == 0:
...@@ -440,7 +479,7 @@ Version: %s''' % __version__ ...@@ -440,7 +479,7 @@ Version: %s''' % __version__
break break
# else keep trying next option # else keep trying next option
else: else:
usage(msg='Invalid option: ' + arg) usage(1, msg='Invalid option: ' + arg)
# now set the values # now set the values
device.setinfo(info) device.setinfo(info)
device.close() device.close()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment