pax_global_header00006660000000000000000000000064123170464300014512gustar00rootroot0000000000000052 comment=11c267082c766fad54ff10eb5ade182bbb7beff5 asoundconf-0.1/000075500000000000000000000000001231704643000135075ustar00rootroot00000000000000asoundconf-0.1/.gear/000075500000000000000000000000001231704643000145035ustar00rootroot00000000000000asoundconf-0.1/.gear/rules000064400000000000000000000000071231704643000155550ustar00rootroot00000000000000tar: . asoundconf-0.1/asoundconf000075500000000000000000000263141231704643000156020ustar00rootroot00000000000000#!/usr/bin/python # (C) 2005 Canonical Ltd. # Author: Martin Pitt # License: GNU General Public License, version 2 or any later version # # Modified by: Thomas Hood, Daniel T Chen, Lukas Jirkovsky # # Get and set configuration parameters in ~/.asoundrc.asoundconf. import sys, re, os.path our_conf_file = os.path.expanduser('~/.asoundrc.asoundconf') asoundrc_file = os.path.expanduser('~/.asoundrc') predefs_file = '/usr/share/alsa/alsa.conf' setting_re_template = '!?\s*%s\s*(?:=|\s)\s*([^;,]+)[;,]?$' our_conf_header = '''# ALSA library configuration file managed by asoundconf(1). # # MANUAL CHANGES TO THIS FILE WILL BE OVERWRITTEN! # # Manual changes to the ALSA library configuration should be implemented # by editing the ~/.asoundrc file, not by editing this file. ''' asoundrc_header = '''# ALSA library configuration file ''' inclusion_comment = '''# Include settings that are under the control of asoundconf(1). # (To disable these settings, comment out this line.)''' usage = '''Usage: asoundconf is-active asoundconf get|delete PARAMETER asoundconf set PARAMETER VALUE asoundconf list Convenience macro functions: asoundconf set-default-card PARAMETER asoundconf reset-default-card asoundconf set-pulseaudio asoundconf unset-pulseaudio asoundconf set-oss PARAMETER asoundconf unset-oss ''' needs_default_card = '''You have omitted a necessary parameter. Please see the output from `asoundconf list`, and use one of those sound card(s) as the parameter. ''' needs_oss_dev = '''You have omitted a necessary parameter. Please specify an OSS device (e.g., /dev/dsp). ''' superuser_warn = '''Please note that you are attempting to run asoundconf as a privileged superuser, which may have unintended consequences. ''' def get_default_predefs(): try: if not os.path.exists(predefs_file): return predefs_file_entire = open(predefs_file).readlines() r = re.compile('^defaults') ## Between these hashes, add additional unique regexps that ## must exist at the end of the user's custom asoundrc. s = re.compile('^defaults.namehint') ## predefs_list = [] must_append_predefs_list = [] for i in predefs_file_entire: if r.match(i) and not s.match(i): predefs_list.append(str(i).strip()) elif s.match(i): must_append_predefs_list.append(str(i).strip()) for i in must_append_predefs_list: predefs_list.append(str(i).strip()) return predefs_list except IOError: pass def ensure_our_conf_exists(): '''If it does not exist then generate a default configuration file with no settings. Return: True on success, False if the file could not be created. ''' if os.path.exists(our_conf_file): return True try: open(our_conf_file, 'w').write(our_conf_header) return True except IOError: print >> sys.stderr, 'Error: could not create', our_conf_file return False def ensure_asound_rc_exists(): '''Generate a default user configuration file with only the inclusion line. Return: True on success, False if the file could not be created. ''' if os.path.exists(asoundrc_file): return True try: open(asoundrc_file, 'w').write('%s\n%s\n<%s>\n\n' % (asoundrc_header, inclusion_comment, our_conf_file)) return True except IOError: print >> sys.stderr, 'Error: could not create', asoundrc_file return False def sds_transition(): '''Replace the magic comments added to the user configuration file by the obsolete set-default-soundcard program with the standard inclusion statement for our configuration file. ''' if not os.path.exists(asoundrc_file): return lines = open(asoundrc_file).readlines() start_marker_re = re.compile('### BEGIN set-default-soundcard') end_marker_re = re.compile('### END set-default-soundcard') userconf_lines = [] our_conf_lines = [] # read up to start comment lineno = 0 found = 0 for l in lines: lineno = lineno+1 if start_marker_re.match(l): found = 1 break userconf_lines.append(l) if found: # replace magic comment section with include userconf_lines.append('%s\n<%s>\n\n' % (inclusion_comment, our_conf_file)) else: # no magic comment return # read magic comment section until end marker and add it to asoundconf found = 0 for l in lines[lineno:]: lineno = lineno+1 if end_marker_re.match(l): found = 1 break if not l.startswith('#'): our_conf_lines.append(l) if not found: # no complete magic comment return # add the rest to user conf userconf_lines = userconf_lines + lines[lineno:] # write our configuration file if not ensure_our_conf_exists(): return try: open(our_conf_file, 'a').writelines(our_conf_lines) except IOError: return # panic out # write user configuration file try: open(asoundrc_file, 'w').writelines(userconf_lines) except IOError: pass def is_active(): '''Check that the user configuration file is either absent, or, if present, that it includifies the asoundconf configuration file; in those cases asoundconf can be used to change the user's ALSA library configuration. Also transition from the legacy set-default-soundcard program. Return True if the above condition is met, False if not. ''' if not os.path.exists(asoundrc_file): return True sds_transition() # check whether or not the file has the inclusion line include_re = re.compile('\s*<\s*%s\s*>' % our_conf_file) for l in open(asoundrc_file): if include_re.match(l): return True return False def get(prmtr): '''Print the value of the given parameter on stdout Also transition from the legacy set-default-soundcard program. Return True on success, and False if the value is not set. ''' sds_transition() if not os.path.exists(our_conf_file): return False setting_re = re.compile(setting_re_template % prmtr) try: for line in open(our_conf_file): m = setting_re.match(line) if m: print m.group(1).strip() return True return False except IOError: return False def list(): '''Get card names from /proc/asound/cards''' cardspath = '/proc/asound/cards' if not os.path.exists(cardspath): return False procfile = open(cardspath, 'rb') cardline = re.compile('^\s*\d+\s*\[') card_lines = [] lines = procfile.readlines() for l in lines: if cardline.match(l): card_lines.append(re.sub(r'^\s*\d+\s*\[(\w+)\s*\].+','\\1',l)) print "Names of available sound cards:" for cardname in card_lines: print cardname.strip() return True def delete(prmtr): '''Delete the given parameter. Also transition from the legacy set-default-soundcard program. Return True on success, and False on an error. ''' sds_transition() if not os.path.exists(our_conf_file): return False setting_re = re.compile(setting_re_template % prmtr) lines = [] try: lines = open(our_conf_file).readlines() except IOError: return False found = 0 for i in xrange(len(lines)): if setting_re.match(lines[i]): del lines[i] found = 1 break if found: # write back file try: f = open(our_conf_file, 'w') except IOError: return False f.writelines(lines) return True def set(prmtr, value): '''Set the given parameter to the given value Also transition from the legacy set-default-soundcard program. Return True on success, and False on an error. ''' sds_transition() setting_re = re.compile(setting_re_template % prmtr) lines = [] ensure_asound_rc_exists() # N.B. We continue even if asoundrc could not be created # and we do NOT ensure that our configuration is "active" if not ensure_our_conf_exists(): return False try: lines = open(our_conf_file).readlines() except IOError: return False newsetting = '%s %s\n' % (prmtr, value) # if setting is already present, change it found = 0 for i in xrange(len(lines)): if setting_re.match(lines[i]): lines[i] = newsetting found = 1 break if not found: lines.append(newsetting) # write back file try: f = open(our_conf_file, 'w') except IOError: return False f.writelines(lines) return True def set_default_card(card): clist = get_default_predefs() sep = re.compile(r'[ \t]') com = re.compile('[ \t]*#.*') r = re.compile('^defaults.pcm.card') s = re.compile('^defaults.ctl.card') ## !defaults.pcm.card and defaults.ctl.card should lead ## the user's custom asoundrc. if set('!defaults.pcm.card', card) and \ set('defaults.ctl.card', card): for i in clist: # remove any comments i = com.sub("",i) (j, k) = sep.split(i) if not r.match(j) and not s.match(j): if not set(j, k): return False return True else: return False def reset_default_card(): clist = get_default_predefs() sep = re.compile(r'[ \t]') com = re.compile('[ \t]*#.*') for i in clist: i = com.sub("",i) (j, k) = sep.split(i) if not delete(j): return False return True def delete_pcm_default(): return delete('pcm.!default') def delete_ctl_default(): return delete('ctl.!default') def set_pulseaudio(): return set('pcm.!default', '{ type pulse }') and \ set('ctl.!default', '{ type pulse }') def unset_pulseaudio(): return delete_pcm_default() and \ delete_ctl_default() def set_oss(device): endbrace = ' }' return set('pcm.!default { type oss device', device + endbrace) def unset_oss(): return delete_pcm_default() def exit_code(result): '''Exit program with code 0 if result is True, otherwise exit with code 1. ''' if result: sys.exit(0) else: sys.exit(1) ## ## main ## if os.geteuid() == 0: print superuser_warn if len(sys.argv) < 2 or sys.argv[1] == '--help' or sys.argv[1] == '-h': print usage sys.exit(0) if sys.argv[1] == 'is-active': exit_code(is_active()) if sys.argv[1] == 'get': if len(sys.argv) != 3: print usage sys.exit(1) exit_code(get(sys.argv[2])) if sys.argv[1] == 'delete': if len(sys.argv) != 3: print usage sys.exit(1) exit_code(delete(sys.argv[2])) if sys.argv[1] == 'set': if len(sys.argv) != 4: print usage sys.exit(1) exit_code(set(sys.argv[2], sys.argv[3])) if sys.argv[1] == 'list': exit_code(list()) if sys.argv[1] == 'set-default-card': if len(sys.argv) != 3: print needs_default_card sys.exit(1) exit_code(set_default_card(sys.argv[2])) if sys.argv[1] == 'reset-default-card': exit_code(reset_default_card()) if sys.argv[1] == 'set-pulseaudio': exit_code(set_pulseaudio()) if sys.argv[1] == 'unset-pulseaudio': exit_code(unset_pulseaudio()) if sys.argv[1] == 'set-oss': if len(sys.argv) != 3: print needs_oss_dev sys.exit(1) exit_code(set_oss(sys.argv[2])) if sys.argv[1] == 'unset-oss': exit_code(unset_oss()) print usage sys.exit(1) asoundconf-0.1/asoundconf.1000064400000000000000000000045451231704643000157400ustar00rootroot00000000000000.TH asoundconf "1" "06 May 2008" .SH NAME asoundconf \- utility to read and change the user's ALSA library configuration .SH SYNOPSIS \fBasoundconf\fR \fBis\-active\fR .PP \fBasoundconf\fR \fBget\fR|\fBdelete\fR \fIPARAMETER\fR .PP \fBasoundconf\fR \fBset\fR \fIPARAMETER\fR \fIVALUE\fR .PP \fBasoundconf\fR \fBlist\fR Convenience macro functions: .PP \fBasoundconf\fR \fBset\-default\-card\fR \fIPARAMETER\fR .PP \fBasoundconf\fR \fBreset\-default\-card\fR .PP \fBasoundconf\fR \fBset\-pulseaudio\fR .PP \fBasoundconf\fR \fBunset\-pulseaudio\fR .PP \fBasoundconf\fR \fBset\-oss\fR \fIPARAMETER\fR .PP \fBasoundconf\fR \fBunset\-oss\fR .SH DESCRIPTION .B asoundconf configures the ALSA library for the user. It does this by reading the values of parameters from and writing the values of parameters to the special file .asoundrc.asoundconf in the user's home directory. The .asoundrc.asoundconf file should not be edited by hand! .PP The .asoundrc.asoundconf file only has an effect on the ALSA library if it is included by the user's .asoundrc file, also located in the user's home directory. When .B asoundconf is run and it finds either that the ~/.asoundrc file does not exist or that the file exists and contains the markers of the obsolete .B set\-default\-soundcard program then .B asoundconf adds the required inclusion statement to ~/.asoundrc; otherwise .B asoundconf does not change ~/.asoundrc. Hence, if you want to disable control of ALSA library configuration parameters by .B asoundconf then simply comment out this inclusion statement but do not delete the ~/.asoundrc file. (It is OK for ~/.asoundrc to be an empty file.) .SH WARNING This program is under development. Its features will change without notice and without preservation of backward compatibility, except insofar as they are put to use by other components of the Debian and/or Ubuntu operating systems. (As of this writing the Ubuntu developers have plans to use .B asoundconf for setting parameters listed in /usr/share/alsa/alsa.conf under the defaults section. Separate graphical frontend tools are under development to ease the configuration of multichannel .asoundrc files.) .SH FILES .TP .I ~/.asoundrc user-specific ALSA library configuration file .TP .I ~/.asoundrc.asoundconf file containing .BR asoundconf -managed parameter settings .SH AUTHOR This program was written by Martin Pitt . asoundconf-0.1/asoundconf.spec000064400000000000000000000030571231704643000165270ustar00rootroot00000000000000Summary: Command-line Python utility to select the default ALSA sound card Name: asoundconf Version: 0.1 Release: alt1 Packager: Igor Vlasenko License: GPL Group: Sound URL: https://code.launchpad.net/~motu/asoundconf-ui # rev 8 of http://bazaar.launchpad.net/~crimsun/asoundconf-ui/asoundconf-trunk Requires: alsa-utils BuildRequires: rpm-build-python Source0: %name-%version.tar BuildArch: noarch %description Command-line Python utility to configure a user's alsa-lib asoundrc Useful if you have two cards, and switch between the two. There is already this functionality in GNOME, but this is indeed useful if you do not use that desktop environment, and asoundconf also supports PulseAudio toggling. It is part of Ubnutu's alsa-utils package. %prep %setup -q %build %install install -d ${RPM_BUILD_ROOT}%_bindir install -m755 asoundconf ${RPM_BUILD_ROOT}%_bindir/ # installing debian man pages install -d ${RPM_BUILD_ROOT}%_man1dir install -m644 asoundconf.1 ${RPM_BUILD_ROOT}%_man1dir/ %files %_bindir/asoundconf %_man1dir/asoundconf.1* %changelog * Tue Apr 01 2014 Igor Vlasenko 0.1-alt1 - synced changes from aur.archlinux.org/packages/asoundconf (1.0.1-3) (see also http://wiki.marklesh.com/How-to/Asoundconf) - (closes: #29795) * Tue Oct 25 2011 Vitaly Kuznetsov 0.0.bzr8-alt1.1.1 - Rebuild with Python-2.7 * Tue Dec 01 2009 Eugeny A. Rostovtsev (REAL) 0.0.bzr8-alt1.1 - Rebuilt with python 2.6 * Wed Jan 28 2009 Igor Vlasenko 0.0.bzr8-alt1 - initial build asoundconf-0.1/set-default-soundcard000064400000000000000000000060771231704643000176410ustar00rootroot00000000000000#!/usr/bin/python # (C) 2005 Canonical Ltd. # Author: Martin Pitt # License: GNU General Public License, version 2 or any later version # Configure default output device in ~/.asoundrc. import sys, re, os.path conffile = os.path.expanduser('~/.asoundrc') def help(): print '''Usage: set-default-soundcard | --check-markers If %s does not exist, or its magic comments are present, change the default sound card setting in it to the given number. If --check-markers is given, the exit code shows whether the configuration file could be modified, but does not actually change it. ''' % conffile def create_conffile(card_num): '''Create a new configuration file with the given card as default.''' try: f = open(conffile, 'w') print >> f, '''### BEGIN set-default-soundcard # If the "### BEGIN..." and "### END..." comments are intact, then you # can change your default soundcard with "set-default-soundcard(1)." # Remove these comments if you want to maintain a custom configuration # that should not be changed automatically. # Default soundcard defaults.pcm.card %s ### END set-default-soundcard ''' % card_num except IOError: print >> sys.stderr, 'Could not create', conffile sys.exit(1) def change_conffile(card_num): '''Change default to given card number an existing configuration file. If successful, return true; return false if the file does not exist, cannot be written, or does not have the magic comments. If card_num is None, then only the markers are checked without actually modifying the file.''' try: lines = open(conffile).readlines() except IOError: return False # search for the BEGIN marker marker = re.compile('### BEGIN set-default-soundcard') lineno = 0 found = 0 for l in lines: lineno = lineno+1 if marker.match(l): found = 1 break if not found: return False # search for default setting marker = re.compile('(defaults.pcm.card\s+)(\d+)(.*)$') found = 0 for l in lines[lineno:]: lineno = lineno+1 m = marker.match(l) if m: if card_num: lines[lineno-1] = m.group(1) + card_num + m.group(3) + '\n' found = 1 break if not found: return False # search for the END marker marker = re.compile('### END set-default-soundcard') found = 0 for l in lines[lineno:]: lineno = lineno+1 if marker.match(l): found = 1 break if not found: return False # write back file if card_num: try: open(conffile, 'w').writelines(lines) except IOError: return False return True if len(sys.argv) < 2 or sys.argv[1] == '--help' or sys.argv[1] == '-h': help() sys.exit(0) check_only = (sys.argv[1] == '--check-markers') if len(sys.argv) != 2 or not (check_only or sys.argv[1].isdigit()): help() sys.exit(1) if not check_only: card_num = sys.argv[1] else: card_num = None # if ~/.asoundrc does not exist, create it if not os.path.exists(conffile): if check_only: sys.exit(0) create_conffile(card_num) else: if not change_conffile(card_num): if not check_only: print >> sys.stderr, conffile, \ 'was modified manually, cannot be changed by this program.' sys.exit(1)