summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Klemkow <web2p10@wemelug.de>2010-07-08 22:29:00 +0200
committerJan Klemkow <web2p10@wemelug.de>2010-07-08 22:29:00 +0200
commit1d09ceecefe1a9a18addf2f9a42294075bc190c2 (patch)
tree6e7c6da7baf10a30562371dcc4faa34cf9c62895
parent4ed3f983f9609ee6b1b3ce20053b31e62ddb2a1f (diff)
downloadpa-sink-ctl-1d09ceecefe1a9a18addf2f9a42294075bc190c2.tar.gz
pa-sink-ctl-1d09ceecefe1a9a18addf2f9a42294075bc190c2.tar.bz2
pa-sink-ctl-1d09ceecefe1a9a18addf2f9a42294075bc190c2.zip
splitting project into seperat files
-rw-r--r--interface.c147
-rw-r--r--interface.h16
-rw-r--r--pa-sink-ctl.h25
-rw-r--r--sink.c35
-rw-r--r--sink.h27
-rw-r--r--sink_input.c54
-rw-r--r--sink_input.h23
7 files changed, 327 insertions, 0 deletions
diff --git a/interface.c b/interface.c
new file mode 100644
index 0000000..c48b953
--- /dev/null
+++ b/interface.c
@@ -0,0 +1,147 @@
+#include <stdio.h>
+#include <pulse/pulseaudio.h>
+#include <ncurses.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "interface.h"
+#include "sink.h"
+#include "pa-sink-ctl.h"
+
+#define VOLUME_MAX UINT16_MAX
+#define VOLUME_BAR_LEN 50
+#define WIDTH 80
+#define HEIGHT 10
+
+// ncurses
+WINDOW *menu_win;
+int chooser;
+int startx;
+int starty;
+
+extern int sink_counter;
+extern int sink_max;
+extern sink_info** sink_list;
+
+extern pa_context* context;
+
+void interface_init(void)
+{
+ // ncurses
+ chooser = 0;
+
+ initscr();
+ clear();
+ noecho();
+ cbreak(); /* Line buffering disabled. pass on everything */
+ startx = (80 - WIDTH) / 2;
+ starty = (24 - HEIGHT) / 2;
+ menu_win = newwin(HEIGHT, WIDTH, starty, startx);
+ keypad(menu_win, TRUE);
+ mvprintw(0, 0, "Use arrow keys to go up and down, Press enter to select a choice");
+ refresh();
+}
+
+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_counter; ++i) {
+ mvwprintw(menu_win, y+i, x, "%d\t%s\t",
+ sink_list[i]->index,
+ sink_list[i]->name);
+ }
+ y += i;
+/* 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, "]");
+}
+
+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;
+ }
+
+ 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));
+}
+
+void interface_clear(void)
+{
+ clrtoeol();
+ refresh();
+ endwin();
+ exit(0);
+}
diff --git a/interface.h b/interface.h
new file mode 100644
index 0000000..5979210
--- /dev/null
+++ b/interface.h
@@ -0,0 +1,16 @@
+#ifndef INTERFACE_H
+#define INTERFACE_H
+
+#include <ncurses.h>
+
+#define VOLUME_MAX UINT16_MAX
+#define VOLUME_BAR_LEN 50
+#define WIDTH 80
+#define HEIGHT 10
+
+void print_sinks(void);
+void print_volume(pa_volume_t, int);
+void get_input(void);
+void interface_clear(void);
+
+#endif
diff --git a/pa-sink-ctl.h b/pa-sink-ctl.h
new file mode 100644
index 0000000..eb14ad2
--- /dev/null
+++ b/pa-sink-ctl.h
@@ -0,0 +1,25 @@
+#ifndef PA_SINK_CTL_H
+#define PA_SINK_CTL_H
+
+#include <stdio.h>
+#include <pulse/pulseaudio.h>
+#include <ncurses.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "sink_input.h"
+#include "sink.h"
+#include "interface.h"
+
+#define VOLUME_MAX UINT16_MAX
+#define VOLUME_BAR_LEN 50
+#define WIDTH 80
+#define HEIGHT 10
+
+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 quit(void);
+
+#endif
diff --git a/sink.c b/sink.c
new file mode 100644
index 0000000..b237d32
--- /dev/null
+++ b/sink.c
@@ -0,0 +1,35 @@
+#include <stdio.h>
+#include <pulse/pulseaudio.h>
+#include <ncurses.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "sink_input.h"
+#include "sink.h"
+
+sink_info* sink_init(void) {
+
+ sink_info* sink = (sink_info*) calloc(1, sizeof(sink_info));
+
+ sink->name = NULL;
+ sink->input_counter = 0;
+ sink->input_max = 1;
+ sink->input_list = NULL;
+
+ sink_input_list_init(sink->input_list, sink->input_max);
+
+ return sink;
+}
+
+/*
+ * free's sink
+ */
+void sink_clear(sink_info* sink) {
+
+ if (sink->name != NULL)
+ free(sink->name);
+
+ sink_input_list_clear(sink->input_list, &sink->input_max);
+
+ free(sink);
+}
diff --git a/sink.h b/sink.h
new file mode 100644
index 0000000..abdb731
--- /dev/null
+++ b/sink.h
@@ -0,0 +1,27 @@
+#ifndef SINK_H
+#define SINK_H
+
+#include <stdio.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;
+ int mute;
+ pa_volume_t vol;
+
+ // input list
+ int input_counter;
+ int input_max;
+ sink_input_info** input_list;
+} sink_info;
+
+sink_info* sink_init(void);
+void sink_clear(sink_info*);
+
+#endif
diff --git a/sink_input.c b/sink_input.c
new file mode 100644
index 0000000..1a6eda2
--- /dev/null
+++ b/sink_input.c
@@ -0,0 +1,54 @@
+#include <stdio.h>
+#include <pulse/pulseaudio.h>
+#include <ncurses.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "sink_input.h"
+
+sink_input_info* sink_input_init() {
+
+ sink_input_info* sink_input = (sink_input_info*) calloc(1, sizeof(sink_input_info));
+ sink_input->name = NULL;
+ sink_input->pid = NULL;
+
+ return sink_input;
+}
+
+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);
+
+ free(sink_input);
+}
+
+void sink_input_list_init(sink_input_info** sink_input_list, int max) {
+ sink_input_list = (sink_input_info**) calloc(max, sizeof(sink_input_info*));
+}
+
+void sink_input_list_clear(sink_input_info** sink_input_list, int *max) {
+
+ for (int i = 0; i < (*max); ++i)
+ sink_input_clear(sink_input_list[i]);
+
+ (*max) = 0;
+
+ free(sink_input_list);
+}
+
+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;
+}
+
diff --git a/sink_input.h b/sink_input.h
new file mode 100644
index 0000000..e426cf7
--- /dev/null
+++ b/sink_input.h
@@ -0,0 +1,23 @@
+#ifndef SINK_INPUT_H
+#define SINK_INPUT_H
+
+#include <pulse/pulseaudio.h>
+// TODO: change this with the given define from pulselib
+#define VOLUME_MAX UINT16_MAX
+
+typedef struct _sink_input_info {
+ uint32_t index;
+ uint32_t sink;
+ char *name;
+ char *pid; // maybe useless?!!?
+ pa_volume_t vol; // TOTO: exchange with the channel-list
+} sink_input_info;
+
+sink_input_info* sink_input_init();
+void sink_input_clear(sink_input_info*);
+
+void sink_input_list_init(sink_input_info**, int);
+void sink_input_list_clear(sink_input_info**, int*);
+int cmp_sink_input_list(const void *, const void *);
+
+#endif