summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorben <benjaminfranzke@googlemail.com>2010-07-15 14:25:04 +0200
committerben <benjaminfranzke@googlemail.com>2010-07-15 14:25:04 +0200
commit9e6611b32a566d5319446f3deb78dcf80f417b20 (patch)
tree7ea2c554643e6771573d48be6c899bd02a8eed7c /src
parent5eff48dddb547a4c7f9914b5430b28fe31c3d144 (diff)
downloadpa-sink-ctl-9e6611b32a566d5319446f3deb78dcf80f417b20.tar.gz
pa-sink-ctl-9e6611b32a566d5319446f3deb78dcf80f417b20.tar.bz2
pa-sink-ctl-9e6611b32a566d5319446f3deb78dcf80f417b20.zip
use easier sink_*_get() instead of g_array_index
Diffstat (limited to 'src')
-rw-r--r--src/interface.c40
-rw-r--r--src/pa-sink-ctl.c2
-rw-r--r--src/sink.c10
-rw-r--r--src/sink.h3
4 files changed, 33 insertions, 22 deletions
diff --git a/src/interface.c b/src/interface.c
index 76fb29e..c3c8ba7 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -58,8 +58,8 @@ 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 < g_array_index(sink_list, sink_info, chooser_sink).input_list->len; ++i) {
- if (selected_index == g_array_index(g_array_index(sink_list, sink_info, chooser_sink).input_list, sink_input_info, i).index) {
+ for (int 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;
}
@@ -72,16 +72,16 @@ void print_sink_list(void)
wattron(menu_win, A_REVERSE);
mvwprintw(menu_win, y+i+offset, x, "%2d %-13s",
- g_array_index(sink_list, sink_info, i).index,
- g_array_index(sink_list, sink_info, i).device != NULL ? g_array_index(sink_list, sink_info, i).device : g_array_index(sink_list, sink_info, i).name);
+ sink_list_get(i)->index,
+ sink_list_get(i)->device != NULL ? sink_list_get(i)->device : sink_list_get(i)->name);
if (i == chooser_sink && chooser_input == -1)
wattroff(menu_win, A_REVERSE);
- print_volume(g_array_index(sink_list, sink_info, i).vol, g_array_index(sink_list, sink_info, i).mute, y+i+offset);
+ print_volume(sink_list_get(i)->vol, sink_list_get(i)->mute, y+i+offset);
print_input_list(i);
- offset += g_array_index(sink_list, sink_info, i).input_list->len;
+ offset += sink_list_get(i)->input_list->len;
}
wrefresh(menu_win);
}
@@ -90,20 +90,18 @@ void print_input_list(int sink_num)
{
int offset = sink_num + 1 + 2;
for (int i = 0; i < sink_num; ++i)
- offset += g_array_index(sink_list, sink_info, i).input_list->len;
+ offset += sink_list_get(i)->input_list->len;
- for (int i = 0; i < g_array_index(sink_list, sink_info, sink_num).input_list->len; ++i) {
+ for (int 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);
- mvwprintw(menu_win, offset + i, 2, "%*s%-*s", 2+1+1, "", 13 - 1,
- g_array_index(g_array_index(sink_list, sink_info, sink_num).input_list, sink_input_info, i).name);
+ mvwprintw(menu_win, offset + i, 2, "%*s%-*s", 2+1+1, "", 13 - 1, sink_input_get(sink_num, i)->name);
if (chooser_sink == sink_num && chooser_input == i)
wattroff(menu_win, A_REVERSE);
- print_volume(g_array_index(g_array_index(sink_list, sink_info, sink_num).input_list, sink_input_info, i).vol,
- g_array_index(g_array_index(sink_list, sink_info, sink_num).input_list, sink_input_info, i).mute, offset + i);
+ print_volume(sink_input_get(sink_num, i)->vol, sink_input_get(sink_num, i)->mute, offset + i);
}
}
@@ -136,7 +134,7 @@ void get_input(void)
case KEY_UP:
if (chooser_input == -1 && chooser_sink > 0) {
--chooser_sink;
- chooser_input = (gint)g_array_index(sink_list, sink_info, chooser_sink).input_list->len - 1;
+ chooser_input = (gint)sink_list_get(chooser_sink)->input_list->len - 1;
}
else if (chooser_input >= 0)
@@ -145,11 +143,11 @@ void get_input(void)
case 'j':
case KEY_DOWN:
- if (chooser_input == ((gint)g_array_index(sink_list, sink_info, chooser_sink).input_list->len - 1) && chooser_sink < (gint)sink_list->len - 1) {
+ if (chooser_input == ((gint)sink_list_get(chooser_sink)->input_list->len - 1) && chooser_sink < (gint)sink_list->len - 1) {
++chooser_sink;
chooser_input = -1;
}
- else if (chooser_input < ((gint)g_array_index(sink_list, sink_info, chooser_sink).input_list->len - 1))
+ else if (chooser_input < ((gint)sink_list_get(chooser_sink)->input_list->len - 1))
++chooser_input;
break;
@@ -170,7 +168,7 @@ void get_input(void)
} tmp;
if (chooser_input >= 0) {
- sink_input_info *input = &g_array_index(g_array_index(sink_list, sink_info, chooser_sink).input_list, sink_input_info, chooser_input);
+ sink_input_info *input = sink_input_get(chooser_sink, chooser_input);
tmp = (struct tmp_t) {
.index = input->index,
.volume = (pa_cvolume) {.channels = input->channels},
@@ -178,7 +176,7 @@ void get_input(void)
.volume_set = pa_context_set_sink_input_volume
};
} else if (chooser_input == -1) {
- sink_info *sink = &g_array_index(sink_list, sink_info, chooser_sink);
+ sink_info *sink = sink_list_get(chooser_sink);
tmp = (struct tmp_t) {
.index = sink->index,
.volume = (pa_cvolume) {.channels = sink->channels},
@@ -203,14 +201,14 @@ void get_input(void)
} tmp;
if (chooser_input >= 0) {
- sink_input_info *input = &g_array_index(g_array_index(sink_list, sink_info, chooser_sink).input_list, sink_input_info, chooser_input);
+ sink_input_info *input = sink_input_get(chooser_sink, chooser_input);
tmp = (struct tmp_t) {
.index = input->index,
.mute = input->mute,
.mute_set = pa_context_set_sink_input_mute
};
} else if (chooser_input == -1) {
- sink_info *sink = &g_array_index(sink_list, sink_info, chooser_sink);
+ sink_info *sink = sink_list_get(chooser_sink);
tmp = (struct tmp_t) {
.index = sink->index,
.mute = sink->mute,
@@ -226,7 +224,7 @@ void get_input(void)
case ' ':
if (chooser_input == -1)
break;
- selected_index = g_array_index(g_array_index(sink_list, sink_info, chooser_sink).input_list, sink_input_info, chooser_input).index;
+ selected_index = sink_input_get(chooser_sink, chooser_input)->index;
if (chooser_sink < (gint)sink_list->len - 1)
chooser_sink++;
else
@@ -234,7 +232,7 @@ void get_input(void)
chooser_input = -2; /* chooser_input needs to be derived from $selected_index */
pa_operation_unref(pa_context_move_sink_input_by_index(context, selected_index,
- g_array_index(sink_list, sink_info, chooser_sink).index,
+ sink_list_get(chooser_sink)->index,
change_callback, NULL));
return;
diff --git a/src/pa-sink-ctl.c b/src/pa-sink-ctl.c
index aa7870a..2acc7df 100644
--- a/src/pa-sink-ctl.c
+++ b/src/pa-sink-ctl.c
@@ -143,7 +143,7 @@ void get_sink_input_info_callback(pa_context *c, const pa_sink_input_info *i, in
snprintf(t, sizeof(t), "%u", i->owner_module);
snprintf(k, sizeof(k), "%u", i->client);
- g_array_append_val(g_array_index(sink_list, sink_info, i->sink).input_list, ((sink_input_info) {
+ g_array_append_val(sink_list_get(i->sink)->input_list, ((sink_input_info) {
.index = i->index,
.sink = i->sink,
.name = strdup(pa_proplist_gets(i->proplist, "application.name")),
diff --git a/src/sink.c b/src/sink.c
index 24d1b4f..a0283eb 100644
--- a/src/sink.c
+++ b/src/sink.c
@@ -8,6 +8,16 @@
#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
*/
diff --git a/src/sink.h b/src/sink.h
index 48688aa..a9f64d1 100644
--- a/src/sink.h
+++ b/src/sink.h
@@ -23,4 +23,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);
+
#endif