00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00042 #include "Aria.h"
00043 #include "ariaTypedefs.h"
00044 #include "ariaUtil.h"
00045 #include "ArSoundsQueue.h"
00046 #include "ArSoundPlayer.h"
00047 #include <iostream>
00048 #include <vector>
00049
00050 using namespace std;
00051
00052 void queueNowEmpty() {
00053 printf("The sound queue is now empty.\n");
00054 }
00055
00056 void queueNowNonempty() {
00057 printf("The sound queue is now non-empty.\n");
00058 }
00059
00060 bool no() {
00061
00062 return false;
00063 }
00064
00065 int main(int argc, char** argv) {
00066 Aria::init();
00067
00068
00069
00070 ArSoundsQueue soundQueue;
00071
00072
00073 soundQueue.setPlayWavFileCallback(ArSoundPlayer::getPlayWavFileCallback());
00074 soundQueue.setInterruptWavFileCallback(ArSoundPlayer::getStopPlayingCallback());
00075
00076
00077 soundQueue.addQueueEmptyCallback(new ArGlobalFunctor(&queueNowEmpty));
00078 soundQueue.addQueueNonemptyCallback(new ArGlobalFunctor(&queueNowNonempty));
00079
00080
00081 soundQueue.runAsync();
00082
00083
00084 if(argc < 2)
00085 {
00086 cerr << "Usage: " << argv[0] << " <up to ten WAV sound file names...>\n";
00087 exit(-1);
00088 }
00089 std::vector<const char*> filenames;
00090 for(int i = 1; i < min(argc, 11); i++)
00091 {
00092 filenames.push_back(argv[i]);
00093 }
00094
00095
00096 ArGlobalRetFunctor<bool> dontPlayItem(&no);
00097
00098 while(Aria::getRunning())
00099 {
00100 cout << "Queue is " <<
00101 string(soundQueue.isPaused()?"paused":(soundQueue.isPlaying()?"playing":"ready"))
00102 << ", with " << soundQueue.getCurrentQueueSize() << " pending sounds." << endl
00103 << "Enter a command followed by the enter key:\n"
00104 << "\tp\trequest pause state (cumulative)\n"
00105 << "\tr\trequest resume state (cumulative)\n"
00106 << "\ti\tinterrupt current sound\n"
00107 << "\tc\tclear the queue\n"
00108 << "\tC\tclear priority < 4 from the queue.\n"
00109 << "\tn\tAdd " << filenames[0] << " to the queue, but with a condition callback to prevent it playing.\n"
00110 ;
00111 for(size_t i = 0; i < filenames.size(); i++)
00112 cout << "\t" << i << "\tadd " << filenames[i] << " to the queue\n";
00113 cout << "\tq\tquit\n\n";
00114
00115 int c = getchar();
00116 if(c == '\n')
00117 continue;
00118 switch(c)
00119 {
00120 case 'p': soundQueue.pause(); break;
00121 case 'r': soundQueue.resume(); break;
00122 case 'i': soundQueue.interrupt(); break;
00123 case 'q': soundQueue.stop(); ArUtil::sleep(100); exit(0);
00124 case 'c': soundQueue.clearQueue(); break;
00125 case 'C': soundQueue.removePendingItems(4); break;
00126 case 'n':
00127 {
00128 cout << "Adding \"" << filenames[0] << "\" but with a condition callback that will prevent it from playing...\n";
00129 ArSoundsQueue::Item item = soundQueue.createDefaultFileItem(filenames[0]);
00130 item.playbackConditionCallbacks.push_back(&dontPlayItem);
00131 soundQueue.addItem(item);
00132 break;
00133 }
00134 default:
00135 if(filenames.size() > 0 && c >= '0' && c <= '9')
00136 {
00137 size_t i = c - '0';
00138 if(i < filenames.size())
00139 {
00140 cout << "Adding \"" << filenames[i] << "\" to the queue...\n";
00141 soundQueue.play(filenames[i]);
00142 }
00143 }
00144 }
00145 }
00146 cout << "Aria ended.\n";
00147 Aria::shutdown();
00148 return 0;
00149 }
00150
00151