From 999cddfdca1fc55a5578cc8db0040c3ed8fa4898 Mon Sep 17 00:00:00 2001 From: NekoCWD Date: Sun, 27 Oct 2024 23:09:38 +0300 Subject: [PATCH] Test release --- README.md | 4 +++- src/main.vala | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ef2f610..414d3a8 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ # Q6Meow Output Switcher -A bridge between q6meowd and callaudiod \ No newline at end of file +A bridge between q6meowd and callaudiod + +This program will receive the callaudiod signal then call q6meowd to stop the stream, then set the ALSA ctl to speaker or earpeace, then call q6meowd to start the stream again \ No newline at end of file diff --git a/src/main.vala b/src/main.vala index bf14419..8c31254 100644 --- a/src/main.vala +++ b/src/main.vala @@ -20,12 +20,23 @@ Alsa.ElemId speaker_id; Alsa.ElemId earpiece_id; +string speaker_mixer; +string earpiece_mixer; +string card_name; + +private const GLib.OptionEntry[] options = { + { "speaker", 's', OptionFlags.NONE, OptionArg.STRING, ref speaker_mixer, "mixer for speaker mode", "QUAT_MI2S_RX Voice Mixer VoiceMMode1" }, + { "earpiece", 'e', OptionFlags.NONE, OptionArg.STRING, ref earpiece_mixer, "mixer for earpiece mode", "SLIMBUS_0_RX Voice Mixer VoiceMMode1" }, + { "card", 'c', OptionFlags.NONE, OptionArg.STRING, ref card_name, "alsa card", "hw:0" }, + { null } +}; + void get_mixes (string earpiece, string speaker) { var list = new List (); Alsa.Card card; Alsa.ElemList elem_list; Alsa.ElemId elem_id; - Alsa.Card.open (out card, "hw:0"); + Alsa.Card.open (out card, card_name); Alsa.ElemList.alloc (out elem_list); Alsa.ElemId.alloc (out elem_id); card.elem_list (elem_list); // Getting list without items @@ -48,17 +59,33 @@ void get_mixes (string earpiece, string speaker) { } if (speaker_id != null) { message ("Speaker Setted %s", speaker_id.get_name ()); + } else { + error ("Speaker mixer not set"); } if (earpiece_id != null) { message ("Earpiece Setted %s", earpiece_id.get_name ()); + } else { + error ("Earpiece mixer not set"); } } int main (string[] args) { - Alsa.Card card; - message ("Card open: %d", Alsa.Card.open (out card, "hw:0", Alsa.CardOpenType.NONBLOCK)); - get_mixes ("SLIMBUS_0_RX Voice Mixer VoiceMMode1", "QUAT_MI2S_RX Voice Mixer VoiceMMode1"); + try { + var opt_context = new OptionContext ("\n\tThis program will receive the callaudiod signal then call q6meowd to stop the stream, then set the ALSA ctl to speaker or earpeace, then call q6meowd to start the stream again"); + opt_context.set_help_enabled (true); + opt_context.add_main_entries (options, null); + opt_context.parse (ref args); + } catch (OptionError e) { + printerr ("error: %s\n", e.message); + printerr ("Run '%s --help' to see a full list of available command line options.\n", args[0]); + return 1; + } + + Alsa.Card card; + message ("Card open: %d", Alsa.Card.open (out card, card_name, Alsa.CardOpenType.NONBLOCK)); + + get_mixes (earpiece_mixer, speaker_mixer); Q6MeowD q6meowd_proxy = Bus.get_proxy_sync (BusType.SYSTEM, "org.postmarketos.q6meowd", "/org/postmarketos/q6meowd", DBusProxyFlags.NONE); CallAudioD callaudiod_proxy = Bus.get_proxy_sync (BusType.SESSION, "org.mobian_project.CallAudio", "/org/mobian_project/CallAudio", DBusProxyFlags.NONE); ((DBusProxy) callaudiod_proxy).g_properties_changed.connect ((props, inv) => {