Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

SoundList.cpp

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 // Lamp : Open source game middleware
00003 // Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
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 Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 //------------------------------------------------------------------------------
00019 
00020 /** @file
00021  * サウンドリスト実装
00022  * @author Junpee
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     // ステレオ、3D
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     // 最小3D距離、最大3D距離
00131     float minimum3DDistance;
00132     float maximum3DDistance;
00133     if(!isStereo){
00134         // 最小3D距離
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         // 最大3D距離
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 } // End of namespace Lamp
00186 //------------------------------------------------------------------------------

Generated on Wed Mar 16 10:29:36 2005 for Lamp by doxygen 1.3.2