Skip to content
This repository has been archived by the owner on Apr 12, 2019. It is now read-only.

Commit

Permalink
added support for changing mixer dev
Browse files Browse the repository at this point in the history
Also switch all tabs to use grids for layout
  • Loading branch information
charlesdaniels committed Nov 17, 2018
1 parent 4923347 commit 938c3ac
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 17 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
0.1.0

* Add support for basic configuration of sndiod, mainly with a focus
* Added support for basic configuration of sndiod, mainly with a focus
on the ability to switch audio devices.

* Switched to using tkinter grids, rather than packed frames for layout,
leading to a more visually appealing widget alignment.

* Added support for switching mixer devices via the "basic" tab by
re-starting the application in-place.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ Contributions are more than welcome. If there is a feature you would like added
to gmixerctl, please feel free to open a pull request. In particular, I would
appreciate help implementing the following features:

* Changing the mixer device at run time (this may be a Tk limitation, but I'm
not experienced enough with Tk at the moment)
* ~~Changing the mixer device at run time (this may be a Tk limitation, but I'm
not experienced enough with Tk at the moment)~~

* Support added in 0.1.0

* ~~Configuring `sndiod` flags (i.e. a menu for running `rcctl set sndiod flags
-f rsnd/X ; rcctl restart sndiod`)~~
Expand Down
2 changes: 2 additions & 0 deletions gmixerctl/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

log_level = logging.DEBUG

mixer_device = "/dev/mixer"

# control names to appear in the basic tab
basic_controls = [
"outputs.master",
Expand Down
52 changes: 40 additions & 12 deletions gmixerctl/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import tkinter.messagebox
import time
import subprocess
import glob

from . import mixerctl
from . import util
Expand Down Expand Up @@ -82,7 +83,17 @@ def on_press (this):
"\n\nerror was:\n\n{}".format(e)
)

class SetMixerDevice:
def __init__(this, parent):
this.parent = parent

def __call__(this, val):
# implement callback for setting mixer device

constants.mixer_device = val
logging.debug("updated mixer device to {}".format(val))
this.parent.destroy()
main()

class MultiSelect(tkinter.Frame):
# https://stackoverflow.com/a/34550169
Expand Down Expand Up @@ -126,7 +137,7 @@ def update(this):
mixerctl.set_value(this.name, ",".join(
[x for x in this.choices if this.choices[x].get() == 1]))

def render_control(parent, control, tabs, tkvars):
def render_control(parent, control, tabs, tkvars, row):
name = control["name"]


Expand All @@ -136,7 +147,7 @@ def render_control(parent, control, tabs, tkvars):
parent,
text = name,
width = constants.label_width)
text_widget.pack(side=tkinter.LEFT)
text_widget.grid(row = row, column = 0)

# create a new callback object - we need to use the update_value
# class so that mixerctl.set_value() knows what control we want
Expand All @@ -160,7 +171,7 @@ def render_control(parent, control, tabs, tkvars):
command = callback,
)
# scale.config(width = constants.control_width)
scale.pack(side=tkinter.RIGHT)
scale.grid(row = row, column = 1)

elif control["type"] == "enum":

Expand All @@ -178,7 +189,7 @@ def render_control(parent, control, tabs, tkvars):
command = callback,
)
menu.config(width = constants.control_width)
menu.pack(side=tkinter.RIGHT)
menu.grid(row = row, column = 1)

elif control["type"] == "set":

Expand All @@ -190,14 +201,14 @@ def render_control(parent, control, tabs, tkvars):
control["possible"],
tkvars[name].choices
)
menu.pack(side=tkinter.RIGHT)
menu.grid(row = row, column = 1)
else:
menu = MultiSelect(
parent,
name,
control["possible"],
)
menu.pack(side=tkinter.RIGHT)
menu.grid(row = row, column = 1)
tkvars[name] = menu


Expand All @@ -222,6 +233,7 @@ def main():
tkvars = {}

# custom-build "basic" tab
row_counter = 0
for name in controls:

# only display the controls we have configured
Expand All @@ -237,9 +249,25 @@ def main():
nb.add(tabs[tab_name], text=tab_name)

# create the frame for this control
frame = ttk.Frame(tabs[tab_name])
render_control(frame, control, tabs, tkvars)
frame.pack()
render_control(tabs[tab_name], control, tabs, tkvars, row_counter)
row_counter += 1

# add mixer device selector to basic tab
dev_selector_label = tkinter.Label(tabs[tab_name],
text = "select mixer device")
dev_selector_label.grid(row = row_counter, column = 0)

callback = SetMixerDevice(root)
available_device = []
dev_selector_var = tkinter.StringVar()
dev_selector_var.set(constants.mixer_device)
mixer_dev_selector = tkinter.OptionMenu(
tabs[tab_name],
dev_selector_var,
*list(glob.glob("/dev/mixer*")),
command = callback,
)
mixer_dev_selector.grid(row = row_counter, column = 1)


# sndiod control tab
Expand Down Expand Up @@ -286,6 +314,7 @@ def main():


# automatically generate the rest of the tabs
row_counter = 0
for name in controls:
control = controls[name]

Expand All @@ -296,9 +325,8 @@ def main():
nb.add(tabs[tab_name], text=tab_name)

# create the frame for this control
frame = ttk.Frame(tabs[tab_name])
render_control(frame, control, tabs, tkvars)
frame.pack()
render_control(tabs[tab_name], control, tabs, tkvars, row_counter)
row_counter += 1

# add about tab
about = ttk.Frame(nb)
Expand Down
8 changes: 6 additions & 2 deletions gmixerctl/mixerctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import subprocess

from . import util
from . import constants

def parse_line(line):
"""parse_line
Expand Down Expand Up @@ -57,7 +58,8 @@ def get_state():
Get the current mixer state.
"""

raw = subprocess.check_output(["mixerctl", "-v"], stderr=subprocess.STDOUT)
raw = subprocess.check_output(["mixerctl", "-f", constants.mixer_device,
"-v"], stderr=subprocess.STDOUT)
raw = raw.decode()

control = {}
Expand All @@ -79,6 +81,8 @@ def set_value(control, value):
:param value:
"""
logging.debug("setting {} = {}".format(control, value))
raw = subprocess.check_output(["mixerctl", "{}={}".format(control, value)],
raw = subprocess.check_output(
["mixerctl", "-f", constants.mixer_device,
"{}={}".format(control, value)],
stderr=subprocess.STDOUT)
logging.debug("mixerctl says {}".format(raw))

0 comments on commit 938c3ac

Please sign in to comment.