441 lines
20 KiB
Text
441 lines
20 KiB
Text
// SE.tjs - 効果音管理
|
|
// Copyright (C)2001-2009, W.Dee and contributors 改変・配布は自由です
|
|
|
|
class SESoundBuffer extends WaveSoundBuffer
|
|
{
|
|
// 効果音クラス ( WaveSoundBuffer を継承 )
|
|
|
|
var owner; // オーナー
|
|
var id; // 効果音バッファID
|
|
var inFading; // フェード中かどうか
|
|
var prevstatus = "unload"; // 直前のステータス
|
|
var currentStorage = ""; // 見かけの演奏中のストレージ
|
|
var currentVolume = 100; // 見かけのボリューム
|
|
var inFadeAndStop = false; // フェード終了時に停止するか
|
|
|
|
//<kuma>
|
|
var _play_elm = %[]; //play()を何度も呼び出すためパラメータを保存しておきます
|
|
var _play_resetvolume = ''; //play()を何度も呼び出すためパラメータを保存しておきます
|
|
var playingList = []; //ストレージをリストで持ちます
|
|
var playingListIndex = -1;
|
|
var playingListUse = false; //リスト再生するか否か
|
|
var playingListLoop = false;
|
|
var playingListEnabled = true; //再生が終端まで行ったのか、途中で停止したのかわからないので、これを使います
|
|
var playingListSyncMode = false; //リスト再生で1ファイル再生終わったら待つかどうか
|
|
var playingListSyncWaiting = false; //待ち中ならtrue
|
|
function playingListInit()
|
|
{
|
|
playingList.clear();
|
|
playingListIndex = 0;
|
|
playingListUse = false;
|
|
playingListLoop = false;
|
|
playingListEnabled = true;
|
|
playingListSyncMode = false;
|
|
playingListSyncWaiting = false;
|
|
}
|
|
function playingListInc()
|
|
{
|
|
playingListIndex++;
|
|
if(playingListIndex>=playingList.count)
|
|
{
|
|
if(playingListLoop){
|
|
playingListIndex=0;
|
|
}
|
|
else{
|
|
playingListIndex=-1;
|
|
}
|
|
}
|
|
return playingListIndex;
|
|
}
|
|
function setPlayingList(storages)
|
|
{
|
|
playingList = storages.split(',',,true);
|
|
playingListUse = (playingList.count>1);
|
|
if(playingList.count>0) return playingList[0];
|
|
return '';
|
|
}
|
|
function nextPlayList()
|
|
{
|
|
//kag.caption = playingList[playingListIndex];
|
|
return playingList[playingListIndex];
|
|
}
|
|
function isSyncWaiting()
|
|
{
|
|
return playingListSyncWaiting;
|
|
}
|
|
//</kuma>
|
|
|
|
function SESoundBuffer(owner, id)
|
|
{
|
|
// コンストラクタ
|
|
super.WaveSoundBuffer(owner);
|
|
|
|
this.owner = owner;
|
|
this.id = id;
|
|
}
|
|
|
|
function finalize()
|
|
{
|
|
// finalize()
|
|
super.finalize(...);
|
|
}
|
|
|
|
//<kuma>
|
|
function play(elm, resetvolume = true)
|
|
{
|
|
playingListInit();
|
|
elm['storage'] = setPlayingList(elm.storage);
|
|
playingListSyncMode = +elm.syncmode;
|
|
playingListSyncWaiting = false;
|
|
(Dictionary.assignStruct incontextof _play_elm)(elm); //play()を何度も呼び出すためパラメータを保存しておきます
|
|
_play_resetvolume = resetvolume; //play()を何度も呼び出すためパラメータを保存しておきます
|
|
play_(elm,resetvolume);
|
|
}
|
|
//</kuma>
|
|
|
|
//function play(elm, resetvolume = true) //<kuma />
|
|
function play_(elm, resetvolume = true) //<kuma />
|
|
{
|
|
// play オーバーライド
|
|
super.stop();
|
|
stopFade();
|
|
var storage = elm.storage;
|
|
var start = elm.start;
|
|
var found = true;
|
|
|
|
if(!Storages.isExistentStorage(storage))
|
|
{
|
|
var test;
|
|
if(test = storage + ".wav", Storages.isExistentStorage(test))
|
|
storage = test;
|
|
else if(test = storage + ".ogg", Storages.isExistentStorage(test))
|
|
storage = test;
|
|
@if(kirikiriz)
|
|
else if(test = storage + ".opus", Storages.isExistentStorage(test))
|
|
storage = test;
|
|
@endif
|
|
else if(test = storage + ".tcw", Storages.isExistentStorage(test))
|
|
storage = test;
|
|
else
|
|
found = false;
|
|
}
|
|
if(!found)
|
|
throw new Exception("効果音 " + storage + " が見つかりません");
|
|
var loop = elm.loop === void ? false : +elm.loop;
|
|
//<kuma>
|
|
if(loop){
|
|
if(playingListUse){
|
|
loop=false;
|
|
playingListLoop=true;
|
|
}
|
|
else{
|
|
playingListLoop=false;
|
|
}
|
|
}
|
|
else{
|
|
if(playingListUse){
|
|
playingListLoop=false;
|
|
}
|
|
else{
|
|
playingListLoop=false;
|
|
}
|
|
}
|
|
playingListEnabled = true;
|
|
//</kuma>
|
|
looping = loop;
|
|
if(loop)
|
|
currentStorage = storage;
|
|
else
|
|
currentStorage = "";
|
|
try
|
|
{
|
|
super.open(storage);
|
|
if(resetvolume) super.volume = currentVolume * 1000;
|
|
// 再生位置指定
|
|
if (start !== void &&
|
|
super.labels !== void &&
|
|
(start = super.labels[start]) !== void &&
|
|
(start = start.samplePosition) !== void) {
|
|
super.samplePosition = start;
|
|
}
|
|
super.play();
|
|
}
|
|
catch(e)
|
|
{
|
|
dm("効果音の再生に失敗しました(実行は続行できます) : " + e.message);
|
|
}
|
|
}
|
|
|
|
function stop()
|
|
{
|
|
// stop オーバーライド
|
|
playingListEnabled = false; //<kuma />
|
|
currentStorage = "";
|
|
try
|
|
{
|
|
super.stop(...);
|
|
}
|
|
catch(e)
|
|
{
|
|
dm("効果音の停止に失敗しました(実行は続行できます) : " + e.message);
|
|
}
|
|
inFadeAndStop = false;
|
|
}
|
|
|
|
function stopFade()
|
|
{
|
|
// stopFade オーバーライド
|
|
playingListEnabled = false; //<kuma />
|
|
try
|
|
{
|
|
super.stopFade();
|
|
}
|
|
catch(e)
|
|
{
|
|
dm("効果音のフェードに失敗しました(実行は続行できます) : " + e.message);
|
|
}
|
|
inFadeAndStop = false;
|
|
}
|
|
|
|
function fade(elm)
|
|
{
|
|
// fade オーバーライド
|
|
inFading = true;
|
|
var time = elm.time === void ? 5000 : +elm.time;
|
|
var vol = +elm.volume * 1000;
|
|
currentVolume = +elm.volume;
|
|
try
|
|
{
|
|
super.fade(vol, time);
|
|
}
|
|
catch(e)
|
|
{
|
|
dm("効果音のフェードに失敗しました(実行は続行できます) : " + e.message);
|
|
}
|
|
}
|
|
|
|
function fadeIn(elm)
|
|
{
|
|
// フェードインしながらの再生
|
|
super.volume = 0;
|
|
play(elm, false);
|
|
inFading = true;
|
|
var time = elm.time === void ? 5000 : +elm.time;
|
|
var vol = currentVolume * 1000;
|
|
try
|
|
{
|
|
super.fade(vol, time);
|
|
}
|
|
catch(e)
|
|
{
|
|
dm("効果音のフェードに失敗しました(実行は続行できます) : " + e.message);
|
|
}
|
|
}
|
|
|
|
function fadeOut(elm)
|
|
{
|
|
// フェードアウト後停止
|
|
playingListEnabled = false; //<kuma />
|
|
currentStorage = ""; // 状態としては停止扱い
|
|
inFading = true;
|
|
inFadeAndStop = true;
|
|
var time = elm.time === void ? 5000 : +elm.time;
|
|
try
|
|
{
|
|
super.fade(0, time);
|
|
}
|
|
catch(e)
|
|
{
|
|
dm("効果音のフェードに失敗しました(実行は続行できます) : " + e.message);
|
|
}
|
|
}
|
|
|
|
function onFadeCompleted()
|
|
{
|
|
// onFadeCompleted オーバーライド
|
|
inFading = false;
|
|
if(inFadeAndStop)
|
|
{
|
|
try
|
|
{
|
|
playingListEnabled = false; //<kuma />
|
|
super.stop(); // 再生停止
|
|
}
|
|
catch(e)
|
|
{
|
|
dm("効果音の停止に失敗しました(実行は続行できます) : " + e.message);
|
|
}
|
|
inFadeAndStop = false;
|
|
}
|
|
super.onFadeCompleted(...);
|
|
owner.onSESoundBufferFadeCompleted(id); // フェード終了
|
|
}
|
|
|
|
function onStatusChanged()
|
|
{
|
|
// onStatusChanged オーバーライド
|
|
// ステータスが変更された
|
|
super.onStatusChanged(...);
|
|
var ps = prevstatus;
|
|
var cs = status;
|
|
prevstatus = cs;
|
|
if(ps == "play" && cs == "stop")
|
|
{
|
|
currentStorage = "";
|
|
owner.onSESoundBufferStop(id); // play => stop : 演奏が停止した
|
|
|
|
//<kuma>
|
|
if(playingListInc()>=0&&playingListEnabled&&playingListUse){
|
|
_play_elm.storage = nextPlayList();
|
|
if(playingListSyncMode) playingListSyncWaiting = true;
|
|
else play_(_play_elm,_play_resetvolume);
|
|
}
|
|
else{
|
|
onStatusChangedPlayEnd(...);
|
|
}
|
|
//</kuma>
|
|
}
|
|
}
|
|
|
|
//<kuma>
|
|
function playingListResume()
|
|
{
|
|
if(playingListSyncWaiting){
|
|
playingListSyncWaiting = false;
|
|
play_(_play_elm,_play_resetvolume);
|
|
}
|
|
}
|
|
function playingListPlayNext()
|
|
{
|
|
playingListEnabled=false;
|
|
playingListInc();
|
|
if(playingListIndex==-1) playingListIndex=0;
|
|
_play_elm.storage = nextPlayList();
|
|
play_(_play_elm,_play_resetvolume);
|
|
}
|
|
//</kuma>
|
|
|
|
function onStatusChangedPlayEnd(){} //<kuma />
|
|
|
|
function canWaitStop()
|
|
{
|
|
// 終了を待てるか
|
|
return status == "play" && !looping;
|
|
}
|
|
|
|
property volume
|
|
{
|
|
setter(x)
|
|
{
|
|
currentVolume = x;
|
|
super.volume = x * 1000;
|
|
}
|
|
getter
|
|
{
|
|
return super.volume \ 1000;
|
|
}
|
|
}
|
|
|
|
property pan
|
|
{
|
|
setter(x)
|
|
{
|
|
super.pan = x * 1000;
|
|
}
|
|
getter
|
|
{
|
|
return super.pan \ 1000;
|
|
}
|
|
}
|
|
|
|
function setOptions(elm)
|
|
{
|
|
if(elm.volume !== void) volume = +elm.volume;
|
|
if(elm.gvolume !== void)
|
|
{
|
|
// 大域ボリューム
|
|
var sysvar = owner.scflags; // システム(コア)変数
|
|
if(sysvar.se === void) sysvar.se = [];
|
|
sysvar = sysvar.se;
|
|
if(sysvar[id] === void) sysvar[id] = %[];
|
|
sysvar = sysvar[id];
|
|
var v2 = +elm.gvolume;
|
|
v2 = int(v2 * 1000);
|
|
sysvar.globalVolume = v2;
|
|
if (sysvar.enable === void || sysvar.enable) {
|
|
volume2 = v2;
|
|
} else {
|
|
volume2 = 0;
|
|
}
|
|
}
|
|
if(elm.pan !== void)
|
|
{
|
|
pan = +elm.pan;
|
|
}
|
|
}
|
|
|
|
function store()
|
|
{
|
|
// 辞書配列に現在の状態を記録する
|
|
var dic = %[];
|
|
dic.currentStorage = currentStorage;
|
|
dic.volume = currentVolume;
|
|
dic.pan = pan;
|
|
//<kuma>
|
|
dic._play_elm = _play_elm;
|
|
dic._play_resetvolume = _play_resetvolume;
|
|
dic.playingList = playingList;
|
|
dic.playingListIndex = playingListIndex;
|
|
dic.playingListUse = playingListUse;
|
|
dic.playingListLoop = playingListLoop;
|
|
dic.playingListEnabled = playingListEnabled;
|
|
dic.playingListSyncMode = playingListSyncMode;
|
|
dic.playingListSyncWaiting = playingListSyncWaiting;
|
|
//</kuma>
|
|
return dic;
|
|
}
|
|
|
|
function restore(dic)
|
|
{
|
|
// 辞書配列から状態を読み出し、復帰する
|
|
currentVolume = dic.volume;
|
|
pan = dic.pan;
|
|
//<kuma>
|
|
_play_elm = dic._play_elm if dic._play_elm !== void;
|
|
_play_resetvolume = dic._play_resetvolume if dic._play_resetvolume !== void;
|
|
playingList = dic.playingList if dic.playingList !== void;
|
|
playingListIndex = dic.playingListIndex if dic.playingListIndex !== void;
|
|
playingListUse = dic.playingListUse if dic.playingListUse !== void;
|
|
playingListLoop = dic.playingListLoop if dic.playingListLoop !== void;
|
|
playingListEnabled = dic.playingListEnabled if dic.playingListEnabled !== void;
|
|
playingListSyncMode = dic.playingListSyncMode if dic.playingListSyncMode !== void;
|
|
playingListSyncWaiting = dic.playingListSyncWaiting if dic.playingListSyncWaiting !== void;
|
|
//</kuma>
|
|
if(dic.currentStorage != "")
|
|
play(%[storage : dic.currentStorage, loop : true]);
|
|
else
|
|
stop();
|
|
}
|
|
|
|
function restoreSystemState(dic)
|
|
{
|
|
// システム変数 dic から情報を設定する
|
|
// 大域ボリュームの情報を得る
|
|
var sysvar = dic.se;
|
|
if(sysvar !== void)
|
|
{
|
|
sysvar = sysvar[id];
|
|
if(sysvar !== void)
|
|
{
|
|
if (sysvar.enable === void || sysvar.enable) {
|
|
var v2 = sysvar.globalVolume;
|
|
if(v2 !== void) {
|
|
volume2 = +v2;
|
|
}
|
|
} else {
|
|
volume2 = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|