diff options
author | Adam Simpkins <adam@adamsimpkins.net> | 2013-01-09 11:52:01 -0800 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2013-02-26 15:19:26 +0100 |
commit | 847ca4193e3fbc5b27285979888ab364bbf1792e (patch) | |
tree | 9bfce2cffe69ddaf74465d6445f589a4de68f42d /src/ui_act.c | |
parent | efd4f393f0378865902c2138e614e9a5466c40ef (diff) | |
download | pianobar-847ca4193e3fbc5b27285979888ab364bbf1792e.tar.gz pianobar-847ca4193e3fbc5b27285979888ab364bbf1792e.tar.bz2 pianobar-847ca4193e3fbc5b27285979888ab364bbf1792e.zip |
Add play and pause commands
Add commands that always play and always pause, in addition to the
current toggle pause command.
Closes #342.
Diffstat (limited to 'src/ui_act.c')
-rw-r--r-- | src/ui_act.c | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/src/ui_act.c b/src/ui_act.c index 70fbc9a..8d9ac09 100644 --- a/src/ui_act.c +++ b/src/ui_act.c @@ -1,5 +1,5 @@ /* -Copyright (c) 2008-2012 +Copyright (c) 2008-2013 Lars-Dominik Braun <lars@6xq.net> Permission is hereby granted, free of charge, to any person obtaining a copy @@ -49,9 +49,9 @@ THE SOFTWARE. static inline void BarUiDoSkipSong (struct audioPlayer *player) { assert (player != NULL); - player->doQuit = 1; - /* unlocking an unlocked mutex is forbidden by some implementations */ - pthread_mutex_trylock (&player->pauseMutex); + pthread_mutex_lock (&player->pauseMutex); + player->doQuit = true; + pthread_cond_broadcast (&player->pauseCond); pthread_mutex_unlock (&player->pauseMutex); } @@ -335,13 +335,31 @@ BarUiActCallback(BarUiActSkipSong) { BarUiDoSkipSong (&app->player); } +/* play + */ +BarUiActCallback(BarUiActPlay) { + pthread_mutex_lock (&app->player.pauseMutex); + app->player.doPause = false; + pthread_cond_broadcast (&app->player.pauseCond); + pthread_mutex_unlock (&app->player.pauseMutex); +} + /* pause */ BarUiActCallback(BarUiActPause) { - /* already locked => unlock/unpause */ - if (pthread_mutex_trylock (&app->player.pauseMutex) == EBUSY) { - pthread_mutex_unlock (&app->player.pauseMutex); - } + pthread_mutex_lock (&app->player.pauseMutex); + app->player.doPause = true; + pthread_cond_broadcast (&app->player.pauseCond); + pthread_mutex_unlock (&app->player.pauseMutex); +} + +/* toggle pause + */ +BarUiActCallback(BarUiActTogglePause) { + pthread_mutex_lock (&app->player.pauseMutex); + app->player.doPause = !app->player.doPause; + pthread_cond_broadcast (&app->player.pauseCond); + pthread_mutex_unlock (&app->player.pauseMutex); } /* rename current station @@ -483,7 +501,7 @@ BarUiActCallback(BarUiActSelectQuickMix) { /* quit */ BarUiActCallback(BarUiActQuit) { - app->doQuit = 1; + app->doQuit = true; BarUiDoSkipSong (&app->player); } |