summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2011-12-18 13:45:40 +0100
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2011-12-18 13:45:40 +0100
commit6a26c5ba1a12a1993c4bd55edcfb5dad1630e75b (patch)
tree55189d1ec8a4bda8821c5507e43504c553ce4333 /src
parent3212f76818abdfd19dc32ffaeef711ea7fc636e0 (diff)
downloadpa-sink-ctl-6a26c5ba1a12a1993c4bd55edcfb5dad1630e75b.tar.gz
pa-sink-ctl-6a26c5ba1a12a1993c4bd55edcfb5dad1630e75b.tar.bz2
pa-sink-ctl-6a26c5ba1a12a1993c4bd55edcfb5dad1630e75b.zip
Add volume_set to vol_ctl_object
Diffstat (limited to 'src')
-rw-r--r--src/command.c76
-rw-r--r--src/pa-sink-ctl.c2
-rw-r--r--src/sink.h3
3 files changed, 41 insertions, 40 deletions
diff --git a/src/command.c b/src/command.c
index 0a0e636..1e9ddef 100644
--- a/src/command.c
+++ b/src/command.c
@@ -91,43 +91,51 @@ down(struct context *ctx, int key)
interface_redraw(ctx);
}
-static void
-volume_change(struct context *ctx, gboolean volume_increment)
+static struct vol_ctl_object *
+interface_get_current_ctl(struct context *ctx)
{
struct sink_info *sink;
struct sink_input_info *input;
- guint32 index;
+
+ sink = g_list_nth_data(ctx->sink_list, ctx->chooser_sink);
+ if (sink == NULL)
+ return NULL;
+
+ if (ctx->chooser_input == SELECTED_SINK)
+ return &sink->base;
+ else if (ctx->chooser_input >= 0) {
+ input = sink_get_nth_input(ctx, sink, ctx->chooser_input);
+ if (input == NULL)
+ return NULL;
+ return &input->base;
+ }
+
+ g_assert(0);
+ return NULL;
+}
+
+static void
+volume_change(struct context *ctx, gboolean volume_increment)
+{
+ struct vol_ctl_object *ctl;
+ pa_operation *o;
pa_cvolume volume;
- pa_volume_t tmp_vol, inc;
- pa_operation* (*volume_set) (pa_context*, guint32, const pa_cvolume *,
- pa_context_success_cb_t, gpointer);
+ pa_volume_t inc;
if (!ctx->context_ready)
return;
- sink = g_list_nth_data(ctx->sink_list, ctx->chooser_sink);
- if (ctx->chooser_input >= 0) {
- input = sink_get_nth_input(ctx, sink, ctx->chooser_input);
- index = input->base.index;
- volume = (pa_cvolume) { .channels = input->base.channels };
- tmp_vol = input->base.vol;
- volume_set = pa_context_set_sink_input_volume;
- } else if (ctx->chooser_input == SELECTED_SINK) {
- index = sink->base.index;
- volume = (pa_cvolume) { .channels = sink->base.channels };
- tmp_vol = sink->base.vol;
- volume_set = pa_context_set_sink_volume_by_index;
- } else {
- g_assert(0);
+ ctl = interface_get_current_ctl(ctx);
+ if (!ctl)
return;
- }
- pa_cvolume_set(&volume, volume.channels, tmp_vol);
+ volume = (pa_cvolume) { .channels = ctl->channels };
+ pa_cvolume_set(&volume, volume.channels, ctl->vol);
inc = 2 * PA_VOLUME_NORM / 100;
if (volume_increment)
- if (PA_VOLUME_NORM > tmp_vol &&
- PA_VOLUME_NORM - tmp_vol > inc)
+ if (PA_VOLUME_NORM > ctl->vol &&
+ PA_VOLUME_NORM - ctl->vol > inc)
pa_cvolume_inc(&volume, inc);
else
pa_cvolume_set(&volume, volume.channels,
@@ -136,7 +144,8 @@ volume_change(struct context *ctx, gboolean volume_increment)
pa_cvolume_dec(&volume, inc);
- pa_operation_unref(volume_set(ctx->context, index, &volume, NULL,NULL));
+ o = ctl->volume_set(ctx->context, ctl->index, &volume, NULL,NULL);
+ pa_operation_unref(o);
}
static void
@@ -151,21 +160,6 @@ volume_up(struct context *ctx, int key)
volume_change(ctx, TRUE);
}
-static struct vol_ctl_object *
-interface_get_current_ctl(struct context *ctx)
-{
- struct sink_info *sink;
- struct sink_input_info *input;
-
- sink = g_list_nth_data(ctx->sink_list, ctx->chooser_sink);
- if (ctx->chooser_input == SELECTED_SINK)
- return &sink->base;
-
- input = sink_get_nth_input(ctx, sink, ctx->chooser_input);
-
- return &input->base;
-}
-
static void
do_mute(struct context *ctx, int key)
{
@@ -176,6 +170,8 @@ do_mute(struct context *ctx, int key)
return;
ctl = interface_get_current_ctl(ctx);
+ if (!ctl)
+ return;
o = ctl->mute_set(ctx->context, ctl->index, !ctl->mute, NULL, NULL);
pa_operation_unref(o);
diff --git a/src/pa-sink-ctl.c b/src/pa-sink-ctl.c
index 784ee8e..adea0ee 100644
--- a/src/pa-sink-ctl.c
+++ b/src/pa-sink-ctl.c
@@ -100,6 +100,7 @@ sink_info_cb(pa_context *c, const pa_sink_info *i,
return;
sink->base.index = i->index;
sink->base.mute_set = pa_context_set_sink_mute_by_index;
+ sink->base.volume_set = pa_context_set_sink_volume_by_index;
sink->priority = get_sink_priority(ctx, i);
ctx->sink_list = g_list_insert_sorted(ctx->sink_list, sink,
@@ -146,6 +147,7 @@ sink_input_info_cb(pa_context *c, const pa_sink_input_info *i,
return;
sink_input->base.index = i->index;
sink_input->base.mute_set = pa_context_set_sink_input_mute;
+ sink_input->base.volume_set = pa_context_set_sink_input_volume;
ctx->input_list = g_list_append(ctx->input_list, sink_input);
} else {
sink_input = el->data;
diff --git a/src/sink.h b/src/sink.h
index 60e47f0..7141a26 100644
--- a/src/sink.h
+++ b/src/sink.h
@@ -35,6 +35,9 @@ struct vol_ctl_object {
pa_operation *(*mute_set)(pa_context *, guint32, int,
pa_context_success_cb_t, void *);
+
+ pa_operation *(*volume_set)(pa_context *, guint32, const pa_cvolume *,
+ pa_context_success_cb_t, gpointer);
};
struct sink_info {