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 #include "LampBasic.h"
00026 #include "Sound/Utility/SoundList.h"
00027 #include "Sound/Utility/SoundCache.h"
00028 #include "Core/InputOutput/TextFileReader.h"
00029 #include "Core/InputOutput/FilePath.h"
00030 #include "Core/Utility/StringTokenizer.h"
00031
00032 namespace Lamp{
00033
00034
00035
00036 bool SoundList::load(SoundCache* soundCache, const String& filePath){
00037 FilePath path(filePath);
00038 if(!path.existFile()){ return false; }
00039 TextFileReader* reader = new TextFileReader(filePath);
00040 bool result = load(soundCache, reader);
00041 delete reader;
00042 return result;
00043 }
00044
00045
00046 bool SoundList::load(SoundCache* soundCache, TextReader* textReader){
00047 String line;
00048 while(!textReader->isEnd()){
00049 String line = textReader->readLine();
00050 if(!loadSound(soundCache, line)){ return false; }
00051 }
00052 return true;
00053 }
00054
00055
00056 bool SoundList::loadSound(SoundCache* soundCache, const String& line){
00057 String temp, errorMethod("SoundList::loadSound() ");
00058 StringTokenizer tokenizer(line, "\t");
00059
00060 if(!tokenizer.hasMoreTokens()){ return true; }
00061 temp = tokenizer.getNextToken();
00062
00063 if(temp.startsWith("//")){ return true; }
00064
00065
00066 String fileName;
00067 fileName = temp;
00068
00069
00070 bool isStereo;
00071 if(!tokenizer.hasMoreTokens()){
00072 ErrorOut(errorMethod + "ステレオ、3D指定がありません。" + line);
00073 return false;
00074 }
00075 temp = tokenizer.getNextToken();
00076 if(temp.equalsIsIgnoreCase("stereo")){
00077 isStereo = true;
00078 }else if(temp.equalsIsIgnoreCase("3d")){
00079 isStereo = false;
00080 }else{
00081 ErrorOut(errorMethod + "ステレオ、3D指定には"
00082 "「Stereo」か「3D」を指定して下さい。" + line);
00083 return false;
00084 }
00085
00086
00087 bool isLoop;
00088 if(!tokenizer.hasMoreTokens()){
00089 ErrorOut(errorMethod + "ループ指定がありません。" + line);
00090 return false;
00091 }
00092 temp = tokenizer.getNextToken();
00093 if(temp.equalsIsIgnoreCase("loop")){
00094 isLoop = true;
00095 }else if(temp.equalsIsIgnoreCase("once")){
00096 isLoop = false;
00097 }else{
00098 ErrorOut(errorMethod + "ループ指定には"
00099 "「Loop」か「Once」を指定して下さい。" + line);
00100 return false;
00101 }
00102
00103
00104 int priority;
00105 if(!tokenizer.hasMoreTokens()){
00106 ErrorOut(errorMethod + "プライオリティ指定がありません。" + line);
00107 return false;
00108 }
00109 temp = tokenizer.getNextToken();
00110 if((!temp.parseInt(&priority)) ||
00111 (priority > Limit::shortMax) || (priority < Limit::shortMin)){
00112 ErrorOut(errorMethod + "プライオリティは32767〜-32768の整数で"
00113 "指定してください。" + line);
00114 return false;
00115 }
00116
00117
00118 int maxMixingCount;
00119 if(!tokenizer.hasMoreTokens()){
00120 ErrorOut(errorMethod + "最大ミキシング数指定がありません。" + line);
00121 return false;
00122 }
00123 temp = tokenizer.getNextToken();
00124 if((!temp.parseInt(&maxMixingCount)) || (maxMixingCount < 0)){
00125 ErrorOut(errorMethod + "最大ミキシング数は0以上の整数で"
00126 "指定してください。" + line);
00127 return false;
00128 }
00129
00130
00131 float minimum3DDistance;
00132 float maximum3DDistance;
00133 if(!isStereo){
00134
00135 if(!tokenizer.hasMoreTokens()){
00136 ErrorOut(errorMethod + "最小3D距離指定がありません。" + line);
00137 return false;
00138 }
00139 temp = tokenizer.getNextToken();
00140 if((!temp.parseFloat(&minimum3DDistance)) ||
00141 (minimum3DDistance <= 0.f)){
00142 ErrorOut(errorMethod + "最小3D距離は正の距離を実数で"
00143 "指定してください。" + line);
00144 return false;
00145 }
00146
00147
00148 if(!tokenizer.hasMoreTokens()){
00149 ErrorOut(errorMethod + "最小3D距離指定がありません。" + line);
00150 return false;
00151 }
00152 temp = tokenizer.getNextToken();
00153 if((!temp.parseFloat(&maximum3DDistance)) ||
00154 (maximum3DDistance <= 0.f)){
00155 ErrorOut(errorMethod + "最大3D距離は正の距離を実数で"
00156 "指定してください。" + line);
00157 return false;
00158 }
00159 if(maximum3DDistance < minimum3DDistance){
00160 ErrorOut(errorMethod + "最大3D距離は最小3D距離よりも大きな実数を"
00161 "指定してください。" + line);
00162 return false;
00163 }
00164 }
00165
00166
00167 if(isStereo){
00168 if(!soundCache->loadStaticSound(
00169 fileName, isLoop, priority, maxMixingCount)){
00170 ErrorOut(errorMethod + "静的サウンドの"
00171 "ロードに失敗しました。" + line);
00172 return false;
00173 }
00174 }else{
00175 if(!soundCache->loadStaticSound3D(fileName, isLoop, priority,
00176 minimum3DDistance, maximum3DDistance, maxMixingCount)){
00177 ErrorOut(errorMethod + "静的3Dサウンドの"
00178 "ロードに失敗しました。" + line);
00179 return false;
00180 }
00181 }
00182 return true;
00183 }
00184
00185 }
00186