summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Klemkow <web2p10@wemelug.de>2010-07-08 22:17:39 +0200
committerJan Klemkow <web2p10@wemelug.de>2010-07-08 22:17:39 +0200
commit4ed3f983f9609ee6b1b3ce20053b31e62ddb2a1f (patch)
tree51431343b5f46dd4b9920f151eab540c63077a95
parent2eb6ed491d5dee2e9a3aded7db2cfbfe5b0b7970 (diff)
downloadpa-sink-ctl-4ed3f983f9609ee6b1b3ce20053b31e62ddb2a1f.tar.gz
pa-sink-ctl-4ed3f983f9609ee6b1b3ce20053b31e62ddb2a1f.tar.bz2
pa-sink-ctl-4ed3f983f9609ee6b1b3ce20053b31e62ddb2a1f.zip
splitting project into seperat files
-rw-r--r--Makefile16
-rw-r--r--pa-sink-ctl.c181
2 files changed, 59 insertions, 138 deletions
diff --git a/Makefile b/Makefile
index 4651f4f..c6057b3 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,20 @@
CC=gcc
CFLAGS=-pedantic -std=c99 -Wall -Werror -lpulse -lncurses -lform
-all: pa-sink-ctl.c
- $(CC) $(CFLAGS) pa-sink-ctl.c -o pa-sink-ctl
+all: pa-sink-ctl.o interface.o sink_input.o sink.o
+ $(CC) $(CFLAGS) -o pa-sink-ctl pa-sink-ctl.o interface.o sink_input.o sink.o
+
+pa-sink-ctl.o: pa-sink-ctl.c pa-sink-ctl.h
+ $(CC) $(CFLAGS) -c pa-sink-ctl.c -o pa-sink-ctl.o
+
+interface: interface.c interface.h
+ $(CC) $(CFLAGS) -c interface.c -o interface.o
+
+sink_input: sink_input.c sink_input.h
+ $(CC) $(CFLAGS) -c sink_input.c -o sink_input.o
+
+sink: sink.c sink.h
+ $(CC) $(CFLAGS) -c sink.c -o sink.o
test:
$(CC) $(CFLAGS) nc-test.c -o nc-test
diff --git a/pa-sink-ctl.c b/pa-sink-ctl.c
index 388c8f1..b024d60 100644
--- a/pa-sink-ctl.c
+++ b/pa-sink-ctl.c
@@ -4,44 +4,26 @@
#include <string.h>
#include <stdlib.h>
+#include "sink_input.h"
+#include "sink.h"
+#include "interface.h"
+#include "pa-sink-ctl.h"
+
#define VOLUME_MAX UINT16_MAX
#define VOLUME_BAR_LEN 50
#define WIDTH 80
#define HEIGHT 10
-static void context_state_callback(pa_context*, void *);
-static void get_sink_input_info_callback(pa_context *, const pa_sink_input_info*, int, void *);
-static void change_callback(pa_context* c, int success, void* userdate);
-static void print_sinks(void);
-static void print_volume(pa_volume_t, int);
-int cmp_sink_input_list(const void *, const void *);
-void get_input(void);
-void quit(void);
-
-typedef struct _sink_input_info {
- uint32_t index;
- uint32_t sink;
- char *name;
- char *pid;
- pa_volume_t vol;
-} sink_input_info;
-
-typedef struct _sink_info {
- uint32_t sink;
- char* name;
- pa_volume_t vol;
-} sink_info;
-
-static sink_info** sink_list = NULL;
+sink_info** sink_list = NULL;
int sink_counter;
uint32_t sink_max;
-static sink_input_info** sink_input_list = NULL;
+sink_input_info** sink_input_list = NULL;
int sink_input_counter;
int sink_input_max;
-static pa_mainloop_api *mainloop_api = NULL;
-static pa_context *context = NULL;
+pa_mainloop_api *mainloop_api = NULL;
+pa_context *context = NULL;
// ncurses
WINDOW *menu_win;
@@ -51,15 +33,16 @@ int starty;
int main(int argc, char** argv)
{
+ // pulseaudio
sink_input_counter = 0;
sink_input_max = 1;
+ sink_input_list = (sink_input_info**) calloc(sink_input_max, sizeof(sink_input_info*));
sink_counter = 0;
sink_max = 1;
-
- sink_input_list = (sink_input_info**) calloc(sink_input_max, sizeof(sink_input_info*));
sink_list = (sink_info**) calloc(sink_max, sizeof(sink_info*));
+ // ncurses
chooser = 0;
initscr();
@@ -101,7 +84,7 @@ int main(int argc, char** argv)
return ret;
}
-static void context_state_callback(pa_context *c, void *userdata) {
+void context_state_callback(pa_context *c, void *userdata) {
switch (pa_context_get_state(c)) {
case PA_CONTEXT_CONNECTING:
@@ -118,8 +101,8 @@ static void context_state_callback(pa_context *c, void *userdata) {
case PA_CONTEXT_READY:
// printf("Menue\n");
-
- pa_operation_unref(pa_context_get_sink_input_info_list(c, get_sink_input_info_callback, NULL));
+ pa_operation_unref(pa_context_get_sink_info_list(c, get_sink_info_callback, NULL));
+// pa_operation_unref(pa_context_get_sink_input_info_list(c, get_sink_input_info_callback, NULL));
break;
default:
printf("unknown state\n");
@@ -127,7 +110,33 @@ static void context_state_callback(pa_context *c, void *userdata) {
}
}
-static void get_sink_input_info_callback(pa_context *c, const pa_sink_input_info *i, int is_last, 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)));
+ quit();
+ }
+
+ if (is_last) {
+ pa_operation_unref(pa_context_get_sink_input_info_list(c, get_sink_input_info_callback, NULL));
+ return;
+ }
+
+ ++sink_counter;
+ if (sink_counter >= sink_max) {
+ sink_max *= 2;
+ sink_list = realloc(sink_list, sizeof(sink_info*) * sink_max);
+ }
+
+ sink_list[sink_counter - 1] = (sink_info*) calloc(1, sizeof(sink_info));
+ sink_list[sink_counter - 1]->index = i->index;
+ sink_list[sink_counter - 1]->mute = i->mute;
+
+ sink_list[sink_counter - 1]->name = (char*) calloc(strlen(i->name) + 1, sizeof(char));
+ strncpy(sink_list[sink_counter - 1]->name, i->name, strlen(i->name));
+}
+
+void get_sink_input_info_callback(pa_context *c, const pa_sink_input_info *i, int is_last, void *userdata) {
char t[32], k[32]; //,cv[PA_CVOLUME_SNPRINT_MAX];
if (is_last < 0) {
@@ -164,8 +173,8 @@ static void get_sink_input_info_callback(pa_context *c, const pa_sink_input_info
const char *name = pa_proplist_gets(i->proplist, "application.name");
- if (i->sink > sink_max)
- sink_max = i->sink;
+// if (i->sink > sink_max)
+// sink_max = i->sink;
++sink_input_counter;
@@ -183,106 +192,6 @@ static void get_sink_input_info_callback(pa_context *c, const pa_sink_input_info
sink_input_list[sink_input_counter-1]->vol = pa_cvolume_avg(&i->volume);
}
-void print_sinks(void) {
- int x, y, i;
- x = 2;
- y = 2;
-
- box(menu_win, 0, 0);
-
-// printf("print sinks: %d\n", sink_input_counter);
-
-// qsort(sink_input_list, sink_input_counter, sizeof(sink_input_info*), cmp_sink_input_list);
-
- for(i = 0; i < sink_input_counter; ++i) {
- if (i == chooser)
- wattron(menu_win, A_REVERSE);
-
- mvwprintw(menu_win, y+i, x, "%d\t%s\t",
- sink_input_list[i]->sink,
- sink_input_list[i]->name);
-
- if (i == chooser)
- wattroff(menu_win, A_REVERSE);
-
- print_volume(sink_input_list[i]->vol, y+i);
- }
-}
-
-void print_volume(pa_volume_t volume, int y) {
-
- int x = 20;
-
- unsigned int vol = (unsigned int) ( (((double)volume) / ((double)VOLUME_MAX)) * VOLUME_BAR_LEN );
- mvwprintw(menu_win, y, x - 1 , "[");
- for (int i = 0; i < vol; ++i)
- mvwprintw(menu_win, y, x + i, "=");
- for (int i = vol; i < VOLUME_BAR_LEN; ++i)
- mvwprintw(menu_win, y, x + i, " ");
-
- mvwprintw(menu_win, y, x + VOLUME_BAR_LEN, "]");
-}
-
-int cmp_sink_input_list(const void *a, const void *b) {
- sink_input_info* sinka = *((sink_input_info**) a);
- sink_input_info* sinkb = *((sink_input_info**) b);
-
- if (sinka->sink < sinkb->sink)
- return -1;
- else if (sinka->sink > sinkb->sink)
- return 1;
- else
- return 0;
-}
-
-void get_input(void)
-{
- int c;
- uint32_t sink;
- c = wgetch(menu_win);
- switch (c) {
- case KEY_UP:
- if (chooser > 0)
- --chooser;
- break;
-
- case KEY_DOWN:
- if (chooser < sink_input_counter - 1)
- ++chooser;
- break;
-
- case KEY_LEFT:
- break;
-
- case KEY_RIGHT:
- break;
-
- case 32:
-
- if (sink_input_list[chooser]->sink < sink_max)
- sink = sink_input_list[chooser]->sink + 1;
- else
- sink = 0;
-
- pa_operation_unref(
- pa_context_move_sink_input_by_index(
- context,
- sink_input_list[chooser]->index,
- sink,
- change_callback,
- NULL));
- return;
- break;
-
- default:
- printf("key: %d\n", c);
- quit();
- break;
- }
- sink_input_counter = 0;
- pa_operation_unref(pa_context_get_sink_input_info_list(context, get_sink_input_info_callback, NULL));
-}
-
void quit(void)
{
clrtoeol();
@@ -291,7 +200,7 @@ void quit(void)
exit(0);
}
-static void change_callback(pa_context* c, int success, void* userdate) {
+void change_callback(pa_context* c, int success, void* userdate) {
sink_input_counter = 0;
pa_operation_unref(pa_context_get_sink_input_info_list(context, get_sink_input_info_callback, NULL));
}