Skip to content

Commit

Permalink
Implemented behaviour of #12 (without the proper graphics)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristiano-belloni committed Oct 26, 2011
1 parent 10d66a7 commit 00346b1
Showing 1 changed file with 38 additions and 11 deletions.
49 changes: 38 additions & 11 deletions morningstar.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ var MORNINGSTAR = {

MORNINGSTAR.resumeState = function () {
console.log ("Restoring local status");
if (!this.supportsLocalStorage()) { return false; }
if (!this.supportsLocalStorage()) {return false;}

for (var i = 0; i < this.STEPS_NUM; i++) {
this.status.steps[i] = {};
Expand Down Expand Up @@ -135,6 +135,18 @@ var MORNINGSTAR = {
return true;
}

MORNINGSTAR.restoreDefaultState = function () {
for (var i = 0; i < this.STEPS_NUM; i+=1) {
this.status.steps[i] = {};
// Not active, by default
this.status.steps[i].active = 0;
// Note = -1 means that there is no note associated with the step
this.status.steps[i].note = -1;
// This depends on the initial velocity value
this.status.steps[i].velocity = this.VELOCITY_DEFAULT;
}
}

// CALLBACKS

// PLAY / STOP BUTTON
Expand Down Expand Up @@ -503,7 +515,7 @@ var MORNINGSTAR = {
var newStep = this.STEPS_PER_PATTERN * this.status.currentEditPattern + this.currentHLStep;
console.log("Switching currentStep to", this.currentStep);
// Trigger a new note in the piano, if needed
this.pianoKeyChange (newStep);
this.pianoKeyChange (newStep, force);

this.currentStep = newStep;

Expand Down Expand Up @@ -608,6 +620,14 @@ var MORNINGSTAR = {
this.ui.refresh();
};

MORNINGSTAR.clearCallback = function(slot, value, ID) {
console.log ("Clear callback called");
this.restoreDefaultState();
this.saveState();
this.switchPattern (0, true);
this.ui.refresh();
}

MORNINGSTAR.afterLoading = function (loaders) {

var key_initial_offset = 67 - 43,
Expand Down Expand Up @@ -857,6 +877,21 @@ var MORNINGSTAR = {

}

// CLEAR PATTERN BUTTON (TODO GRAPHICS)
var clearArgs = {
preserveBg: false,
isClickable: true,
top: 6,
left: 125,
ID: "clear",
imagesArray : loaders["greenled_loader"].images,
onValueSet : this.clearCallback.bind(MORNINGSTAR)
};

this.clear = new Button (clearArgs);
this.ui.addElement(this.clear, {zIndex: 10});


// AUDIO ON / OFF
var onoffArgs = {
preserveBg: false,
Expand Down Expand Up @@ -1095,15 +1130,7 @@ if (this.audioOk === true) {
// Try to resume saved state.
if (this.resumeState() === false) {
// No state? Fall back to default parameters.
for (var i = 0; i < this.STEPS_NUM; i+=1) {
this.status.steps[i] = {};
// Not active, by default
this.status.steps[i].active = 0;
// Note = -1 means that there is no note associated with the step
this.status.steps[i].note = -1;
// This depends on the initial velocity value
this.status.steps[i].velocity = this.VELOCITY_DEFAULT;
}
this.restoreDefaultState();
}

// Load keys
Expand Down

0 comments on commit 00346b1

Please sign in to comment.