SiON 複数のシーケンスの演奏をしつつcompile()できるか確認

by cat2151 forked from SiONの練習(プリセットボイスを使う) (diff: 26)
複数のシーケンスの演奏をしつつcompile()できるか確認
確認方法:Button1を押したあと、Button2を押す
確認内容:演奏が止まるかどうか
♥0 | Line 32 | Modified 2010-04-24 09:38:48 | MIT License
play

ActionScript3 source code

/**
 * Copyright cat2151 ( http://wonderfl.net/user/cat2151 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/mh5C
 */

// forked from logicalyze's SiONの練習(プリセットボイスを使う)

// 複数のシーケンスの演奏をしつつcompile()できるか確認

//確認方法:Button1を押したあと、Button2を押す
//確認内容:演奏が止まるかどうか


package {
    import flash.display.Sprite;
    import flash.events.*;
    import com.bit101.components.*;
    import org.si.sion.*;
    import org.si.sion.utils.SiONPresetVoice;
    [SWF(width = "300", height = "150", backgroundColor = "#FFFFFF")]
    public class PlayWithPresetVoice extends Sprite {
        // SiONDriverクラスのインスタンスを生成
//        public var driver2:SiONDriver = new SiONDriver();
        public var driver:SiONDriver = new SiONDriver();
        // SiONPresetVoiceクラスのインスタンスを生成
        public var presetVoice:SiONPresetVoice = new SiONPresetVoice();
        // SiONVoice型変数を宣言
        public var voice1:SiONVoice;
        public var voice2:SiONVoice;
        // SiONData型変数を宣言
        public var musicData1:SiONData;
        public var musicData2:SiONData;
        //コンストラクタ
        function PlayWithPresetVoice() {
	    //MMLをSiONData型にコンパイル
            musicData1 = driver.compile("t123 l8 [ccggaag4 ffeeddc4 | [ggffeed4]2 ]2")
            musicData2 = driver.compile("t100 l8 [ccggaag4 ffeeddc4 | [ggffeed4]2 ]2")
            //SiONVoice型変数にプリセットボイスを設定
            voice1 = presetVoice["valsound.piano8"];
            voice2 = presetVoice["valsound.wind1"];
            //ボタンコンポーネント(ボタン1、2)
		    new PushButton(this,  20, 50, "Button1-piano8", _play_preset1);
            new PushButton(this, 170, 50, "Button2-wind1", _play_preset2);
            driver.play();
        }
        // ボタン1のアクション
        private function _play_preset1(e:MouseEvent) : void {
		    //MMLをSiONData型にコンパイル
  //          musicData1 = driver.compile("t123 l8 [ccggaag4 ffeeddc4 | [ggffeed4]2 ]2")
	// 第一引数にSiONData、第二引数にSiONVoice、第三引数以降は、length=0(play all of sequence), delay=0(no delay), quantize=2(8th beat)
	            driver.sequenceOn(musicData1, voice1, 0, 0, 2);
        }
	// ボタン2のアクション
         private function _play_preset2(e:MouseEvent) : void {
          		    //MMLをSiONData型にコンパイル
            musicData2 = driver.compile("t100 l8 [ccggaag4 ffeeddc4 | [ggffeed4]2 ]2")
			 // ボタン1と同じでプリセットボイスのみ違う
			 // ↑コメントアウトの場合は音が出る
            driver.sequenceOn(musicData2, voice2, 0, 0, 2);
//			driver2.play("cde");
//			driver.play("cde");
                    }
    }
}