summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mg_playlist.c82
-rw-r--r--mg_playlist.h22
-rw-r--r--vdr_player.c20
3 files changed, 56 insertions, 68 deletions
diff --git a/mg_playlist.c b/mg_playlist.c
index 8f9303d..38d4d0f 100644
--- a/mg_playlist.c
+++ b/mg_playlist.c
@@ -2,8 +2,8 @@
* \file mg_playlist.c
* \brief defines functions to be executed on playlists for the vdr muggle plugindatabase
*
- * \version $Revision: 1.4 $
- * \date $Date: 2004/07/25 21:33:35 $
+ * \version $Revision: 1.5 $
+ * \date $Date: 2004/07/26 22:20:54 $
* \author Ralf Klueber, Lars von Wedel, Andreas Kellner
* \author Responsible author: $Author: lvw $
*
@@ -24,7 +24,7 @@ using namespace std;
mgPlaylist::mgPlaylist()
{
- m_current_idx = 0;
+ m_current_idx = -1;
char *buffer;
asprintf( &buffer, "Playlist-%ld", random() );
@@ -54,7 +54,7 @@ void mgPlaylist::toggleLoop()
void mgPlaylist::initialize()
{
- m_current_idx = -1;
+ m_current_idx = 0;
}
/* ==== add/remove tracks ==== */
@@ -66,7 +66,7 @@ void mgPlaylist::append(mgContentItem* item)
}
/* append a list of tracks at the end of the playlist */
-void mgPlaylist::appendList(vector<mgContentItem*> *tracks)
+void mgPlaylist::appendList( vector<mgContentItem*> *tracks )
{
vector<mgContentItem*>::iterator iter;
@@ -82,7 +82,7 @@ void mgPlaylist::appendList(vector<mgContentItem*> *tracks)
}
/* add a song after 'position' */
-void mgPlaylist::insert(mgContentItem* item, unsigned int position)
+void mgPlaylist::insert( mgContentItem* item, unsigned int position )
{
if( position >= m_list.size() )
{
@@ -136,80 +136,64 @@ int mgPlaylist::count()
}
// returns the first item of the list
-mgContentItem* mgPlaylist::getFirst()
+mgContentItem* mgPlaylist::getCurrent()
{
- m_current = m_list.begin();
- m_current_idx = 0;
-
- return *m_current;
+ return *( m_list.begin() + m_current_idx );
}
// returns the nth track from the playlist
-mgContentItem* mgPlaylist::getPosition(unsigned int position)
+void mgPlaylist::gotoPosition(unsigned int position)
{
if( position >= m_list.size() )
{
// TODO: why not return a NULL pointer? LVW
- return &(mgContentItem::UNDEFINED); //invalid
+ m_current_idx = -1;
+ }
+ else
+ {
+ m_current_idx = position;
}
- m_current = m_list.begin() + position;
-
- return *m_current;
}
// proceeds to the next item
-mgContentItem* mgPlaylist::skipFwd()
+void mgPlaylist::skipFwd()
{
- mgContentItem* next;
-
- if( m_current_idx < 0 )
+ if( m_current_idx + 1 <= m_list.size() ) // unless loop mode
{
- return getFirst();
- }
-
- if( m_current + 1 == m_list.end() ) // unless loop mode
- {
- // TODO: why not return a NULL pointer? LVW
- next = &(mgContentItem::UNDEFINED); //invalid item
+ m_current_idx ++;
}
else
{
- return * (++ m_current);
+ // or goto 1 in case of loop mode
+ m_current_idx = -1;
}
-
- return next;
}
// goes back to the previous item
-mgContentItem* mgPlaylist::skipBack()
+void mgPlaylist::skipBack()
{
- mgContentItem* prev;
-
- if( m_current == m_list.begin() )
+ if( m_current_idx > 0 )
{
- // TODO: why not return a NULL pointer? LVW
- prev = &(mgContentItem::UNDEFINED); //invalid
+ m_current_idx --;
}
else
{
- prev = * (--m_current);
+ // or goto last in case of loop mode
+ m_current_idx = -1;
}
-
- return prev;
}
// get next track, do not update data structures
mgContentItem* mgPlaylist::sneakNext()
{
- if( m_current+1 == m_list.end() )
- {
- // TODO: why not return a NULL pointer? LVW
- return &(mgContentItem::UNDEFINED); //invalid
- }
- else
- {
- return * (m_current+1);
- }
+ if( m_current_idx + 1 <= m_list.size() ) // unless loop mode
+ {
+ return *(m_list.begin() + m_current_idx + 1);
+ }
+ else
+ {
+ return &(mgContentItem::UNDEFINED);
+ }
}
bool mgPlaylist::exportM3U( string m3u_file )
@@ -229,7 +213,7 @@ bool mgPlaylist::exportM3U( string m3u_file )
for( iter = m_list.begin(); iter != m_list.end(); iter++ )
{ // each item in the list
- fprintf( listfile, "#EXTINF:0,%s", (*iter)->getLabel().c_str() );
+ fprintf( listfile, "#EXTINF:0,%s\n", (*iter)->getLabel().c_str() );
fprintf( listfile, "%s", (*iter)->getSourceFile().c_str() );
}
diff --git a/mg_playlist.h b/mg_playlist.h
index 4a0da71..df677d4 100644
--- a/mg_playlist.h
+++ b/mg_playlist.h
@@ -2,8 +2,8 @@
* \file mg_playlist.c
* \brief defines functions to be executed on playlists for the vdr muggle plugindatabase
*
- * \version $Revision: 1.5 $
- * \date $Date: 2004/07/25 21:33:35 $
+ * \version $Revision: 1.6 $
+ * \date $Date: 2004/07/26 22:20:55 $
* \author Ralf Klueber, Lars von Wedel, Andreas Kellner
* \author Responsible author: $Author: lvw $
*
@@ -29,6 +29,7 @@ class mgPlaylist : public mgTracklist
{
private:
+
//! \brief current index in the playlist
// TODO: should be a property of the player?
int m_current_idx;
@@ -40,9 +41,6 @@ protected:
//! \brief the name of the playlist
std::string m_listname;
- //! \brief the current item as an iterator
- std::vector<mgContentItem*>::iterator m_current;
-
public:
/* ==== constructors and initialization ==== */
@@ -114,6 +112,9 @@ public:
//! \brief obtain the listname
std::string getListname() ;
+ //! \brief returns the current item of the list
+ virtual mgContentItem* getCurrent();
+
/*! \brief set the listname
*
* \param name - the new name of this list
@@ -123,24 +124,21 @@ public:
//! \brief returns the count of items in the list
int count();
- //! \brief returns the first item of the list
- virtual mgContentItem* getFirst();
-
/*! \brief returns the nth track from the playlist
*
* \param position - the position to skip to
*/
- virtual mgContentItem* getPosition(unsigned int position);
+ virtual void gotoPosition(unsigned int position);
//! \brief proceeds to the next item
- virtual mgContentItem* skipFwd();
+ virtual void skipFwd();
//! \brief goes back to the previous item
- virtual mgContentItem* skipBack();
+ virtual void skipBack();
//! \brief obtain the next item without skipping the current position
virtual mgContentItem* sneakNext();
- virtual bool storePlaylist()=0;
+ virtual bool storePlaylist() = 0;
//! \brief export the playlist in m3u format
virtual bool exportM3U( std::string m3u_file );
diff --git a/vdr_player.c b/vdr_player.c
index 36a712b..bc790f4 100644
--- a/vdr_player.c
+++ b/vdr_player.c
@@ -2,12 +2,12 @@
* \file vdr_player.c
* \brief A generic PCM player for a VDR media plugin (muggle)
*
- * \version $Revision: 1.5 $
- * \date $Date: 2004/07/26 20:03:00 $
+ * \version $Revision: 1.6 $
+ * \date $Date: 2004/07/26 22:20:55 $
* \author Ralf Klueber, Lars von Wedel, Andreas Kellner
* \author Responsible author: $Author: lvw $
*
- * $Id: vdr_player.c,v 1.5 2004/07/26 20:03:00 lvw Exp $
+ * $Id: vdr_player.c,v 1.6 2004/07/26 22:20:55 lvw Exp $
*
* Adapted from
* MP3/MPlayer plugin to VDR (C++)
@@ -707,7 +707,8 @@ bool mgPCMPlayer::NextFile()
{
bool res = false;
- mgContentItem *newcurr = m_playlist->skipFwd();
+ m_playlist->skipFwd();
+ mgContentItem *newcurr = m_playlist->getCurrent();
if( newcurr && newcurr != &(mgContentItem::UNDEFINED) )
{
@@ -722,7 +723,8 @@ bool mgPCMPlayer::PrevFile(void)
{
bool res = false;
- mgContentItem *newcurr = m_playlist->skipBack();
+ m_playlist->skipBack();
+ mgContentItem *newcurr = m_playlist->getCurrent();
if( newcurr && newcurr != &(mgContentItem::UNDEFINED) )
{
@@ -803,9 +805,10 @@ void mgPCMPlayer::Backward(void)
void mgPCMPlayer::Goto( int index, bool still )
{
- mgContentItem *next = m_playlist->getPosition( index-1 );
+ m_playlist->gotoPosition( index-1 );
+ mgContentItem *next = m_playlist->getCurrent();
- if( next != &(mgContentItem::UNDEFINED) ) //invalid
+ if( next && next != &(mgContentItem::UNDEFINED) ) //invalid
{
Lock();
StopPlay();
@@ -1047,6 +1050,9 @@ eOSState mgPlayerControl::ProcessKey(eKeys key)
/************************************************************
*
* $Log: vdr_player.c,v $
+ * Revision 1.6 2004/07/26 22:20:55 lvw
+ * Reworked playlist indexing
+ *
* Revision 1.5 2004/07/26 20:03:00 lvw
* Bug in initalizing playlist removed
*