-#!/usr/bin/env python
+#!/usr/bin/env python3
#
# Copyright (c) 2008-2012 by Jaroslav Kysela <perex@perex.cz>
#
from hda_graph import create_graph
def gethttpfile(url, size=1024*1024):
- from urllib import splithost
- from httplib import HTTP
- if not url.startswith('http:'):
- raise ValueError, "URL %s" % url
- host, selector = splithost(url[5:])
- h = HTTP(host)
- h.putrequest('GET', url)
- h.endheaders()
- h.getreply()
- res = h.getfile().read(size)
- h.close()
- return res
+ from urllib.request import urlopen
+ with urlopen(f"{URL}/{f}") as response:
+ contents = response.read()
+ return contents
def read_nodes2(card, codec):
try:
c = HDACodec(card, codec)
- except OSError, msg:
- if msg[0] == 13:
- print "Codec %i/%i unavailable - permissions..." % (card, codec)
- elif msg[0] == 16:
- print "Codec %i/%i is busy..." % (card, codec)
- elif msg[0] != 2:
- print "Codec %i/%i access problem (%s)" % repr(msg)
+ except OSError as msg:
+ if msg.errno == 13:
+ print("Codec %i/%i unavailable - permissions..." % (card, codec))
+ elif msg.errno == 16:
+ print("Codec %i/%i is busy..." % (card, codec))
+ elif msg.errno != 2:
+ print("Codec %i/%i access problem (%s)" % repr(msg))
return
c.analyze()
if not card in CODEC_TREE:
proc_file = gethttpfile(a[0])
elif len(a[0]) == 40 and not os.path.exists(a[0]):
url = 'http://www.alsa-project.org/db/?f=' + a[0]
- print 'Downloading contents from %s' % url
+ print('Downloading contents from %s' % url)
proc_file = gethttpfile(url)
if not proc_file:
- print "HASH %s cannot be downloaded..." % a[0]
+ print("HASH %s cannot be downloaded..." % a[0])
continue
else:
- print ' Success'
+ print(' Success')
else:
proc_file = DecodeProcFile(a[0])
proc_file = DecodeAlsaInfoFile(proc_file)
fp.write(txt)
fp.close()
if mode:
- os.chmod(filename, 0755)
+ os.chmod(filename, 0o755)
except:
- print "Unable to save text to '%s'" % filename
+ print("Unable to save text to '%s'" % filename)
(
TITLE_COLUMN,
sr = sdialog.run()
if sr == Gtk.ResponseType.OK:
- save_to_file(sdialog.get_filename(), str, 0755)
+ save_to_file(sdialog.get_filename(), str, 0o755)
sdialog.destroy()
def __graph_clicked(self, button):
def monitor():
from time import sleep
- print "Watching %s cards" % len(CODEC_TREE)
+ print("Watching %s cards" % len(CODEC_TREE))
dumps = {}
while 1:
ok = False
diff = do_diff1(c, dumps[card][codec])
dumps[card][codec] = dump1
if diff:
- print "======================================"
- print diff
+ print("======================================")
+ print(diff)
if not ok:
- print "Nothing to monitor (no hwdep access)"
+ print("Nothing to monitor (no hwdep access)")
break
sleep(1)
def main(argv):
cmd = None
if len(argv) > 1 and argv[1] in ('-h', '-help', '--help'):
- print __doc__ % globals()
+ print(__doc__ % globals())
return 0
if len(argv) > 1 and argv[1] in ('-m', '-monitor', '--monitor'):
cmd = 'monitor'
cmd = 'graph'
del argv[1]
if read_nodes(sys.argv[1:]) == 0:
- print "No HDA codecs were found or insufficient priviledges for "
- print "/dev/snd/controlC* and /dev/snd/hwdepC*D* device files."
- print
- print "You may also check, if you compiled HDA driver with HWDEP"
- print "interface as well or close all application using HWDEP."
- print
- print "Try run this program as root user."
+ print("No HDA codecs were found or insufficient priviledges for ")
+ print("/dev/snd/controlC* and /dev/snd/hwdepC*D* device files.")
+ print()
+ print("You may also check, if you compiled HDA driver with HWDEP")
+ print("interface as well or close all application using HWDEP.")
+ print()
+ print("Try run this program as root user.")
return 0
else:
if cmd == 'monitor':
-#!/usr/bin/env python
+#!/usr/bin/env python3
#
# Copyright (c) 2008-2012 by Jaroslav Kysela <perex@perex.cz>
#
if val > self.nsteps:
db = off + self.nsteps * range
if val != 0 or self.nsteps != 0:
- print "val > nsteps? for nid 0x%02x" % self.nid, val, self.nsteps
+ print("val > nsteps? for nid 0x%02x" % self.nid, val, self.nsteps)
else:
db = off + val * range
return db
dir = self.dir == HDA_OUTPUT and (1<<15) or (1<<14)
verb = VERBS['SET_AMP_GAIN_MUTE']
if self.stereo:
- indice = idx / 2
+ indice = idx // 2
dir |= idx & 1 and (1 << 12) or (1 << 13)
else:
indice = idx
except:
e = None
if not e:
- print "Control ID not found:", ctl.dump_extra().strip().lstrip()
+ print("Control ID not found:", ctl.dump_extra().strip().lstrip())
continue
e.hdactl = ctl
res.append(e)
idx = 0
if dst_node.amp_vals_in.indices == dst_node.connections:
if not self.nid in dst_node.connections:
- raise ValueError, "nid 0x%02x is not connected to nid 0x%02x (%s, %s)" % (dst_node.nid, self.nid, repr(self.connections), repr(dst_node.connections))
+ raise ValueError("nid 0x%02x is not connected to nid 0x%02x (%s, %s)" % (dst_node.nid, self.nid, repr(self.connections), repr(dst_node.connections)))
idx = dst_node.connections.index(self.nid)
res.append(dst_node.amp_vals_in.get_val_str(idx))
else:
idx = 0
if dst_node.amp_vals_in.indices == dst_node.connections:
if not self.nid in dst_node.connections:
- raise ValueError, "nid 0x%02x is not connected to nid 0x%02x (%s, %s)" % (dst_node.nid, self.nid, repr(self.connections), repr(dst_node.connections))
+ raise ValueError("nid 0x%02x is not connected to nid 0x%02x (%s, %s)" % (dst_node.nid, self.nid, repr(self.connections), repr(dst_node.connections)))
idx = dst_node.connections.index(self.nid)
vals = dst_node.amp_vals_in.get_val_db(idx)
for idx in range(len(vals)):
self.fd = ctl_fd = os.open("/dev/snd/controlC%i" % card, os.O_RDONLY)
else:
self.fd = os.dup(ctl_fd)
- info = struct.pack('ii16s16s32s80s16s80s128s', 0, 0, '', '', '', '', '', '', '')
+ info = struct.pack('ii16s16s32s80s16s80s128s', 0, 0, b'', b'', b'', b'', b'', b'', b'')
res = ioctl(ctl_fd, CTL_IOCTL_CARD_INFO, info)
a = struct.unpack('ii16s16s32s80s16s80s128s', res)
- self.id = a[2].replace('\x00', '')
- self.driver = a[3].replace('\x00', '')
- self.name = a[4].replace('\x00', '')
- self.longname = a[5].replace('\x00', '')
- self.components = a[8].replace('\x00', '')
+ self.id = a[2].replace(b'\x00', b'').decode('ascii')
+ self.driver = a[3].replace(b'\x00', b'').decode('ascii')
+ self.name = a[4].replace(b'\x00', b'').decode('ascii')
+ self.longname = a[5].replace(b'\x00', b'').decode('ascii')
+ self.components = a[8].replace(b'\x00', b'').decode('ascii')
def __del__(self):
if not self.fd is None:
self.fd = os.open("/dev/snd/hwC%sD%s" % (card, device), os.O_RDWR)
else:
self.fd = os.dup(clonefd)
- info = struct.pack('Ii64s80si64s', 0, 0, '', '', 0, '')
+ info = struct.pack('Ii64s80si64s', 0, 0, b'', b'', 0, b'')
res = ioctl(self.fd, IOCTL_INFO, info)
- name = struct.unpack('Ii64s80si64s', res)[3]
+ name = struct.unpack('Ii64s80si64s', res)[3].decode('ascii')
if not name.startswith('HDA Codec'):
- raise IOError, "unknown HDA hwdep interface"
+ raise IOError("unknown HDA hwdep interface")
res = ioctl(self.fd, IOCTL_PVERSION, struct.pack('I', 0))
- self.version = struct.unpack('I', res)
+ self.version = struct.unpack('I', res)[0]
if self.version < 0x00010000: # 1.0.0
- raise IOError, "unknown HDA hwdep version"
+ raise IOError("unknown HDA hwdep version")
self.mixer = AlsaMixer(self.card, ctl_fd=ctl_fd)
self.parse_proc()
parm >>= shift
if range_val:
if not prev_nid or prev_nid >= val:
- raise IOError, "invalid dep_range_val 0x%x:0x%x\n" % (prev_nid, val)
+ raise IOError("invalid dep_range_val 0x%x:0x%x\n" % (prev_nid, val))
n = prev_nid + 1
while n <= val:
res.append(n)
self.proc_codec = HDACodecProc(self.card, self.device, file)
else:
self.proc_codec = None
- print "Unable to find proc file '%s'" % file
+ print("Unable to find proc file '%s'" % file)
def analyze(self):
self.afg = None
str += 'Default Amp-Out caps: '
str += print_amp_caps(self.amp_caps_out)
- if self.base_nid == 0 or self.nodes < 0:
+ if self.base_nid == 0 or len(self.nodes) == 0:
str += 'Invalid AFG subtree\n'
return str
nid = res[y][x]
if not nid is None:
if nid in check:
- raise ValueError, "double nid in graph matrix"
+ raise ValueError("double nid in graph matrix")
if not nid in self.nodes:
- raise ValueError, "unknown nid in graph matrix"
+ raise ValueError("unknown nid in graph matrix")
check.append(nid)
if len(check) != len(self.nodes):
- raise ValueError, "not all nids in graph matrix"
+ raise ValueError("not all nids in graph matrix")
# do addition dump
if dump:
- print "****", len(self.nodes)
+ print("****", len(self.nodes))
for nodes in res:
str = ''
for node2 in nodes:
str += node2 is None and '-- ' or '%02x ' % node2
- print str
- print "****"
+ print(str)
+ print("****")
return res
class HDA_Exporter_pyscript:
def rw(self, old, nid, verb, param):
if verb & 0x0800:
- raise ValueError, "read: nid=0x%x, verb=0x%x, param=0x%x" % (nid, verb, param)
+ raise ValueError("read: nid=0x%x, verb=0x%x, param=0x%x" % (nid, verb, param))
#print "old = 0x%x, nid = 0x%x, verb = 0x%x, param = 0x%x" % (old, nid, verb, param)
verb |= param >> 8
if old:
text = '# no change'
else:
text = """\
-#!/usr/bin/env python
+#!/usr/bin/env python3
import os
import struct
from fcntl import ioctl
-def __ioctl_val(val):
- # workaround for OverFlow bug in python 2.4
- if val & 0x80000000:
- return -((val^0xffffffff)+1)
- return val
-
-IOCTL_INFO = __ioctl_val(0x80dc4801)
-IOCTL_PVERSION = __ioctl_val(0x80044810)
-IOCTL_VERB_WRITE = __ioctl_val(0xc0084811)
+IOCTL_INFO = 0x80dc4801
+IOCTL_PVERSION = 0x80044810
+IOCTL_VERB_WRITE = 0xc0084811
def set(nid, verb, param):
verb = (nid << 24) | (verb << 8) | param
res = ioctl(FD, IOCTL_INFO, info)
name = struct.unpack('Ii64s80si64s', res)[3]
if not name.startswith('HDA Codec'):
- raise IOError, "unknown HDA hwdep interface"
+ raise IOError("unknown HDA hwdep interface")
res = ioctl(FD, IOCTL_PVERSION, struct.pack('I', 0))
version = struct.unpack('I', res)
if version < 0x00010000: # 1.0.0
- raise IOError, "unknown HDA hwdep version"
+ raise IOError("unknown HDA hwdep version")
# initialization sequence starts here...
return text
def HDA_card_list():
- from dircache import listdir
+ from os import listdir
result = []
for name in listdir('/dev/snd/'):
if name.startswith('controlC'):
try:
- fd = os.open("/dev/snd/%s" % name, os.O_RDONLY)
- except OSError, msg:
+ fd = os.open("/dev/snd/%s" % name, os.O_RDONLY)
+ except OSError as msg:
continue
- info = struct.pack('ii16s16s32s80s16s80s128s', 0, 0, '', '', '', '', '', '', '')
+ info = struct.pack('ii16s16s32s80s16s80s128s', 0, 0, b'', b'', b'', b'', b'', b'', b'')
res = ioctl(fd, CTL_IOCTL_CARD_INFO, info)
a = struct.unpack('ii16s16s32s80s16s80s128s', res)
card = a[0]
- components = a[8].replace('\x00', '')
+ components = a[8].replace(b'\x00', b'').decode('ascii')
if components.find('HDA:') >= 0:
result.append(HDACard(card, ctl_fd=fd))
os.close(fd)
if __name__ == '__main__':
v = HDACodec()
v.analyze()
- print "vendor_id = 0x%x, subsystem_id = 0x%x, revision_id = 0x%x" % (v.vendor_id, v.subsystem_id, v.revision_id)
- print "afg = %s, mfg = %s" % (v.afg and "0x%x" % v.afg or 'None', v.mfg and "0x%x" % v.mfg or 'None')
- print
- print
- print v.dump()[:-1]
+ print("vendor_id = 0x%x, subsystem_id = 0x%x, revision_id = 0x%x" % (v.vendor_id, v.subsystem_id, v.revision_id))
+ print("afg = %s, mfg = %s" % (v.afg and "0x%x" % v.afg or 'None', v.mfg and "0x%x" % v.mfg or 'None'))
+ print()
+ print()
+ print(v.dump()[:-1])
-4#!/usr/bin/env python
+4#!/usr/bin/env python3
#
# Copyright (c) 2008-2010 by Jaroslav Kysela <perex@perex.cz>
#
if posx == line[0] and posx == line[2]:
if line[1] < line[3]:
if posy >= line[1] and posy <= line[3]:
- #print "Clash1", posx, posy, line
+ #print("Clash1", posx, posy, line)
return True
else:
if posy >= line[3] and posy <= line[1]:
- #print "Clash2", posx, posy, line
+ #print("Clash2", posx, posy, line)
return True
if posy == line[1] and posy == line[3]:
if line[0] < line[2]:
if posx >= line[0] and posx <= line[2]:
- #print "Clash3", posx, posy, line
+ #print("Clash3", posx, posy, line)
return True
else:
if posx >= line[2] and posx <= line[0]:
- #print "Clash4", posx, posy, line
+ #print("Clash4", posx, posy, line)
return True
if posx == line[0] and posy == line[1]:
- #print "Clash5", posx, posy, line
+ #print("Clash5", posx, posy, line)
return True
if posx == line[2] and posy == line[3]:
- #print "Clash6", posx, posy, line
+ #print("Clash6", posx, posy, line)
return True
return False
check_dot(line[2], line[3], p) or \
check_dot(p[0], p[1], line) or \
check_dot(p[2], p[3], line):
- #print "Found1", p
+ #print("Found1", p)
found = True
break
if nodes and not found:
xx2 += xx1
yy2 += yy1
if x1 < xx2 and x2 >= xx1 and y1 < yy2 and y2 >= yy1:
- #print "Found2", x1, y1, x2, y2, xx1, yy1, xx2, yy2
+ #print("Found2", x1, y1, x2, y2, xx1, yy1, xx2, yy2)
found = True
break
if not found:
- #print "OK x1=%s,y1=%s,x2=%s,y2=%s" % (p[0], p[1], p[2], p[3])
+ #print("OK x1=%s,y1=%s,x2=%s,y2=%s" % (p[0], p[1], p[2], p[3]))
return p
def analyze_routes(self, routes, nodes):
possible = []
startx = posx >= dposx and posx - extra or posx + width
- xrange = range(5, extra-1, 5)
+ xrange = list(range(5, extra-1, 5))
if posx >= dposx:
xrange.reverse()
- a = range(width+extra+5, width+extra*2-1, 5)
+ a = list(range(width+extra+5, width+extra*2-1, 5))
a.reverse()
xrange = xrange + a
for i in range(2, 10):
- a = range(width*i+extra*i+5, width*i+extra*(i+1)-1, 5)
+ a = list(range(width*i+extra*i+5, width*i+extra*(i+1)-1, 5))
a.reverse()
xrange = xrange + a
else:
startx + j, dposy + height + 5])
sel = self.select_line(routes, None, possible)
if not sel:
- raise ValueError, "unable to route"
+ raise ValueError("unable to route")
self.lines.append(sel)
sel1[0] -= fixup + sub
sel1[2] += fixup
possible = []
- for j in range(0, width/2-10, 5):
+ for j in range(0, width//2-10, 5):
possible.append([sel1[0]+j, y, sel1[0]+j, sel1[1]])
sel2 = self.select_line(routes, nodes, possible)
if sel2:
break
if tryit >= 0:
self.wronglines.append([x+5, y, sel[0], sel[1]])
- print "[1] displaced route 0x%x->0x%x %s %s" % (self.src.node.nid, self.dst.node.nid, repr(self.lines[-1]), repr(sel))
+ print("[1] displaced route 0x%x->0x%x %s %s" % (self.src.node.nid, self.dst.node.nid, repr(self.lines[-1]), repr(sel)))
res = False
x = dposx
sel1[0] -= fixup + sub
sel1[2] += fixup
possible = []
- for j in range(0, width/2-10, 5):
+ for j in range(0, width//2-10, 5):
possible.append([sel1[0]+j, y, sel1[0]+j, sel1[1]])
sel2 = self.select_line(routes, nodes, possible)
if sel2:
break
if tryit >= 0:
self.wronglines.append([x+5, y, sel[2], sel[3]])
- print "[2] displaced route 0x%x->0x%x %s %s" % (self.src.node.nid, self.dst.node.nid, repr(self.lines[-1]), repr(sel))
+ print("[2] displaced route 0x%x->0x%x %s %s" % (self.src.node.nid, self.dst.node.nid, repr(self.lines[-1]), repr(sel)))
res = False
return res
ok = True
break
if not ok:
- print "Not all routes are placed correctly!!!"
+ print("Not all routes are placed correctly!!!")
def __destroy(self, widget):
if self.popup_win:
diff += do_diff1(c, DIFF_TREE[card][codec])
if len(diff) > 0:
open(DIFF_FILE, "w+").write(diff + '\n')
- print "Diff was stored to: %s" % DIFF_FILE
+ print("Diff was stored to: %s" % DIFF_FILE)
return (diff and hw > 0) and True or False
class NodeGui(Gtk.ScrolledWindow):
frame.set_border_width(4)
if len(node.wcaps_list) == 0:
return frame
- str = ''
+ s = ''
for i in node.wcaps_list:
- str += node.wcap_name(i) + '\n'
- frame.add(self.__new_text_view(text=str))
+ s += node.wcap_name(i) + '\n'
+ frame.add(self.__new_text_view(text=s))
return frame
def __node_connection_toggled(self, widget, row, data):
frame.set_border_width(4)
vbox = Gtk.VBox(False, 0)
if caps:
+ s = ''
if caps.ofs != None:
- str = 'Offset: %d\n' % caps.ofs
- str += 'Number of steps: %d\n' % caps.nsteps
- str += 'Step size: %d\n' % caps.stepsize
- str += 'Mute: %s\n' % (caps.mute and "True" or "False")
- vbox.pack_start(self.__new_text_view(text=str), True, True, 0)
+ s += 'Offset: %d\n' % caps.ofs
+ s += 'Number of steps: %d\n' % caps.nsteps
+ s += 'Step size: %d\n' % caps.stepsize
+ s += 'Mute: %s\n' % (caps.mute and "True" or "False")
+ vbox.pack_start(self.__new_text_view(text=s), True, True, 0)
idx = 0
frame1 = None
vbox1 = None
if node.pincap or node.pincap_vref:
frame = Gtk.Frame.new('PIN Caps')
frame.set_border_width(4)
- str = ''
+ s = ''
for i in node.pincap:
- str += node.pincap_name(i) + '\n'
+ s += node.pincap_name(i) + '\n'
for i in node.pincap_vref:
- str += 'VREF_%s\n' % i
- frame.add(self.__new_text_view(text=str))
+ s += 'VREF_%s\n' % i
+ frame.add(self.__new_text_view(text=s))
vbox.pack_start(frame, True, True, 0)
if 'EAPD' in node.pincap:
frame = Gtk.Frame.new('EAPD')
frame = Gtk.Frame.new('Config Default')
frame.set_border_width(4)
- str = 'Jack connection: %s\n' % node.jack_conn_name
- str += 'Jack type: %s\n' % node.jack_type_name
- str += 'Jack location: %s\n' % node.jack_location_name
- str += 'Jack location2: %s\n' % node.jack_location2_name
- str += 'Jack connector: %s\n' % node.jack_connector_name
- str += 'Jack color: %s\n' % node.jack_color_name
+ s = 'Jack connection: %s\n' % node.jack_conn_name
+ s += 'Jack type: %s\n' % node.jack_type_name
+ s += 'Jack location: %s\n' % node.jack_location_name
+ s += 'Jack location2: %s\n' % node.jack_location2_name
+ s += 'Jack connector: %s\n' % node.jack_connector_name
+ s += 'Jack color: %s\n' % node.jack_color_name
if 'NO_PRESENCE' in node.defcfg_misc:
- str += 'No presence\n'
- frame.add(self.__new_text_view(text=str))
+ s += 'No presence\n'
+ frame.add(self.__new_text_view(text=s))
vbox.pack_start(frame, True, True, 0)
frame = Gtk.Frame.new('Widget Control')
try:
val = int(val)
except:
- print "Unknown category value '%s'" % val
+ print("Unknown category value '%s'" % val)
return
if node.dig1_set_value('category', val):
HDA_SIGNAL.emit("hda-node-changed", self, node)
frame = Gtk.Frame.new('Converter')
frame.set_border_width(4)
- str = 'Audio Stream:\t%s\n' % node.aud_stream
- str += 'Audio Channel:\t%s\n' % node.aud_channel
+ s = 'Audio Stream:\t%s\n' % node.aud_stream
+ s += 'Audio Channel:\t%s\n' % node.aud_channel
if node.format_ovrd:
- str += 'Rates:\t\t%s\n' % node.pcm_rates[:6]
+ s += 'Rates:\t\t%s\n' % node.pcm_rates[:6]
if len(node.pcm_rates) > 6:
- str += '\t\t\t\t%s\n' % node.pcm_rates[6:]
- str += 'Bits:\t\t%s\n' % node.pcm_bits
- str += 'Streams:\t%s\n' % node.pcm_streams
+ s += '\t\t\t\t%s\n' % node.pcm_rates[6:]
+ s += 'Bits:\t\t%s\n' % node.pcm_bits
+ s += 'Streams:\t%s\n' % node.pcm_streams
else:
- str += 'Global Rates:\t%s\n' % node.codec.pcm_rates[:6]
+ s += 'Global Rates:\t%s\n' % node.codec.pcm_rates[:6]
if len(node.codec.pcm_rates) > 6:
- str += '\t\t%s\n' % node.codec.pcm_rates[6:]
- str += 'Global Bits:\t%s\n' % node.codec.pcm_bits
- str += 'Global Streams:\t%s\n' % node.codec.pcm_streams
- frame.add(self.__new_text_view(text=str))
+ s += '\t\t%s\n' % node.codec.pcm_rates[6:]
+ s += 'Global Bits:\t%s\n' % node.codec.pcm_bits
+ s += 'Global Streams:\t%s\n' % node.codec.pcm_streams
+ frame.add(self.__new_text_view(text=s))
vbox.pack_start(frame, True, True, 0)
if not node.sdi_select is None:
def __build_proc(self, node):
frame = Gtk.Frame.new('Processing Caps')
frame.set_border_width(4)
- str = 'benign=%i\nnumcoef=%i\n' % (node.proc_benign, node.proc_numcoef)
- frame.add(self.__new_text_view(text=str))
+ s = 'benign=%i\nnumcoef=%i\n' % (node.proc_benign, node.proc_numcoef)
+ frame.add(self.__new_text_view(text=s))
return frame
def __read_all_node(self):
a.append((HDA_OUTPUT, node.amp_caps_out, node.amp_vals_out))
for dir, caps, vals in a:
for idx in range(len(vals.vals)):
- val = vals.vals[idx]
- checkbutton = self.amp_checkbuttons[dir][idx]
- if checkbutton:
- checkbutton.set_active(val & 0x80 and True or False)
- adj = self.amp_adjs[dir][idx]
- if adj:
- adj.set_value((val & 0x7f) % (caps.nsteps+1))
- idx += 1
+ val = vals.vals[idx]
+ checkbutton = self.amp_checkbuttons[dir][idx]
+ if checkbutton:
+ checkbutton.set_active(val & 0x80 and True or False)
+ adj = self.amp_adjs[dir][idx]
+ if adj:
+ adj.set_value((val & 0x7f) % (caps.nsteps+1))
+ idx += 1
if hasattr(self, 'connection_model'):
for r in self.connection_model:
r[0] = False
vbox.pack_start(self.__build_aud(node), False, False,0)
else:
if not node.wtype_id in ['AUD_MIX', 'BEEP', 'AUD_SEL']:
- print 'Node type %s has no GUI support' % node.wtype_id
+ print('Node type %s has no GUI support' % node.wtype_id)
if node.proc_wid:
vbox.pack_start(self.__build_proc(node), False, False,0)
frame = Gtk.Frame.new('Codec Identification')
frame.set_border_width(4)
- str = 'Audio Fcn Group: %s\n' % (codec.afg and "0x%02x" % codec.afg or "N/A")
+ s = 'Audio Fcn Group: %s\n' % (codec.afg and "0x%02x" % codec.afg or "N/A")
if codec.afg:
- str += 'AFG Function Id: 0x%02x (unsol %u)\n' % (codec.afg_function_id, codec.afg_unsol)
- str += 'Modem Fcn Group: %s\n' % (codec.mfg and "0x%02x" % codec.mfg or "N/A")
+ s += 'AFG Function Id: 0x%02x (unsol %u)\n' % (codec.afg_function_id, codec.afg_unsol)
+ s += 'Modem Fcn Group: %s\n' % (codec.mfg and "0x%02x" % codec.mfg or "N/A")
if codec.mfg:
- str += 'MFG Function Id: 0x%02x (unsol %u)\n' % (codec.mfg_function_id, codec.mfg_unsol)
- str += 'Vendor ID:\t 0x%08x\n' % codec.vendor_id
- str += 'Subsystem ID:\t 0x%08x\n' % codec.subsystem_id
- str += 'Revision ID:\t 0x%08x\n' % codec.revision_id
- frame.add(self.__new_text_view(text=str))
+ s += 'MFG Function Id: 0x%02x (unsol %u)\n' % (codec.mfg_function_id, codec.mfg_unsol)
+ s += 'Vendor ID:\t 0x%08x\n' % codec.vendor_id
+ s += 'Subsystem ID:\t 0x%08x\n' % codec.subsystem_id
+ s += 'Revision ID:\t 0x%08x\n' % codec.revision_id
+ frame.add(self.__new_text_view(text=s))
vbox.pack_start(frame, False, False,0)
frame = Gtk.Frame.new('PCM Global Capabilities')
frame.set_border_width(4)
- str = 'Rates:\t\t %s\n' % codec.pcm_rates[:6]
+ s = 'Rates:\t\t %s\n' % codec.pcm_rates[:6]
if len(codec.pcm_rates) > 6:
- str += '\t\t %s\n' % codec.pcm_rates[6:]
- str += 'Bits:\t\t %s\n' % codec.pcm_bits
- str += 'Streams:\t %s\n' % codec.pcm_streams
- frame.add(self.__new_text_view(text=str))
+ s += '\t\t %s\n' % codec.pcm_rates[6:]
+ s += 'Bits:\t\t %s\n' % codec.pcm_bits
+ s += 'Streams:\t %s\n' % codec.pcm_streams
+ frame.add(self.__new_text_view(text=s))
vbox.pack_start(frame, False, False, 0)
return vbox
frame = Gtk.Frame.new(title)
frame.set_border_width(4)
if caps and caps.ofs != None:
- str = 'Offset:\t\t %d\n' % caps.ofs
- str += 'Number of steps: %d\n' % caps.nsteps
- str += 'Step size:\t %d\n' % caps.stepsize
- str += 'Mute:\t\t %s\n' % (caps.mute and "True" or "False")
- frame.add(self.__new_text_view(text=str))
+ s = 'Offset:\t\t %d\n' % caps.ofs
+ s += 'Number of steps: %d\n' % caps.nsteps
+ s += 'Step size:\t %d\n' % caps.stepsize
+ s += 'Mute:\t\t %s\n' % (caps.mute and "True" or "False")
+ frame.add(self.__new_text_view(text=s))
return frame
hbox = Gtk.HBox(False, 0)
return hbox
- def __gpio_toggled(self, button, (codec, id, idx)):
+ def __gpio_toggled(self, button, arg):
+ codec, id, idx = arg
if codec.gpio.set(id, idx, button.get_active()):
HDA_SIGNAL.emit("hda-codec-changed", self, codec)
button.set_active(codec.gpio.test(id, idx))
frame = Gtk.Frame.new('GPIO')
frame.set_border_width(4)
hbox = Gtk.HBox(False, 0)
- str = 'IO Count: %d\n' % codec.gpio_max
- str += 'O Count: %d\n' % codec.gpio_o
- str += 'I Count: %d\n' % codec.gpio_i
- str += 'Unsolicited: %s\n' % (codec.gpio_unsol and "True" or "False")
- str += 'Wake: %s\n' % (codec.gpio_wake and "True" or "False")
- hbox.pack_start(self.__new_text_view(text=str), False, False,0)
+ s = 'IO Count: %d\n' % codec.gpio_max
+ s += 'O Count: %d\n' % codec.gpio_o
+ s += 'I Count: %d\n' % codec.gpio_i
+ s += 'Unsolicited: %s\n' % (codec.gpio_unsol and "True" or "False")
+ s += 'Wake: %s\n' % (codec.gpio_wake and "True" or "False")
+ hbox.pack_start(self.__new_text_view(text=s), False, False,0)
frame.add(hbox)
self.gpio_checkbuttons = []
for id in GPIO_IDS:
self.read_all = self.__read_all_codec
def __build_card_info(self, card):
- str = 'Card: %s\n' % card.card
- str += 'Id: %s\n' % card.id
- str += 'Driver: %s\n' % card.driver
- str += 'Name: %s\n' % card.name
- str += 'LongName: %s\n' % card.longname
- return self.__new_text_view(text=str)
+ s = 'Card: %s\n' % card.card
+ s += 'Id: %s\n' % card.id
+ s += 'Driver: %s\n' % card.driver
+ s += 'Name: %s\n' % card.name
+ s += 'LongName: %s\n' % card.longname
+ return self.__new_text_view(text=s)
def __build_card(self, card, doframe=False):
self.mytitle = card.name
for card in CODEC_TREE:
for codec in CODEC_TREE[card]:
CODEC_TREE[card][codec].revert()
- print "Settings for all codecs were reverted..."
+ print("Settings for all codecs were reverted...")
TRACKER = TrackWindows()
import struct
from fcntl import ioctl
-def __ioctl_val1(val):
- # workaround for OverFlow bug in python 2.4
- if val & 0x80000000:
- return -((val^0xffffffff)+1)
- return val
-
-CTL_IOCTL_CARD_INFO = __ioctl_val1(0x81785501)
-CTL_IOCTL_ELEM_INFO = __ioctl_val1(0xc1105511)
-CTL_IOCTL_ELEM_READ = __ioctl_val1(0xc4c85512)
-CTL_IOCTL_ELEM_WRITE = __ioctl_val1(0xc4c85513)
+CTL_IOCTL_CARD_INFO = 0x81785501
+CTL_IOCTL_ELEM_INFO = 0xc1105511
+CTL_IOCTL_ELEM_READ = 0xc4c85512
+CTL_IOCTL_ELEM_WRITE = 0xc4c85513
CTL_ELEM_TYPE_BOOLEAN = 1
CTL_ELEM_TYPE_INTEGER = 2
def pack(self):
return struct.pack('IiII44sI',
self.numid, self.iface, self.device, self.subdevice,
- self.name, self.index)
+ self.name.encode('ascii'), self.index)
def unpack(self, binid):
self.numid, self.iface, self.device, self.subdevice, \
self.name, self.index = struct.unpack('IiII44sI', binid)
- self.name = self.name.replace('\x00', '')
+ self.name = self.name.replace(b'\x00', b'').decode('ascii')
def get_text_info(self):
return 'iface="%s",name="%s",index=%s,device=%s,subdevice=%s' % \
self.dimen = info['dimen']
def __info(self):
- bin = self.id.pack()+struct.pack('iIIi128s8s64s', 0, 0, 0, 0, '', '', '')
+ bin = self.id.pack()+struct.pack('iIIi128s8s64s', 0, 0, 0, 0, b'', b'', b'')
res = ioctl(self.mixer.fd, CTL_IOCTL_ELEM_INFO, bin)
self.id.unpack(res[:self.id.binsize])
a = struct.unpack('iIIi128s8s64s', res[self.id.binsize:])
return b
def read(self):
- bin = self.id.pack() + struct.pack('I512s128s', 0, '', '')
+ bin = self.id.pack() + struct.pack('I512s128s', 0, b'', b'')
startoff = self.id.binsize + UINTSIZE
if LONGSIZE == 8:
- bin += '\x00\x00\x00\x00'
+ bin += b'\x00\x00\x00\x00'
startoff += 4
res = ioctl(self.mixer.fd, CTL_IOCTL_ELEM_READ, bin)
if self.type == CTL_ELEM_TYPE_BOOLEAN:
elif self.type == CTL_ELEM_TYPE_BYTES:
return res[startoff:startoff+self.count]
else:
- raise ValueError, "Unsupported type %s" % CTL_ELEM_RTYPEs[self.type]
+ raise ValueError("Unsupported type %s" % CTL_ELEM_RTYPEs[self.type])
def get_text_info(self, idx=None):
res = self.id.get_text_info() + '\n'
os.close(self.fd)
if __name__ == '__main__':
- mixer = AlsaMixer(0)
- elem = AlsaMixerElem(mixer, AlsaMixerElemId(name="Mic Boost"))
- print elem.read()
+ mixer = AlsaMixer(1)
+ elem = AlsaMixerElem(mixer, AlsaMixerElemId(name="Mic Boost Volume"))
+ print(elem.read())
elem = AlsaMixerElem(mixer, AlsaMixerElemId(name="Capture Volume"))
- print elem.read()
+ print(elem.read())
self.wrongfile('integer decode %s (%s)' % (repr(str), repr(prefix)))
def wrongfile(self, msg=''):
- raise ValueError, "wrong proc file format (%s)" % msg
+ raise ValueError("wrong proc file format (%s)" % msg)
class HDApcmDevice:
idx = param & (1<<13) and 1 or 0
val = param & 0x7f
if val >= len(self.amp_vals[dir]):
- print "AMP index out of range (%s >= %s)" % (val, len(self.amp_vals[dir]))
+ print("AMP index out of range (%s >= %s)" % (val, len(self.amp_vals[dir])))
while val >= len(self.amp_vals[dir]):
self.amp_vals[dir].append([128, 128])
return self.amp_vals[dir][val][idx]
elif verb in SET_VERBS:
self.verbs[SET_VERBS[verb]] = param
return param
- raise ValueError, "unimplemented node rw (0x%x, 0x%x, 0x%x)" % (self.nid, verb, param)
+ raise ValueError("unimplemented node rw (0x%x, 0x%x, 0x%x)" % (self.nid, verb, param))
def param_read(self, param):
if param in self.params:
return self.params[param]
elif param == PARAMS['CONNLIST_LEN']:
return len(self.connections) + (1 << 7) # use long format
- raise ValueError, "unimplemented node param read (0x%x, 0x%x)" % (self.nid, param)
+ raise ValueError("unimplemented node param read (0x%x, 0x%x)" % (self.nid, param))
def add_verb(self, verb, param, do_or=False):
if do_or and verb in self.verbs:
idx = 0
idx, self.proc_codec_id = lookfor(idx, 'Codec: ')
if not self.proc_codec_id:
- print "Proc Text Contents is not valid"
+ print("Proc Text Contents is not valid")
return
idx, tmp = lookforint(idx, 'Address: ')
self.device = tmp # really?
return
line = lines[idx].strip()
if line == 'Invalid AFG subtree':
- print "Invalid AFG subtree for codec %s?" % self.proc_codec_id
+ print("Invalid AFG subtree for codec %s?" % self.proc_codec_id)
return
while line.startswith('Power-Map: ') or \
line.startswith('Analog Loopback: '):
- print 'Sigmatel specific "%s" verb ignored for the moment' % line
+ print('Sigmatel specific "%s" verb ignored for the moment' % line)
idx += 1
line = lines[idx].strip()
node = None
return 0
node = self.proc_nids[nid]
return node.param_read(param)
- raise ValueError, "unimplemented param_read(0x%x, 0x%x)" % (nid, param)
+ raise ValueError("unimplemented param_read(0x%x, 0x%x)" % (nid, param))
def get_sub_nodes(self, nid):
if nid == AC_NODE_ROOT:
return 0, 0
elif nid is None:
return 0, 0
- raise ValueError, "unimplemented get_sub_nodes(0x%x)" % nid
+ raise ValueError("unimplemented get_sub_nodes(0x%x)" % nid)
def get_wcap(self, nid):
node = self.proc_nids[nid]
return 0
node = self.proc_nids[nid]
return node.rw(verb, param)
- raise ValueError, "unimplemented rw(0x%x, 0x%x, 0x%x)" % (nid, verb, param)
+ raise ValueError( "unimplemented rw(0x%x, 0x%x, 0x%x)" % (nid, verb, param))
def dump_node_extra(self, node):
if not node or not node.nid in self.proc_nids:
if os.path.isdir(file):
dotest1(file)
else:
- print file
+ print(file)
file = DecodeProcFile(file)
file = DecodeAlsaInfoFile(file)
for a in file:
def dotest():
import sys
if len(sys.argv) < 2:
- raise ValueError, "Specify directory with codec dumps"
+ raise ValueError("Specify directory with codec dumps")
dotest1(sys.argv[1])
if __name__ == '__main__':