Skip to content

Commit

Permalink
Implement pause_on_output_change option (closes cmus#1139)
Browse files Browse the repository at this point in the history
  • Loading branch information
pgaskin authored and flyingmutant committed Dec 24, 2021
1 parent 5ecc3ad commit 0f0db50
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Doc/cmus.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,11 @@ mpris (true)
output_plugin [roar, pulse, alsa, arts, oss, sndio, sun, coreaudio]
Name of output plugin.

pause_on_output_change (false)
Pauses playback when the audio output changes.

Supported output plugins: none.

pl_sort () [`Sort Keys`]
Sort keys for the playlist view (3). Empty value disables sorting and
enables manually moving tracks.
Expand Down
4 changes: 3 additions & 1 deletion mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@

enum {
/* volume changes */
MIXER_FDS_VOLUME
MIXER_FDS_VOLUME,
/* output changes */
MIXER_FDS_OUTPUT
};

struct mixer_plugin_ops {
Expand Down
17 changes: 17 additions & 0 deletions options.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ int start_view = TREE_VIEW;
int stop_after_queue = 0;
int tree_width_percent = 33;
int tree_width_max = 0;
int pause_on_output_change = 0;

int colors[NR_COLORS] = {
-1,
Expand Down Expand Up @@ -1215,6 +1216,21 @@ static void toggle_stop_after_queue(void *data)
stop_after_queue ^= 1;
}

static void get_pause_on_output_change(void *data, char *buf, size_t size)
{
strscpy(buf, bool_names[pause_on_output_change], size);
}

static void set_pause_on_output_change(void *data, const char *buf)
{
parse_bool(buf, &pause_on_output_change);
}

static void toggle_pause_on_output_change(void *data)
{
pause_on_output_change ^= 1;
}

/* }}} */

/* special callbacks (id set) {{{ */
Expand Down Expand Up @@ -1465,6 +1481,7 @@ static const struct {
DT(stop_after_queue)
DN(tree_width_percent)
DN(tree_width_max)
DT(pause_on_output_change)
{ NULL, NULL, NULL, NULL, 0 }
};

Expand Down
1 change: 1 addition & 0 deletions options.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ extern int start_view;
extern int stop_after_queue;
extern int tree_width_percent;
extern int tree_width_max;
extern int pause_on_output_change;

extern const char * const aaa_mode_names[];
extern const char * const view_names[NR_VIEWS + 1];
Expand Down
17 changes: 17 additions & 0 deletions ui_curses.c
Original file line number Diff line number Diff line change
Expand Up @@ -2140,6 +2140,7 @@ static void main_loop(void)
int poll_mixer = 0;
int i;
int nr_fds_vol = 0, fds_vol[NR_MIXER_FDS];
int nr_fds_out = 0, fds_out[NR_MIXER_FDS];
struct list_head *item;
struct client *client;

Expand Down Expand Up @@ -2186,6 +2187,12 @@ static void main_loop(void)
}
}

nr_fds_out = mixer_get_fds(MIXER_FDS_OUTPUT, fds_out);
for (i = 0; i < nr_fds_out; i++) {
BUG_ON(fds_out[i] <= 0);
SELECT_ADD_FD(fds_out[i]);
}

rc = select(fd_high + 1, &set, NULL, NULL, tv.tv_usec ? &tv : NULL);
if (poll_mixer) {
int ol = volume_l;
Expand Down Expand Up @@ -2215,6 +2222,16 @@ static void main_loop(void)
update_statusline();
}
}
for (i = 0; i < nr_fds_out; i++) {
if (FD_ISSET(fds_out[i], &set)) {
d_print("out changed\n");
if (pause_on_output_change) {
player_pause_playback();
update_statusline();
}
clear_pipe(fds_out[i], -1);
}
}
if (FD_ISSET(server_socket, &set))
server_accept();

Expand Down

0 comments on commit 0f0db50

Please sign in to comment.