diff options
author | lvw <lvw@e10066b5-e1e2-0310-b819-94efdf66514b> | 2004-10-08 15:10:50 +0000 |
---|---|---|
committer | lvw <lvw@e10066b5-e1e2-0310-b819-94efdf66514b> | 2004-10-08 15:10:50 +0000 |
commit | a5b382c907acc3474b0800b4cc868cd0ed153851 (patch) | |
tree | fed04ffd34787113e057e84b29888323912151a1 | |
parent | 58177a6fe280784452dee940bb93f17bb6329a9a (diff) | |
download | vdr-plugin-muggle-a5b382c907acc3474b0800b4cc868cd0ed153851.tar.gz vdr-plugin-muggle-a5b382c907acc3474b0800b4cc868cd0ed153851.tar.bz2 |
Added loop mode handling
git-svn-id: https://vdr-muggle.svn.sourceforge.net/svnroot/vdr-muggle/trunk/muggle-plugin@210 e10066b5-e1e2-0310-b819-94efdf66514b
-rw-r--r-- | mg_playlist.c | 66 | ||||
-rw-r--r-- | mg_playlist.h | 86 | ||||
-rwxr-xr-x | mugglei.c | 19 |
3 files changed, 131 insertions, 40 deletions
diff --git a/mg_playlist.c b/mg_playlist.c index 988f35d..86d3d8e 100644 --- a/mg_playlist.c +++ b/mg_playlist.c @@ -20,9 +20,6 @@ #include <vector> #include <iostream> - -/* ==== constructors ==== */ - mgPlaylist::mgPlaylist() { m_current_idx = -1; @@ -45,17 +42,21 @@ mgPlaylist::~mgPlaylist() { } -void mgPlaylist::toggleShuffle() +void mgPlaylist::setLoopMode( LoopMode lm ) { + m_loop_mode = lm; } -void mgPlaylist::toggleLoop() +void mgPlaylist::setShuffleMode( ShuffleMode sm ) { + m_shuffle_mode = sm; } void mgPlaylist::initialize() { m_current_idx = 0; + m_loop_mode = mgPlaylist::LM_NONE; + m_shuffle_mode = mgPlaylist::SM_NONE; } /* ==== add/remove tracks ==== */ @@ -148,7 +149,6 @@ void mgPlaylist::move( int from, int to ) } } -/*==== access tracks ====*/ std::string mgPlaylist::getListname() { return m_listname; @@ -207,9 +207,23 @@ bool mgPlaylist::skipFwd() { bool result = false; - if( m_current_idx + 1 < (int) m_list.size() ) // unless loop mode + if( m_loop_mode == mgPlaylist::LM_SINGLE ) { - m_current_idx ++; + result = true; + } + else + { + if( m_current_idx + 1 < (int) m_list.size() ) // unless loop mode + { + m_current_idx ++; + } + else + { + if( m_loop_mode == mgPlaylist::LM_FULL ) + { + m_current_idx = 0; + } + } result = true; } @@ -222,12 +236,25 @@ bool mgPlaylist::skipBack() { bool result = false; - if( m_current_idx > 0 ) + if( m_loop_mode == mgPlaylist::LM_SINGLE ) { - m_current_idx --; result = true; } - + else + { + if( m_current_idx > 0 ) + { + m_current_idx --; + } + else + { + if( m_loop_mode == mgPlaylist::LM_FULL ) + { + m_current_idx = m_list.size() -1; + } + } + result = true; + } // if we are at the beginning -- just do nothing unless in loop mode return result; } @@ -235,14 +262,25 @@ bool mgPlaylist::skipBack() // get next track, do not update data structures mgContentItem* mgPlaylist::sneakNext() { + mgContentItem* result; + if( m_current_idx + 1 <= (int) m_list.size() ) // unless loop mode { - return *(m_list.begin() + m_current_idx + 1); + result = *(m_list.begin() + m_current_idx + 1); } else { - return &(mgContentItem::UNDEFINED); + if( m_loop_mode == mgPlaylist::LM_FULL ) + { + result = *(m_list.begin()); + } + else + { + return &(mgContentItem::UNDEFINED); + } } + + return result; } bool mgPlaylist::exportM3U( std::string m3u_file ) @@ -262,7 +300,7 @@ bool mgPlaylist::exportM3U( std::string m3u_file ) for( iter = m_list.begin(); iter != m_list.end(); iter++ ) { // each item in the list - fprintf( listfile, "#EXTINF:0,%s\n", (*iter)->getLabel().c_str() ); + fprintf( listfile, "#EXTINF:%d,%s\n", (*iter)->getLength(), (*iter)->getLabel().c_str() ); fprintf( listfile, "%s", (*iter)->getSourceFile().c_str() ); } diff --git a/mg_playlist.h b/mg_playlist.h index d35dec0..a0ff4c2 100644 --- a/mg_playlist.h +++ b/mg_playlist.h @@ -36,6 +36,12 @@ private: // TODO: should be a property of the player? int m_current_idx; + //! \brief the current loop mode + LoopMode m_loop_mode; + + //! \brief the current shuffle mode + ShuffleMode m_shuffle_mode; + protected: // TODO: Why not make these private? Subclasses should use access functions. LVW @@ -44,9 +50,26 @@ protected: std::string m_listname; public: - - /* ==== constructors and initialization ==== */ - + + //! \brief define various ways to play music in random order + enum + { + SM_NONE, //!< \brief play normal sequence + SM_NORMAL, //!< \brief a shuffle with a fair distribution + SM_PARTY //!< \brief select the next few songs randomly, continue forever + } ShuffleMode; + + //! \brief define various ways to play music in a neverending loop + enum + { + LM_NONE, //!< \brief do not loop + LM_SINGLE, //!< \brief loop a single track + LM_FULL //!< \brief loop the whole playlist + } LoopMode; + + //! \brief object construction and destruction + //@{ + //! \brief the default constructor (random listname) mgPlaylist(); @@ -58,20 +81,24 @@ public: void initialize(); - /* ==== destructor ==== */ //! \brief the destructor virtual ~mgPlaylist(); - /* === control behavior */ + //@} - //! \brief toggle the loop mode. TODO. - void toggleLoop(); + //! \brief control behavior + //@{ - //! \brief toggle the shuffle mode. TODO. - void toggleShuffle(); - - /* ==== add/ remove tracks ==== */ + //! \brief toggle the loop mode. + void setLoopMode( LoopMode lm ); + + //! \brief toggle the shuffle mode. + void setShuffleMode( ShuffleMode sm ); + + //@} + //! \brief modify playlist items + //@{ /*! \brief adds a song at the end of the playlist * * \param item - the item to be appended @@ -94,7 +121,7 @@ public: virtual void insert(mgContentItem* item, unsigned int position); //! \brief clear all tracks - virtual void clear(); +m virtual void clear(); /*! \brief move tracks within playlist * @@ -109,18 +136,11 @@ public: */ bool remove( int pos ); - /* ==== access tracks ==== */ - + //@} + //! \brief obtain the listname std::string getListname() ; - /*! - * \brief returns the current item of the list - * - * \todo Return null in case of an empty list or invalid index - */ - virtual mgContentItem* getCurrent(); - /*! \brief set the listname * * \param name - the new name of this list @@ -130,9 +150,25 @@ public: //! \brief returns the count of items in the list int getCount(); + //! \brief access playlist items + //@{ + //! \brief returns current index in the playlist int getIndex() const; + //! \brief make playlist persistent + virtual bool storePlaylist() = 0; + + //! \brief export the playlist in m3u format + virtual bool exportM3U( std::string m3u_file ); + + /*! + * \brief returns the current item of the list + * + * \todo Return null in case of an empty list or invalid index + */ + virtual mgContentItem* getCurrent(); + /*! \brief returns the nth track from the playlist * * \param position - the position to skip to @@ -155,13 +191,11 @@ public: * \todo Handle play modes */ virtual bool skipBack(); - + //! \brief obtain the next item without skipping the current position virtual mgContentItem* sneakNext(); - virtual bool storePlaylist() = 0; - - //! \brief export the playlist in m3u format - virtual bool exportM3U( std::string m3u_file ); + //@} + }; #endif @@ -106,6 +106,25 @@ long find_file_in_database( MYSQL *db, std::string filename ) return atol( row[0] ); } +TagLib::String find_genre_id( TagLib::String genre ) +{ + TagLib::String result; + + if( genre.size() ) + { + MYSQL_RES *result = mgSqlReadQuery( db, "SELECT id FROM genre WHERE genre=\"%s\"", genre.toCString() ); + + if( mysql_num_rows(result) ) + { + MYSQL_ROW row = mysql_fetch_row( result ); + + result = TagLib::String( row[0] ); + } + } + + return result; +} + // read tags from the mp3 file and store them into the corresponding database entry void update_db( long uid, std::string filename ) { |