Skip to content

Commit

Permalink
Port music related variables to Singer
Browse files Browse the repository at this point in the history
  • Loading branch information
meganindya committed Jul 14, 2020
1 parent a529d73 commit 222a277
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 211 deletions.
16 changes: 11 additions & 5 deletions js/blocks/EnsembleBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,13 +452,19 @@ function setupEnsembleBlocks() {
});
}

/**
* @todo FIXME
*/
arg(logo, turtle, blk, receivedArg) {
let thisTurtle = _blockFindTurtle(logo, turtle, blk, receivedArg);

if (thisTurtle)
return logo.notesPlayed[i][0] / logo.notesPlayed[i][1];
if (thisTurtle) {
let tur = logo.turtles.ithTurtle(thisTurtle);
return tur.singer.notesPlayed[0] / tur.singer.notesPlayed[1];
}

return logo.notesPlayed[turtle][0] / logo.notesPlayed[turtle][1];
let tur = logo.turtles.ithTurtle(turtle);
return tur.singer.notesPlayed[0] / tur.singer.notesPlayed[1];
}
}

Expand Down Expand Up @@ -505,7 +511,7 @@ function setupEnsembleBlocks() {
thisTurtle.singer.noteOctaves[0],
0,
logo.keySignature[i],
logo.moveable[turtle],
tur.singer.moveable,
null,
logo.errorMsg,
logo.synth.inTemperament
Expand Down Expand Up @@ -549,7 +555,7 @@ function setupEnsembleBlocks() {
tur.singer.noteOctaves[last(logo.inNoteBlock[turtle])][0],
0,
logo.keySignature[turtle],
logo.moveable[turtle],
tur.singer.moveable,
null,
logo.errorMsg,
logo.synth.inTemperament
Expand Down
61 changes: 28 additions & 33 deletions js/blocks/IntervalsBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ function setupIntervalsBlocks() {
logo.errorMsg(NOINPUTERRORMSG, blk);
return 0;
} else {
let tur = logo.turtles.ithTurtle(turtle);

let saveSuppressStatus = logo.suppressOutput[turtle];

// We need to save the state of the boxes and heap
Expand All @@ -197,16 +199,15 @@ function setupIntervalsBlocks() {
let saveBoxes = JSON.stringify(logo.boxes);
let saveTurtleHeaps = JSON.stringify(logo.turtleHeaps[turtle]);
// And the turtle state
let saveX = logo.turtles.turtleList[turtle].x;
let saveY = logo.turtles.turtleList[turtle].y;
let saveColor = logo.turtles.turtleList[turtle].painter.color;
let saveValue = logo.turtles.turtleList[turtle].painter.value;
let saveChroma = logo.turtles.turtleList[turtle].painter.chroma;
let saveStroke = logo.turtles.turtleList[turtle].painter.stroke;
let saveCanvasAlpha = logo.turtles.turtleList[turtle].painter.canvasAlpha;
let saveOrientation =
logo.turtles.turtleList[turtle].orientation;
let savePenState = logo.turtles.turtleList[turtle].painter.penState;
let saveX = tur.x;
let saveY = tur.y;
let saveColor = tur.painter.color;
let saveValue = tur.painter.value;
let saveChroma = tur.painter.chroma;
let saveStroke = tur.painter.stroke;
let saveCanvasAlpha = tur.painter.canvasAlpha;
let saveOrientation = tur.orientation;
let savePenState = tur.painter.penState;

logo.suppressOutput[turtle] = true;

Expand All @@ -225,7 +226,7 @@ function setupIntervalsBlocks() {
}

let actionArgs = [];
let saveNoteCount = logo.notesPlayed[turtle];
let saveNoteCount = tur.singer.notesPlayed;
logo.turtles.turtleList[turtle].running = true;
logo.runFromBlockNow(
logo,
Expand Down Expand Up @@ -254,7 +255,7 @@ function setupIntervalsBlocks() {
);
}

logo.notesPlayed[turtle] = saveNoteCount;
tur.singer.notesPlayed = saveNoteCount;

// Restore previous state
logo.boxes = JSON.parse(saveBoxes);
Expand Down Expand Up @@ -304,6 +305,8 @@ function setupIntervalsBlocks() {
logo.errorMsg(NOINPUTERRORMSG, blk);
return 0;
} else {
let tur = logo.turtles.ithTurtle(turtle);

let saveSuppressStatus = logo.suppressOutput[turtle];

// We need to save the state of the boxes and heap
Expand All @@ -312,16 +315,15 @@ function setupIntervalsBlocks() {
let saveBoxes = JSON.stringify(logo.boxes);
let saveTurtleHeaps = JSON.stringify(logo.turtleHeaps[turtle]);
// And the turtle state
let saveX = logo.turtles.turtleList[turtle].x;
let saveY = logo.turtles.turtleList[turtle].y;
let saveColor = logo.turtles.turtleList[turtle].painter.color;
let saveValue = logo.turtles.turtleList[turtle].painter.value;
let saveChroma = logo.turtles.turtleList[turtle].painter.chroma;
let saveStroke = logo.turtles.turtleList[turtle].painter.stroke;
let saveCanvasAlpha = logo.turtles.turtleList[turtle].painter.canvasAlpha;
let saveOrientation =
logo.turtles.turtleList[turtle].orientation;
let savePenState = logo.turtles.turtleList[turtle].painter.penState;
let saveX = tur.x;
let saveY = tur.y;
let saveColor = tur.painter.color;
let saveValue = tur.painter.value;
let saveChroma = tur.painter.chroma;
let saveStroke = tur.painter.stroke;
let saveCanvasAlpha = tur.painter.canvasAlpha;
let saveOrientation = tur.orientation;
let savePenState = tur.painter.penState;

logo.suppressOutput[turtle] = true;

Expand All @@ -340,16 +342,9 @@ function setupIntervalsBlocks() {
}

let actionArgs = [];
let saveNoteCount = logo.notesPlayed[turtle];
let saveNoteCount = tur.singer.notesPlayed;
logo.turtles.turtleList[turtle].running = true;
logo.runFromBlockNow(
logo,
turtle,
cblk,
true,
actionArgs,
logo.turtles.turtleList[turtle].queue.length
);
logo.runFromBlockNow(logo, turtle, cblk, true, actionArgs, tur.queue.length);

if (
logo.firstPitch[turtle].length > 0 &&
Expand All @@ -370,7 +365,7 @@ function setupIntervalsBlocks() {
);
}

logo.notesPlayed[turtle] = saveNoteCount;
tur.singer.notesPlayed = saveNoteCount;

// Restore previous state
logo.boxes = JSON.parse(saveBoxes);
Expand Down Expand Up @@ -815,7 +810,7 @@ function setupIntervalsBlocks() {

flow(args, logo, turtle) {
if (args.length === 1) {
logo.moveable[turtle] = args[0];
logo.turtles.ithTurtle(turtle).singer.moveable = args[0];
}
}
}
Expand Down
60 changes: 26 additions & 34 deletions js/blocks/MeterBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,24 +129,23 @@ function setupMeterBlocks() {
arg(logo, turtle, blk) {
if (
logo.inStatusMatrix &&
logo.blocks.blockList[logo.blocks.blockList[blk].connections[0]]
.name === "print"
logo.blocks.blockList[logo.blocks.blockList[blk].connections[0]].name === "print"
) {
logo.statusFields.push([blk, "measurevalue"]);
} else {
if (
logo.notesPlayed[turtle][0] / logo.notesPlayed[turtle][1] <
logo.pickup[turtle]
) {
let tur = logo.turtles.ithTurtle(turtle);

if (tur.singer.notesPlayed[0] / tur.singer.notesPlayed[1] < logo.pickup[turtle]) {
return 0;
} else {
return (
Math.floor(
((logo.notesPlayed[turtle][0] /
logo.notesPlayed[turtle][1] -
logo.pickup[turtle]) *
logo.noteValuePerBeat[turtle]) /
logo.beatsPerMeasure[turtle]
(
(
tur.singer.notesPlayed[0] / tur.singer.notesPlayed[1] -
logo.pickup[turtle]
) * logo.noteValuePerBeat[turtle]
) / logo.beatsPerMeasure[turtle]
) + 1
);
}
Expand Down Expand Up @@ -199,25 +198,23 @@ function setupMeterBlocks() {
arg(logo, turtle, blk) {
if (
logo.inStatusMatrix &&
logo.blocks.blockList[logo.blocks.blockList[blk].connections[0]]
.name === "print"
logo.blocks.blockList[logo.blocks.blockList[blk].connections[0]].name === "print"
) {
logo.statusFields.push([blk, "beatvalue"]);
} else {
if (
logo.notesPlayed[turtle][0] / logo.notesPlayed[turtle][1] <
logo.pickup[turtle]
) {
let tur = logo.turtles.ithTurtle(turtle);

if (tur.singer.notesPlayed[0] / tur.singer.notesPlayed[1] < logo.pickup[turtle]) {
return 0;
} else {
return (
(((logo.notesPlayed[turtle][0] /
logo.notesPlayed[turtle][1] -
logo.pickup[turtle]) *
logo.noteValuePerBeat[turtle]) %
logo.beatsPerMeasure[turtle]) +
1
);
(
(
tur.singer.notesPlayed[0] / tur.singer.notesPlayed[1] -
logo.pickup[turtle]
) * logo.noteValuePerBeat[turtle]
) % logo.beatsPerMeasure[turtle]
) + 1;
}
}
}
Expand Down Expand Up @@ -284,14 +281,12 @@ function setupMeterBlocks() {
arg(logo, turtle, blk) {
if (
logo.inStatusMatrix &&
logo.blocks.blockList[logo.blocks.blockList[blk].connections[0]]
.name === "print"
logo.blocks.blockList[logo.blocks.blockList[blk].connections[0]].name === "print"
) {
logo.statusFields.push([blk, "elapsednotes"]);
} else {
return (
logo.notesPlayed[turtle][0] / logo.notesPlayed[turtle][1]
);
let tur = logo.turtles.ithTurtle(turtle);
return tur.singer.notesPlayed[0] / tur.singer.notesPlayed[1];
}
}
}
Expand Down Expand Up @@ -348,11 +343,8 @@ function setupMeterBlocks() {
if (notevalue === null || notevalue === 0) {
return 0;
} else {
return (
logo.notesPlayed[turtle][0] /
logo.notesPlayed[turtle][1] /
notevalue
);
let tur = logo.turtles.ithTurtle(turtle);
return tur.singer.notesPlayed[0] / tur.singer.notesPlayed[1] / notevalue;
}
}
}
Expand Down
26 changes: 13 additions & 13 deletions js/blocks/PitchBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ function setupPitchBlocks() {
octave,
nhalf,
logo.keySignature[turtle],
logo.moveable[turtle],
tur.singer.moveable,
null,
logo.errorMsg,
logo.synth.inTemperament
Expand Down Expand Up @@ -302,7 +302,7 @@ function setupPitchBlocks() {
octave,
nhalf,
logo.keySignature[turtle],
logo.moveable[turtle],
tur.singer.moveable,
null,
logo.errorMsg,
logo.synth.inTemperament
Expand Down Expand Up @@ -391,7 +391,7 @@ function setupPitchBlocks() {
tur.singer.noteOctaves[last(logo.inNoteBlock[turtle])][0],
0,
logo.keySignature[turtle],
logo.moveable[turtle],
tur.singer.moveable,
null,
logo.errorMsg
);
Expand Down Expand Up @@ -495,7 +495,7 @@ function setupPitchBlocks() {
lc2 = lc2
.replace("#", SHARP)
.replace("b", FLAT);
if (logo.moveable[turtle] === false) {
if (tur.singer.moveable === false) {
return SOLFEGECONVERSIONTABLE[lc2];
} else {
let scale = _buildScale(logo.keySignature[turtle])[0];
Expand All @@ -519,7 +519,7 @@ function setupPitchBlocks() {
let scalarClass = scaleDegreeToPitchMapping(
logo.keySignature[turtle],
null,
logo.moveable[turtle],
tur.singer.moveable,
note2
);
return scalarClass[0];
Expand All @@ -532,7 +532,7 @@ function setupPitchBlocks() {
let scalarClass1 = scaleDegreeToPitchMapping(
logo.keySignature[turtle],
null,
logo.moveable[turtle],
tur.singer.moveable,
note3
);
return scalarClass1[0] + scalarClass1[1];
Expand Down Expand Up @@ -581,7 +581,7 @@ function setupPitchBlocks() {
tur.singer.noteOctaves[last(logo.inNoteBlock[turtle])][0],
0,
logo.keySignature[turtle],
logo.moveable[turtle],
tur.singer.moveable,
null,
logo.errorMsg
);
Expand Down Expand Up @@ -1541,7 +1541,7 @@ function setupPitchBlocks() {
octave,
t,
logo.keySignature[turtle],
logo.moveable[turtle],
tur.singer.moveable,
direction,
logo.errorMsg,
logo.synth.inTemperament
Expand Down Expand Up @@ -1572,7 +1572,7 @@ function setupPitchBlocks() {
octave,
0,
logo.keySignature[turtle],
logo.moveable[turtle],
tur.singer.moveable,
null,
logo.errorMsg
);
Expand Down Expand Up @@ -1635,7 +1635,7 @@ function setupPitchBlocks() {
noteObj1[1],
ii,
logo.keySignature[turtle],
logo.moveable[turtle],
tur.singer.moveable,
null,
logo.errorMsg,
logo.synth.inTemperament
Expand All @@ -1658,7 +1658,7 @@ function setupPitchBlocks() {
noteObj1[1],
logo.semitoneIntervals[turtle][i][0],
logo.keySignature[turtle],
logo.moveable[turtle],
tur.singer.moveable,
null,
logo.errorMsg,
logo.synth.inTemperament
Expand Down Expand Up @@ -2289,7 +2289,7 @@ function setupPitchBlocks() {
noteObj1[1],
ii,
logo.keySignature[turtle],
logo.moveable[turtle],
tur.singer.moveable,
null,
logo.errorMsg,
logo.synth.inTemperament
Expand All @@ -2312,7 +2312,7 @@ function setupPitchBlocks() {
noteObj1[1],
logo.semitoneIntervals[turtle][i][0],
logo.keySignature[turtle],
logo.moveable[turtle],
tur.singer.moveable,
null,
logo.errorMsg,
logo.synth.inTemperament
Expand Down
Loading

0 comments on commit 222a277

Please sign in to comment.