pianod2
multisource multiuser scriptable networked music player
musictypes.h
Go to the documentation of this file.
1 
9 #pragma once
10 
11 #include <config.h>
12 
13 #include <string>
14 #include <stack>
15 #include <vector>
16 #include <list>
17 #include <unordered_map>
18 #include <type_traits>
19 
20 #include "logging.h"
21 #include "ownership.h"
22 #include "ratings.h"
23 #include "ratings.h"
24 
25 namespace Media {
26  class Source;
27  class Player;
28  enum class SelectionMethod;
29 }
30 
31 #include "fundamentals.h"
32 #include "ownership.h"
33 
34 class Filter;
35 class ThingieList;
36 class SongList;
37 class PlaylistList;
38 class PianodConnection;
39 class ResponseGroup;
40 namespace Football {
41  class Thingie;
42 }
43 namespace Parsnip {
44  class Data;
45 }
46 
47 
48 class MusicThingie;
49 class PianodArtist;
50 class PianodAlbum;
51 class PianodSong;
52 class PianodPlaylist;
53 
54 class MusicAutoReleasePool : private std::stack<MusicThingie *> {
55  friend class MusicThingie;
57  inline void add (MusicThingie *item) {
58  push (item);
59  }
60  void unadd (MusicThingie *item);
61 public:
64 };
65 
78  friend class MusicAutoReleasePool;
79 private:
80  mutable short useCount = 1;
82 protected:
83  // Non-public destructor prevents allocation outside heap (C++PL/4 525)
84  virtual ~MusicThingie (void);
85 public:
86  enum class Type: char {
87  Playlist = 'p',
88  Artist = 'a',
89  Album = 'l',
90  Song = 's',
91 
92  PlaylistSuggestion = 'e',
93  ArtistSuggestion = 't',
94  AlbumSuggestion = 'b',
95  SongSuggestion = 'n',
96 
97  PlaylistSeed = 'y',
98  ArtistSeed = 'd',
99  AlbumSeed = 'u',
100  SongSeed = 'g',
101 
102  SongRating = 'i'
103  };
104  static std::string TypeName (Type type);
105  static Type TypeFromName (const std::string &name);
106 
107  MusicThingie (void);
108 
109  static inline constexpr bool isPrimary (Type t) {
110  return (t == Type::Playlist ||
111  t == Type::Artist ||
112  t == Type::Album ||
113  t == Type::Song);
114  }
115  inline bool isPrimary (void) const {
116  return isPrimary (type());
117  }
118  static inline constexpr bool isSuggestion (const Type t) {
119  return (t == Type::PlaylistSuggestion ||
120  t == Type::ArtistSuggestion ||
121  t == Type::AlbumSuggestion ||
122  t == Type::SongSuggestion);
123  }
124  inline bool isSuggestion (void) const {
125  return isSuggestion (type());
126  }
127  static inline constexpr bool isSeed (const Type t) {
128  return (t == Type::PlaylistSeed ||
129  t == Type::ArtistSeed ||
130  t == Type::AlbumSeed ||
131  t == Type::SongSeed ||
132  t == Type::SongRating);
133  }
134  inline bool isSeed (void) const {
135  return isSeed (type());
136  }
137 
138  static inline constexpr bool isPlaylist (const Type t) {
139  return (t == Type::Playlist ||
141  t == Type::PlaylistSeed);
142  }
143  inline bool isPlaylist (void) const {
144  return isPlaylist (type());
145  }
146  static inline constexpr bool isSong (const Type t) {
147  return (t == Type::Song ||
148  t == Type::SongSuggestion ||
149  t == Type::SongSeed ||
150  t == Type::SongRating);
151  }
152  inline bool isSong (void) const {
153  return isSong (type());
154  }
155  static inline constexpr bool isAlbum (const Type t) {
156  return (t == Type::Album ||
157  t == Type::AlbumSuggestion ||
158  t == Type::AlbumSeed);
159  }
160  inline bool isAlbum (void) const {
161  return isAlbum (type());
162  }
163  static inline constexpr bool isArtist (const Type t) {
164  return (t == Type::Artist ||
165  t == Type::ArtistSuggestion ||
166  t == Type::ArtistSeed);
167  }
168  inline bool isArtist (void) const {
169  return isArtist (type());
170  }
171  static inline constexpr bool isValidType (const Type t) {
172  return (isSong (t) || isAlbum (t) || isArtist (t) || isPlaylist (t));
173  };
174  inline bool isValidType (void) const {
175  return isValidType (type());
176  }
177  static Type primaryType (const Type t);
178  inline Type primaryType (void) const {
179  return primaryType (type());
180  }
181 
183  virtual bool canQueue() const { return false; };
184 
185  // Speed up and ease typecasting
186  virtual PianodArtist *asArtist () { return nullptr; }
187  virtual PianodAlbum *asAlbum () { return nullptr; }
188  virtual PianodSong *asSong () { return nullptr; }
189  virtual PianodPlaylist *asPlaylist () { return nullptr; }
190  virtual const PianodArtist *asArtist () const { return nullptr; }
191  virtual const PianodAlbum *asAlbum () const { return nullptr; }
192  virtual const PianodSong *asSong () const { return nullptr; }
193  virtual const PianodPlaylist *asPlaylist () const { return nullptr; }
194 
195  std::string operator()(void) const;
196 
198 #ifndef NDEBUG
199  inline
200 #endif
201  void retain (void) const {
202  useCount++;
203 #ifndef NDEBUG
204  flog (Log::ALLOCATIONS, "Retained ", (*this)(), ", useCount=", useCount);
205 #endif
206 };
208 #ifndef NDEBUG
209  inline
210 #endif
211  void release (void) {
212  assert (useCount > 0);
213 #ifndef NDEBUG
214  flog (Log::ALLOCATIONS, "Releasing ", (*this)(), ", useCount=", useCount - 1);
215 #else
216  if (useCount == 1) {
217  flog (Log::ALLOCATIONS, "Deleting ", (*this)());
218  }
219 #endif
220  if (--useCount == 0) delete this;
221  };
222  inline int getUseCount (void) const { return useCount; };
223 
225  virtual Ownership *parentOwner (void) const;
227  virtual Media::Source * const source (void) const = 0;
230  virtual const std::string id (void) const = 0;
232  virtual const std::string id (MusicThingie::Type type) const = 0;
234  virtual const std::string &internalId (MusicThingie::Type type) const = 0;
236  virtual const std::string &name (void) const = 0;
239  virtual Type type (void) const = 0;
241  virtual Football::Thingie &transmitCommon (Football::Thingie &recipient) const = 0;
243  virtual PianodConnection &transmitPrivate (PianodConnection &recipient) const = 0;
245  virtual Parsnip::Data serialize () const = 0;
247  virtual void serializePrivate (Parsnip::Data &, const User *user) const = 0;
248  void serializeCommon (Parsnip::Data &) const;
250  virtual bool matches (const Filter &filter) const = 0;
253  virtual bool operator==(const std::string &compare) const = 0;
257  virtual bool operator==(const MusicThingie &compare) const = 0;
258  inline bool operator !=(const std::string &compare) {
259  return !(*this == compare);
260  }
261  inline bool operator !=(const MusicThingie &compare) {
262  return !(*this == compare);
263  }
264  virtual SongList songs ();
265 };
266 
267 /*
268  * Artists
269  */
270 
272 class PianodArtist : public MusicThingie {
273 public:
274  virtual const std::string &artistId (void) const = 0;
275  virtual const std::string id (void) const override;
276  virtual const std::string id (MusicThingie::Type type) const override;
277  virtual const std::string &internalId (MusicThingie::Type type) const override;
278  virtual const std::string &name (void) const override { return artist(); };
279  virtual Type type (void) const override { return Type::Artist; };
280  static inline Type typetype (void) { return Type::Artist; };
281  virtual Football::Thingie &transmitCommon (Football::Thingie &recipient) const override;
282  virtual PianodConnection &transmitPrivate (PianodConnection &recipient) const override;
283  virtual Parsnip::Data serialize () const override;
284  virtual void serializePrivate (Parsnip::Data &, const User *user) const override;
285  virtual bool matches (const Filter &filter) const override;
286  virtual PianodArtist *asArtist () override { return this; }
287  virtual const PianodArtist *asArtist () const override { return this; }
288 
289  virtual const std::string &artist (void) const = 0;
290 
294  virtual bool operator==(const std::string &compare) const override;
298  virtual bool operator==(const MusicThingie &compare) const override;
299 };
300 
301 
302 /*
303  * Albums
304  */
305 
307 class PianodAlbum : public PianodArtist {
308 public:
309  virtual const std::string &albumId (void) const = 0;
310  virtual const std::string id (void) const override;
311  virtual const std::string id (MusicThingie::Type type) const override;
312  virtual const std::string &internalId (MusicThingie::Type type) const override;
313  virtual const std::string &name (void) const override { return albumTitle(); };
314  virtual Type type (void) const override { return Type::Album; };
315  static inline Type typetype (void) { return Type::Album; };
316  virtual Football::Thingie &transmitCommon (Football::Thingie &recipient) const override;
317  virtual PianodConnection &transmitPrivate (PianodConnection &recipient) const override;
318  virtual Parsnip::Data serialize () const override;
319  virtual void serializePrivate (Parsnip::Data &, const User *user) const override;
320  virtual bool matches (const Filter &filter) const override;
321  virtual PianodArtist *asArtist () override { return compilation() ? nullptr : this; }
322  virtual const PianodArtist *asArtist () const override { return compilation() ? nullptr : this; }
323  virtual PianodAlbum *asAlbum () override final { return this; }
324  virtual const PianodAlbum *asAlbum () const override final { return this; }
325 
326  virtual const std::string &albumTitle (void) const = 0;
327  virtual const std::string &coverArtUrl(void) const = 0;
328  virtual bool compilation () const { return false; };
329  virtual bool operator==(const std::string &compare) const override;
330  virtual bool operator==(const MusicThingie &compare) const override;
331 };
332 
333 
334 /*
335  * Songs
336  */
337 
339 class PianodSong : public PianodAlbum {
340 protected:
341  time_t expiration = 0;
342  time_t last_played = 0;
343 public:
344  virtual const std::string &songId (void) const = 0;
345  virtual const std::string id (void) const override;
346  virtual const std::string id (MusicThingie::Type type) const override final;
347  virtual const std::string &internalId (MusicThingie::Type type) const override final;
348  virtual const std::string &name (void) const override final { return title(); };
349  virtual Type type (void) const override { return Type::Song; };
350  static inline Type typetype (void) { return Type::Song; };
351  virtual Football::Thingie &transmitCommon (Football::Thingie &recipient) const override final;
352  virtual PianodConnection &transmitPrivate (PianodConnection &recipient) const override;
353  virtual Parsnip::Data serialize () const override final;
354  virtual void serializePrivate (Parsnip::Data &, const User *user) const override;
355  ResponseGroup assembleRatings (const User *user, const PianodPlaylist *playlist, bool include_json) const;
356  ResponseGroup assembleCapabilities (const User *user, const PianodPlaylist *playlist) const;
357  Parsnip::Data serializeRatings (const User *user, const PianodPlaylist *playlist) const;
358  Parsnip::Data serializeCapabilities (const User *user, const PianodPlaylist *playlist) const;
359  virtual bool matches (const Filter &filter) const override final;
360  virtual PianodSong *asSong () override final { return this; }
361  virtual const PianodSong *asSong () const override final { return this; }
362 
363  inline bool expires (void) { return expiration != 0; };
364  inline bool expired (void) { return expires() && expiration < time (NULL); };
367  inline time_t lastPlayed (void) const { return last_played; };
368  inline void lastPlayed (time_t t) { last_played = t; };
369 
370  virtual const std::string &title (void) const = 0;
371  virtual PianodPlaylist *playlist (void) const = 0;
372  virtual const std::string &playlistName (void) const;
373  virtual const std::string &genre (void) const = 0;
374  virtual const std::string &infoUrl (void) const;
377  virtual int trackNumber (void) const = 0;
380  virtual int duration (void) const = 0;
383  virtual int year (void) const = 0;
384 
385  virtual RatingScheme ratingScheme (void) const { return RatingScheme::NOBODY; };
389  virtual RESPONSE_CODE rate (Rating value, User *user) = 0;
391  virtual Rating rating (const User *user) const = 0;
393  float averageRating () const;
394 
395  virtual bool operator==(const std::string &compare) const override;
396  virtual bool operator==(const MusicThingie &compare) const override;
397 
398  // Actions and action checks
399  virtual SongList songs () override;
400  virtual bool canSkip (time_t *whenAllowed);
401  virtual bool mustPlay () const;
402  Media::Player *play (const AudioSettings &audio);
403 };
404 
405 
406 
407 
408 
409 
410 
411 /*
412  * Playlists
413  */
414 
416 class PianodPlaylist : public MusicThingie {
417 public:
422  TRANSIENT
423  };
424 
425  virtual const std::string &playlistId (void) const = 0;
426  virtual const std::string id (void) const override;
427  virtual const std::string id (MusicThingie::Type type) const override final;
428  virtual const std::string &internalId (MusicThingie::Type type) const override final;
429  virtual const std::string &name (void) const override final { return playlistName(); };
430  virtual Type type (void) const override { return Type::Playlist; };
431  static inline Type typetype (void) { return Type::Playlist; };
432  virtual Football::Thingie &transmitCommon (Football::Thingie &recipient) const override final;
433  virtual PianodConnection &transmitPrivate (PianodConnection &recipient) const override;
434  class Response assembleRatings (const User *user) const;
435  virtual Parsnip::Data serialize () const override final;
436  virtual void serializePrivate (Parsnip::Data &, const User *user) const override;
437  Parsnip::Data serializeRatings (const User *user) const;
438  virtual bool matches (const Filter &filter) const override final;
439  virtual PianodPlaylist *asPlaylist () override final { return this; }
440  virtual const PianodPlaylist *asPlaylist () const override final { return this; }
441 
442  virtual PlaylistType playlistType (void) const = 0;
443  virtual const std::string &playlistName (void) const = 0;
444  virtual const std::string &genre (void) const = 0;
445 
446  virtual SongList getRandomSongs (const UserList &users,
447  Media::SelectionMethod selectionMethod);
448  virtual bool operator==(const std::string &compare) const override;
449  virtual bool operator==(const MusicThingie &compare) const override;
450  virtual bool includedInMix (void) const = 0;
451  virtual void includedInMix (bool include) = 0;
453  Rating rating (const User *user) const;
454  float averageRating () const;
455 
456  virtual bool canSeed (MusicThingie::Type seedType) const;
457  virtual bool seed (MusicThingie::Type seedType, const MusicThingie *music) const;
458  virtual void seed (MusicThingie::Type seedType, MusicThingie *music, bool value);
459  virtual ThingieList getSeeds (void) const;
460  virtual SongList songs () override;
461  virtual SongList songs (const Filter &filter);
462 
463  virtual void updateSelector (const Filter &new_selector);
464  virtual void rename (const std::string &newname) = 0;
465  virtual void erase () = 0;
466 };
467 
468 
470 template<class BasePlaylist>
471 class PianodTransientPlaylist : virtual public BasePlaylist {
472 public:
473  virtual PianodPlaylist::PlaylistType playlistType (void) const override { return PianodPlaylist::TRANSIENT; };
474 
475  virtual bool includedInMix (void) const override { return false; };
476  virtual void includedInMix (bool) override { throw CommandError (E_MEDIA_TRANSIENT); };
477 
478  virtual bool canSeed (MusicThingie::Type) const override { return false; };
479  virtual bool seed (MusicThingie::Type, const MusicThingie *) const override {
480  assert (!"Queried seed for transient playlist.");
481  return false;
482  }
483  virtual void seed (MusicThingie::Type, MusicThingie *, bool) override {
484  assert (!"Set seed for transient playlist");
485  }
486 
487  virtual void rename (const std::string &) override { throw CommandError (E_MEDIA_TRANSIENT); };
488  virtual void erase () override { throw CommandError (E_MEDIA_TRANSIENT); };
489 };
490 
491 
492 
493 /*
494  * Thingie Management
495  */
496 
500 
Exception for command execution problems.
Definition: fundamentals.h:293
Track data filter.
Definition: filter.h:38
Base class for services, events, and connections.
Definition: football.h:37
Class to map between enumerations and their text values.
Definition: lookup.h:30
Base class for playing audio from some source.
Definition: mediaplayer.h:46
Base class that wraps any audio source, such as Pandora, Spotify, or local music.
Definition: mediaunit.h:68
Definition: musictypes.h:54
void add(MusicThingie *item)
Definition: musictypes.h:57
~MusicAutoReleasePool()
Definition: musictypes.cpp:44
MusicAutoReleasePool()
Definition: musictypes.cpp:40
MusicAutoReleasePool * previousPool
Definition: musictypes.h:56
void unadd(MusicThingie *item)
Remove an item from the release pool when it fails subsequent construction.
Definition: musictypes.cpp:53
Base class for songs, albums, artists, playlists, genres, etc.
Definition: musictypes.h:77
virtual bool operator==(const std::string &compare) const =0
Check if the primary name of this thingie matches.
Definition: musictypes.cpp:82
std::string operator()(void) const
Definition: musictypes.cpp:144
int getUseCount(void) const
Definition: musictypes.h:222
virtual const std::string id(void) const =0
Get the primary id of this thingie.
bool isSeed(void) const
Definition: musictypes.h:134
virtual const PianodArtist * asArtist() const
Definition: musictypes.h:190
virtual const std::string & internalId(MusicThingie::Type type) const =0
Return the inner ID when used in a specific context.
virtual ~MusicThingie(void)
Definition: musictypes.cpp:74
bool isSong(void) const
Definition: musictypes.h:152
virtual const PianodPlaylist * asPlaylist() const
Definition: musictypes.h:193
static constexpr bool isAlbum(const Type t)
Definition: musictypes.h:155
virtual PianodConnection & transmitPrivate(PianodConnection &recipient) const =0
Transmit the thingie's user-specific data on a connection.
void serializeCommon(Parsnip::Data &) const
Insert common items into the serialization dictionary.
Definition: musictypes.cpp:87
bool isPlaylist(void) const
Definition: musictypes.h:143
virtual bool matches(const Filter &filter) const =0
Check if a filter matches this item.
bool isAlbum(void) const
Definition: musictypes.h:160
static MusicAutoReleasePool * releasePool
The current autorelease pool to put newly created music thingies into.
Definition: musictypes.h:81
bool isValidType(void) const
Definition: musictypes.h:174
static constexpr bool isArtist(const Type t)
Definition: musictypes.h:163
virtual PianodArtist * asArtist()
Definition: musictypes.h:186
virtual const PianodSong * asSong() const
Definition: musictypes.h:192
bool isSuggestion(void) const
Definition: musictypes.h:124
static constexpr bool isValidType(const Type t)
Definition: musictypes.h:171
virtual Football::Thingie & transmitCommon(Football::Thingie &recipient) const =0
Transmit the thingie's data to a connection or service.
static constexpr bool isSeed(const Type t)
Definition: musictypes.h:127
short useCount
Definition: musictypes.h:80
MusicThingie(void)
When allocated, use count starts at 1 and the object is put in the release pool, justifying its exist...
Definition: musictypes.cpp:69
Type primaryType(void) const
Definition: musictypes.h:178
virtual bool canQueue() const
Indicate if specific item can be queued/requested.
Definition: musictypes.h:183
virtual void serializePrivate(Parsnip::Data &, const User *user) const =0
Add the thingie's user-specific data for JSON transmission.
virtual bool operator==(const MusicThingie &compare) const =0
Compare a thingie's name to another of the equivalent or decendent type.
virtual const std::string id(MusicThingie::Type type) const =0
Return the complete ID when used in a specific context.
virtual SongList songs()
Retrieve a list of requestable songs applicable to this thingie.
Definition: musictypes.cpp:162
virtual Parsnip::Data serialize() const =0
Assemble the thingie's data for JSON tranmission.
virtual Type type(void) const =0
Return the type letter for a thingie.
bool isPrimary(void) const
Definition: musictypes.h:115
static constexpr bool isSuggestion(const Type t)
Definition: musictypes.h:118
virtual const PianodAlbum * asAlbum() const
Definition: musictypes.h:191
void release(void)
Abandon an instance.
Definition: musictypes.h:211
virtual PianodPlaylist * asPlaylist()
Definition: musictypes.h:189
virtual Media::Source *const source(void) const =0
MediaSource from which this thingie originates.
static std::string TypeName(Type type)
Get the type name of a music thingie.
Definition: musictypes.cpp:121
virtual Ownership * parentOwner(void) const
Defer the ownership to the source.
Definition: musictypes.cpp:166
bool operator!=(const std::string &compare)
Definition: musictypes.h:258
virtual const std::string & name(void) const =0
Return the most specific name of this, whatever type it is.
static Type TypeFromName(const std::string &name)
Definition: musictypes.cpp:135
Type
Definition: musictypes.h:86
static constexpr bool isPlaylist(const Type t)
Definition: musictypes.h:138
static constexpr bool isPrimary(Type t)
Definition: musictypes.h:109
void retain(void) const
Claim an instance.
Definition: musictypes.h:201
virtual PianodSong * asSong()
Definition: musictypes.h:188
bool isArtist(void) const
Definition: musictypes.h:168
virtual PianodAlbum * asAlbum()
Definition: musictypes.h:187
static constexpr bool isSong(const Type t)
Definition: musictypes.h:146
Privilege management for media sources.
Definition: fundamentals.h:351
Type
Access levels for an object.
Definition: fundamentals.h:355
Generic data type.
Definition: parsnip.h:81
Base class for albums, these are also MusicThingies and artists.
Definition: musictypes.h:307
virtual PianodArtist * asArtist() override
Definition: musictypes.h:321
virtual PianodAlbum * asAlbum() override final
Definition: musictypes.h:323
virtual PianodConnection & transmitPrivate(PianodConnection &recipient) const override
Transmit the thingie's user-specific data on a connection.
Definition: musictypes.cpp:299
virtual const PianodAlbum * asAlbum() const override final
Definition: musictypes.h:324
virtual bool matches(const Filter &filter) const override
Check if a filter matches this item.
Definition: musictypes.cpp:334
virtual bool operator==(const std::string &compare) const override
Is album a compilation?
Definition: musictypes.cpp:338
virtual Football::Thingie & transmitCommon(Football::Thingie &recipient) const override
Typecode for album type.
Definition: musictypes.cpp:290
virtual const std::string & name(void) const override
Return the most specific name of this, whatever type it is.
Definition: musictypes.h:313
virtual Parsnip::Data serialize() const override
Assemble the thingie's data for JSON tranmission.
Definition: musictypes.cpp:306
virtual const std::string & coverArtUrl(void) const =0
virtual void serializePrivate(Parsnip::Data &, const User *user) const override
Add the thingie's user-specific data for JSON transmission.
Definition: musictypes.cpp:326
static Type typetype(void)
Typecode for album objects.
Definition: musictypes.h:315
virtual Type type(void) const override
Return the type letter for a thingie.
Definition: musictypes.h:314
virtual const std::string & albumTitle(void) const =0
virtual const std::string id(void) const override
Primary ID is album ID.
Definition: musictypes.cpp:260
virtual bool compilation() const
Definition: musictypes.h:328
virtual const std::string & albumId(void) const =0
Item's album ID.
virtual const PianodArtist * asArtist() const override
Definition: musictypes.h:322
virtual const std::string & internalId(MusicThingie::Type type) const override
Return the inner ID when used in a specific context.
Definition: musictypes.cpp:277
Base class for artists, derived from MusicThingies.
Definition: musictypes.h:272
virtual const std::string & internalId(MusicThingie::Type type) const override
Return the inner ID when used in a specific context.
Definition: musictypes.cpp:194
virtual const std::string & name(void) const override
Return the most specific name of this, whatever type it is.
Definition: musictypes.h:278
virtual PianodArtist * asArtist() override
Definition: musictypes.h:286
virtual void serializePrivate(Parsnip::Data &, const User *user) const override
Add the thingie's user-specific data for JSON transmission.
Definition: musictypes.cpp:229
virtual Football::Thingie & transmitCommon(Football::Thingie &recipient) const override
Typecode for artist type.
Definition: musictypes.cpp:206
virtual Parsnip::Data serialize() const override
Assemble the thingie's data for JSON tranmission.
Definition: musictypes.cpp:219
virtual const std::string & artistId(void) const =0
Item's artist ID.
virtual const PianodArtist * asArtist() const override
Definition: musictypes.h:287
static Type typetype(void)
Typecode for artist objects.
Definition: musictypes.h:280
virtual Type type(void) const override
Return the type letter for a thingie.
Definition: musictypes.h:279
virtual bool operator==(const std::string &compare) const override
See if the artist has a certain name.
Definition: musictypes.cpp:241
virtual bool matches(const Filter &filter) const override
Check if a filter matches this item.
Definition: musictypes.cpp:237
virtual PianodConnection & transmitPrivate(PianodConnection &recipient) const override
Transmit the thingie's user-specific data on a connection.
Definition: musictypes.cpp:212
virtual const std::string id(void) const override
Get primary ID with media manager ID on it.
Definition: musictypes.cpp:179
virtual const std::string & artist(void) const =0
Get artist name.
Connection to a pianod client, along with context and state of that connection.
Definition: connection.h:54
Base class for playlists, but still a MusicThingie.
Definition: musictypes.h:416
virtual PlaylistType playlistType(void) const =0
Mix, everything, transient or single list.
virtual const std::string & playlistName(void) const =0
Name of the playlist.
virtual bool includedInMix(void) const =0
virtual void rename(const std::string &newname)=0
virtual const std::string id(void) const override
Primary ID is playlist ID.
Definition: musictypes.cpp:702
RESPONSE_CODE rate(Rating value, User *user)
Set a user's playlist's rating.
Definition: musictypes.cpp:838
virtual const std::string & name(void) const override final
Return the most specific name of this, whatever type it is.
Definition: musictypes.h:429
virtual bool matches(const Filter &filter) const override final
Check if a filter matches this item.
Definition: musictypes.cpp:815
virtual const std::string & genre(void) const =0
Get genre of this playlist.
virtual PianodConnection & transmitPrivate(PianodConnection &recipient) const override
Transmit the thingie's user-specific data on a connection.
Definition: musictypes.cpp:739
virtual PianodPlaylist * asPlaylist() override final
Definition: musictypes.h:439
virtual const std::string & playlistId(void) const =0
Item's playlist ID.
virtual bool operator==(const std::string &compare) const override
Check if the primary name of this thingie matches.
Definition: musictypes.cpp:819
virtual SongList getRandomSongs(const UserList &users, Media::SelectionMethod selectionMethod)
Choose some random songs for queueing.
Definition: musictypes.cpp:694
virtual const PianodPlaylist * asPlaylist() const override final
Definition: musictypes.h:440
virtual bool seed(MusicThingie::Type seedType, const MusicThingie *music) const
Check if there is a seed of a particular type for this thingie.
Definition: musictypes.cpp:890
virtual ThingieList getSeeds(void) const
Get the seed list for a playlist.
Definition: musictypes.cpp:910
virtual const std::string & internalId(MusicThingie::Type type) const override final
Return the inner ID when used in a specific context.
Definition: musictypes.cpp:718
virtual Type type(void) const override
Return the type letter for a thingie.
Definition: musictypes.h:430
Parsnip::Data serializeRatings(const User *user) const
Definition: musictypes.cpp:800
virtual bool canSeed(MusicThingie::Type seedType) const
Determine if a particular type of seeding is possible.
Definition: musictypes.cpp:882
virtual SongList songs() override
Retrieve a list of requestable songs applicable to this thingie.
Definition: musictypes.cpp:677
virtual void erase()=0
virtual void serializePrivate(Parsnip::Data &, const User *user) const override
Add the thingie's user-specific data for JSON transmission.
Definition: musictypes.cpp:787
class Response assembleRatings(const User *user) const
Definition: musictypes.cpp:766
float averageRating() const
Return the average rating of a playlist, considering all ratings.
Definition: musictypes.cpp:869
virtual Football::Thingie & transmitCommon(Football::Thingie &recipient) const override final
Typecode for playlist type.
Definition: musictypes.cpp:730
PlaylistType
Definition: musictypes.h:418
@ MIX
Definition: musictypes.h:420
@ SINGLE
Definition: musictypes.h:419
@ EVERYTHING
Definition: musictypes.h:421
@ TRANSIENT
Definition: musictypes.h:422
virtual void includedInMix(bool include)=0
virtual Parsnip::Data serialize() const override final
Assemble the thingie's data for JSON tranmission.
Definition: musictypes.cpp:775
static Type typetype(void)
Typecode for playlist objects.
Definition: musictypes.h:431
virtual void updateSelector(const Filter &new_selector)
Update a playlist's selector algorithm.
Definition: musictypes.cpp:917
Rating rating(const User *user) const
Retrieve a user's playlist's rating.
Definition: musictypes.cpp:859
Base class for songs, these are also MusicThingies, artists and albums.
Definition: musictypes.h:339
virtual const std::string id(void) const override
Primary ID is album ID.
Definition: musictypes.cpp:357
virtual SongList songs() override
Retrieve a list of requestable songs applicable to this thingie.
Definition: musictypes.cpp:654
virtual Type type(void) const override
Return the type letter for a thingie.
Definition: musictypes.h:349
ResponseGroup assembleRatings(const User *user, const PianodPlaylist *playlist, bool include_json) const
Definition: musictypes.cpp:430
virtual RESPONSE_CODE rate(Rating value, User *user)=0
Rate a song.
time_t last_played
Time song was last played, 0 if never or unknown.
Definition: musictypes.h:342
ResponseGroup assembleCapabilities(const User *user, const PianodPlaylist *playlist) const
Definition: musictypes.cpp:465
virtual Rating rating(const User *user) const =0
Get a song's rating.
virtual RatingScheme ratingScheme(void) const
Definition: musictypes.h:385
virtual PianodSong * asSong() override final
Definition: musictypes.h:360
virtual const std::string & playlistName(void) const
Get name of a playlist to which this belongs.
Definition: musictypes.cpp:671
bool expired(void)
Definition: musictypes.h:364
virtual const std::string & name(void) const override final
Return the most specific name of this, whatever type it is.
Definition: musictypes.h:348
time_t expiration
Time at which a queued item becomes invalid, or 0 if good forever.
Definition: musictypes.h:341
static Type typetype(void)
Definition: musictypes.h:350
virtual const std::string & internalId(MusicThingie::Type type) const override final
Return the inner ID when used in a specific context.
Definition: musictypes.cpp:378
virtual PianodPlaylist * playlist(void) const =0
Get a playlist instance.
virtual int duration(void) const =0
Duration of song in seconds.
virtual bool canSkip(time_t *whenAllowed)
Check for permission to skip a song.
Definition: musictypes.cpp:634
virtual void serializePrivate(Parsnip::Data &, const User *user) const override
Add the thingie's user-specific data for JSON transmission.
Definition: musictypes.cpp:531
virtual int year(void) const =0
Year of release of song.
Parsnip::Data serializeCapabilities(const User *user, const PianodPlaylist *playlist) const
Provide a list of actions a user can take on this song.
Definition: musictypes.cpp:574
virtual const std::string & songId(void) const =0
virtual int trackNumber(void) const =0
Get track number (sequence number within an album/original media).
virtual const std::string & title(void) const =0
Get the song's title.
virtual const std::string & infoUrl(void) const
Provide a URL with additional info.
Definition: musictypes.cpp:664
virtual bool matches(const Filter &filter) const override final
Check if a filter matches this item.
Definition: musictypes.cpp:595
virtual Football::Thingie & transmitCommon(Football::Thingie &recipient) const override final
Typecode for album type.
Definition: musictypes.cpp:396
virtual PianodConnection & transmitPrivate(PianodConnection &recipient) const override
Transmit the thingie's user-specific data on a connection.
Definition: musictypes.cpp:420
Media::Player * play(const AudioSettings &audio)
Play the song.
Definition: musictypes.cpp:646
float averageRating() const
Return the average rating of a song, considering all ratings.
Definition: musictypes.cpp:616
void lastPlayed(time_t t)
Definition: musictypes.h:368
virtual const PianodSong * asSong() const override final
Definition: musictypes.h:361
virtual Parsnip::Data serialize() const override final
Assemble the thingie's data for JSON tranmission.
Definition: musictypes.cpp:493
time_t lastPlayed(void) const
Get time a song last played.
Definition: musictypes.h:367
virtual RESPONSE_CODE rateOverplayed(User *)
Definition: musictypes.h:392
bool expires(void)
Definition: musictypes.h:363
virtual const std::string & genre(void) const =0
Get genre of this song.
Parsnip::Data serializeRatings(const User *user, const PianodPlaylist *playlist) const
Definition: musictypes.cpp:536
virtual bool mustPlay() const
Mark songs (err, adverts) as must-play; they can't be skipped over even when playlist selections are ...
Definition: musictypes.cpp:641
virtual bool operator==(const std::string &compare) const override
Is album a compilation?
Definition: musictypes.cpp:599
Template to make a corresponding transient playlist.
Definition: musictypes.h:471
virtual bool canSeed(MusicThingie::Type) const override
Definition: musictypes.h:478
virtual void includedInMix(bool) override
Definition: musictypes.h:476
virtual void rename(const std::string &) override
Definition: musictypes.h:487
virtual bool seed(MusicThingie::Type, const MusicThingie *) const override
Definition: musictypes.h:479
virtual bool includedInMix(void) const override
Definition: musictypes.h:475
virtual PianodPlaylist::PlaylistType playlistType(void) const override
Definition: musictypes.h:473
virtual void erase() override
Definition: musictypes.h:488
virtual void seed(MusicThingie::Type, MusicThingie *, bool) override
Definition: musictypes.h:483
A container for lists of playlists.
Definition: retainedlist.h:324
Container for multiple Responses.
Definition: response.h:155
Type combining RESPONSE_CODE with a value or explanation:
Definition: response.h:49
const class User * user
User triggering the response.
Definition: response.h:73
A container for holding songs.
Definition: retainedlist.h:328
Ownership where privilege is regulated by some parent object.
Definition: ownership.h:37
Base class for storing lists of thingies, which need to be reference counted accurately.
Definition: retainedlist.h:20
Data about each user.
Definition: user.h:53
Essential data structures and support.
std::vector< const class User * > UserList
Definition: fundamentals.h:348
enum server_status_t RESPONSE_CODE
@ E_NOT_IMPLEMENTED
Definition: fundamentals.h:221
@ E_MEDIA_TRANSIENT
Transient playlist.
Definition: fundamentals.h:219
Debug/event logging interface.
void flog(LogType level, MoreItems &&... more)
Log messages when their logging category is enabled.
Definition: logging.h:109
const LookupTable< MusicThingie::Type > ThingieTypesLookup
Look up table for thingie type names and type codes.
Definition: musictypes.h:498
ThingieTypesLookup THINGIETYPES
uint32_t value
Definition: audiooutput.cpp:68
Football C++ connections, services and parsers.
Definition: fb_arena.cpp:23
static const char * Data
Definition: responsejson.cpp:42
const char * Source
Definition: pandoratypes.h:113
Media source, source parameters and player interfaces.
Definition: connection.h:22
SelectionMethod
The manner in which shuffling is performed.
Definition: mediaunit.h:55
const char * Song
Definition: musickeys.cpp:69
const char * Playlist
Definition: musickeys.cpp:66
const char * Album
Definition: musickeys.cpp:68
const char * Artist
Definition: musickeys.cpp:67
Serialization and parsing library.
Definition: mediaunit.h:26
Access control for objects.
Ratings support.
Rating
Discrete ratings values.
Definition: ratings.h:24
RatingScheme
Rules of who may rate an object.
Definition: ratings.h:17
@ NOBODY
Ratings are unsupported.
Audio output device & driver parameters.
Definition: fundamentals.h:52