aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--pavolctld.c (renamed from pavolctrld.c)49
-rw-r--r--todo19
3 files changed, 67 insertions, 5 deletions
diff --git a/Makefile b/Makefile
index c99c777..6f50833 100644
--- a/Makefile
+++ b/Makefile
@@ -4,8 +4,8 @@ CC = gcc
CFLAGS = -Wall
LDFLAGS = -lpulse
-TARGET = pavolctrld
-SOURCES = pavolctrld.c
+TARGET = pavolctld
+SOURCES = pavolctld.c
all: $(TARGET)
diff --git a/pavolctrld.c b/pavolctld.c
index dc56292..deb5796 100644
--- a/pavolctrld.c
+++ b/pavolctld.c
@@ -6,6 +6,7 @@
//TODO pa_operation_unref(o);
static int default_sink_index;
+static int command_sink_index; // commands will modify this sink
static void sink_info_volume_callback(pa_context *c, const pa_sink_info *i, int eol, void *userdata) {
@@ -64,6 +65,9 @@ static void context_state_callback(pa_context *c, void *userdata) {
// output initial default sink
pa_context_get_server_info(c, server_info_default_sink_callback, userdata);
+ // set command sink equal to the default sink on startup
+ command_sink_index = default_sink_index;
+
// output initial sink descriptions for each sink
pa_context_get_sink_info_list(c, sink_info_sink_desc_callback, userdata);
@@ -75,10 +79,48 @@ static void context_state_callback(pa_context *c, void *userdata) {
}
}
+/* commands */
+static void sink_info_set_volume_callback(pa_context *c, const pa_sink_info *i, int eol, void *userdata) {
+ pa_cvolume *vol;
+ double input_vol;
+ char *cmd = (char *)userdata;
+ if (eol) return;
+
+ vol = (pa_cvolume *)&i->volume; // disregard const qualifier, avoid warnings :)
+ switch(cmd[1]) {
+ case '\n':
+ pa_context_get_sink_info_by_index(c, i->index, sink_info_volume_callback, userdata);
+ return;
+ case '+':
+ input_vol = atof(&cmd[2])/100;
+ vol = pa_cvolume_inc(vol, (pa_volume_t)(input_vol * PA_VOLUME_NORM));
+ break;
+ case '-':
+ input_vol = atof(&cmd[2])/100;
+ vol = pa_cvolume_dec(vol, (pa_volume_t)(input_vol * PA_VOLUME_NORM));
+ break;
+ default:
+ input_vol = atof(&cmd[1])/100;
+ vol = pa_cvolume_set(vol, i->volume.channels, (pa_volume_t)(input_vol * PA_VOLUME_NORM * -1));
+ break;
+ }
+
+ pa_context_set_sink_volume_by_index(c, i->index, vol, NULL, NULL);
+}
+
+static void handle_command(pa_context *c, char *cmd) {
+ // send the command to each callback using userdata
+ switch (cmd[0]) {
+ case 'v':
+ pa_context_get_sink_info_by_index(c, command_sink_index, sink_info_set_volume_callback, (void *)cmd);
+ break;
+ }
+}
+
int main() {
pa_threaded_mainloop *mainloop = pa_threaded_mainloop_new();
pa_mainloop_api *mainloop_api = pa_threaded_mainloop_get_api(mainloop);
- pa_context *context = pa_context_new(mainloop_api, "pavolctrld");
+ pa_context *context = pa_context_new(mainloop_api, "pavolctld");
char stdin_buffer[256];
pa_context_connect(context, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL);
@@ -90,8 +132,9 @@ int main() {
while(1) {
if (fgets(stdin_buffer, sizeof(stdin_buffer), stdin) != NULL) {
- printf("You entered: %s", stdin_buffer);
- fflush(stdout);
+ handle_command(context, stdin_buffer);
+ //printf("You entered: %s", stdin_buffer);
+ //fflush(stdout);
}
}
diff --git a/todo b/todo
new file mode 100644
index 0000000..148e532
--- /dev/null
+++ b/todo
@@ -0,0 +1,19 @@
+pavolctrld
+
+out # DONE
+v{sink},{vol},{db},{mute} # volume change
+f{idx} # default (fallback) sink change
+s{idx},{name},{desc} # sink add / first connect
+x{idx} # sink remove
+
+in
+s56 # set the editing sink to 56
+v50 # set vol 50%
+v+5 # inc vol 5%
+v-5.2 # dec vol -5.2%
+d-1.2 # dec vol 1.2dB
+m0 # unmute
+m1 # mute
+f # make the current sink the default (fallback) sink
+f35 # make sink 35 the default (fallback) sink
+