ふわふわ時間
K-ON! fuwafuwatime
Thank SiON sound library
MIDI is from: http://www.nicovideo.jp/watch/sm6983629
2009-09-27 20:25:29
/**
* Copyright civet ( http://wonderfl.net/user/civet )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/gcsz
*/
/**
* K-ON! fuwafuwatime
*
* Thank SiON sound library
* MIDI is from: http://www.nicovideo.jp/watch/sm6983629
*
* 2009-09-27 20:25:29
*/
package
{
import com.bit101.components.*;
import flash.display.*;
import flash.events.*;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.system.Security;
import flash.utils.Timer;
import org.si.sion.SiONData;
import org.si.sion.SiONDriver;
import org.si.sion.SiONVoice;
import org.si.sion.utils.SiONPresetVoice;
[SWF(width="640", height="480", backgroundColor="0x000000", frameRate="30")]
public class FuwafuwaTime extends Sprite
{
private var driver:SiONDriver;
private var mml:String;
private var channel:SoundChannel;
private var PATH:String = "http://dreamana.com/lab/sion/";
public function FuwafuwaTime()
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
Security.loadPolicyFile("http://dreamana.com/crossdomain.xml");
init();
}
private function init():void
{
//Driver
driver = new SiONDriver();
//SamplerSounds
loadSounds(PATH + "TR909.swf");
}
private function loadSounds(url:String):void
{
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, soundLoaded);
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, soundLoading);
loader.load(new URLRequest(url));
}
private function soundLoading(e:ProgressEvent):void
{
var w:int = 300;
var h:int = 4;
var ox:int = (stage.stageWidth - w)/2;
var oy:int = (stage.stageHeight - h)/2;
var g:Graphics = this.graphics;
g.clear();
g.beginFill(0xffffff);
g.drawRect(ox, oy, w, h);
g.endFill();
g.beginFill(0xff0000);
g.drawRect(ox, oy, w * (e.bytesLoaded / e.bytesTotal), h);
g.endFill();
}
private function soundLoaded(e:Event):void
{
this.graphics.clear();
var loaderInfo:LoaderInfo = e.currentTarget as LoaderInfo;
loaderInfo.removeEventListener(Event.COMPLETE, soundLoaded);
var lib:Object = loaderInfo.content;
for(var i:int=27; i < 88; ++i) {
var snd:Sound = lib.getInstance(GMStandard.percussion[i]) as Sound;
if(snd != null) driver.setSamplerSound(i, snd);
}
//MML
loadMML(PATH + "fuwafuwaTime.txt");
}
private function loadMML(url:String):void
{
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, mmlLoaded);
loader.load(new URLRequest(url));
}
private function mmlLoaded(e:Event):void
{
var data:String = URLLoader(e.currentTarget).data;
this.mml = data.replace(/\r\n/g, '\n');
buildUI();
}
private var container:Sprite;
private var leftBar:ProgressBar;
private var rightBar:ProgressBar;
private var timer:Timer;
private function buildUI():void
{
container = new Sprite();
this.addChild(container);
var stopButton:PushButton = new PushButton(this, 0, 0, "Stop", onStopClick);
stopButton.setSize(60, 20);
var playButton:PushButton = new PushButton(this, 70, 0, "Play", onPlayClick);
playButton.setSize(60, 20);
leftBar = new ProgressBar(this, 140, 0);
rightBar = new ProgressBar(this, 140, 10);
timer = new Timer(6400);
timer.addEventListener(TimerEvent.TIMER, onTick);
showPhoto(1);
}
private function playMML(mml:String):void
{
var data:SiONData = driver.compile(mml);
var presetVoice:SiONPresetVoice = new SiONPresetVoice();
var voice0:SiONVoice = presetVoice["valsound.brass5"];
var voice1:SiONVoice = presetVoice["valsound.guitar13"];
var voice2:SiONVoice = presetVoice["valsound.bass14"];
var voice3:SiONVoice = presetVoice["valsound.lead7"];
data.setVoice(0, voice0);
data.setVoice(1, voice1);
data.setVoice(2, voice2);
data.setVoice(3, voice3);
//Let's rock!
channel = driver.play(data);
this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
count = 2;
timer.start();
}
/* event handlers */
private function onStopClick(e:Event):void
{
driver.stop();
this.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
timer.stop();
count = 1;
showPhoto(1);
}
private function onPlayClick(e:Event):void
{
playMML(this.mml);
}
private function onEnterFrame(e:Event):void
{
leftBar.value = channel.leftPeak;
rightBar.value = channel.rightPeak;
}
private var count:int = 1;
private var lastPhoto:Bitmap;
private function onTick(e:Event):void
{
if(count > 12) {
lastPhoto.addEventListener(Event.ENTER_FRAME, bmpFadeOut);
timer.stop();
}
else {
showPhoto(count);
count++;
}
}
private function showPhoto(i:int):void
{
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, photoLoaded);
loader.load(new URLRequest(PATH + "images/Toyosato" + i + ".jpg"));
}
private function photoLoaded(e:Event):void
{
var loaderInfo:LoaderInfo = e.currentTarget as LoaderInfo;
var bmp:Bitmap = loaderInfo.content as Bitmap;
bmp.alpha = 0;
container.addChild(bmp);
bmp.addEventListener(Event.ENTER_FRAME, bmpFadeIn);
}
private function bmpFadeIn(e:Event):void
{
var bmp:Bitmap = e.currentTarget as Bitmap;
bmp.alpha += 0.05;
if(bmp.alpha >= 1) {
bmp.alpha = 1;
bmp.removeEventListener(Event.ENTER_FRAME, bmpFadeIn);
if(lastPhoto) {
container.removeChild(lastPhoto);
lastPhoto.bitmapData.dispose();
}
lastPhoto = bmp;
}
}
private function bmpFadeOut(e:Event):void
{
var bmp:Bitmap = e.currentTarget as Bitmap;
bmp.alpha -= 0.05;
if(bmp.alpha <= 0) {
bmp.alpha = 0;
bmp.removeEventListener(Event.ENTER_FRAME, bmpFadeOut);
container.removeChild(bmp);
lastPhoto = null;
}
}
}
}
class GMStandard
{
public static const percussion:Array = new Array();
{
//GM1
percussion[35] = "BassDrum2";
percussion[36] = "BassDrum1";
percussion[37] = "SideStick";
percussion[38] = "SnareDrum1";
percussion[39] = "HandClap";
percussion[40] = "SnareDrum2";
percussion[41] = "LowTom2";
percussion[42] = "ClosedHiHat";
percussion[43] = "LowTom1";
percussion[44] = "PedalHiHat";
percussion[45] = "MidTom2";
percussion[46] = "OpenHiHat";
percussion[47] = "MidTom1";
percussion[48] = "HighTom2";
percussion[49] = "CrashCymbal1";
percussion[50] = "HighTom1";
percussion[51] = "RideCymbal1";
percussion[52] = "ChineseCymbal";
percussion[53] = "RideBell";
percussion[54] = "Tambourine";
percussion[55] = "SplashCymbal";
percussion[56] = "Cowbell";
percussion[57] = "CrashCymbal2";
percussion[58] = "VibraSlap";
percussion[59] = "RideCymbal2";
percussion[60] = "HighBongo";
percussion[61] = "LowBongo";
percussion[62] = "MuteHighConga";
percussion[63] = "OpenHighConga";
percussion[64] = "LowConga";
percussion[65] = "HighTimbale";
percussion[66] = "LowTimbale";
percussion[67] = "HighAgogo";
percussion[68] = "LowAgogo";
percussion[69] = "Cabasa";
percussion[70] = "Maracas";
percussion[71] = "ShortWhistle";
percussion[72] = "LongWhistle";
percussion[73] = "ShortGuiro";
percussion[74] = "LongGuiro";
percussion[75] = "Claves";
percussion[76] = "HighWoodBlock";
percussion[77] = "LowWoodBlock";
percussion[78] = "MuteCuica";
percussion[79] = "OpenCuica";
percussion[80] = "MuteTriangle";
percussion[81] = "OpenTriangle";
//GM2
percussion[27] = "HighQ";
percussion[28] = "Slap";
percussion[29] = "ScratchPush";
percussion[30] = "ScratchPull";
percussion[31] = "Sticks";
percussion[32] = "SquareClick";
percussion[33] = "MetronomeClick";
percussion[34] = "MetronomeBell";
percussion[34] = "MetronomeBell";
percussion[82] = "Shaker";
percussion[83] = "JingleBell";
percussion[84] = "BellTree";
percussion[85] = "Castanets";
percussion[86] = "MuteSurdo";
percussion[87] = "OpenSurdo";
}
}