From 803b7b24229c42cd9d5eee8c1da166382a321d5c Mon Sep 17 00:00:00 2001 From: ben Date: Tue, 13 Jul 2010 16:28:36 +0200 Subject: sink_inputs volume made changable --- src/interface.c | 26 ++++++++++++++++++++++++-- src/pa-sink-ctl.c | 1 + src/sink_input.c | 12 ++++++------ src/sink_input.h | 1 + 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/interface.c b/src/interface.c index 5492fbf..f46f6dc 100644 --- a/src/interface.c +++ b/src/interface.c @@ -149,6 +149,8 @@ void get_input(void) int c; // uint32_t sink; c = wgetch(menu_win); + int volume_mult = 0; + switch (c) { case KEY_UP: if (chooser_input == -1 && chooser_sink > 0) { @@ -170,9 +172,29 @@ void get_input(void) break; case KEY_LEFT: - break; - + volume_mult = -1; case KEY_RIGHT: + if (volume_mult == 0) + volume_mult = 1; + if (chooser_input == -1) + break; + sink_input_info *input = sink_list[chooser_sink]->input_list[chooser_input]; + pa_cvolume volume; + volume.channels = input->channels; + + int input_vol = input->vol + 2 * volume_mult * (VOLUME_MAX / 100); +#define CHECK_MIN_MAX(val, min, max) ((val) > (max) ? (max) : ((val) < (min) ? (min) : (val))) + pa_volume_t new_vol = CHECK_MIN_MAX(input_vol, 0, VOLUME_MAX); +#undef CHECK_MIN_MAX + for (int i = 0; i < volume.channels; ++i) + volume.values[i] = new_vol; + + pa_operation_unref(pa_context_set_sink_input_volume(context, + input->index, + &volume, + change_callback, + NULL)); + return; break; case 32: diff --git a/src/pa-sink-ctl.c b/src/pa-sink-ctl.c index 42ebc07..fce5a84 100644 --- a/src/pa-sink-ctl.c +++ b/src/pa-sink-ctl.c @@ -164,6 +164,7 @@ void get_sink_input_info_callback(pa_context *c, const pa_sink_input_info *i, in 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->channels = i->volume.channels; input->vol = pa_cvolume_avg(&i->volume); ++(sink_list[sink_num]->input_counter); diff --git a/src/sink_input.c b/src/sink_input.c index 8b3eab8..a1440df 100644 --- a/src/sink_input.c +++ b/src/sink_input.c @@ -16,10 +16,10 @@ sink_input_info* sink_input_init(void) { } 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); @@ -33,12 +33,12 @@ sink_input_info** sink_input_list_init(int max) { for (int i = 0; i < max; ++i) sink_input_list[i] = NULL; - + return sink_input_list; } void sink_input_list_enlarge(sink_input_info*** sink_input_list, int* max, int counter) { - + *max *= 2; *sink_input_list = (sink_input_info**) realloc(*sink_input_list, (*max) * sizeof(sink_input_info*)); @@ -47,7 +47,7 @@ void sink_input_list_enlarge(sink_input_info*** sink_input_list, int* max, int c } void sink_input_list_clear(sink_input_info** sink_input_list, int *max) { - + for (int i = 0; i < (*max); ++i) if (sink_input_list[i] != NULL) sink_input_clear(sink_input_list[i]); @@ -59,7 +59,7 @@ 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"); diff --git a/src/sink_input.h b/src/sink_input.h index 92ff4bb..03ed476 100644 --- a/src/sink_input.h +++ b/src/sink_input.h @@ -10,6 +10,7 @@ typedef struct _sink_input_info { uint32_t sink; char *name; char *pid; // maybe useless?!!? + uint8_t channels; pa_volume_t vol; // TOTO: exchange with the channel-list } sink_input_info; -- cgit