00001 /* 00002 libwt - Vassilis Virvilis Toolkit - a widget library 00003 Copyright (C) 2006 Vassilis Virvilis <vasvir2@fastmail.fm> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public 00007 License as published by the Free Software Foundation; either 00008 version 2.1 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with this library; if not, write to the 00017 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00018 Boston, MA 02111-1307, SA. 00019 */ 00020 00021 #include <wt/sound.h> 00022 00023 namespace Wt { 00024 00025 Sound::Sound(const std::string& filename) 00026 : chunk(Audio::instance()->loadChunk(filename)), 00027 filename_(filename) {} 00028 00029 Sound::Sound() 00030 : chunk(static_cast<Audio::Chunk *>(0)) {} 00031 00032 const std::string& Sound::fileName() const { 00033 return filename_; 00034 } 00035 00036 bool Sound::isFinished() const { 00037 return (chunk) ? !chunk->playing() : true; 00038 } 00039 00040 void Sound::play() { 00041 if (chunk) { 00042 detach(); 00043 chunk->play(); 00044 } 00045 } 00046 00047 void Sound::stop() { 00048 if (chunk) { 00049 detach(); 00050 chunk->stop(); 00051 } 00052 } 00053 00054 void Sound::detach() { 00055 //avoid detaching if we are the only client for this Sound 00056 if (!chunk.unique()) { 00057 chunk.reset(chunk->clone()); 00058 } 00059 } 00060 00061 bool Sound::available() { 00062 return Audio::instance()->isAvailable(); 00063 } 00064 00065 bool Sound::isAvailable() { 00066 return Audio::instance()->isAvailable(); 00067 } 00068 00069 static void finished_chunk(Audio::Chunk *c) { 00070 delete c; 00071 } 00072 00073 void Sound::play(const std::string& filename) { 00074 Audio::Chunk *c = Audio::instance()->loadChunk(filename); 00075 if (c) { 00076 c->finished.connect(sigc::slot1<void, 00077 Audio::Chunk *>(sigc::ptr_fun(&finished_chunk))); 00078 c->play(); 00079 } 00080 } 00081 00082 } // namespace Wt
This document is licensed under the terms of the GNU Free Documentation License and may be freely distributed under the conditions given by this license.