/* Echo Media Player
* Copyright (C) 2008 Shane O'Connell
*
* [ The original file includes a copyright header in this location describing
* the file as being released under the terms of the GNU General Public
* License. It has been removed in order to display the file as part of the
* archive. ]
*/
#include "DbPlaySource.h"
#include <iostream>
using namespace std;
TrackRef DbPlaySource::get_track(int index) const
{
assert(index >= 0);
assert(index < get_num_tracks());
if (m_track_cache_index >= 0
&& index >= m_track_cache_index
&& index < (m_track_cache_index + (int)m_track_cache.size())) {
return m_track_cache[index - m_track_cache_index];
}
m_track_cache_index = index - (m_track_cache.size() / 2);
if (m_track_cache_index < 0)
m_track_cache_index = 0;
m_get_track_stmt.bind(1, m_track_cache_index);
for (int i = 0; i < (int)m_track_cache.size(); i++) {
if (!m_get_track_stmt.step())
break;
m_track_cache[i]->_artist = StringRef(new Glib::ustring(m_get_track_stmt.get_column_text(0)));
m_track_cache[i]->_album = StringRef(new Glib::ustring(m_get_track_stmt.get_column_text(1)));
// release_date = m_get_track_stmt.get_column_int(2);
m_track_cache[i]->_title = m_get_track_stmt.get_column_text(3);
m_track_cache[i]->_track_number = m_get_track_stmt.get_column_int(4);
m_track_cache[i]->_uri = m_get_track_stmt.get_column_text(5);
}
m_get_track_stmt.reset();
return m_track_cache[index - m_track_cache_index];
}