Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

music.cpp

Go to the documentation of this file.
00001 #include "music.h"
00002 #include <SDL/SDL_mixer.h>
00003 #include <iostream>
00004 #include <string>
00005 
00006 using namespace std;
00007 
00008 //default const NF
00009 Music::Music() : music(NULL), name(NULL), playing(false) {}
00010 
00011 //Takes a pathname and loads the music associated with it. NF
00012 Music::Music(string fileName) {
00013         music = Mix_LoadMUS(fileName.c_str());
00014         if (!music) {
00015                 cerr << "Mix_LoadMUS Error: " << Mix_GetError() << endl;
00016                 //exit(0);
00017         }
00018         name = fileName;
00019         playing = false;
00020 }
00021 
00022 //destructor
00023 Music::~Music() {
00024         Mix_FreeMusic(music);
00025         music = NULL;
00026         playing = false;
00027 }
00028 
00029 //Plays the music loops + 1 times.  If loops == -1 plays infinitely.
00030 bool Music::Play(int loops) {
00031         if (playing) return false;
00032         int success;
00033         success = Mix_PlayMusic(music, loops);
00034         if (success < 0) {
00035                 cerr << "Mix_PlayMusic Error: " << Mix_GetError() << endl;
00036                 return false;
00037         }
00038         playing = true;
00039         return true;
00040 }
00041 
00042 /*bool Music::Play(vector<Music *> &mVec, int loops) {
00043   return true;
00044   }*/
00045 
00046 
00047 //stops the music if it is playing. NF
00048 bool Music::Stop() {
00049         if (!playing) return false;
00050         Mix_HaltMusic();
00051         playing = false;
00052         return true; 
00053 }
00054 
00055 bool Music::IsPlaying() {
00056         return playing;
00057 }

Generated on Sun Dec 8 12:02:19 2002 for nnc by doxygen1.3-rc1