diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/monitor.c | 268 |
1 files changed, 163 insertions, 105 deletions
diff --git a/examples/monitor.c b/examples/monitor.c index dca5105..71d8b61 100644 --- a/examples/monitor.c +++ b/examples/monitor.c @@ -26,7 +26,7 @@ #include <libmatemixer/matemixer.h> -static MateMixerControl *control; +static MateMixerContext *context; static GMainLoop *mainloop; static gchar * @@ -57,6 +57,30 @@ create_app_string (const gchar *app_name, } static const gchar * +get_stream_control_role_string (MateMixerStreamControlRole role) +{ + switch (role) { + case MATE_MIXER_STREAM_CONTROL_ROLE_UNKNOWN: + return "Unknown"; + case MATE_MIXER_STREAM_CONTROL_ROLE_MASTER: + return "Master"; + case MATE_MIXER_STREAM_CONTROL_ROLE_PCM: + return "PCM"; + case MATE_MIXER_STREAM_CONTROL_ROLE_BASS: + return "Bass"; + case MATE_MIXER_STREAM_CONTROL_ROLE_TREBLE: + return "Treble"; + case MATE_MIXER_STREAM_CONTROL_ROLE_CD: + return "CD"; + case MATE_MIXER_STREAM_CONTROL_ROLE_SPEAKER: + return "PC Speaker"; + case MATE_MIXER_STREAM_CONTROL_ROLE_PORT: + return "Port"; + } + return "Unknown"; +} + +static const gchar * create_role_string (MateMixerClientStreamRole role) { switch (role) { @@ -122,39 +146,21 @@ static void print_devices (void) { const GList *devices; - const GList *ports; const GList *profiles; MateMixerDeviceProfile *active_profile; - devices = mate_mixer_control_list_devices (control); + devices = mate_mixer_context_list_devices (context); while (devices) { MateMixerDevice *device = MATE_MIXER_DEVICE (devices->data); g_print ("Device %s\n" - " |-| Description : %s\n" - " |-| Icon Name : %s\n\n", + " |-| Label : %s\n" + " |-| Icon Name : %s\n\n", mate_mixer_device_get_name (device), - mate_mixer_device_get_description (device), + mate_mixer_device_get_label (device), mate_mixer_device_get_icon (device)); - ports = mate_mixer_device_list_ports (device); - while (ports) { - MateMixerPort *port = MATE_MIXER_PORT (ports->data); - - g_print (" |-| Port %s\n" - " |-| Description : %s\n" - " |-| Icon Name : %s\n" - " |-| Priority : %u\n" - " |-| Status : \n\n", - mate_mixer_port_get_name (port), - mate_mixer_port_get_description (port), - mate_mixer_port_get_icon (port), - mate_mixer_port_get_priority (port)); - - ports = ports->next; - } - profiles = mate_mixer_device_list_profiles (device); active_profile = mate_mixer_device_get_active_profile (device); @@ -162,15 +168,15 @@ print_devices (void) MateMixerDeviceProfile *profile = MATE_MIXER_DEVICE_PROFILE (profiles->data); g_print (" |%c| Profile %s\n" - " |-| Description : %s\n" - " |-| Priority : %u\n" - " |-| Inputs : %u\n" - " |-| Outputs : %u\n\n", + " |-| Label : %s\n" + " |-| Priority : %u\n" + " |-| Inputs : %u\n" + " |-| Outputs : %u\n\n", (profile == active_profile) ? 'A' : '-', mate_mixer_device_profile_get_name (profile), - mate_mixer_device_profile_get_description (profile), + mate_mixer_device_profile_get_label (profile), mate_mixer_device_profile_get_priority (profile), mate_mixer_device_profile_get_num_input_streams (profile), mate_mixer_device_profile_get_num_output_streams (profile)); @@ -179,6 +185,35 @@ print_devices (void) } g_print ("\n"); + const GList *switches = mate_mixer_device_list_switches (device); + + while (switches != NULL) { + MateMixerSwitch *swtch = MATE_MIXER_SWITCH (switches->data); + MateMixerSwitchOption *active = mate_mixer_switch_get_active_option (swtch); + + const GList *options; + + options = mate_mixer_switch_list_options (swtch); + + g_print ("Switch %s\n", + mate_mixer_switch_get_name (swtch)); + + while (options != NULL) { + MateMixerSwitchOption *option = MATE_MIXER_SWITCH_OPTION (options->data); + + g_print (" |%c| %s\n", + (option == active) + ? '*' + : '-', + mate_mixer_switch_option_get_label (option)); + + options = options->next; + } + + switches = switches->next; + } + g_print ("\n"); + devices = devices->next; } } @@ -187,42 +222,85 @@ static void print_streams (void) { const GList *streams; - const GList *ports; - streams = mate_mixer_control_list_streams (control); + streams = mate_mixer_context_list_streams (context); while (streams) { MateMixerStream *stream = MATE_MIXER_STREAM (streams->data); MateMixerStreamControl *ctl; + MateMixerSwitch *swtch; MateMixerClientStream *client = NULL; gchar *volume_bar; gdouble volume; + const GList *controls; + const GList *switches; + if (mate_mixer_stream_get_flags (stream) & MATE_MIXER_STREAM_CLIENT) { /* The application-specific details are accessible through the client * interface, which all client streams implement */ client = MATE_MIXER_CLIENT_STREAM (stream); } - ctl = mate_mixer_stream_get_default_control (stream); + controls = mate_mixer_stream_list_controls (stream); - volume_bar = create_volume_bar (ctl, &volume); + while (controls != NULL) { + ctl = MATE_MIXER_STREAM_CONTROL (controls->data); - g_print ("Stream %s\n" - " |-| Description : %s\n" - " |-| Volume : %s %.1f %%\n" - " |-| Muted : %s\n" - " |-| Channels : %d\n" - " |-| Balance : %.1f\n" - " |-| Fade : %.1f\n", - mate_mixer_stream_get_name (stream), - mate_mixer_stream_get_description (stream), - volume_bar, - volume, - mate_mixer_stream_control_get_mute (ctl) ? "Yes" : "No", - mate_mixer_stream_control_get_num_channels (ctl), - mate_mixer_stream_control_get_balance (ctl), - mate_mixer_stream_control_get_fade (ctl)); + const gchar *role; + + role = get_stream_control_role_string (mate_mixer_stream_control_get_role (ctl)); + + // XXX volume is sometimes -nan, use flags + volume_bar = create_volume_bar (ctl, &volume); + + g_print ("Stream %s control %s / %s\n" + " |-| Volume : %s %.1f %% (%.1f dB)\n" + " |-| Muted : %s\n" + " |-| Channels : %d\n" + " |-| Balance : %.1f\n" + " |-| Fade : %.1f\n" + " |-| Role : %s\n", + mate_mixer_stream_get_name (stream), + mate_mixer_stream_control_get_name (ctl), + mate_mixer_stream_control_get_label (ctl), + volume_bar, + volume, + mate_mixer_stream_control_get_decibel (ctl), + mate_mixer_stream_control_get_mute (ctl) ? "Yes" : "No", + mate_mixer_stream_control_get_num_channels (ctl), + mate_mixer_stream_control_get_balance (ctl), + mate_mixer_stream_control_get_fade (ctl), + role); + + g_free (volume_bar); + + controls = controls->next; + } + + switches = mate_mixer_stream_list_switches (stream); + + while (switches != NULL) { + swtch = MATE_MIXER_SWITCH (switches->data); + const GList *options; + + options = mate_mixer_switch_list_options (swtch); + + g_print ("Switch %s\n", + mate_mixer_switch_get_name (swtch)); + + while (options != NULL) { + MateMixerSwitchOption *option = MATE_MIXER_SWITCH_OPTION (options->data); + + g_print (" |%c| %s\n", + '-', + mate_mixer_switch_option_get_label (option)); + + options = options->next; + } + + options = options->next; + } if (client != NULL) { MateMixerClientStreamFlags client_flags; @@ -240,35 +318,17 @@ print_streams (void) } g_print ("\n"); - g_free (volume_bar); - - ports = mate_mixer_stream_list_ports (stream); - while (ports) { - MateMixerPort *port = MATE_MIXER_PORT (ports->data); - - g_print (" |-| Port %s\n" - " |-| Description : %s\n" - " |-| Icon Name : %s\n" - " |-| Priority : %u\n" - " |-| Status : \n\n", - mate_mixer_port_get_name (port), - mate_mixer_port_get_description (port), - mate_mixer_port_get_icon (port), - mate_mixer_port_get_priority (port)); - - ports = ports->next; - } streams = streams->next; } } static void -print_cached_streams (void) +print_stored_streams (void) { const GList *streams; - streams = mate_mixer_control_list_cached_streams (control); + streams = mate_mixer_context_list_stored_streams (context); while (streams) { MateMixerStream *stream = MATE_MIXER_STREAM (streams->data); @@ -287,7 +347,7 @@ print_cached_streams (void) volume_bar = create_volume_bar (ctl, &volume); - g_print ("Cached stream %s\n" + g_print ("Stored stream %s\n" " |-| Role : %s\n" " |-| Volume : %s %.1f %%\n" " |-| Muted : %s\n" @@ -323,11 +383,11 @@ static void connected (void) { g_print ("Connected using the %s backend.\n\n", - mate_mixer_control_get_backend_name (control)); + mate_mixer_context_get_backend_name (context)); print_devices (); print_streams (); - print_cached_streams (); + print_stored_streams (); g_print ("Waiting for events. Hit CTRL+C to quit.\n"); } @@ -337,7 +397,7 @@ state_cb (void) { MateMixerState state; - state = mate_mixer_control_get_state (control); + state = mate_mixer_context_get_state (context); switch (state) { case MATE_MIXER_STATE_READY: @@ -353,25 +413,25 @@ state_cb (void) } static void -device_added_cb (MateMixerControl *control, const gchar *name) +device_added_cb (MateMixerContext *context, const gchar *name) { g_print ("Device added: %s\n", name); } static void -device_removed_cb (MateMixerControl *control, const gchar *name) +device_removed_cb (MateMixerContext *context, const gchar *name) { g_print ("Device removed: %s\n", name); } static void -stream_added_cb (MateMixerControl *control, const gchar *name) +stream_added_cb (MateMixerContext *context, const gchar *name) { g_print ("Stream added: %s\n", name); } static void -stream_removed_cb (MateMixerControl *control, const gchar *name) +stream_removed_cb (MateMixerContext *context, const gchar *name) { g_print ("Stream removed: %s\n", name); } @@ -388,22 +448,22 @@ signal_cb (gpointer mainloop) int main (int argc, char *argv[]) { MateMixerState state; - GOptionContext *context; + GOptionContext *ctx; gchar *backend = NULL; gchar *server = NULL; GError *error = NULL; GOptionEntry entries[] = { - { "backend", 'b', 0, G_OPTION_ARG_STRING, &backend, "Sound system to use (pulseaudio, oss, oss4, null)", NULL }, + { "backend", 'b', 0, G_OPTION_ARG_STRING, &backend, "Sound system to use (pulseaudio, alsa, oss, null)", NULL }, { "server", 's', 0, G_OPTION_ARG_STRING, &server, "Sound server address", NULL }, { NULL } }; - context = g_option_context_new ("- libmatemixer monitor"); + ctx = g_option_context_new ("- libmatemixer monitor"); - g_option_context_add_main_entries (context, entries, NULL); + g_option_context_add_main_entries (ctx, entries, NULL); - if (!g_option_context_parse (context, &argc, &argv, &error)) { + if (!g_option_context_parse (ctx, &argc, &argv, &error)) { g_printerr ("%s\n", error->message); g_error_free (error); return 1; @@ -415,24 +475,24 @@ int main (int argc, char *argv[]) setlocale (LC_ALL, ""); - /* Set up the controller, through which we access the main functionality */ - control = mate_mixer_control_new (); + /* Set up the contextler, through which we access the main functionality */ + context = mate_mixer_context_new (); /* Some details about our application, only used with the PulseAudio backend */ - mate_mixer_control_set_app_name (control, "MateMixer Monitor"); - mate_mixer_control_set_app_id (control, "org.mate-desktop.libmatemixer-monitor"); - mate_mixer_control_set_app_version (control, "1.0"); - mate_mixer_control_set_app_icon (control, "multimedia-volume-control"); + mate_mixer_context_set_app_name (context, "MateMixer Monitor"); + mate_mixer_context_set_app_id (context, "org.mate-desktop.libmatemixer-monitor"); + mate_mixer_context_set_app_version (context, "1.0"); + mate_mixer_context_set_app_icon (context, "multimedia-volume-context"); if (backend) { if (!strcmp (backend, "pulseaudio")) - mate_mixer_control_set_backend_type (control, MATE_MIXER_BACKEND_PULSEAUDIO); + mate_mixer_context_set_backend_type (context, MATE_MIXER_BACKEND_PULSEAUDIO); + else if (!strcmp (backend, "alsa")) + mate_mixer_context_set_backend_type (context, MATE_MIXER_BACKEND_ALSA); else if (!strcmp (backend, "oss")) - mate_mixer_control_set_backend_type (control, MATE_MIXER_BACKEND_OSS); - else if (!strcmp (backend, "oss4")) - mate_mixer_control_set_backend_type (control, MATE_MIXER_BACKEND_OSS4); + mate_mixer_context_set_backend_type (context, MATE_MIXER_BACKEND_OSS); else if (!strcmp (backend, "null")) - mate_mixer_control_set_backend_type (control, MATE_MIXER_BACKEND_NULL); + mate_mixer_context_set_backend_type (context, MATE_MIXER_BACKEND_NULL); else g_printerr ("Sound system backend '%s' is unknown, it will be auto-detected.\n", backend); @@ -441,40 +501,39 @@ int main (int argc, char *argv[]) } if (server) { - mate_mixer_control_set_server_address (control, server); + mate_mixer_context_set_server_address (context, server); g_free (server); } /* Initiate connection to the sound server */ - if (!mate_mixer_control_open (control)) { - g_object_unref (control); - mate_mixer_deinit (); + if (!mate_mixer_context_open (context)) { + g_object_unref (context); return 1; } - g_signal_connect (G_OBJECT (control), + g_signal_connect (G_OBJECT (context), "device-added", G_CALLBACK (device_added_cb), NULL); - g_signal_connect (G_OBJECT (control), + g_signal_connect (G_OBJECT (context), "device-removed", G_CALLBACK (device_removed_cb), NULL); - g_signal_connect (G_OBJECT (control), + g_signal_connect (G_OBJECT (context), "stream-added", G_CALLBACK (stream_added_cb), NULL); - g_signal_connect (G_OBJECT (control), + g_signal_connect (G_OBJECT (context), "stream-removed", G_CALLBACK (stream_removed_cb), NULL); - /* If mate_mixer_control_open() returns TRUE, the state will be either + /* If mate_mixer_context_open() returns TRUE, the state will be either * MATE_MIXER_STATE_READY or MATE_MIXER_STATE_CONNECTING. * - * In case mate_mixer_control_open() returned FALSE, the current state + * In case mate_mixer_context_open() returned FALSE, the current state * would be MATE_MIXER_STATE_FAILED */ - state = mate_mixer_control_get_state (control); + state = mate_mixer_context_get_state (context); switch (state) { case MATE_MIXER_STATE_READY: @@ -484,7 +543,7 @@ int main (int argc, char *argv[]) g_print ("Waiting for connection...\n"); /* Wait for the state transition */ - g_signal_connect (control, + g_signal_connect (context, "notify::state", G_CALLBACK (state_cb), NULL); @@ -503,8 +562,7 @@ int main (int argc, char *argv[]) g_main_loop_run (mainloop); - g_object_unref (control); - mate_mixer_deinit (); + g_object_unref (context); return 0; } |