00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
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
00046 string s_result = "Play";
00047 sendMessage(s_result.data());
00048
00049 string input(argv[0]);
00050
00051 string name( input, 1, input.size() );
00052
00053
00054 if (nameToSound.find(name) != nameToSound.end())
00055 {
00056
00057 nameToSound.find(name)->second->play->set(true);
00058 }
00059
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
00071 string s_result = "Stop";
00072 sendMessage(s_result.data());
00073
00074 string input( argv[0] );
00075
00076 string name( input, 1, input.size() );
00077
00078
00079 if (nameToSound.find(name) != nameToSound.end())
00080 {
00081 sound = nameToSound.find(name)->second;
00082 sound->stop->set(true);
00083 }
00084
00085 }
00086
00087 void SoundOutputAgent::handlePauseSoundMessage(IvyApplication *app, int argc, const char **argv)
00088 {
00089
00090 string s_result = "Pause";
00091 sendMessage(s_result.data());
00092
00093 string input( argv[0] );
00094
00095 string name( input, 1, input.size() );
00096
00097
00098 if ( nameToSound.find(name) != nameToSound.end() )
00099 {
00100 sound = nameToSound.find(name)->second;
00101 sound->play->set(false);
00102 }
00103
00104 }
00105
00106 void SoundOutputAgent::handleCancelSoundMessage(IvyApplication *app, int argc, const char **argv)
00107 {
00108
00109 string s_result = "Cancel";
00110 sendMessage(s_result.data());
00111
00112 string input( argv[0] );
00113
00114 string name( input, 1, input.size() );
00115
00116
00117 if ( nameToSound.find(name) != nameToSound.end() )
00118 {
00119 sound = nameToSound.find(name)->second;
00120 sound->stop->set(true);
00121 }
00122
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 }