Skip to content

Commit

Permalink
Note / vel / act parameters parsing OK (but they don't change status …
Browse files Browse the repository at this point in the history
…yet). Addresses #17

Export function generates a querystring for these parameters (but not the knob's). Addresses #27
  • Loading branch information
cristiano-belloni committed Oct 27, 2011
1 parent 00346b1 commit 6b4f172
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions morningstar.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var MORNINGSTAR = {
tempo: 0.5
},
STEPS_NUM : 64,
NOTES_NUM : 24,
VELOCITY_DEFAULT : 0.5,
PATTERN_NUM: 4,
STEPS_PER_PATTERN: 16,
Expand Down Expand Up @@ -146,6 +147,17 @@ var MORNINGSTAR = {
this.status.steps[i].velocity = this.VELOCITY_DEFAULT;
}
}

MORNINGSTAR.exportParameters = function() {
var string = "?";
for (var i = 0; i < this.STEPS_NUM; i += 1) {
if (i !== 0) string += "&";
string += "n" + i + "=" + this.status.steps[i].note + "&";
string += "a" + i + "=" + this.status.steps[i].active + "&";
string += "v" + i + "=" + this.status.steps[i].velocity;
}
return string;
}

// CALLBACKS

Expand Down Expand Up @@ -627,6 +639,11 @@ var MORNINGSTAR = {
this.switchPattern (0, true);
this.ui.refresh();
}

MORNINGSTAR.exportCallback = function (slot, value, ID) {
var string = this.exportParameters();
console.log ("Export string: " + string);
}

MORNINGSTAR.afterLoading = function (loaders) {

Expand Down Expand Up @@ -890,6 +907,20 @@ var MORNINGSTAR = {

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

// EXPORT SONG BUTTON (TODO GRAPHICS)
var exportArgs = {
preserveBg: false,
isClickable: true,
top: 6,
left: 155,
ID: "export",
imagesArray : loaders["redled_loader"].images,
onValueSet : this.exportCallback.bind(MORNINGSTAR)
};

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


// AUDIO ON / OFF
Expand Down Expand Up @@ -1021,6 +1052,8 @@ var MORNINGSTAR = {
var temp_parm;

// DEFAULTS AND PARAMETERS

// THESE FUNCTION PARSE THE QUERY STRING
this.parseFloatParam = function (param) {
var tmp;
if (typeof(this.QueryString[param]) !== 'undefined') {
Expand All @@ -1035,6 +1068,62 @@ var MORNINGSTAR = {
}
return false;
}

this.parseNoteParameters = function () {

This comment has been minimized.

Copy link
@cristiano-belloni

cristiano-belloni Oct 27, 2011

Author Owner

These 3 are similar, could probably compact them (but would it lose in clarity?)

var tmp;
for (var i = 0; i < this.STEPS_NUM; i += 1) {
if (typeof(this.QueryString["n"+i]) !== 'undefined') {

tmp = parseInt(this.QueryString["n"+i], 10);

if (isNaN(tmp) || (tmp < -1) || (tmp >= this.NOTES_NUM)) {
console.log ("Invalid note ", i, ": ", this.QueryString["n"+i]);
}
else {
console.log ("Valid note ", i, ": ", this.QueryString["n"+i]);
}
}
}
}

this.parseActiveParameters = function () {
var tmp;
for (var i = 0; i < this.STEPS_NUM; i += 1) {
if (typeof(this.QueryString["a"+i]) !== 'undefined') {

tmp = parseInt(this.QueryString["a"+i], 10);

if (isNaN(tmp) || ((tmp !== 0) && (tmp !== 1))) {
console.log ("Invalid activeness for note ", i, ": ", this.QueryString["a"+i]);
}
else {
console.log ("Valid activeness for note ", i, ": ", tmp);
}
}
}
}

this.parseVelocityParameters = function () {
var tmp;
for (var i = 0; i < this.STEPS_NUM; i += 1) {
if (typeof(this.QueryString["v"+i]) !== 'undefined') {

tmp = parseFloat(this.QueryString["v"+i], 10);

if (isNaN(tmp) || (tmp < 0) || (tmp > 1)) {
console.log ("Invalid velocity for note ", i, ": ", this.QueryString["v"+i]);
}
else {
console.log ("Valid velocity for note ", i, ": ", tmp);
}
}
}
}

// DO THE PARSING AND CHANGE THE STATUS, IF NEEDED.
this.parseNoteParameters();
this.parseActiveParameters();
this.parseVelocityParameters();

if ((temp_parm = this.parseFloatParam ('tempo')) !== false) {
this.status.tempo = temp_parm;
Expand Down

0 comments on commit 6b4f172

Please sign in to comment.