]> git.tdb.fi Git - libs/al.git/blobdiff - source/jukebox.cpp
Split Sound into SoundDecoder and Waveform parts
[libs/al.git] / source / jukebox.cpp
index b8224b29596acd234f67c5cb22c7104cbb6eb83d..02a33cdfee3e1d55e56eed59b647b7fe630131a0 100644 (file)
@@ -1,15 +1,8 @@
-/* $Id$
-
-This file is part of libmspal
-Copyright © 2009  Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
 #include <algorithm>
 #include <cstdlib>
-#include <msp/core/except.h>
+#include <stdexcept>
 #include "jukebox.h"
-#include "sound.h"
+#include "sounddecoder.h"
 
 using namespace std;
 
@@ -18,7 +11,7 @@ namespace AL {
 
 Jukebox::Jukebox():
        streamer(source),
-       sound(0),
+       decoder(0),
        current_track(tracks.end()),
        shuffle(false)
 { }
@@ -26,30 +19,30 @@ Jukebox::Jukebox():
 Jukebox::~Jukebox()
 {
        streamer.stop();
-       delete sound;
+       delete decoder;
 }
 
 void Jukebox::add_track(const string &trk)
 {
-       bool was_empty=tracks.empty();
+       bool was_empty = tracks.empty();
        tracks.push_back(trk);
        if(was_empty)
        {
-               current_track=tracks.begin();
+               current_track = tracks.begin();
                signal_track_changed.emit(*current_track);
        }
 }
 
 void Jukebox::remove_track(const string &trk)
 {
-       list<string>::iterator i=find(tracks.begin(), tracks.end(), trk);
+       list<string>::iterator i = find(tracks.begin(), tracks.end(), trk);
        if(i!=tracks.end())
        {
                if(i==current_track)
                        next();
                tracks.erase(i);
                if(tracks.empty())
-                       current_track=tracks.end();
+                       current_track = tracks.end();
        }
 }
 
@@ -57,29 +50,29 @@ void Jukebox::clear_tracks()
 {
        stop();
        tracks.clear();
-       current_track=tracks.end();
+       current_track = tracks.end();
 }
 
 const string &Jukebox::get_current_track() const
 {
        if(tracks.empty())
-               throw InvalidState("No current track");
+               throw logic_error("No current track");
        return *current_track;
 }
 
 void Jukebox::set_shuffle(bool s)
 {
-       shuffle=s;
+       shuffle = s;
 }
 
 void Jukebox::play()
 {
-       if(tracks.empty() || sound)
+       if(tracks.empty() || decoder)
                return;
 
-       sound=new AL::Sound;
-       sound->open_file(*current_track);
-       streamer.play(*sound);
+       decoder = new AL::SoundDecoder;
+       decoder->open_file(*current_track);
+       streamer.play(*decoder);
 }
 
 void Jukebox::next()
@@ -91,7 +84,7 @@ void Jukebox::next()
                {
                        while(1)
                        {
-                               list<string>::iterator i=tracks.begin();
+                               list<string>::iterator i = tracks.begin();
                                advance(i, rand()%tracks.size());
                                if(i!=current_track)
                                {
@@ -104,7 +97,7 @@ void Jukebox::next()
                {
                        ++current_track;
                        if(current_track==tracks.end())
-                               current_track=tracks.begin();
+                               current_track = tracks.begin();
                }
                signal_track_changed.emit(*current_track);
        }
@@ -120,7 +113,7 @@ void Jukebox::previous()
        if(tracks.size()>1)
        {
                if(current_track==tracks.begin())
-                       current_track=tracks.end();
+                       current_track = tracks.end();
                --current_track;
                signal_track_changed.emit(*current_track);
        }
@@ -130,14 +123,14 @@ void Jukebox::previous()
 void Jukebox::stop()
 {
        streamer.stop();
-       delete sound;
-       sound=0;
+       delete decoder;
+       decoder = 0;
 }
 
 void Jukebox::tick()
 {
        streamer.tick();
-       if(sound && sound->eof())
+       if(decoder && decoder->eof())
                next();
 }