- function hazard(v1, v2) {
- return v1+Math.floor(Math.random()*(v2+1-v1));
- }
- Tracker = function (loops) {
- this.loops = loops;
- this.mcs = [];
- for (var i = 0; i<this.loops.length; i++) {
- this.mcs[i] = createEmptyMovieClip("loopMC"+i, i);
- this.mcs[i].sobj = new Sound(this.mcs[i]);
- this.mcs[i].sobj.attachSound(this.loops[i]);
- // trace(this.mcs[i]);
- }
- };
- Tracker.prototype.playBack = function(song) {
- this.song = song;
- this.sPosition = 0;
- this.nextPattern();
- };
- Tracker.prototype.nextPattern = function() {
- if (y == 1) {
- x = hazard(0, 2);
- this.sPosition = x;
- }
- if (y == 2) {
- x = hazard(3, 6);
- this.sPosition = x;
- }
- if (y == 3) {
- x = hazard(7, 11);
- this.sPosition = x;
- }
- //trace(this.sPosition);
- first = true;
- for (var i = 0; i<this.loops.length; i++) {
- delete this.mcs[i].sobj.onSoundComplete;
- if (this.song[this.sPosition][i] == 1) {
- if (first) {
- first = false;
- this.mcs[i].sobj.obj = this;
- this.mcs[i].sobj.onSoundComplete = function() {
- this.obj.nextPattern();
- };
- }
- this.mcs[i].sobj.start(0, 2);
- }
- }
- };
- song = [[1, 0, 0, 0, 0, 0, 0], [1, 0, 1, 0, 0, 0, 0], [1, 0, 1, 0, 0, 0, 0], [1, 1, 1, 0, 0, 0, 0], [1, 1, 1, 0, 0, 1, 0], [1, 1, 1, 0, 1, 0, 0], [1, 1, 1, 0, 0, 1, 1], [1, 1, 1, 1, 0, 0, 0], [1, 1, 1, 1, 1, 0, 0], [1, 1, 1, 1, 0, 0, 0], [1, 1, 1, 1, 0, 1, 0, 1], [1, 1, 1, 1, 0, 0, 0, 0]];
- loops = ["bass", "bat", "maracas", "violon", "effect", "piano", "piano2", "voix"];
- mySong = new Tracker(loops);
- mySong.playBack(song);
-
function hazard(v1, v2) {
return v1+Math.floor(Math.random()*(v2+1-v1));
}
Tracker = function (loops) {
this.loops = loops;
this.mcs = [];
for (var i = 0; i<this.loops.length; i++) {
this.mcs[i] = createEmptyMovieClip("loopMC"+i, i);
this.mcs[i].sobj = new Sound(this.mcs[i]);
this.mcs[i].sobj.attachSound(this.loops[i]);
// trace(this.mcs[i]);
}
};
Tracker.prototype.playBack = function(song) {
this.song = song;
this.sPosition = 0;
this.nextPattern();
};
Tracker.prototype.nextPattern = function() {
if (y == 1) {
x = hazard(0, 2);
this.sPosition = x;
}
if (y == 2) {
x = hazard(3, 6);
this.sPosition = x;
}
if (y == 3) {
x = hazard(7, 11);
this.sPosition = x;
}
//trace(this.sPosition);
first = true;
for (var i = 0; i<this.loops.length; i++) {
delete this.mcs[i].sobj.onSoundComplete;
if (this.song[this.sPosition][i] == 1) {
if (first) {
first = false;
this.mcs[i].sobj.obj = this;
this.mcs[i].sobj.onSoundComplete = function() {
this.obj.nextPattern();
};
}
this.mcs[i].sobj.start(0, 2);
}
}
};
song = [[1, 0, 0, 0, 0, 0, 0], [1, 0, 1, 0, 0, 0, 0], [1, 0, 1, 0, 0, 0, 0], [1, 1, 1, 0, 0, 0, 0], [1, 1, 1, 0, 0, 1, 0], [1, 1, 1, 0, 1, 0, 0], [1, 1, 1, 0, 0, 1, 1], [1, 1, 1, 1, 0, 0, 0], [1, 1, 1, 1, 1, 0, 0], [1, 1, 1, 1, 0, 0, 0], [1, 1, 1, 1, 0, 1, 0, 1], [1, 1, 1, 1, 0, 0, 0, 0]];
loops = ["bass", "bat", "maracas", "violon", "effect", "piano", "piano2", "voix"];
mySong = new Tracker(loops);
mySong.playBack(song);