#ifndef SPIRCCONTROLLER_H #define SPIRCCONTROLLER_H #include #include #include #include "Utils.h" #include "MercuryManager.h" #include "Session.h" #include "PlayerState.h" #include "SpotifyTrack.h" #include "ConstantParameters.h" #include "Player.h" #include "ConfigJSON.h" #include #include enum class CSpotEventType { PLAY_PAUSE, VOLUME, TRACK_INFO, DISC, NEXT, PREV, SEEK, LOAD, }; struct CSpotEvent { CSpotEventType eventType; std::variant data; }; typedef std::function cspotEventHandler; class SpircController { private: std::shared_ptr manager; std::string username; bool firstFrame = true; std::unique_ptr player; std::unique_ptr state; std::shared_ptr audioSink; std::shared_ptr config; cspotEventHandler eventHandler; void sendCmd(MessageType typ); void notify(); void sendEvent(CSpotEventType eventType, std::variant data = 0); void handleFrame(std::vector &data); void loadTrack(uint32_t position_ms = 0, bool isPaused = 0); public: SpircController(std::shared_ptr manager, std::string username, std::shared_ptr audioSink); void subscribe(); /** * @brief Pauses / Plays current song * * Calling this function will pause or resume playback, setting the * necessary state value and notifying spotify SPIRC. * * @param pause if true pause content, play otherwise */ void setPause(bool pause, bool notifyPlayer = true); /** * @brief Toggle Play/Pause */ void playToggle(); /** * @brief Notifies spotify servers about volume change * * @param volume int between 0 and `MAX_VOLUME` */ void setRemoteVolume(int volume); /** * @brief Set device volume and notifies spotify * * @param volume int between 0 and `MAX_VOLUME` */ void setVolume(int volume); /** * @brief change volume by a given value * * @param volume int between 0 and `MAX_VOLUME` */ void adjustVolume(int by); /** * @brief Goes back to previous track and notfies spotify SPIRC */ void prevSong(); /** * @brief Skips to next track and notfies spotify SPIRC */ void nextSong(); void setEventHandler(cspotEventHandler handler); void stopPlayer(); /** * @brief Disconnect players and notify */ void disconnect(); }; #endif