~schnouki/pustule

52679e6938e9dc3e1bd928240bcfdb975de951aa — Thomas Jost 4 years ago 02e9243
More preparation for other events
4 files changed, 19 insertions(+), 19 deletions(-)

M guile.c
M pulse.c
M pustule.h
M pustule.scm
M guile.c => guile.c +4 -4
@@ 35,9 35,9 @@ struct pustule_exported_func {
    scm_t_subr func;
    const char* doc;
} exported_funcs[] = {
    {"pustule-get-volume", 1, 0, 0, &pustule_get_volume,
    {"pustule-get-input-volume", 1, 0, 0, &pustule_get_input_volume,
     "Gets the volume of the input whose index is INPUT-IDX (an integer)."},
    {"pustule-set-volume", 2, 0, 0, &pustule_set_volume,
    {"pustule-set-input-volume", 2, 0, 0, &pustule_set_input_volume,
     "Sets the volume of the input whose index is INPUT-IDX (an integer) to\n"
     "VOLUME (a number between 0 and 1)."},
    {NULL, 0, 0, 0, NULL}


@@ 48,7 48,7 @@ SCM input_added_hook = NULL;
SCM input_removed_hook = NULL;

/* Get the volume for the specified input */
SCM pustule_get_volume(SCM idx) {
SCM pustule_get_input_volume(SCM idx) {
    pustule_volume_t vol = {0, PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER};

    /* Query the volume with PulseAudio */


@@ 65,7 65,7 @@ SCM pustule_get_volume(SCM idx) {
}

/* Set volume for the specified input */
SCM pustule_set_volume(SCM idx, SCM volume) {
SCM pustule_set_input_volume(SCM idx, SCM volume) {
    uint32_t idx_ = scm_to_uint32(idx);
    double volume_ = scm_to_double(volume);


M pulse.c => pulse.c +2 -2
@@ 45,7 45,7 @@ void state_callback(pa_context* ctx, void* userdata) {
}

/* Event handler -- dispatch Scheme events */
void input_event_callback(pa_context* ctx, pa_subscription_event_type_t t, uint32_t idx, void* userdata) {
void event_callback(pa_context* ctx, pa_subscription_event_type_t t, uint32_t idx, void* userdata) {
    if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_NEW) {
        // Input added: query info about it
        pa_context_get_sink_input_info(ctx, idx, input_info_callback, NULL);


@@ 61,7 61,7 @@ void input_event_callback(pa_context* ctx, pa_subscription_event_type_t t, uint3
    }
}

/* New input available (or infos about an existing input): defer a call the added callback */
/* New input available (or infos about an existing input): defer a call to the "input added" callback */
void input_info_callback(pa_context* ctx, const pa_sink_input_info* i, int eol, void* userdata) {
    if (!i) return;


M pustule.h => pustule.h +3 -3
@@ 54,7 54,7 @@ typedef struct {
} pustule_volume_t;

/* PulseAudio callbacks */
void input_event_callback(pa_context* ctx, pa_subscription_event_type_t t, uint32_t idx, void* userdata);
void event_callback(pa_context* ctx, pa_subscription_event_type_t t, uint32_t idx, void* userdata);
void input_info_callback(pa_context* ctx, const pa_sink_input_info* i, int eol, void* userdata);
void state_callback(pa_context* ctx, void* userdata);



@@ 62,8 62,8 @@ void state_callback(pa_context* ctx, void* userdata);
void input_get_info(uint32_t idx, pustule_volume_t* vol);

/* Guile functions */
SCM pustule_get_volume(SCM idx);
SCM pustule_set_volume(SCM idx, SCM volume);
SCM pustule_get_input_volume(SCM idx);
SCM pustule_set_input_volume(SCM idx, SCM volume);

/* Guile helpers */
void pustule_init_guile();

M pustule.scm => pustule.scm +10 -10
@@ 27,7 27,7 @@
;; removed from the PulseAudio daemon.
;;
;; The volume of each input (a number between 0 and 1) can be set using the
;; `pustule-set-volume' function.
;; `pustule-set-input-volume' function.
;;
;; In the default script, there are a few helpers that provide sane defaults for
;; writing rich rules. For instance everything is logged, including all the


@@ 47,9 47,9 @@
;; Association list of all the active inputs
(define active-inputs '())

(define (set-volume idx vol)
(define (set-input-volume idx vol)
  (format #t "[~d] Setting volume to ~,2f.\n" idx vol)
  (pustule-set-volume idx vol)
  (pustule-set-input-volume idx vol)
  (set! active-inputs (assoc-set! active-inputs idx #t)))

(define (volume-set? idx)


@@ 74,7 74,7 @@
             (or (prop= input "application.process.binary" "firefox")
                 (prop= input "application.process.binary" "chromium")
                 (prop= input "application.process.binary" "plugin-container")))
    (set-volume idx 0.8)))
    (set-input-volume idx 0.8)))
(add-hook! pustule-input-added-hook added/browser)

(define (added/gajim idx input)


@@ 85,11 85,11 @@
           (event (basename fn ".wav")))
      (cond
       ((member event '("connected" "disconnected"))
        (set-volume idx 0.5))
        (set-input-volume idx 0.5))
       ((string= event "sent")
        (set-volume idx 0.75))
        (set-input-volume idx 0.75))
       ((string= event "message2")
        (set-volume idx 1))))))
        (set-input-volume idx 1))))))
(add-hook! pustule-input-added-hook added/gajim)
;; }}}



@@ 113,8 113,8 @@

    ;; Set volume depending on the role
    (cond
     ((prop= input "media.role" "music") (set-volume idx 0.5))
     ((prop= input "media.role" "video") (set-volume idx 0.8)))))
     ((prop= input "media.role" "music") (set-input-volume idx 0.5))
     ((prop= input "media.role" "video") (set-input-volume idx 0.8)))))
(add-hook! pustule-input-added-hook added/media-role #t)

(define (removed/media-roles idx)


@@ 140,6 140,6 @@
  "Set a default value for the volume if it wasn't set by the previous hooks."
  (when (not (volume-set? idx))
    (show-input idx input)
    (set-volume idx 0.6)))
    (set-input-volume idx 0.6)))
(add-hook! pustule-input-added-hook added/default-volume #t)
;; }}}