aboutsummaryrefslogtreecommitdiff
path: root/pavolctld.c
diff options
context:
space:
mode:
Diffstat (limited to 'pavolctld.c')
-rw-r--r--pavolctld.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/pavolctld.c b/pavolctld.c
index deb5796..2e6d13d 100644
--- a/pavolctld.c
+++ b/pavolctld.c
@@ -3,18 +3,22 @@
#include <string.h>
#include <pulse/pulseaudio.h>
+#define ROUND_POS(x) ((int)((x) + 0.5f))
+
//TODO pa_operation_unref(o);
-static int default_sink_index;
+/* context vars */
+static int default_sink_index; // should always point to default sink
static int command_sink_index; // commands will modify this sink
+/* output callbacks */
static void sink_info_volume_callback(pa_context *c, const pa_sink_info *i, int eol, void *userdata) {
pa_volume_t vol;
if (eol) return;
vol = pa_cvolume_avg(&i->volume);
- printf("v%d,%d,%.02f,%d\n", i->index, vol*100/PA_VOLUME_NORM, pa_sw_volume_to_dB(vol), i->mute);
+ printf("v%d,%d,%.02f,%d\n", i->index, ROUND_POS(vol*100.0f/PA_VOLUME_NORM), pa_sw_volume_to_dB(vol), i->mute);
fflush(stdout);
}
@@ -35,6 +39,7 @@ static void server_info_default_sink_callback(pa_context *c, const pa_server_inf
fflush(stdout);
}
+/* subscription callback is called whenever a listened-to event occurs */
static void subscription_callback(pa_context *c, pa_subscription_event_type_t t, uint32_t idx, void *userdata) {
switch (t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) {
case PA_SUBSCRIPTION_EVENT_SINK:
@@ -58,6 +63,7 @@ static void subscription_callback(pa_context *c, pa_subscription_event_type_t t,
}
}
+/* context state will really only change at startup or exit etc. */
static void context_state_callback(pa_context *c, void *userdata) {
if (pa_context_get_state(c) == PA_CONTEXT_READY) {
pa_context_set_subscribe_callback(c, subscription_callback, userdata);
@@ -79,7 +85,7 @@ static void context_state_callback(pa_context *c, void *userdata) {
}
}
-/* commands */
+/* stdin 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;
@@ -101,13 +107,14 @@ static void sink_info_set_volume_callback(pa_context *c, const pa_sink_info *i,
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));
+ vol = pa_cvolume_set(vol, i->volume.channels, (pa_volume_t)(input_vol * PA_VOLUME_NORM));
break;
}
pa_context_set_sink_volume_by_index(c, i->index, vol, NULL, NULL);
}
+/* handle stdin commands */
static void handle_command(pa_context *c, char *cmd) {
// send the command to each callback using userdata
switch (cmd[0]) {
@@ -117,6 +124,7 @@ static void handle_command(pa_context *c, char *cmd) {
}
}
+/* main */
int main() {
pa_threaded_mainloop *mainloop = pa_threaded_mainloop_new();
pa_mainloop_api *mainloop_api = pa_threaded_mainloop_get_api(mainloop);
@@ -131,11 +139,8 @@ int main() {
pa_threaded_mainloop_start(mainloop);
while(1) {
- if (fgets(stdin_buffer, sizeof(stdin_buffer), stdin) != NULL) {
+ if (fgets(stdin_buffer, sizeof(stdin_buffer), stdin) != NULL)
handle_command(context, stdin_buffer);
- //printf("You entered: %s", stdin_buffer);
- //fflush(stdout);
- }
}
// clean up