From befce0824fcebb86e49b9f45dc40b730c209b100 Mon Sep 17 00:00:00 2001 From: "Geoffrey D. Bennett" Date: Sun, 19 Nov 2023 13:12:50 +1030 Subject: [PATCH] Check Firmware Version before enabling Levels menu item The level meters don't work correctly on earlier kernel versions, so they shouldn't be displayed in that case. The "Firmware Version" ALSA control was added to the kernel at the same time as the level meters were fixed, so use the presence of that to determine whether or not to enable the menu item. --- src/alsa.c | 9 +++++++++ src/alsa.h | 1 + src/menu.c | 14 +++++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/alsa.c b/src/alsa.c index 39a6fe9..4b64d95 100644 --- a/src/alsa.c +++ b/src/alsa.c @@ -470,6 +470,14 @@ static void alsa_add_card_callback(struct alsa_card *card) { ); } +static void alsa_get_firmware_version(struct alsa_card *card) { + struct alsa_elem *elem = get_elem_by_name(card->elems, "Firmware Version"); + + if (!elem) + return; + card->firmware_version = alsa_get_elem_value(elem); +} + static void alsa_subscribe(struct alsa_card *card) { int count = snd_ctl_poll_descriptors_count(card->handle); @@ -524,6 +532,7 @@ void alsa_scan_cards(void) { card->handle = ctl; alsa_get_elem_list(card); + alsa_get_firmware_version(card); alsa_subscribe(card); create_card_window(card); diff --git a/src/alsa.h b/src/alsa.h index 6c46145..c0d58c6 100644 --- a/src/alsa.h +++ b/src/alsa.h @@ -145,6 +145,7 @@ struct alsa_card { char *name; snd_ctl_t *handle; struct pollfd pfd; + int firmware_version; GArray *elems; struct alsa_elem *sample_capture_elem; struct alsa_elem *level_meter_elem; diff --git a/src/menu.c b/src/menu.c index 2fecee6..3411eff 100644 --- a/src/menu.c +++ b/src/menu.c @@ -149,7 +149,10 @@ void add_startup_action_map(struct alsa_card *card) { static const GActionEntry mixer_entries[] = { {"routing", activate_routing, NULL, "false"}, - {"mixer", activate_mixer, NULL, "false"}, + {"mixer", activate_mixer, NULL, "false"} +}; + +static const GActionEntry levels_entries[] = { {"levels", activate_levels, NULL, "false"} }; @@ -160,4 +163,13 @@ void add_mixer_action_map(struct alsa_card *card) { G_N_ELEMENTS(mixer_entries), card ); + + if (card->firmware_version) { + g_action_map_add_action_entries( + G_ACTION_MAP(card->window_main), + levels_entries, + G_N_ELEMENTS(levels_entries), + card + ); + } }