2009.01.16.06:14:53 8fingers RE:







import mx.transitions.Tween;
import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Matrix;
import flash.geom.ColorTransform;
//
var stgW:Number = 700;
var stgH:Number = 400;
// MUSICIAN \\
manTotal = 8;
beatTotal = 8;
FPS = 30;
chordTimeTotal = FPS*beatTotal;
noteCycle = 12;
chanceForNull = 8;
//
depthRange = 200;
minDepth = stgH-depthRange;
maxDepth = stgH;
minWidth = 400;
maxWidth = stgW;
// LAYERS \\
performMC = this.createEmptyMovieClip("layer0", 0);
screenMC = this.createEmptyMovieClip("layer1", 1);
chordTabLayer = this.attachMovie("chordTabLayer", "layer2", 2);
chordNameLayer = this.attachMovie("chordNameLayer", "layer3", 3);
//
// CHORD \\
var keyNameArray:Array = new Array('C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B');
var chordArray:Array = new Array();
// Major
chordArray.push(['Major', [0, 4, 7]]);
// Minor
chordArray.push(['Minor', [0, 3, 7]]);
// Seventh
chordArray.push(['Seventh', [0, 4, 10, 7]]);
// Minor 7th
chordArray.push(['Minor 7th', [3, 10, 7]]);
// Diminished
chordArray.push(['Diminished', [0, 3, 6, 9]]);
// Augmented
chordArray.push(['Augented', [0, 4, 8]]);
// Suspended 4th
chordArray.push(['Suspended 4th', [0, 5, 7]]);
// Major 7th
chordArray.push(['Major 7th', [0, 4, 7, 11]]);
// Major 6th
chordArray.push(['Major 6th', [0, 4, 7, 9]]);
// Major 9th
chordArray.push(['Major 9th', [0, 4, 2, 10, 7]]);

//
chordNameLayer.paper_beat.text = "String : "+manTotal+newline+"Beat : "+beatTotal+newline+FPS+" frame per beat";
// BITMAPS \\
screenMC.attachBitmap(screenBmpData,0);
// SETUP SOUND & MAN
soundFile = "gtrLine";
for (i=0; i<manTotal; i++) {
// MUSIC MAN
//manObj = performMC.attachMovie("boyRed", "mc"+i, i);
manObj = performMC.createEmptyMovieClip("mc"+i, i);
// SOUND
manObj.soundObj = new Sound(manObj);
manObj.soundObj.attachSound(soundFile);
//
// manObj._y = stgH;
manObj._x = i*stgW/manTotal+50;
//
manObj.stop();
}
//
function formChord() {
var newKeyIncrement = random(keyNameArray.length);
var newKeyName = keyNameArray[newKeyIncrement];
var newChordIncrement = random(chordArray.length);
var newChordFamily = chordArray[newChordIncrement][0];
var newChordFingering = chordArray[newChordIncrement][1];
for (u=0; u<newChordFingering.length; u++) {
newChordFingering[u] += newKeyIncrement;
}
trace(newKeyIncrement);
trace(newKeyName);
trace(newChordFamily);
trace(newChordFingering);
//
chordNameLayer.paper_chord.text = newKeyName+" "+newChordFamily;
chordTabLayer.paper_note.text = "";
// there is X man Y beat
progressionArray = new Array();
for (a=0; a<manTotal; a++) {
var tmpBox = new Array();
for (b=0; b<beatTotal; b++) {
if (random(chanceForNull)<=a) {
var possibleNote = newChordFingering[random(newChordFingering.length)]+noteCycle*random(2);
} else {
var possibleNote = null;
}
//
var possibeVolume = (a+1)/manTotal*50;
tmpBox.push([possibleNote, possibeVolume]);
}
progressionArray.push(tmpBox);
}
trace("progressionArray:"+progressionArray);
//
playChord();
}
function playChord() {
countTime = 0;
f = 0;
beat = 0;
this.onEnterFrame = function() {
if (f%FPS == 0) {
noteObj = chordTabLayer["paper_note"+beat];
noteObj.text = "";
for (a=0; a<manTotal; a++) {
var tmpNote:Number = progressionArray[a][beat][0];
var tmpVol:Number = progressionArray[a][beat][1];
// trace("tmpBox "+a+" : "+tmpNote);
noteObj.text += tmpNote+newline;
//
if (tmpNote != null) {
manObj = performMC["mc"+a];
// SOUND
manObj.soundObj.stop();
manObj.soundObj.setVolume(tmpVol);
manObj.soundObj.start(tmpNote*2,1);
}

}
//trace("- - - - - - - - ");
beat++;
}
f++;
countTime++;
if (countTime == chordTimeTotal) {
for (a=0; a<manTotal; a++) {

manObj = performMC["mc"+a];
// SOUND
manObj.soundObj.stop();
}
//delete this.onEnterFrame;
formChord();
}
};
}

this.onMouseDown = function() {
formChord();
};
formChord();<