src/tools/tPlayList.cpp

Go to the documentation of this file.
00001 /*
00002 
00003 *************************************************************************
00004 
00005 ArmageTron -- Just another Tron Lightcycle Game in 3D.
00006 Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
00007 
00008 **************************************************************************
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00023 
00024 ***************************************************************************
00025 
00026 tPlayList by Dave Fancella
00027 
00028 */
00029 
00030 #include "tDirectories.h"
00031 #include "tPlayList.h"
00032 #include <fstream>
00033 #include <iostream>
00034 #include "tString.h"
00035 #include <algorithm>
00036 #include "tConsole.h"
00037 
00038 tSong::tSong() {
00039     // do nothing constructor
00040 }
00041 
00042 tSong::tSong(tString& pathToSong) {
00043     location = pathToSong;
00044 }
00045 
00046 tSong::tSong(const tSong& copySong) {
00047     location = copySong.location;
00048 }
00049 
00050 tPlayList::tPlayList() {
00051 }
00052 
00053 void tPlayList::Randomize() {
00054     std::random_shuffle(m_Playlist.begin(), m_Playlist.end());
00055     m_CurrentSong = m_Playlist.begin();
00056 }
00057 
00058 const tSong& tPlayList::GetNextSong() {
00059     std::cout << "Getting next song from playlist\n";
00060     if(m_CurrentSong == m_Playlist.end() ) {
00061         m_CurrentSong = m_Playlist.begin();
00062     } else {
00063         if(m_Playlist.size() > 1)
00064             m_CurrentSong++;
00065         if(m_CurrentSong == m_Playlist.end() )
00066             m_CurrentSong = m_Playlist.begin();
00067     }
00068     std::cout << "Got song:" << (*m_CurrentSong).location << "\n";
00069     return (*m_CurrentSong);
00070 }
00071 
00072 const tSong& tPlayList::GetPreviousSong() {
00073     std::cout << "Getting previous song from playlist\n";
00074     if(m_CurrentSong == m_Playlist.begin() ) {
00075         m_CurrentSong = m_Playlist.end();
00076         m_CurrentSong--;
00077     } else {
00078         if(m_Playlist.size() > 1)
00079             m_CurrentSong--;
00080     }
00081     std::cout << "Got song:" << (*m_CurrentSong).location << "\n";
00082     return (*m_CurrentSong);
00083 }
00084 
00085 bool tPlayList::LoadPlaylist(const char *playlist) {
00086     std::ifstream playList(playlist);
00087     if(playList.good() ) {
00088         std::cout << "Opened playlist\n";
00089     } else {
00090         std::cout << "Couldn't open playlist\n";
00091         return false;
00092     }
00093     while(! playList.eof() && playList.good() ) {
00094         tString oneLine;
00095 
00096         oneLine.ReadLine( playList );
00097         oneLine = oneLine.Trim();
00098 
00099         // We only care about lines that start with '#', those are music files
00100         // Also, we require a playlist entry to be at least 2 characters long
00101         if(! oneLine.StartsWith("#") && oneLine.Len() > 2) {
00102             const tPath& vpath = tDirectories::Data();
00103             tSong newSong(oneLine);
00104             if(usePlaylist == PLAYLIST_INTERNAL) {
00105                 newSong.location = vpath.GetReadPath(oneLine);
00106                 //std::cout << newSong.location << "\n";
00107             }
00108             m_Playlist.push_back( newSong );
00109             //std::cout << newSong.location.GetFileMimeExtension() << "\n";
00110             tSong last = m_Playlist.back();
00111         }
00112     }
00113 
00114     m_CurrentSong = m_Playlist.begin();
00115 
00116     /*/ add at least one song
00117     if ( m_Playlist.empty() )
00118         m_Playlist.push_back( tSong() );*/
00119 
00120     return true;
00121 }
00122 
00123 bool tPlayList::empty() {
00124     return m_Playlist.empty();
00125 }
00126 
00127 
00128 
00129 
00130 
00131 

Generated on Sat Mar 15 22:56:01 2008 for Armagetron Advanced by  doxygen 1.5.4