Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transport remaining Turtle/Music state variables to Turtle/Singer #2432

Merged
merged 4 commits into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/abc.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ saveAbcOutput = function(logo) {
for (let t in logo.notation.notationStaging) {
logo.notationOutput +=
"K:" +
logo.keySignature[t]
logo.turtles.ithTurtle(t).singer.keySignature
.toUpperCase()
.replace(" ", "")
.replace("♭", "b")
Expand Down
32 changes: 13 additions & 19 deletions js/blocks/DrumBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ function setupDrumBlocks() {

let tur = logo.turtles.ithTurtle(turtle);

if (logo.inNoteBlock[turtle].length > 0) {
if (tur.singer.inNoteBlock.length > 0) {
// Add the noise sound as if it were a drum
tur.singer.noteDrums[last(logo.inNoteBlock[turtle])].push(noisename);
tur.singer.noteDrums[last(tur.singer.inNoteBlock)].push(noisename);
if (tur.singer.synthVolume[noisename] === undefined) {
tur.singer.synthVolume[noisename] = [DEFAULTVOLUME];
tur.singer.crescendoInitialVolume[noisename] = [DEFAULTVOLUME];
Expand All @@ -105,8 +105,8 @@ function setupDrumBlocks() {
return;
}

if (logo.inNoteBlock[turtle].length > 0) {
tur.singer.noteBeatValues[last(logo.inNoteBlock[turtle])].push(
if (tur.singer.inNoteBlock.length > 0) {
tur.singer.noteBeatValues[last(tur.singer.inNoteBlock)].push(
tur.singer.beatFactor
);
}
Expand Down Expand Up @@ -288,7 +288,7 @@ function setupDrumBlocks() {

let __listener = event => {
tur.singer.drumStyle.pop();
logo.pitchDrumTable[turtle] = {};
tur.singer.pitchDrumTable = {};
};

logo.setTurtleListener(turtle, listenerName, __listener);
Expand Down Expand Up @@ -383,8 +383,8 @@ function setupDrumBlocks() {
if (logo.drumBlocks.indexOf(blk) === -1) {
logo.drumBlocks.push(blk);
}
} else if (logo.inNoteBlock[turtle].length > 0) {
tur.singer.noteDrums[last(logo.inNoteBlock[turtle])].push(drumname);
} else if (tur.singer.inNoteBlock.length > 0) {
tur.singer.noteDrums[last(tur.singer.inNoteBlock)].push(drumname);
if (tur.singer.synthVolume[drumname] === undefined) {
tur.singer.synthVolume[drumname] = [DEFAULTVOLUME];
tur.singer.crescendoInitialVolume[drumname] = [DEFAULTVOLUME];
Expand All @@ -395,28 +395,22 @@ function setupDrumBlocks() {
) {
// Play a stand-alone drum block as a quarter note.
logo.clearNoteParams(tur, blk, []);
logo.inNoteBlock[turtle].push(blk);
tur.singer.noteDrums[last(logo.inNoteBlock[turtle])].push(drumname);
tur.singer.inNoteBlock.push(blk);
tur.singer.noteDrums[last(tur.singer.inNoteBlock)].push(drumname);

let noteBeatValue = 4;

__callback = function() {
let j = logo.inNoteBlock[turtle].indexOf(blk);
logo.inNoteBlock[turtle].splice(j, 1);
};
let __callback =
() => tur.singer.inNoteBlock.splice(tur.singer.inNoteBlock.indexOf(blk), 1);

Singer.processNote(logo, noteBeatValue, blk, turtle, __callback);
} else {
// logo.errorMsg(
// _("Drum Block: Did you mean to use a Note block?"),
// blk
// );
console.debug('PLAY DRUM ERROR: missing context');
return;
}

if (logo.inNoteBlock[turtle].length > 0) {
tur.singer.noteBeatValues[last(logo.inNoteBlock[turtle])].push(
if (tur.singer.inNoteBlock.length > 0) {
tur.singer.noteBeatValues[last(tur.singer.inNoteBlock)].push(
tur.singer.beatFactor
);
}
Expand Down
31 changes: 13 additions & 18 deletions js/blocks/EnsembleBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ function setupEnsembleBlocks() {
thisTurtle.singer.notePitches[0],
thisTurtle.singer.noteOctaves[0],
0,
logo.keySignature[i],
thisTurtle.singer.keySignature,
tur.singer.moveable,
null,
logo.errorMsg,
Expand All @@ -521,7 +521,7 @@ function setupEnsembleBlocks() {
}

value =
pitchToNumber(obj[0], obj[1], logo.keySignature[i]) -
pitchToNumber(obj[0], obj[1], thisTurtle.singer.keySignature) -
tur.singer.pitchNumberOffset;
logo.blocks.blockList[blk].value = value;
break;
Expand All @@ -530,15 +530,9 @@ function setupEnsembleBlocks() {

if (value === null) {
if (_THIS_IS_MUSIC_BLOCKS_) {
logo.errorMsg(
_("Cannot find mouse") + " " + targetTurtle,
blk
);
logo.errorMsg(_("Cannot find mouse") + " " + targetTurtle, blk);
} else {
logo.errorMsg(
_("Cannot find turtle") + " " + targetTurtle,
blk
);
logo.errorMsg(_("Cannot find turtle") + " " + targetTurtle, blk);
}

let obj;
Expand All @@ -549,10 +543,10 @@ function setupEnsembleBlocks() {
obj = [pitch, octave];
} else if (tur.singer.notePitches.length > 0) {
obj = getNote(
tur.singer.notePitches[last(logo.inNoteBlock[turtle])][0],
tur.singer.noteOctaves[last(logo.inNoteBlock[turtle])][0],
tur.singer.notePitches[last(tur.singer.inNoteBlock)][0],
tur.singer.noteOctaves[last(tur.singer.inNoteBlock)][0],
0,
logo.keySignature[turtle],
tur.singer.keySignature,
tur.singer.moveable,
null,
logo.errorMsg,
Expand All @@ -565,7 +559,7 @@ function setupEnsembleBlocks() {
}

value =
pitchToNumber(obj[0], obj[1], logo.keySignature[turtle]) -
pitchToNumber(obj[0], obj[1], tur.singer.keySignature) -
tur.singer.pitchNumberOffset;
logo.blocks.blockList[blk].value = value;
}
Expand Down Expand Up @@ -595,14 +589,15 @@ function setupEnsembleBlocks() {
let thisTurtle = logo.turtles.ithTurtle(i);
if (targetTurtle === thisTurtle.name) {
if (
logo.inNoteBlock[i].length > 0 &&
last(logo.inNoteBlock[i]) in thisTurtle.singer.noteValue
thisTurtle.singer.inNoteBlock.length > 0 &&
last(thisTurtle.singer.inNoteBlock) in thisTurtle.singer.noteValue
) {
value = 1 / thisTurtle.singer.noteValue[last(logo.inNoteBlock[i])];
value =
1 / thisTurtle.singer.noteValue[last(thisTurtle.singer.inNoteBlock)];
} else if (thisTurtle.singer.lastNotePlayed !== null) {
value = thisTurtle.singer.lastNotePlayed[1];
} else if (thisTurtle.singer.notePitches.length > 0) {
value = thisTurtle.singer.noteBeat[last(logo.inNoteBlock[i])];
value = thisTurtle.singer.noteBeat[last(thisTurtle.singer.inNoteBlock)];
} else {
value = -1;
}
Expand Down
18 changes: 8 additions & 10 deletions js/blocks/ExtrasBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,15 +382,13 @@ function setupExtrasBlocks() {
let name = logo.parseArg(logo, turtle, cblk, blk, receivedArg);
let blockNumber = logo.blocks.blockList.length;

let x = logo.turtles.turtleX2screenX(
logo.turtles.turtleList[turtle].x
);
let y = logo.turtles.turtleY2screenY(
logo.turtles.turtleList[turtle].y
);
let tur = logo.turtles.ithTurtle(turtle);

let x = logo.turtles.turtleX2screenX(tur.x);
let y = logo.turtles.turtleY2screenY(tur.y);

// We need to wait for the new block to load before continuing.
logo.doWait(turtle, 1);
// We need to wait for the new block to load before continuing
tur.doWait(1);

// We special case note blocks.
//.TRANS: a musical note consisting of pitch and duration
Expand Down Expand Up @@ -789,7 +787,7 @@ function setupExtrasBlocks() {
let noteBeatValue = bpmFactor / (1 / args[0]);
tur.singer.previousTurtleTime = tur.singer.turtleTime;
tur.singer.turtleTime += noteBeatValue;
logo.doWait(turtle, args[0]);
tur.doWait(args[0]);
}
}
}
Expand Down Expand Up @@ -861,7 +859,7 @@ function setupExtrasBlocks() {
logo.textMsg(args[0].toString());
}
} else if (logo.runningLilypond) {
if (logo.inNoteBlock[turtle].length > 0) {
if (tur.singer.inNoteBlock.length > 0) {
logo.notation.notationMarkup(turtle, args[0].toString());
}
}
Expand Down
5 changes: 2 additions & 3 deletions js/blocks/FlowBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ function setupFlowBlocks() {

logo.connectionStoreLock = true;

// Check to see if another turtle has already disconnected
// these blocks.
// Check to see if another turtle has already disconnected these blocks
let otherTurtle = __lookForOtherTurtles(blk, turtle);
if (otherTurtle != null) {
// Copy the connections and queue the blocks.
Expand Down Expand Up @@ -482,7 +481,7 @@ function setupFlowBlocks() {
let queueBlock = new Queue(blk, 1, parentBlk);
tur.parentFlowQueue.push(parentBlk);
tur.queue.push(queueBlock);
logo.doWait(0.05);
tur.doWait(0.05);
} else {
// Since a wait for block was requeued each
// time, we need to flush the queue of all but
Expand Down
48 changes: 24 additions & 24 deletions js/blocks/GraphicsBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ function setupGraphicsBlocks() {
logo.blocks.blockList[blk].name
);
logo.pitchTimeMatrix.rowArgs.push([args[0], args[1]]);
} else if (logo.inNoteBlock[turtle].length > 0) {
tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk);
} else if (tur.singer.inNoteBlock.length > 0) {
tur.singer.embeddedGraphics[last(tur.singer.inNoteBlock)].push(blk);
} else {
if (tur.singer.suppressOutput) {
let savedPenState =
Expand Down Expand Up @@ -194,8 +194,8 @@ function setupGraphicsBlocks() {

if (logo.inMatrix) {
// ignore clear block in matrix
} else if (logo.inNoteBlock[turtle].length > 0) {
tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk);
} else if (tur.singer.inNoteBlock.length > 0) {
tur.singer.embeddedGraphics[last(tur.singer.inNoteBlock)].push(blk);
} else {
if (tur.singer.suppressOutput) {
let savedPenState = tur.painter.penState;
Expand Down Expand Up @@ -239,8 +239,8 @@ function setupGraphicsBlocks() {
if (args.length === 2) {
if (typeof args[0] === "string" || typeof args[1] === "string") {
logo.errorMsg(NANERRORMSG, blk);
} else if (logo.inNoteBlock[turtle].length > 0) {
tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk);
} else if (tur.singer.inNoteBlock.length > 0) {
tur.singer.embeddedGraphics[last(tur.singer.inNoteBlock)].push(blk);
} else {
tur.painter.cp2x = args[0];
tur.painter.cp2y = args[1];
Expand Down Expand Up @@ -277,8 +277,8 @@ function setupGraphicsBlocks() {
if (args.length === 2) {
if (typeof args[0] === "string" || typeof args[1] === "string") {
logo.errorMsg(NANERRORMSG, blk);
} else if (logo.inNoteBlock[turtle].length > 0) {
tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk);
} else if (tur.singer.inNoteBlock.length > 0) {
tur.singer.embeddedGraphics[last(tur.singer.inNoteBlock)].push(blk);
} else {
tur.painter.cp1x = args[0];
tur.painter.cp1y = args[1];
Expand Down Expand Up @@ -313,8 +313,8 @@ function setupGraphicsBlocks() {
if (args.length === 2) {
if (typeof args[0] === "string" || typeof args[1] === "string") {
logo.errorMsg(NANERRORMSG, blk);
} else if (logo.inNoteBlock[turtle].length > 0) {
tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk);
} else if (tur.singer.inNoteBlock.length > 0) {
tur.singer.embeddedGraphics[last(tur.singer.inNoteBlock)].push(blk);
} else {
if (tur.singer.suppressOutput) {
let savedPenState = tur.painter.penState;
Expand Down Expand Up @@ -366,8 +366,8 @@ function setupGraphicsBlocks() {
logo.blocks.blockList[blk].name
);
logo.pitchTimeMatrix.rowArgs.push([args[0], args[1]]);
} else if (logo.inNoteBlock[turtle].length > 0) {
tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk);
} else if (tur.singer.inNoteBlock.length > 0) {
tur.singer.embeddedGraphics[last(tur.singer.inNoteBlock)].push(blk);
} else {
if (tur.singer.suppressOutput) {
let savedPenState = tur.painter.penState;
Expand Down Expand Up @@ -414,8 +414,8 @@ function setupGraphicsBlocks() {
logo.blocks.blockList[blk].name
);
logo.pitchTimeMatrix.rowArgs.push(args[0]);
} else if (logo.inNoteBlock[turtle].length > 0) {
tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk);
} else if (tur.singer.inNoteBlock.length > 0) {
tur.singer.embeddedGraphics[last(tur.singer.inNoteBlock)].push(blk);
} else {
tur.painter.doSetHeading(args[0]);
}
Expand Down Expand Up @@ -462,8 +462,8 @@ function setupGraphicsBlocks() {
logo.blocks.blockList[blk].name
);
logo.pitchTimeMatrix.rowArgs.push([args[0], args[1]]);
} else if (logo.inNoteBlock[turtle].length > 0) {
tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk);
} else if (tur.singer.inNoteBlock.length > 0) {
tur.singer.embeddedGraphics[last(tur.singer.inNoteBlock)].push(blk);
} else {
if (tur.singer.suppressOutput) {
let savedPenState = tur.painter.penState;
Expand Down Expand Up @@ -514,8 +514,8 @@ function setupGraphicsBlocks() {
logo.blocks.blockList[blk].name
);
logo.pitchTimeMatrix.rowArgs.push(args[0]);
} else if (logo.inNoteBlock[turtle].length > 0) {
tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk);
} else if (tur.singer.inNoteBlock.length > 0) {
tur.singer.embeddedGraphics[last(tur.singer.inNoteBlock)].push(blk);
} else {
if (tur.singer.suppressOutput) {
let savedPenState = tur.painter.penState;
Expand Down Expand Up @@ -566,8 +566,8 @@ function setupGraphicsBlocks() {
logo.blocks.blockList[blk].name
);
logo.pitchTimeMatrix.rowArgs.push(args[0]);
} else if (logo.inNoteBlock[turtle].length > 0) {
tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk);
} else if (tur.singer.inNoteBlock.length > 0) {
tur.singer.embeddedGraphics[last(tur.singer.inNoteBlock)].push(blk);
} else {
if (tur.singer.suppressOutput) {
let savedPenState = tur.painter.penState;
Expand Down Expand Up @@ -617,8 +617,8 @@ function setupGraphicsBlocks() {
logo.blocks.blockList[blk].name
);
logo.pitchTimeMatrix.rowArgs.push(args[0]);
} else if (logo.inNoteBlock[turtle].length > 0) {
tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk);
} else if (tur.singer.inNoteBlock.length > 0) {
tur.singer.embeddedGraphics[last(tur.singer.inNoteBlock)].push(blk);
} else {
if (tur.singer.suppressOutput) {
let savedPenState = tur.painter.penState;
Expand Down Expand Up @@ -668,8 +668,8 @@ function setupGraphicsBlocks() {
logo.blocks.blockList[blk].name
);
logo.pitchTimeMatrix.rowArgs.push(args[0]);
} else if (logo.inNoteBlock[turtle].length > 0) {
tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk);
} else if (tur.singer.inNoteBlock.length > 0) {
tur.singer.embeddedGraphics[last(tur.singer.inNoteBlock)].push(blk);
} else {
if (tur.singer.suppressOutput) {
let savedPenState = tur.painter.penState;
Expand Down
Loading