pianod2
multisource multiuser scriptable networked music player
pandorastation.h
Go to the documentation of this file.
1 
9 #pragma once
10 
11 #include <config.h>
12 
13 #include <string>
14 #include <unordered_map>
15 #include <list>
16 
17 #include <parsnip/parsnip.h>
18 
19 #include "fundamentals.h"
20 #include "musictypes.h"
21 #include "mediaparameters.h"
22 #include "encapmusic.h"
23 #include "retainer.h"
24 #include "retainedlist.h"
25 
26 namespace Pandora {
27  class Source;
28 
29  extern const int StationListCacheTime;
30  extern const int StationDetailCacheTime;
31 
33  class SkipTracker : private std::list<time_t> {
34  size_t skip_limit;
35  time_t interval;
36 
38  inline void purge() {
39  while (!empty() && front() < time (nullptr)) {
40  pop_front();
41  }
42  }
43 
44  public:
45  SkipTracker (int limit, int interv);
46  bool canSkip (time_t *when);
47  bool skip (time_t *when = nullptr);
48  inline void setLimit (int limit) {
49  skip_limit = limit;
50  }
51  };
52 
53  // Helper class for storing/tracking seeds and ratings.
54  template <typename InfoType>
57  friend class Station;
60  mutable std::unordered_map<std::string, Retainer<InfoType *>> cache;
61 
62  InfoType *find (const MusicThingie *primary) const;
63 
64  private:
66  inline const ListType &list() const {
67  return info_list;
68  }
69  void operator= (ListType &&list);
70  bool isSeedPresent (const MusicThingie *seed) const;
71  public:
72  void storeDetail (const MusicThingie *primary, InfoType *rating);
73  InfoType *getDetail (const MusicThingie *primary) const;
74  void erase (InfoType *item);
75  };
76 
77  class Station : public EncapsulatedPlaylist {
79 
80  std::string station_token;
81  bool is_shared{ false };
82  bool may_rename{ false };
83  bool in_quick_mix{ false };
84 
85  time_t details_expiration = 0;
86 
87  public:
88  Station (Source *const owner, const Parsnip::Data &message);
89  Station &operator= (const Station &update);
90 
91  void forceRefreshDetails();
92  bool seedAppliesToStation (const MusicThingie *seed) const;
94  void takePossession();
95 
96  SkipTracker skips{ 6, 3600 };
101 
102  public:
103  inline Source *const pandora() const {
104  return reinterpret_cast<Source *const> (source());
105  }
106 
107  // API implementation
108  virtual bool includedInMix (void) const override final;
109  virtual void includedInMix (bool include) override final;
110  virtual bool canSeed (MusicThingie::Type seedType) const override;
111  virtual bool seed (MusicThingie::Type seedType, const MusicThingie *music) const override;
112  virtual void seed (MusicThingie::Type seedType, MusicThingie *music, bool value) override;
113  virtual ThingieList getSeeds (void) const override;
114  virtual void rename (const std::string &newname) override;
115  virtual void erase() override;
116 
117  inline const std::string &getToken() const {
118  return station_token;
119  }
120  };
121 
123  class QuickMixStation : public Station {
124  public:
125  QuickMixStation (Source *const src, const Parsnip::Data &message) : Station (src, message) {
127  }
128  };
129 
131  class MixEverythingStation : public Station {
132  public:
133  MixEverythingStation (Source *const src, const Parsnip::Data &message) : Station (src, message) {
135  playlistName ("Everything");
136  }
137  };
138 
140 
143  class StationLookup : public std::unordered_map<std::string, Retainer<Station *>> {};
144 
145 } // namespace Pandora
A PianodPlaylist that is self-contained.
Definition: encapmusic.h:201
virtual PlaylistType playlistType(void) const override
Mix, everything, transient or single list.
Definition: encapmusic.h:216
virtual const std::string & playlistName(void) const override
Name of the playlist.
Definition: encapmusic.h:218
virtual Media::Source *const source(void) const override
MediaSource from which this thingie originates.
Definition: encapmusic.h:214
Base class for songs, albums, artists, playlists, genres, etc.
Definition: musictypes.h:77
Type
Definition: musictypes.h:86
Class representing a mix of all of a user's Pandora stations.
Definition: pandorastation.h:131
MixEverythingStation(Source *const src, const Parsnip::Data &message)
Definition: pandorastation.h:133
Class representing the Pandora quick mix station.
Definition: pandorastation.h:123
QuickMixStation(Source *const src, const Parsnip::Data &message)
Definition: pandorastation.h:125
Pandora message: transform a shared station into a personal station.
Definition: pandoramessages.h:165
A class to manage Pandora skips.
Definition: pandorastation.h:33
void setLimit(int limit)
Definition: pandorastation.h:48
bool skip(time_t *when=nullptr)
Check if a skip is available, and record one if it is.
Definition: pandorastation.cpp:57
SkipTracker(int limit, int interv)
Construct a skip tracker.
Definition: pandorastation.cpp:36
bool canSkip(time_t *when)
Check if (and when) a skip is available.
Definition: pandorastation.cpp:42
size_t skip_limit
The limit on the number of skips.
Definition: pandorastation.h:34
time_t interval
The duration over which the limit applies.
Definition: pandorastation.h:35
void purge()
Remove expired skips from the front of the list.
Definition: pandorastation.h:38
Definition: pandora.h:44
Definition: pandorastation.h:55
bool isSeedPresent(const MusicThingie *seed) const
See if details originated from this list.
Definition: pandoraseeds.cpp:58
MusicThingie::Type type
The primary type stored herein.
Definition: pandorastation.h:59
const ListType & list() const
Definition: pandorastation.h:66
StationDefinitionDetails(MusicThingie::Type ty)
Definition: pandorastation.h:65
ListType info_list
The authoritative list of details.
Definition: pandorastation.h:58
RetainedList< InfoType * > ListType
Definition: pandorastation.h:56
void operator=(ListType &&list)
Replace the details stored and clear cache.
Definition: pandoraseeds.cpp:67
void storeDetail(const MusicThingie *primary, InfoType *rating)
Add a single new detail item.
Definition: pandoraseeds.cpp:76
InfoType * getDetail(const MusicThingie *primary) const
Retrieve details for an item.
Definition: pandoraseeds.cpp:88
std::unordered_map< std::string, Retainer< InfoType * > > cache
Faster access to info.
Definition: pandorastation.h:60
void erase(InfoType *item)
Remove a detail record from the list and cache.
Definition: pandoraseeds.cpp:103
InfoType * find(const MusicThingie *primary) const
Search the authoritative list for a matching item.
Definition: pandoraseeds.cpp:34
Definition: pandorastation.h:77
void forceRefreshDetails()
Definition: pandoraseeds.cpp:287
bool in_quick_mix
The station is participating in the quickmix/shuffle.
Definition: pandorastation.h:83
void takePossession()
Convert a shared Pandora station into a private one.
Definition: pandorastation.cpp:106
Source *const pandora() const
Definition: pandorastation.h:103
virtual bool includedInMix(void) const override final
Definition: pandorastation.cpp:142
std::string station_token
Definition: pandorastation.h:80
virtual bool seed(MusicThingie::Type seedType, const MusicThingie *music) const override
Check if there is a seed of a particular type for this thingie.
Definition: pandoraseeds.cpp:152
SkipTracker skips
Definition: pandorastation.h:96
Station(Source *const owner, const Parsnip::Data &message)
Definition: pandorastation.cpp:70
virtual void erase() override
Definition: pandorastation.cpp:129
bool seedAppliesToStation(const MusicThingie *seed) const
Check if a seed record is applicable to the current station.
Definition: pandoraseeds.cpp:138
void refreshSeedsAndRatings()
Retrieve a station's seed information on file with the servers.
Definition: pandoraseeds.cpp:254
bool is_shared
The station is owned by another listener (like a symlink)
Definition: pandorastation.h:81
virtual ThingieList getSeeds(void) const override
Get the seed list for a playlist.
Definition: pandoraseeds.cpp:292
bool may_rename
The user may rename the station.
Definition: pandorastation.h:82
virtual bool canSeed(MusicThingie::Type seedType) const override
Determine if a particular type of seeding is possible.
Definition: pandoraseeds.cpp:130
StationDefinitionDetails< SongSeed > song_seeds
Definition: pandorastation.h:98
StationDefinitionDetails< SongRating > feedback
Definition: pandorastation.h:97
time_t details_expiration
Time at which seeds expire.
Definition: pandorastation.h:85
virtual void rename(const std::string &newname) override
Definition: pandorastation.cpp:116
StationDefinitionDetails< GenreSeed > genre_seeds
Definition: pandorastation.h:100
const std::string & getToken() const
Definition: pandorastation.h:117
StationDefinitionDetails< ArtistSeed > artist_seeds
Definition: pandorastation.h:99
Station & operator=(const Station &update)
This is not a full-copy assignment, this is to update station details in the master when changes are ...
Definition: pandorastation.cpp:95
Station lookup.
Definition: pandorastation.h:143
Generic data type.
Definition: parsnip.h:81
@ MIX
Definition: musictypes.h:420
@ EVERYTHING
Definition: musictypes.h:421
Base class for storing lists of thingies, which need to be reference counted accurately.
Definition: retainedlist.h:20
Playlist / Artist / Album / Song datatypes that are self-implemented.
Essential data structures and support.
Class for source parameters and their parsing.
Playlist / Artist / Album / Song data types.
uint32_t value
Definition: audiooutput.cpp:68
const char * Source
Definition: pandoratypes.h:113
Pandora source, player and related datatype specializations.
Definition: pandora.h:32
const int StationDetailCacheTime
Definition: pandorastation.cpp:22
const int StationListCacheTime
Definition: pandorastation.cpp:21
Parsnip serialization.
Collections for music thingie types.
Smart pointers for music thingie types.