From 69f1ba2a7b14cffe33f6ba13cce6555ef9be020a Mon Sep 17 00:00:00 2001 From: Bruno Morais Date: Fri, 6 Sep 2019 11:31:48 -0400 Subject: [PATCH] move remaining implementation --- src/plugins/mpris/mpris.cpp | 138 +++++++++++++++++++++++++++++++ src/plugins/mpris/mpris.h | 157 ++++-------------------------------- 2 files changed, 155 insertions(+), 140 deletions(-) diff --git a/src/plugins/mpris/mpris.cpp b/src/plugins/mpris/mpris.cpp index 9cf7ae062..9741d946c 100644 --- a/src/plugins/mpris/mpris.cpp +++ b/src/plugins/mpris/mpris.cpp @@ -186,3 +186,141 @@ struct MPRISMetadataValues MPRISRemote::MPRISGetMetadata() { } return metadata; } + +void MPRISRemote::SetPlaybackService(IPlaybackService* playback) { + std::unique_lock lock(sd_mutex); + this->playback = playback; + mpris_initialized = MPRISInit(); +} + +void MPRISRemote::MPRISNext() { + if (playback) { + playback->Next(); + } +} + +void MPRISRemote::MPRISPrev() { + if (playback) { + playback->Previous(); + } +} + +void MPRISRemote::MPRISPause() { + if (playback) { + auto state = playback->GetPlaybackState(); + if (state == PlaybackState::PlaybackPlaying) { + playback->PauseOrResume(); + } + } +} + +void MPRISRemote::MPRISPlayPause() { + if (playback) { + playback->PauseOrResume(); + } +} + +void MPRISRemote::MPRISStop() { + if (playback) { + playback->Stop(); + } +} + +void MPRISRemote::MPRISPlay() { + if (playback) { + auto state = playback->GetPlaybackState(); + if (state != PlaybackState::PlaybackPlaying) { + playback->PauseOrResume(); + } + } +} + +void MPRISRemote::MPRISSeek(uint64_t position, bool relative) { + double _pos = ((double)position)/(1000*1000); + if (playback) { + } +} + +const char* MPRISRemote::MPRISGetPlaybackStatus() { + if (playback) { + auto state = playback->GetPlaybackState(); + switch (state) { + case PlaybackState::PlaybackPlaying: + return "Playing"; + case PlaybackState::PlaybackPaused: + return "Paused"; + case PlaybackState::PlaybackPrepared: + case PlaybackState::PlaybackStopped: + default: + break; + } + } + return "Stopped"; +} + +const char* MPRISRemote::MPRISGetLoopStatus() { + if (playback) { + auto state = playback->GetRepeatMode(); + switch (state) { + case RepeatMode::RepeatTrack: + return "Track"; + case RepeatMode::RepeatList: + return "Playlist"; + case RepeatMode::RepeatNone: + default: + break; + } + } + return "None"; +} + +void MPRISRemote::MPRISSetLoopStatus(const char* state) { + if (playback) { + if (!strcmp(state, "None")) { + playback->SetRepeatMode(RepeatMode::RepeatNone); + } + else if (!strcmp(state, "Playlist")) { + playback->SetRepeatMode(RepeatMode::RepeatList); + } + else if (!strcmp(state, "Track")) { + playback->SetRepeatMode(RepeatMode::RepeatTrack); + } + } +} + +uint64_t MPRISRemote::MPRISGetPosition() { + if (playback) { + return (uint64_t)(playback->GetPosition()*1000*1000); + } + return 0; +} + +unsigned int MPRISRemote::MPRISGetShuffleStatus() { + if (playback) { + return playback->IsShuffled() ? 1: 0; + } + return 0; +} + +void MPRISRemote::MPRISSetShuffleStatus(unsigned int state) { + if (playback) + { + unsigned int isShuffled = playback->IsShuffled() ? 1: 0; + if ((state & 0x1) ^ isShuffled) { + playback->ToggleShuffle(); + } + } +} + +double MPRISRemote::MPRISGetVolume() { + if (playback) { + return playback->GetVolume(); + } + return 0.0; +} + +void MPRISRemote::MPRISSetVolume(double vol) { + if (playback) { + playback->SetVolume(vol); + } +} diff --git a/src/plugins/mpris/mpris.h b/src/plugins/mpris/mpris.h index 1382c207a..c36fbad4a 100644 --- a/src/plugins/mpris/mpris.h +++ b/src/plugins/mpris/mpris.h @@ -79,12 +79,7 @@ class MPRISRemote : public IPlaybackRemote { virtual void Release() { } - virtual void SetPlaybackService(IPlaybackService* playback) { - std::unique_lock lock(sd_mutex); - this->playback = playback; - mpris_initialized = MPRISInit(); - } - + virtual void SetPlaybackService(IPlaybackService* playback); virtual void OnTrackChanged(ITrack* track); virtual void OnPlaybackStateChanged(PlaybackState state); virtual void OnVolumeChanged(double volume); @@ -92,138 +87,20 @@ class MPRISRemote : public IPlaybackRemote { virtual void OnModeChanged(RepeatMode repeatMode, bool shuffled); virtual void OnPlayQueueChanged() { } - void MPRISNext() { - if (playback) { - playback->Next(); - } - } - - void MPRISPrev() { - if (playback) { - playback->Previous(); - } - } - - void MPRISPause() { - if (playback) { - auto state = playback->GetPlaybackState(); - if (state == PlaybackState::PlaybackPlaying) { - playback->PauseOrResume(); - } - } - } - - void MPRISPlayPause() { - if (playback) { - playback->PauseOrResume(); - } - } - - void MPRISStop() { - if (playback) { - playback->Stop(); - } - } - - void MPRISPlay() { - if (playback) { - auto state = playback->GetPlaybackState(); - if (state != PlaybackState::PlaybackPlaying) { - playback->PauseOrResume(); - } - } - } - - void MPRISSeek(uint64_t position, bool relative=false) { - double _pos = ((double)position)/(1000*1000); - if (playback) { - } - } - - const char* MPRISGetPlaybackStatus() { - if (playback) { - auto state = playback->GetPlaybackState(); - switch (state) { - case PlaybackState::PlaybackPlaying: - return "Playing"; - case PlaybackState::PlaybackPaused: - return "Paused"; - case PlaybackState::PlaybackPrepared: - case PlaybackState::PlaybackStopped: - default: - break; - } - } - return "Stopped"; - } - - const char* MPRISGetLoopStatus() { - if (playback) { - auto state = playback->GetRepeatMode(); - switch (state) { - case RepeatMode::RepeatTrack: - return "Track"; - case RepeatMode::RepeatList: - return "Playlist"; - case RepeatMode::RepeatNone: - default: - break; - } - } - return "None"; - } - - void MPRISSetLoopStatus(const char* state) { - if (playback) { - if (!strcmp(state, "None")) { - playback->SetRepeatMode(RepeatMode::RepeatNone); - } - else if (!strcmp(state, "Playlist")) { - playback->SetRepeatMode(RepeatMode::RepeatList); - } - else if (!strcmp(state, "Track")) { - playback->SetRepeatMode(RepeatMode::RepeatTrack); - } - } - } - - uint64_t MPRISGetPosition() { - if (playback) { - return (uint64_t)(playback->GetPosition()*1000*1000); - } - return 0; - } - - unsigned int MPRISGetShuffleStatus() { - if (playback) { - return playback->IsShuffled() ? 1: 0; - } - return 0; - } - - void MPRISSetShuffleStatus(unsigned int state) { - if (playback) - { - unsigned int isShuffled = playback->IsShuffled() ? 1: 0; - if ((state & 0x1) ^ isShuffled) { - playback->ToggleShuffle(); - } - } - } - - double MPRISGetVolume() { - if (playback) { - return playback->GetVolume(); - } - return 0.0; - } - - void MPRISSetVolume(double vol) { - if (playback) { - playback->SetVolume(vol); - } - } - - struct MPRISMetadataValues MPRISGetMetadata(); - + void MPRISNext(); + void MPRISPrev(); + void MPRISPause(); + void MPRISPlayPause(); + void MPRISStop(); + void MPRISPlay(); + void MPRISSeek(uint64_t position, bool relative=false); + const char* MPRISGetPlaybackStatus(); + const char* MPRISGetLoopStatus(); + void MPRISSetLoopStatus(const char* state); + uint64_t MPRISGetPosition(); + unsigned int MPRISGetShuffleStatus(); + void MPRISSetShuffleStatus(unsigned int state); + double MPRISGetVolume(); + void MPRISSetVolume(double vol); + struct MPRISMetadataValues MPRISGetMetadata(); };