Music Hub  ..
A session-wide music playback service
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
track.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2013 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Thomas Voß <thomas.voss@canonical.com>
17  */
18 #ifndef CORE_UBUNTU_MEDIA_TRACK_H_
19 #define CORE_UBUNTU_MEDIA_TRACK_H_
20 
21 #include <chrono>
22 #include <functional>
23 #include <map>
24 #include <memory>
25 #include <sstream>
26 #include <string>
27 #include <vector>
28 
29 namespace core
30 {
31 namespace ubuntu
32 {
33 namespace media
34 {
35 template<typename T> class Property;
36 
37 class Track
38 {
39 public:
40  typedef std::string UriType;
41  typedef std::string Id;
42 
43  class MetaData
44  {
45  public:
46  bool operator==(const MetaData& rhs) const
47  {
48  return map == rhs.map;
49  }
50 
51  bool operator!=(const MetaData& rhs) const
52  {
53  return map != rhs.map;
54  }
55 
56  template<typename Tag>
57  std::size_t count() const
58  {
59  return count(Tag::name());
60  }
61 
62  template<typename Tag>
63  void set(const typename Tag::ValueType& value)
64  {
65  std::stringstream ss; ss << value;
66  set(Tag::name(), ss.str());
67  }
68 
69  template<typename Tag>
70  typename Tag::ValueType get() const
71  {
72  std::stringstream ss(get(Tag::name()));
73  typename Tag::ValueType value; ss >> value;
74 
75  return std::move(value);
76  }
77 
78  std::size_t count(const std::string& key) const
79  {
80  return map.count(key);
81  }
82 
83  void set(const std::string& key, const std::string& value)
84  {
85  map[key] = value;
86  }
87 
88  const std::string& get(const std::string& key) const
89  {
90  return map.at(key);
91  }
92 
93  const std::map<std::string, std::string>& operator*() const
94  {
95  return map;
96  }
97 
98  private:
99  std::map<std::string, std::string> map;
100  };
101 
102  Track(const Id& id);
103  Track(const Track&) = delete;
104  virtual ~Track();
105 
106  Track& operator=(const Track&);
107  bool operator==(const Track&) const;
108 
109  virtual const Id& id() const;
110  /*
111  class MetaData
112  {
113  public:
114  MetaData() = default;
115  MetaData(const MetaData&) = default;
116  ~MetaData() = default;
117 
118  MetaData& operator=(const MetaData&) = default;
119 
120  bool operator==(const MetaData&) const
121  {
122  return true;
123  }
124 
125  bool operator!=(const MetaData&) const
126  {
127  return false;
128  }
129 
130  struct NotImplementedFields
131  {
132  NotImplementedFields() = default;
133 
134  virtual const UriType& uri() const = 0;
135  virtual const std::chrono::microseconds length() const = 0;
136  virtual const UriType& art_uri() const = 0;
137  virtual const std::string& album() const = 0;
138  virtual const std::vector<std::string>& album_artist() const = 0;
139  virtual const std::vector<std::string>& artist() const = 0;
140  virtual const std::string& as_text() const = 0;
141  virtual unsigned int audio_bpm() const = 0;
142  virtual float auto_rating() const = 0;
143  virtual const std::vector<std::string>& comment() const = 0;
144  virtual const std::vector<std::string>& composer() const = 0;
145  virtual unsigned int disc_number() const = 0;
146  virtual const std::vector<std::string>& genre() const = 0;
147  virtual const std::vector<std::string>& lyricist() const = 0;
148  virtual const std::string title() const = 0;
149  virtual unsigned int track_number() const = 0;
150  virtual unsigned int use_count() const = 0;
151  virtual float user_rating() const = 0;
152  };
153  };
154 */
155 private:
156  struct Private;
157  std::unique_ptr<Private> d;
158 };
159 }
160 }
161 }
162 
163 #endif // CORE_UBUNTU_MEDIA_TRACK_H_
bool operator==(const MetaData &rhs) const
Definition: track.h:46
Track & operator=(const Track &)
const std::map< std::string, std::string > & operator*() const
Definition: track.h:93
Definition: player.h:29
void set(const typename Tag::ValueType &value)
Definition: track.h:63
bool operator!=(const MetaData &rhs) const
Definition: track.h:51
void set(const std::string &key, const std::string &value)
Definition: track.h:83
virtual const Id & id() const
std::size_t count(const std::string &key) const
Definition: track.h:78
std::string UriType
Definition: track.h:40
std::size_t count() const
Definition: track.h:57
bool operator==(const Track &) const