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 PlayWithPreseVoicet extends Sprite { // 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 mainMelody:SiONData; //コンストラクタ function PlayWithPreseVoicet() { //MMLをSiONData型にコンパイル mainMelody = 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 { // 第一引数にSiONData、第二引数にSiONVoice、第三引数以降は、length=0(play all of sequence), delay=0(no delay), quantize=2(8th beat) driver.sequenceOn(mainMelody, voice1, 0, 0, 2); } // ボタン2のアクション private function _play_preset2(e:MouseEvent) : void { // ボタン1と同じでプリセットボイスのみ違う driver.sequenceOn(mainMelody, voice2, 0, 0, 2); } } } SiONの練習(プリセットボイスを使う)