From 9b566cf3fd0a48107d273081b24f3cc6534e90f6 Mon Sep 17 00:00:00 2001 From: Jan Klemkow Date: Mon, 12 Jul 2010 18:59:23 +0200 Subject: wip: bugfix: interface --- src/interface.c | 51 ++++++++++++++++++++++++++++++++++++++++++--------- src/interface.h | 3 ++- src/pa-sink-ctl.c | 18 +++++++----------- src/pa-sink-ctl.h | 2 ++ src/sink.c | 8 +++++++- src/sink_input.c | 9 ++++++--- src/sink_input.h | 2 +- 7 files changed, 67 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/interface.c b/src/interface.c index c48b953..462b82c 100644 --- a/src/interface.c +++ b/src/interface.c @@ -15,7 +15,8 @@ // ncurses WINDOW *menu_win; -int chooser; +int chooser_sink; +int chooser_input; int startx; int starty; @@ -28,7 +29,8 @@ extern pa_context* context; void interface_init(void) { // ncurses - chooser = 0; + chooser_sink = 0; + chooser_input = 0; initscr(); clear(); @@ -42,7 +44,7 @@ void interface_init(void) refresh(); } -void print_sinks(void) { +void print_sink_list(void) { int x, y, i; x = 2; y = 2; @@ -54,9 +56,18 @@ void print_sinks(void) { // qsort(sink_input_list, sink_input_counter, sizeof(sink_input_info*), cmp_sink_input_list); for (i = 0; i < sink_counter; ++i) { + + if (i == chooser_sink) + wattron(menu_win, A_REVERSE); + mvwprintw(menu_win, y+i, x, "%d\t%s\t", sink_list[i]->index, sink_list[i]->name); + + print_input_list(i); + + if (i == chooser_sink) + wattroff(menu_win, A_REVERSE); } y += i; /* for (i = 0; i < sink_input_counter; ++i) { @@ -74,6 +85,18 @@ void print_sinks(void) { }*/ } +void print_input_list(int sink_num) { + int offset = sink_num + 1 + 2; + for (int i = 0; i < sink_num; ++i) + offset += sink_list[i]->input_counter; + + for (int i = 0; i < sink_list[sink_num]->input_counter; ++i) { + mvwprintw(menu_win, offset + i, 2 + 5, "\t%s", + sink_list[sink_num]->input_list[i]->name); + } + +} + void print_volume(pa_volume_t volume, int y) { int x = 20; @@ -95,13 +118,22 @@ void get_input(void) c = wgetch(menu_win); switch (c) { case KEY_UP: - if (chooser > 0) - --chooser; + if (chooser_input == -1 && chooser_sink > 0) { + --chooser_sink; + chooser_input = sink_list[chooser_sink]->input_counter - 1; + } + + else if (chooser_input >= 0) + --chooser_input; break; case KEY_DOWN: -// if (chooser < sink_input_counter - 1) -// ++chooser; + if (chooser_input == sink_list[chooser_sink]->input_counter - 1 && chooser_sink < sink_counter - 1) { + ++chooser_sink; + chooser_input = 0; + } + else if (chooser_input < sink_list[chooser_sink]->input_counter) + ++chooser_input; break; case KEY_LEFT: @@ -132,8 +164,9 @@ void get_input(void) quit(); break; } - - pa_operation_unref(pa_context_get_sink_info_list(context, get_sink_info_callback, NULL)); + + collect_all_info(); +// pa_operation_unref(pa_context_get_sink_info_list(context, get_sink_info_callback, NULL)); // sink_input_counter = 0; // pa_operation_unref(pa_context_get_sink_input_info_list(context, get_sink_input_info_callback, NULL)); } diff --git a/src/interface.h b/src/interface.h index d152c7d..e805dfc 100644 --- a/src/interface.h +++ b/src/interface.h @@ -8,7 +8,8 @@ #define WIDTH 80 #define HEIGHT 10 -void print_sinks(void); +void print_sink_list(void); +void print_input_list(int sink_num); void print_volume(pa_volume_t, int); void get_input(void); void interface_init(void); diff --git a/src/pa-sink-ctl.c b/src/pa-sink-ctl.c index 5fe67c1..a33646b 100644 --- a/src/pa-sink-ctl.c +++ b/src/pa-sink-ctl.c @@ -83,7 +83,7 @@ void context_state_callback(pa_context *c, void *userdata) { case PA_CONTEXT_READY: // printf("Menue\n"); - pa_operation_unref(pa_context_get_sink_info_list(c, get_sink_info_callback, NULL)); + collect_all_info(); // pa_operation_unref(pa_context_get_sink_input_info_list(c, get_sink_input_info_callback, NULL)); break; default: @@ -98,7 +98,7 @@ void context_state_callback(pa_context *c, void *userdata) { void get_sink_info_callback(pa_context *c, const pa_sink_info *i, int is_last, void *userdata) { if (is_last < 0) { - printf("Failed to get sink information: %s", pa_strerror(pa_context_errno(c))); + printf("Failed to get sink information: %s\n", pa_strerror(pa_context_errno(c))); quit(); } @@ -108,11 +108,9 @@ void get_sink_info_callback(pa_context *c, const pa_sink_info *i, int is_last, v } sink_list_check(sink_list, &sink_max, sink_counter); - - sink_list[sink_counter] = (sink_info*) calloc(1, sizeof(sink_info)); + sink_check(&(sink_list[sink_counter])); sink_list[sink_counter]->index = i->index; sink_list[sink_counter]->mute = i->mute; - sink_list[sink_counter]->name = strdup(i->name); ++sink_counter; } @@ -129,7 +127,7 @@ void get_sink_input_info_callback(pa_context *c, const pa_sink_input_info *i, in } if (is_last) { - print_sinks(); + print_sink_list(); get_input(); return; } @@ -159,18 +157,16 @@ void get_sink_input_info_callback(pa_context *c, const pa_sink_input_info *i, in int sink_num = i->sink; int counter = sink_list[sink_num]->input_counter; - // check the length of the list sink_check_input_list(sink_list[sink_num]); // check the current element of the list sink_input_check(&(sink_list[ sink_num ]->input_list[ counter ])); sink_input_info* input = sink_list[sink_num]->input_list[counter]; - input->name = strdup(pa_proplist_gets(i->proplist, "application.name")); input->index = i->index; input->vol = pa_cvolume_avg(&i->volume); - ++sink_list[sink_num]->input_counter; + ++(sink_list[sink_num]->input_counter); } void quit(void) { @@ -189,7 +185,7 @@ void change_callback(pa_context* c, int success, void* userdate) { pa_operation_unref(pa_context_get_sink_input_info_list(context, get_sink_input_info_callback, NULL)); } -void collect_all_infomation(void) { +void collect_all_info(void) { sink_list_reset(sink_list, &sink_counter); - + 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 eb14ad2..36201cb 100644 --- a/src/pa-sink-ctl.h +++ b/src/pa-sink-ctl.h @@ -22,4 +22,6 @@ void get_sink_input_info_callback(pa_context *, const pa_sink_input_info*, int, void change_callback(pa_context* c, int success, void* userdate); void quit(void); +void collect_all_info(void); + #endif diff --git a/src/sink.c b/src/sink.c index 5abff14..38f061b 100644 --- a/src/sink.c +++ b/src/sink.c @@ -40,16 +40,22 @@ void sink_clear(sink_info* sink) { void sink_check(sink_info** sink) { + if (sink == NULL) + printf("Error: sink = NULL\n"); + if ((*sink) == NULL) - (*sink) = (sink_info*) calloc(1, sizeof(sink_input_info)); + (*sink) = sink_init(); +// (*sink) = (sink_info*) calloc(1, sizeof(sink_input_info)); } /* * check the list length and resize the list, if current position = max */ void sink_list_check(sink_info** sink_list, uint32_t* max, uint32_t counter) { + if (counter >= (*max)) { (*max) *= 2; sink_list = (sink_info**) realloc(sink_list, (*max) * sizeof(sink_info*)); + for (int i = counter; i < (*max); ++i) sink_list[i] = NULL; } diff --git a/src/sink_input.c b/src/sink_input.c index 54f7c04..0940a4b 100644 --- a/src/sink_input.c +++ b/src/sink_input.c @@ -6,7 +6,7 @@ #include "sink_input.h" -sink_input_info* sink_input_init() { +sink_input_info* sink_input_init(void) { sink_input_info* sink_input = (sink_input_info*) calloc(1, sizeof(sink_input_info)); sink_input->name = NULL; @@ -32,7 +32,7 @@ sink_input_info** sink_input_list_init(int max) { sink_input_info** sink_input_list = (sink_input_info**) calloc(max, sizeof(sink_input_info*)); for (int i = 0; i < max; ++i) - sink_input_list = NULL; + sink_input_list[i] = NULL; return sink_input_list; } @@ -58,9 +58,12 @@ void sink_input_list_clear(sink_input_info** sink_input_list, int *max) { } void sink_input_check(sink_input_info** sink_input) { + + if (sink_input == NULL) + printf("Error: NULL\n"); if ((*sink_input) == NULL) - (*sink_input) = (sink_input_info*) calloc(1, sizeof(sink_input_info)); + (*sink_input) = sink_input_init(); } int cmp_sink_input_list(const void *a, const void *b) { diff --git a/src/sink_input.h b/src/sink_input.h index d16924c..f6fa1ac 100644 --- a/src/sink_input.h +++ b/src/sink_input.h @@ -13,7 +13,7 @@ typedef struct _sink_input_info { pa_volume_t vol; // TOTO: exchange with the channel-list } sink_input_info; -sink_input_info* sink_input_init(); +sink_input_info* sink_input_init(void); void sink_input_clear(sink_input_info*); sink_input_info** sink_input_list_init(int); -- cgit