SoundOutputAgent.cpp

Go to the documentation of this file.
00001 /*
00002  * This file is part of Micole Architecture
00003  *
00004  * Copyright (C) 2007 Micole partners
00005  *
00006  * Micole Architecture is free software: you can redistribute it 
00007  * and/or modify it under the terms of the GNU Lesser General 
00008  * Public License as published by the Free Software Foundation, 
00009  * either version 3 of the License, or (at your option) any 
00010  * later version.
00011  *
00012  * Micole Architecture is distributed in the hope that it will be 
00013  * useful, * but WITHOUT ANY WARRANTY; without even the implied 
00014  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00015  * PURPOSE.  See the GNU Lesser General Public License for more 
00016  * details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with Micole Architecture.  If not, see
00020  * <http://www.gnu.org/licenses/>.
00021  */
00022 
00023 #include "SoundOutputAgent.h"
00024 #include "ReachinMicoleApplication.h"
00025 #include "MicoleAgentThread.h"
00026 
00027 
00028 SoundOutputAgent::SoundOutputAgent(const string &lan): MicoleAgent("SoundOutputAgent","SenderAgent")  
00029 {
00030         //set language of choice
00031         language = lan;
00032 
00033         bindMessage( "^PlaySound(.*)", BUS_CALLBACK_OF(SoundOutputAgent, handlePlaySoundMessage ));
00034         bindMessage( "^StopSound(.*)", BUS_CALLBACK_OF(SoundOutputAgent, handleStopSoundMessage ));
00035         bindMessage( "^PauseSound(.*)", BUS_CALLBACK_OF(SoundOutputAgent, handlePauseSoundMessage ));
00036         bindMessage( "^CancelSound(.*)", BUS_CALLBACK_OF(SoundOutputAgent, handleCancelSoundMessage ));
00037 
00038         LoadLibrary("ALSound_d.dll");
00039         dis = ReachinMicoleApplication::getInstance()->getDisplay();
00040 }
00041 
00042 
00043 void SoundOutputAgent::handlePlaySoundMessage(IvyApplication *app, int argc, const char **argv)
00044 {
00045         //echo "Play"
00046         string s_result = "Play";
00047         sendMessage(s_result.data());
00048         
00049         string input(argv[0]);
00050         //copy all letters but one, starting at position 1
00051         string name( input, 1, input.size() );
00052         
00053         //if soundsource exists - play it
00054         if (nameToSound.find(name) != nameToSound.end())
00055         {
00056                 //find soundsource and play it
00057                 nameToSound.find(name)->second->play->set(true);
00058         }
00059         //if no match - create soundsource and play it
00060         else
00061         {
00062                 createSound(name, language);
00063                 sound = nameToSound.find(name)->second;
00064                 sound->play->set(true);
00065         }
00066 }
00067 
00068 void SoundOutputAgent::handleStopSoundMessage(IvyApplication *app, int argc, const char **argv)
00069 {
00070         //echo "Stop"
00071         string s_result = "Stop";
00072         sendMessage(s_result.data());
00073 
00074         string input( argv[0] );
00075         //copy all letters but one, starting at position 1
00076         string name( input, 1, input.size() );
00077 
00078         //if soundsource exists - stop it
00079         if (nameToSound.find(name) != nameToSound.end())
00080         {
00081                 sound = nameToSound.find(name)->second;
00082                 sound->stop->set(true);
00083         }
00084         //if not - do nothing
00085 }
00086 
00087 void SoundOutputAgent::handlePauseSoundMessage(IvyApplication *app, int argc, const char **argv) 
00088 {
00089         //echo "Pause"
00090         string s_result = "Pause";
00091         sendMessage(s_result.data());
00092 
00093         string input( argv[0] );
00094         //copy all letters but one, startin at position 1
00095         string name( input, 1, input.size() );
00096 
00097         //if soundsource exists and is playing - pause it
00098         if ( nameToSound.find(name) != nameToSound.end() )
00099         {
00100                 sound = nameToSound.find(name)->second;
00101                 sound->play->set(false);
00102         }
00103         //if not - do nothing
00104 }
00105 
00106 void SoundOutputAgent::handleCancelSoundMessage(IvyApplication *app, int argc, const char **argv)
00107 {
00108         //echo "Cancel"
00109         string s_result = "Cancel";
00110         sendMessage(s_result.data());
00111 
00112         string input( argv[0] );
00113         //copy all letters but one, starting at position 1
00114         string name( input, 1, input.size() );
00115 
00116         //if soundsource exists and is playing - cancel it
00117         if ( nameToSound.find(name) != nameToSound.end() )
00118         {
00119                 sound = nameToSound.find(name)->second;
00120                 sound->stop->set(true);
00121         }
00122         //if not - do nothing
00123 }
00124 
00125 void SoundOutputAgent::setGain(string name, float gain )
00126 {
00127         if ( nameToSound.find(name) != nameToSound.end() )
00128         {
00129                 sound = nameToSound.find(name)->second;
00130                 sound->gain->set( gain );
00131         }
00132 }
00133 
00134 void SoundOutputAgent::setPitch( string name, float pitch )
00135 {
00136         if ( nameToSound.find(name) != nameToSound.end() )
00137         {
00138                 sound = nameToSound.find(name)->second;
00139                 sound->pitch->set( pitch );
00140         }
00141 }
00142 
00143 void SoundOutputAgent::setLoop( string name, bool loop )
00144 {
00145         if ( nameToSound.find(name) != nameToSound.end() )
00146         {
00147                 sound = nameToSound.find(name)->second;
00148                 sound->loop->set( loop );
00149         }
00150 }

Generated on Tue Oct 16 17:10:43 2007 for Micole by  doxygen 1.4.7