summaryrefslogtreecommitdiff
path: root/tools/playlist.h
blob: 50c3d97af62d82694502374c0193f99010108dc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
 * playlist.h: Media player playlist
 *
 * See the main source file 'xineliboutput.c' for copyright information and
 * how to reach the author.
 *
 * $Id: playlist.h,v 1.8 2008-02-19 04:24:34 phintuka Exp $
 *
 */

#ifndef __XINELIBOUTPUT_PLAYLIST_H
#define __XINELIBOUTPUT_PLAYLIST_H

#include <vdr/tools.h>  // cString, cListObject, cList<>
#include <vdr/thread.h> // cMutex


//
// cPlaylistItem
//
 
class cPlaylistItem : public cListObject 
{
 private:
  cPlaylistItem();

  virtual int Compare(const cListObject &ListObject) const;

 public:
  cPlaylistItem(const char *filename); /* file name with full path */
  cPlaylistItem(const char *filename,  /* file name without path */
		const char *path,
		const char *title = NULL, 
		int position = -1);
  
  cString Filename; /* file name and full path */

  // Metainfo (ID3 etc.)
  cString Title;
  cString Tracknumber;
  cString Artist;
  cString Album;
    
  // position in playlist (if given in playlist file)
  int Position;
};


//
// cPlaylistChangeNotify interface
//

class cPlaylistChangeNotify 
{
 public:
  virtual void PlaylistChanged(const cPlaylistItem *Item) = 0;

  virtual ~cPlaylistChangeNotify() {}
};


//
// cPlaylist
//


class cID3Scanner;

class cPlaylist : protected cList<cPlaylistItem> 
{
 private:

  cMutex         m_Lock;
  cString        m_Name;    // playlist (or folder) name
  cString        m_Folder;  // path to "root" of playlist
  cPlaylistItem *m_Current; // now playing
  unsigned int   m_Version;

  enum { ePlaylist, eImplicit } m_Origin;

  cPlaylistChangeNotify *m_Menu;
  cID3Scanner *m_Scanner;
 
 protected:

  bool StoreCache(void);
  bool ReadCache(void);

  int ReadPlaylist(const char *PlaylistFile);
  int ScanFolder(const char *FolderName, 
		 bool Recursive = false,
		 bool (config_t::*Filter)(const char *) = &config_t::IsAudioFile);

  friend class cID3Scanner;
  friend class cPlaylistReader;
  void PlaylistChanged(const cPlaylistItem *Item);
  cPlaylistItem *Last(void) { return cList<cPlaylistItem>::Last(); }

 public:

  cPlaylist();
  virtual ~cPlaylist();

  const cString& Name(void) const { return m_Name; }

  // listen for changes in playlist
  void Listen(cPlaylistChangeNotify *Menu = NULL);

  // read playlist from file or create playlist from directory tree 
  bool Read(const char *PlaylistFile, bool Recursive = false);
  void StartScanner(void);
  void Del(cPlaylistItem *it);

  void Sort(void);
  int  Count(void) const;

  // access/iterate playlist items
  cPlaylistItem *First(void) { return Next(NULL); }
  cPlaylistItem *Next(const cPlaylistItem *i);

  // get/set current (now playing) item
  cPlaylistItem *Current(void);
  void           SetCurrent(cPlaylistItem *current);
  cPlaylistItem *Next(void);
  cPlaylistItem *Prev(void);

  static cString EscapeMrl(const char *name);
  static cString GetEntry(cPlaylistItem *i, bool isPlaylist = false, bool isCurrent = false);
};


#endif // __XINELIBOUTPUT_PLAYLIST_H