diff options
author | ben <benjaminfranzke@googlemail.com> | 2010-07-22 00:05:22 +0200 |
---|---|---|
committer | ben <benjaminfranzke@googlemail.com> | 2010-07-22 00:05:22 +0200 |
commit | 1a1785595a9079850e1b9d490d486af6c6f47873 (patch) | |
tree | bb0e10925f3ecbcd490ad7e21a85f79d94f84a55 /src | |
parent | bc5846ff488f8ec7418c2a91ef0794c3f0405d8d (diff) | |
download | pa-sink-ctl-1a1785595a9079850e1b9d490d486af6c6f47873.tar.gz pa-sink-ctl-1a1785595a9079850e1b9d490d486af6c6f47873.tar.bz2 pa-sink-ctl-1a1785595a9079850e1b9d490d486af6c6f47873.zip |
glib-ify datatype, functions etc + header cleanup
Diffstat (limited to 'src')
-rw-r--r-- | src/interface.c | 85 | ||||
-rw-r--r-- | src/interface.h | 9 | ||||
-rw-r--r-- | src/pa-sink-ctl.c | 50 | ||||
-rw-r--r-- | src/pa-sink-ctl.h | 22 | ||||
-rw-r--r-- | src/sink.c | 37 | ||||
-rw-r--r-- | src/sink.h | 18 | ||||
-rw-r--r-- | src/sink_input.c | 16 | ||||
-rw-r--r-- | src/sink_input.h | 14 |
8 files changed, 103 insertions, 148 deletions
diff --git a/src/interface.c b/src/interface.c index d88f6a0..3219faa 100644 --- a/src/interface.c +++ b/src/interface.c @@ -1,8 +1,3 @@ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <stdbool.h> - #include <signal.h> #include <unistd.h> #include <sys/ioctl.h> @@ -18,48 +13,49 @@ #define VOLUME_BAR_LEN 50 #define H_MSG_BOX 3 -// ncurses +extern GArray *sink_list; +extern pa_context* context; + WINDOW *menu_win; WINDOW *msg_win; -int height; -int width; -int chooser_sink; -int chooser_input; -uint32_t selected_index; -extern GArray *sink_list; -extern pa_context* context; +gint height; +gint width; -void resize(int signal); +gint chooser_sink; +gint chooser_input; +guint32 selected_index; -bool resize_running = false; -bool resize_pending = false; +gboolean resize_running = FALSE; +gboolean resize_pending = FALSE; + +static void resize(gint signal); static void set_resize_callback(void) { signal(SIGWINCH, resize); } -void resize(int signal) +static void resize(gint signal) { set_resize_callback(); if (resize_running) { - resize_pending = true; + resize_pending = TRUE; return; } - resize_running = true; + resize_running = TRUE; do { - resize_pending = false; + resize_pending = FALSE; interface_resize(); } while (resize_pending); - resize_running = false; + resize_running = FALSE; } void interface_init(void) { - chooser_sink = 0; + chooser_sink = 0; chooser_input = -1; initscr(); @@ -101,10 +97,10 @@ void interface_resize(void) void print_sink_list(void) { - int i = 0; - int x = 2; - int y = 2; - int offset = 0; + gint i = 0; + gint x = 2; + gint y = 2; + gint offset = 0; werase(msg_win); box(msg_win, 0, 0); @@ -118,7 +114,7 @@ void print_sink_list(void) if (chooser_input == -2) { chooser_input = -1; /* if index is going to be not found, select the sink itself */ /* step through inputs for current sink and find the selected */ - for (int i = 0; i < sink_list_get(chooser_sink)->input_list->len; ++i) { + for (i = 0; i < sink_list_get(chooser_sink)->input_list->len; ++i) { if (selected_index == sink_input_get(chooser_sink, i)->index) { chooser_input = i; break; @@ -146,13 +142,14 @@ void print_sink_list(void) wrefresh(menu_win); } -void print_input_list(int sink_num) +void print_input_list(gint sink_num) { - int offset = sink_num + 1 + 2; - for (int i = 0; i < sink_num; ++i) + gint offset = sink_num + 1 + 2; + + for (gint i = 0; i < sink_num; ++i) offset += sink_list_get(i)->input_list->len; - for (int i = 0; i < sink_list_get(sink_num)->input_list->len; ++i) { + for (gint i = 0; i < sink_list_get(sink_num)->input_list->len; ++i) { if (chooser_sink == sink_num && chooser_input == i) wattron(menu_win, A_REVERSE); @@ -168,26 +165,26 @@ void print_input_list(int sink_num) void print_volume(pa_volume_t volume, int mute, int y) { - int x = 2 /* left */ + 2 /* index num width */ + 1 /* space */ + + gint x = 2 /* left */ + 2 /* index num width */ + 1 /* space */ + 1 /* space */ + 13 /* input name*/ + 1 /* space */; - int vol = (int) (VOLUME_BAR_LEN * volume / PA_VOLUME_NORM); + gint vol = (gint) (VOLUME_BAR_LEN * volume / PA_VOLUME_NORM); mvwprintw(menu_win, y, x - 1, "[%c]", mute ? 'M' : ' '); x += 3; + mvwprintw(menu_win, y, x - 1 , "["); - for (int i = 0; i < vol; ++i) + for (gint i = 0; i < vol; ++i) mvwprintw(menu_win, y, x + i, "="); - for (int i = vol; i < VOLUME_BAR_LEN; ++i) + for (gint i = vol; i < VOLUME_BAR_LEN; ++i) mvwprintw(menu_win, y, x + i, " "); - mvwprintw(menu_win, y, x + VOLUME_BAR_LEN, "]"); } void get_input(void) { - int c; - bool volume_increment = true; + gint c; + gboolean volume_increment = TRUE; c = wgetch(menu_win); switch (c) { @@ -220,15 +217,15 @@ void get_input(void) case 'h': case KEY_LEFT: - volume_increment = false; + volume_increment = FALSE; /* fall through */ case 'l': case KEY_RIGHT: { struct tmp_t { - uint32_t index; + guint32 index; pa_cvolume volume; pa_volume_t tmp_vol; - pa_operation* (*volume_set) (pa_context*, uint32_t, const pa_cvolume*, pa_context_success_cb_t, void*); + pa_operation* (*volume_set) (pa_context*, guint32, const pa_cvolume*, pa_context_success_cb_t, gpointer); } tmp; if (chooser_input >= 0) { @@ -265,11 +262,12 @@ void get_input(void) pa_operation_unref(tmp.volume_set(context, tmp.index, &tmp.volume, change_callback, NULL)); break; } + case 'm': case 'M': { struct tmp_t { - uint32_t index; - int mute; + guint32 index; + gint mute; pa_operation* (*mute_set) (pa_context*, uint32_t, int, pa_context_success_cb_t, void*); } tmp; @@ -293,6 +291,7 @@ void get_input(void) pa_operation_unref(tmp.mute_set(context, tmp.index, !tmp.mute, change_callback, NULL)); break; } + case '\n': case ' ': if (chooser_input == -1) diff --git a/src/interface.h b/src/interface.h index 20aa559..fa368cb 100644 --- a/src/interface.h +++ b/src/interface.h @@ -1,15 +1,12 @@ #ifndef INTERFACE_H #define INTERFACE_H +#include <glib.h> #include <pulse/pulseaudio.h> -#define VOLUME_BAR_LEN 50 -#define WIDTH 80 -#define HEIGHT 10 - void print_sink_list(void); -void print_input_list(int sink_num); -void print_volume(pa_volume_t, int, int); +void print_input_list(gint); +void print_volume(pa_volume_t, gint, gint); void get_input(void); void interface_init(void); void interface_resize(void); diff --git a/src/pa-sink-ctl.c b/src/pa-sink-ctl.c index ba35bb3..ff36be7 100644 --- a/src/pa-sink-ctl.c +++ b/src/pa-sink-ctl.c @@ -1,33 +1,22 @@ -#define _XOPEN_SOURCE 500 #include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <stdbool.h> #include <glib.h> - #include <pulse/pulseaudio.h> #include <pulse/glib-mainloop.h> -#include <ncurses.h> - #include "sink_input.h" #include "sink.h" #include "interface.h" #include "pa-sink-ctl.h" -#define VOLUME_BAR_LEN 50 -#define WIDTH 80 -#define HEIGHT 10 - -GArray *sink_list = NULL; +GArray *sink_list = NULL; GArray *sink_list_tmp = NULL; pa_mainloop_api *mainloop_api = NULL; pa_context *context = NULL; -bool info_callbacks_finished = true; -bool state_callback_pending = false; +gboolean info_callbacks_finished = TRUE; +gboolean state_callback_pending = FALSE; int main(int argc, char** argv) { @@ -40,7 +29,7 @@ int main(int argc, char** argv) interface_init(); g_context = g_main_context_default(); - g_loop = g_main_loop_new(g_context, false); + g_loop = g_main_loop_new(g_context, FALSE); if (!(m = pa_glib_mainloop_new(g_context))) { printf("error: pa_glib_mainloop_new() failed.\n"); @@ -70,10 +59,10 @@ int main(int argc, char** argv) return 0; } -static void subscribe_cb(pa_context *c, pa_subscription_event_type_t t, uint32_t idx, void *userdata) +static void subscribe_cb(pa_context *c, pa_subscription_event_type_t t, guint32 idx, gpointer userdata) { if (!info_callbacks_finished) - state_callback_pending = true; + state_callback_pending = TRUE; else collect_all_info(); } @@ -81,13 +70,13 @@ static void subscribe_cb(pa_context *c, pa_subscription_event_type_t t, uint32_t static int loop(gpointer data) { get_input(); - return true; + return TRUE; } /* * is called after connection */ -void context_state_callback(pa_context *c, void *userdata) +void context_state_callback(pa_context *c, gpointer userdata) { switch (pa_context_get_state(c)) { case PA_CONTEXT_CONNECTING: @@ -114,7 +103,7 @@ void context_state_callback(pa_context *c, void *userdata) /* * the begin of the callback loops */ -void get_sink_info_callback(pa_context *c, const pa_sink_info *i, int is_last, void *userdata) +void get_sink_info_callback(pa_context *c, const pa_sink_info *i, gint is_last, gpointer userdata) { if (is_last < 0) { printf("Failed to get sink information: %s\n", pa_strerror(pa_context_errno(c))); @@ -131,9 +120,9 @@ void get_sink_info_callback(pa_context *c, const pa_sink_info *i, int is_last, v .mute = i->mute, .vol = pa_cvolume_avg(&i->volume), .channels = i->volume.channels, - .name = strdup(i->name), + .name = g_strdup(i->name), .device = pa_proplist_contains(i->proplist, "device.product.name") ? - strdup(pa_proplist_gets(i->proplist, "device.product.name")) : NULL, + g_strdup(pa_proplist_gets(i->proplist, "device.product.name")) : NULL, .input_list = sink_input_list_alloc() })); } @@ -141,24 +130,22 @@ void get_sink_info_callback(pa_context *c, const pa_sink_info *i, int is_last, v /* * is called after sink-input */ -void get_sink_input_info_callback(pa_context *c, const pa_sink_input_info *i, int is_last, void *userdata) +void get_sink_input_info_callback(pa_context *c, const pa_sink_input_info *i, gint is_last, gpointer userdata) { - char t[32], k[32]; - if (is_last < 0) { printf("Failed to get sink input information: %s\n", pa_strerror(pa_context_errno(c))); return; } if (is_last) { - info_callbacks_finished = true; + info_callbacks_finished = TRUE; sink_list_free(sink_list); sink_list = sink_list_tmp; print_sink_list(); if (state_callback_pending) { - state_callback_pending = false; + state_callback_pending = FALSE; collect_all_info(); } return; @@ -166,13 +153,10 @@ void get_sink_input_info_callback(pa_context *c, const pa_sink_input_info *i, in if (!(i->client != PA_INVALID_INDEX)) return; - snprintf(t, sizeof(t), "%u", i->owner_module); - snprintf(k, sizeof(k), "%u", i->client); - g_array_append_val(g_array_index(sink_list_tmp, sink_info, i->sink).input_list, ((sink_input_info) { .index = i->index, .sink = i->sink, - .name = strdup(pa_proplist_gets(i->proplist, "application.name")), + .name = g_strdup(pa_proplist_gets(i->proplist, "application.name")), .mute = i->mute, .channels = i->volume.channels, .vol = pa_cvolume_avg(&i->volume), @@ -190,7 +174,7 @@ void quit(void) /* * is called, after user input */ -void change_callback(pa_context* c, int success, void* userdate) +void change_callback(pa_context* c, gint success, gpointer userdata) { return; } @@ -199,7 +183,7 @@ void collect_all_info(void) { if (!info_callbacks_finished) return; - info_callbacks_finished = false; + info_callbacks_finished = FALSE; sink_list_tmp = sink_list_alloc(); pa_operation_unref(pa_context_get_sink_info_list(context, get_sink_info_callback, NULL)); diff --git a/src/pa-sink-ctl.h b/src/pa-sink-ctl.h index 899e14d..3175838 100644 --- a/src/pa-sink-ctl.h +++ b/src/pa-sink-ctl.h @@ -1,25 +1,15 @@ #ifndef PA_SINK_CTL_H #define PA_SINK_CTL_H -#include <stdio.h> -#include <stdlib.h> -#include <stdint.h> +#include <glib.h> #include <pulse/pulseaudio.h> -#include <ncurses.h> -#include <string.h> -#include "sink_input.h" -#include "sink.h" -#include "interface.h" - -#define VOLUME_BAR_LEN 50 - -void context_state_callback(pa_context*, void *); -void get_sink_info_callback(pa_context *, const pa_sink_info *, int, void *); -void get_sink_input_info_callback(pa_context *, const pa_sink_input_info*, int, void *); -void change_callback(pa_context* c, int success, void* userdate); +void collect_all_info(void); void quit(void); -void collect_all_info(void); +void context_state_callback(pa_context*, gpointer); +void get_sink_info_callback(pa_context *, const pa_sink_info *, gint, gpointer); +void get_sink_input_info_callback(pa_context *, const pa_sink_input_info*, gint, gpointer); +void change_callback(pa_context* c, gint success, gpointer); #endif @@ -1,29 +1,16 @@ -#include <stdio.h> #include <glib.h> -#include <pulse/pulseaudio.h> -#include <ncurses.h> -#include <string.h> -#include <stdlib.h> #include "sink_input.h" #include "sink.h" extern GArray *sink_list; -sink_info *sink_list_get(int index) { - return &g_array_index(sink_list, sink_info, index); -} - -sink_input_info *sink_input_get(int sink_list_index, int index) { - return &g_array_index(sink_list_get(sink_list_index)->input_list, sink_input_info, index); -} - /* * init a sink list */ GArray *sink_list_alloc(void) { - return g_array_sized_new(false, false, sizeof(sink_info), 16); + return g_array_sized_new(FALSE, FALSE, sizeof(sink_info), 16); } /* @@ -31,10 +18,8 @@ GArray *sink_list_alloc(void) */ static void sink_clear(sink_info* sink) { - if (sink->name != NULL) - free(sink->name); - if (sink->device != NULL) - free(sink->device); + g_free(sink->name); + g_free(sink->device); sink_input_list_free(sink->input_list); } @@ -45,7 +30,21 @@ void sink_list_free(GArray *sink_list) { for (int i = 0; i < sink_list->len; ++i) sink_clear(&g_array_index(sink_list, sink_info, i)); - g_array_free(sink_list, true); + g_array_free(sink_list, TRUE); } +/* + * get sink at index from sink_list + */ +sink_info *sink_list_get(gint index) +{ + return &g_array_index(sink_list, sink_info, index); +} +/* + * get an input association to an sink by their indizes + */ +sink_input_info *sink_input_get(gint sink_list_index, gint index) +{ + return &g_array_index(sink_list_get(sink_list_index)->input_list, sink_input_info, index); +} @@ -1,21 +1,17 @@ #ifndef SINK_H #define SINK_H -#include <stdio.h> #include <glib.h> #include <pulse/pulseaudio.h> -#include <ncurses.h> -#include <string.h> -#include <stdlib.h> #include "sink_input.h" typedef struct _sink_info { - uint32_t index; - char* name; - char* device; - int mute; - uint8_t channels; + guint32 index; + gchar* name; + gchar* device; + gint mute; + guint8 channels; pa_volume_t vol; GArray *input_list; } sink_info; @@ -23,7 +19,7 @@ typedef struct _sink_info { GArray *sink_list_alloc(void); void sink_list_free(GArray *sink_list); -sink_info *sink_list_get(int index); -sink_input_info *sink_input_get(int sink_list_index, int index); +sink_info *sink_list_get(gint index); +sink_input_info *sink_input_get(gint sink_list_index, gint index); #endif diff --git a/src/sink_input.c b/src/sink_input.c index 3d0c1cd..d4341d4 100644 --- a/src/sink_input.c +++ b/src/sink_input.c @@ -1,28 +1,20 @@ -#include <stdio.h> #include <glib.h> -#include <pulse/pulseaudio.h> -#include <ncurses.h> -#include <string.h> -#include <stdlib.h> - #include "sink_input.h" GArray *sink_input_list_alloc(void) { - return g_array_sized_new(false, false, sizeof(sink_input_info), 8); + return g_array_sized_new(FALSE, FALSE, sizeof(sink_input_info), 8); } static void sink_input_clear(sink_input_info* sink_input) { - if (sink_input->name != NULL) - free(sink_input->name); - if (sink_input->pid != NULL) - free(sink_input->pid); + g_free(sink_input->name); + g_free(sink_input->pid); } void sink_input_list_free(GArray *sink_input_list) { for (int i = 0; i < sink_input_list->len; ++i) sink_input_clear(&g_array_index(sink_input_list, sink_input_info, i)); - g_array_free(sink_input_list, true); + g_array_free(sink_input_list, TRUE); } diff --git a/src/sink_input.h b/src/sink_input.h index ec636d0..a62a00b 100644 --- a/src/sink_input.h +++ b/src/sink_input.h @@ -1,18 +1,16 @@ #ifndef SINK_INPUT_H #define SINK_INPUT_H -#include <stdint.h> - #include <glib.h> #include <pulse/pulseaudio.h> typedef struct _sink_input_info { - uint32_t index; - uint32_t sink; - char *name; - char *pid; // maybe useless?!!? - int mute; - uint8_t channels; + guint32 index; + guint32 sink; + gchar *name; + gchar *pid; // maybe useless?!!? + gint mute; + guint8 channels; pa_volume_t vol; // TOTO: exchange with the channel-list } sink_input_info; |