libvisual  0.5.0
lv_songinfo.cpp
1 /* Libvisual - The audio visualisation framework.
2  *
3  * Copyright (C) 2012 Libvisual team
4  *
5  * Authors: Chong Kai Xiong <kaixiong@codeleft.sg>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */
21 
22 #include "config.h"
23 #include "lv_songinfo.h"
24 #include "lv_common.h"
25 #include "lv_libvisual.h"
26 
27 namespace LV {
28 
29  SongInfo::SongInfo (SongInfoType type)
30  : m_type (type)
31  , m_length (0)
32  , m_elapsed (0)
33  {
34  // empty
35  }
36 
37  SongInfo::~SongInfo ()
38  {
39  // empty
40  }
41 
42  void SongInfo::set_type (SongInfoType type)
43  {
44  m_type = type;
45  }
46 
47  SongInfoType SongInfo::get_type () const
48  {
49  return m_type;
50  }
51 
52  void SongInfo::set_length (int length)
53  {
54  m_length = length;
55  }
56 
57  int SongInfo::get_length () const
58  {
59  return m_length;
60  }
61 
62  void SongInfo::set_elapsed (int elapsed)
63  {
64  m_elapsed = elapsed;
65  }
66 
67  int SongInfo::get_elapsed () const
68  {
69  return m_elapsed;
70  }
71 
72  void SongInfo::set_simple_name (std::string const& name)
73  {
74  m_song_name = name;
75  }
76 
77  std::string SongInfo::get_simple_name () const
78  {
79  return m_song_name;
80  }
81 
82  void SongInfo::set_artist (std::string const& artist)
83  {
84  m_artist = artist;
85  }
86 
87  std::string SongInfo::get_artist () const
88  {
89  return m_artist;
90  }
91 
92  void SongInfo::set_album (std::string const& album)
93  {
94  m_album = album;
95  }
96 
97  std::string SongInfo::get_album () const
98  {
99  return m_album;
100  }
101 
102  void SongInfo::set_song (std::string const& song)
103  {
104  m_song = song;
105  }
106 
107  std::string SongInfo::get_song () const
108  {
109  return m_song;
110  }
111 
112  void SongInfo::set_cover (VideoPtr const& cover)
113  {
114  // Get the desired cover art size
115  auto& system_params = LV::System::instance()->get_params ();
116  auto xparam = system_params.get ("songinfo-cover-width");
117  auto yparam = system_params.get ("songinfo-cover-height");
118 
119  int cover_width = 64;
120  int cover_height = 64;
121 
122  if (xparam && yparam) {
123  cover_width = visual_param_get_value_integer (xparam);
124  cover_height = visual_param_get_value_integer (yparam);
125  }
126 
127  // The coverart image
128  m_cover = Video::create_scale_depth (cover, cover_width, cover_height,
131  }
132 
133  void SongInfo::mark ()
134  {
135  m_timer.start ();
136  }
137 
138  long SongInfo::get_age ()
139  {
140  auto cur = Time::now ();
141  auto start_time = m_timer.get_start_time ();
142 
143  // Clock has been changed into the past
144  if (cur < start_time)
145  mark ();
146 
147  cur -= start_time;
148 
149  return cur.sec;
150  }
151 
152  bool operator== (SongInfo const& lhs, SongInfo const& rhs)
153  {
154  if (lhs.m_song_name != rhs.m_song_name)
155  return false;
156 
157  if (lhs.m_artist != rhs.m_artist)
158  return false;
159 
160  if (lhs.m_album != rhs.m_album)
161  return false;
162 
163  if (lhs.m_song != rhs.m_song)
164  return false;
165 
166  return true;
167  }
168 
169 } // LV namespace