Skip to content

Commit

Permalink
showing the input configuration greyed out if the card cannot be foun…
Browse files Browse the repository at this point in the history
…d anymore
  • Loading branch information
sezanzeb committed Sep 20, 2020
1 parent 215531f commit 35c5852
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 17 deletions.
10 changes: 7 additions & 3 deletions alsacontrol/cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ def get_current_card(source):
Returns
-------
A tuple of (d, card) with d being the index in
the list of options from get_cards.
A tuple of (d, card) with d being the index in the list of options
from get_cards.
"""
pcm_name = get_config().get(source)
if pcm_name == 'null':
Expand All @@ -133,7 +133,7 @@ def get_current_card(source):
card = get_card(pcm_name)
if card not in cards:
logger.warning('Found unknown %s "%s" in config', source, pcm_name)
return None, None
return None, card

index = cards.index(card)
return index, card
Expand Down Expand Up @@ -167,6 +167,8 @@ def select_output_pcm(card):
"""
# figure out if this is an actual hardware device or not
cards = alsaaudio.cards()
if card is None:
card = 'null'
if card in cards:
plugin = get_config().get('output_plugin')
pcm_name = f'{plugin}:CARD={card}'
Expand All @@ -185,6 +187,8 @@ def select_input_pcm(card):
"""
# figure out if this is an actual hardware device or not
cards = alsaaudio.cards()
if card is None:
card = 'null'
if card in cards:
plugin = get_config().get('input_plugin')
pcm_name = f'{plugin}:CARD={card}'
Expand Down
8 changes: 4 additions & 4 deletions alsacontrol/cardstracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ def log_new_pcms(self):
# first time running, don't log yet
pass
else:
for pcm in self.cards.difference(cards):
logger.info('PCM %s was removed', pcm)
for card in self.cards.difference(cards):
logger.info('Card "%s" was removed', card)
changes += 1
for pcm in cards.difference(self.cards):
logger.info('Found new PCM %s', pcm)
for card in cards.difference(self.cards):
logger.info('Found new card "%s"', card)
changes += 1
self.cards = cards
return changes > 0
56 changes: 46 additions & 10 deletions bin/alsacontrol-gtk
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,13 @@ class InputLevel:
if self.stopped:
return False

new_level = get_level(self.pcm)
try:
new_level = get_level(self.pcm)
except alsaaudio.ALSAAudioError:
logger.error('Could not monitor the level of "%s"', self.card)
self.valid = False
return False

if new_level is None:
# try again
return True
Expand Down Expand Up @@ -532,18 +538,14 @@ class ALSAControlWindow:
)
self.input_rows.append(input_row)

self.display_input()

def select_input_card(self, card):
"""Select a card as input source."""
"""Select a card as input source in UI and asoundrc."""
if not input_exists('select_input_card'):
record_to_nowhere()

label = self.builder.get_object('input_card_name')
label.set_label(card)
for input_row in self.input_rows:
if input_row.card != card:
input_row.set_active(0)
else:
input_row.set_active(1)
self.display_input(card)

select_input_pcm(card)
setup_asoundrc()
Expand Down Expand Up @@ -571,11 +573,45 @@ class ALSAControlWindow:
self.input_levels = []

def select_current_input(self):
"""Select the configured input."""
"""Show the configured input in the UI and configure asoundrc."""
card = get_current_card('pcm_input')[1]
if card is not None:
self.select_input_card(card)

def display_input(self, card=None):
"""Show the name of the input card and tick its checkbox if available.
If it is not found in the system, will grey the name out.
Parameters
----------
card : string
If None, will show the current output, but it won't modify
asoundrc unlike select_current_input in that case.
"""
if card is None:
card = get_current_card('pcm_input')[1]

label = self.builder.get_object('input_card_name')

if card is None:
label.set_label('')
return

for input_row in self.input_rows:
if input_row.card != card:
input_row.set_active(0)
else:
input_row.set_active(1)

cards = get_cards()
if card in cards:
label.set_label(card)
else:
label.set_label(
f'<span alpha="50%"><i>{card} (not found)</i></span>'
)


if __name__ == '__main__':
set_bus(DBusGMainLoop())
Expand Down

0 comments on commit 35c5852

Please sign in to comment.