diff --git a/js/blocks/BoxesBlocks.js b/js/blocks/BoxesBlocks.js index f0263ea6e0..71d60c3fea 100644 --- a/js/blocks/BoxesBlocks.js +++ b/js/blocks/BoxesBlocks.js @@ -152,13 +152,7 @@ function setupBoxesBlocks() { updateParameter(logo, turtle, blk) { let cblk = logo.blocks.blockList[blk].connections[1]; - let boxname = logo.parseArg( - that, - turtle, - cblk, - blk, - logo.receivedArg - ); + let boxname = logo.parseArg(that, turtle, cblk, blk, logo.receivedArg); if (boxname in logo.boxes) { return logo.boxes[boxname]; } else { diff --git a/js/blocks/DrumBlocks.js b/js/blocks/DrumBlocks.js index bd0ceafef5..b62ca12cb3 100644 --- a/js/blocks/DrumBlocks.js +++ b/js/blocks/DrumBlocks.js @@ -91,11 +91,11 @@ function setupDrumBlocks() { } } + let tur = logo.turtles.ithTurtle(turtle); + if (logo.inNoteBlock[turtle].length > 0) { // Add the noise sound as if it were a drum - logo.noteDrums[turtle][last(logo.inNoteBlock[turtle])].push( - noisename - ); + tur.singer.noteDrums[last(logo.inNoteBlock[turtle])].push(noisename); if (logo.synthVolume[turtle][noisename] === undefined) { logo.synthVolume[turtle][noisename] = [DEFAULTVOLUME]; logo.crescendoInitialVolume[turtle][noisename] = [ @@ -111,9 +111,9 @@ function setupDrumBlocks() { } if (logo.inNoteBlock[turtle].length > 0) { - logo.noteBeatValues[turtle][ - last(logo.inNoteBlock[turtle]) - ].push(logo.beatFactor[turtle]); + tur.singer.noteBeatValues[last(logo.inNoteBlock[turtle])].push( + tur.singer.beatFactor + ); } logo.pushedNote[turtle] = true; @@ -365,6 +365,8 @@ function setupDrumBlocks() { } } + let tur = logo.turtles.ithTurtle(turtle); + // If we are in a setdrum clamp, override the drum name. if (logo.drumStyle[turtle].length > 0) { drumname = last(logo.drumStyle[turtle]); @@ -385,9 +387,7 @@ function setupDrumBlocks() { logo.drumBlocks.push(blk); } } else if (logo.inNoteBlock[turtle].length > 0) { - logo.noteDrums[turtle][last(logo.inNoteBlock[turtle])].push( - drumname - ); + tur.singer.noteDrums[last(logo.inNoteBlock[turtle])].push(drumname); if (logo.synthVolume[turtle][drumname] === undefined) { logo.synthVolume[turtle][drumname] = [DEFAULTVOLUME]; logo.crescendoInitialVolume[turtle][drumname] = [ @@ -399,19 +399,9 @@ function setupDrumBlocks() { last(logo.blocks.blockList[blk].connections) == null ) { // Play a stand-alone drum block as a quarter note. - logo.clearNoteParams(turtle, blk, []); + logo.clearNoteParams(tur, blk, []); logo.inNoteBlock[turtle].push(blk); - logo.noteDrums[turtle][last(logo.inNoteBlock[turtle])].push( - drumname - ); - - // let bpmFactor; - // if (logo.bpm[turtle].length > 0) { - // bpmFactor = TONEBPM / last(logo.bpm[turtle]); - // } else { - // bpmFactor = TONEBPM / logo._masterBPM; - // } - // let beatValue = bpmFactor / noteBeatValue; + tur.singer.noteDrums[last(logo.inNoteBlock[turtle])].push(drumname); let noteBeatValue = 4; @@ -426,14 +416,14 @@ function setupDrumBlocks() { // _("Drum Block: Did you mean to use a Note block?"), // blk // ); - console.debug('PLAY DRUM ERROR: missing context'); + console.debug('PLAY DRUM ERROR: missing context'); return; } if (logo.inNoteBlock[turtle].length > 0) { - logo.noteBeatValues[turtle][ - last(logo.inNoteBlock[turtle]) - ].push(logo.beatFactor[turtle]); + tur.singer.noteBeatValues[last(logo.inNoteBlock[turtle])].push( + tur.singer.beatFactor + ); } logo.pushedNote[turtle] = true; diff --git a/js/blocks/EnsembleBlocks.js b/js/blocks/EnsembleBlocks.js index d95632d314..c22c538ffc 100644 --- a/js/blocks/EnsembleBlocks.js +++ b/js/blocks/EnsembleBlocks.js @@ -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]; } } @@ -485,32 +491,27 @@ function setupEnsembleBlocks() { arg(logo, turtle, blk, receivedArg) { let value = null; let cblk = logo.blocks.blockList[blk].connections[1]; - let targetTurtle = logo.parseArg( - logo, - turtle, - cblk, - blk, - receivedArg - ); + let targetTurtle = logo.parseArg(logo, turtle, cblk, blk, receivedArg); + + let tur = logo.turtles.ithTurtle(turtle); + for (let i = 0; i < logo.turtles.turtleList.length; i++) { let thisTurtle = logo.turtles.turtleList[i]; if (targetTurtle === thisTurtle.name) { let obj; - if (logo.lastNotePlayed[i] !== null) { - let len = logo.lastNotePlayed[i][0].length; - let pitch = logo.lastNotePlayed[i][0].slice(0, len - 1); - let octave = parseInt( - logo.lastNotePlayed[i][0].slice(len - 1) - ); + if (thisTurtle.singer.lastNotePlayed !== null) { + let len = thisTurtle.singer.lastNotePlayed[0].length; + let pitch = thisTurtle.singer.lastNotePlayed[0].slice(0, len - 1); + let octave = parseInt(thisTurtle.singer.lastNotePlayed[0].slice(len - 1)); obj = [pitch, octave]; - } else if (logo.notePitches[i].length > 0) { + } else if (thisTurtle.singer.notePitches.length > 0) { obj = getNote( - logo.notePitches[i][0], - logo.noteOctaves[i][0], + thisTurtle.singer.notePitches[0], + thisTurtle.singer.noteOctaves[0], 0, logo.keySignature[i], - logo.moveable[turtle], + tur.singer.moveable, null, logo.errorMsg, logo.synth.inTemperament @@ -523,7 +524,7 @@ function setupEnsembleBlocks() { value = pitchToNumber(obj[0], obj[1], logo.keySignature[i]) - - logo.pitchNumberOffset[turtle]; + tur.singer.pitchNumberOffset; logo.blocks.blockList[blk].value = value; break; } @@ -543,27 +544,18 @@ function setupEnsembleBlocks() { } let obj; - if (logo.lastNotePlayed[turtle] !== null) { - let len = logo.lastNotePlayed[turtle][0].length; - let pitch = logo.lastNotePlayed[turtle][0].slice( - 0, - len - 1 - ); - let octave = parseInt( - logo.lastNotePlayed[turtle][0].slice(len - 1) - ); + if (tur.singer.lastNotePlayed !== null) { + let len = tur.singer.lastNotePlayed[0].length; + let pitch = tur.singer.lastNotePlayed[0].slice(0, len - 1); + let octave = parseInt(tur.singer.lastNotePlayed[0].slice(len - 1)); obj = [pitch, octave]; - } else if (logo.notePitches[turtle].length > 0) { + } else if (tur.singer.notePitches.length > 0) { obj = getNote( - logo.notePitches[turtle][ - last(logo.inNoteBlock[turtle]) - ][0], - logo.noteOctaves[turtle][ - last(logo.inNoteBlock[turtle]) - ][0], + tur.singer.notePitches[last(logo.inNoteBlock[turtle])][0], + tur.singer.noteOctaves[last(logo.inNoteBlock[turtle])][0], 0, logo.keySignature[turtle], - logo.moveable[turtle], + tur.singer.moveable, null, logo.errorMsg, logo.synth.inTemperament @@ -576,7 +568,7 @@ function setupEnsembleBlocks() { value = pitchToNumber(obj[0], obj[1], logo.keySignature[turtle]) - - logo.pitchNumberOffset[turtle]; + tur.singer.pitchNumberOffset; logo.blocks.blockList[blk].value = value; } } @@ -599,26 +591,20 @@ function setupEnsembleBlocks() { arg(logo, turtle, blk, receivedArg) { let value = null; let cblk = logo.blocks.blockList[blk].connections[1]; - let targetTurtle = logo.parseArg( - logo, - turtle, - cblk, - blk, - receivedArg - ); + let targetTurtle = logo.parseArg(logo, turtle, cblk, blk, receivedArg); + for (let i = 0; i < logo.turtles.turtleList.length; i++) { - let thisTurtle = logo.turtles.turtleList[i]; + let thisTurtle = logo.turtles.ithTurtle(i); if (targetTurtle === thisTurtle.name) { if ( logo.inNoteBlock[i].length > 0 && - last(logo.inNoteBlock[i]) in logo.noteValue[i] + last(logo.inNoteBlock[i]) in thisTurtle.singer.noteValue ) { - value = - 1 / logo.noteValue[i][last(logo.inNoteBlock[i])]; - } else if (logo.lastNotePlayed[i] !== null) { - value = logo.lastNotePlayed[i][1]; - } else if (logo.notePitches[i].length > 0) { - value = logo.noteBeat[i][last(logo.inNoteBlock[i])]; + value = 1 / thisTurtle.singer.noteValue[last(logo.inNoteBlock[i])]; + } 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])]; } else { value = -1; } diff --git a/js/blocks/ExtrasBlocks.js b/js/blocks/ExtrasBlocks.js index 77e4dbc168..a6731f9a9c 100644 --- a/js/blocks/ExtrasBlocks.js +++ b/js/blocks/ExtrasBlocks.js @@ -779,12 +779,9 @@ function setupExtrasBlocks() { flow(args, logo, turtle) { if (args.length === 1) { - let bpmFactor; - if (logo.bpm[turtle].length > 0) { - bpmFactor = TONEBPM / last(logo.bpm[turtle]); - } else { - bpmFactor = TONEBPM / logo._masterBPM; - } + let bpmFactor = + TONEBPM / + logo.bpm[turtle].length > 0 ? last(logo.bpm[turtle]) : Singer.masterBPM; let noteBeatValue = bpmFactor / (1 / args[0]); logo.previousTurtleTime[turtle] = logo.turtleTime[turtle]; diff --git a/js/blocks/GraphicsBlocks.js b/js/blocks/GraphicsBlocks.js index 2e485c632f..d9e60ef3c2 100644 --- a/js/blocks/GraphicsBlocks.js +++ b/js/blocks/GraphicsBlocks.js @@ -144,11 +144,10 @@ function setupGraphicsBlocks() { } flow(args, logo, turtle, blk) { + let tur = logo.turtles.ithTurtle(turtle); + if (args.length === 2) { - if ( - typeof args[0] === "string" || - typeof args[1] === "string" - ) { + if (typeof args[0] === "string" || typeof args[1] === "string") { logo.errorMsg(NANERRORMSG, blk); } else if (logo.inMatrix) { logo.pitchTimeMatrix.addRowBlock(blk); @@ -160,9 +159,7 @@ function setupGraphicsBlocks() { ); logo.pitchTimeMatrix.rowArgs.push([args[0], args[1]]); } else if (logo.inNoteBlock[turtle].length > 0) { - logo.embeddedGraphics[turtle][ - last(logo.inNoteBlock[turtle]) - ].push(blk); + tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk); } else { if (logo.suppressOutput[turtle]) { let savedPenState = @@ -193,23 +190,22 @@ function setupGraphicsBlocks() { } flow(args, logo, turtle, blk) { + let tur = logo.turtles.ithTurtle(turtle); + if (logo.inMatrix) { // ignore clear block in matrix } else if (logo.inNoteBlock[turtle].length > 0) { - logo.embeddedGraphics[turtle][ - last(logo.inNoteBlock[turtle]) - ].push(blk); + tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk); } else { if (logo.suppressOutput[turtle]) { - let savedPenState = - logo.turtles.turtleList[turtle].painter.penState; - logo.turtles.turtleList[turtle].painter.penState = false; - logo.turtles.turtleList[turtle].painter.doSetXY(0, 0); - logo.turtles.turtleList[turtle].painter.doSetHeading(0); - logo.turtles.turtleList[turtle].painter.penState = savedPenState; + let savedPenState = tur.painter.penState; + tur.painter.penState = false; + tur.painter.doSetXY(0, 0); + tur.painter.doSetHeading(0); + tur.painter.penState = savedPenState; } else { logo.svgBackground = true; - logo.turtles.turtleList[turtle].painter.doClear(true, true, true); + tur.painter.doClear(true, true, true); } } } @@ -238,16 +234,13 @@ function setupGraphicsBlocks() { } flow(args, logo, turtle, blk) { + let tur = logo.turtles.ithTurtle(turtle); + if (args.length === 2) { - if ( - typeof args[0] === "string" || - typeof args[1] === "string" - ) { + if (typeof args[0] === "string" || typeof args[1] === "string") { logo.errorMsg(NANERRORMSG, blk); } else if (logo.inNoteBlock[turtle].length > 0) { - logo.embeddedGraphics[turtle][ - last(logo.inNoteBlock[turtle]) - ].push(blk); + tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk); } else { logo.cp2x[turtle] = args[0]; logo.cp2y[turtle] = args[1]; @@ -279,16 +272,13 @@ function setupGraphicsBlocks() { } flow(args, logo, turtle, blk) { + let tur = logo.turtles.ithTurtle(turtle); + if (args.length === 2) { - if ( - typeof args[0] === "string" || - typeof args[1] === "string" - ) { + if (typeof args[0] === "string" || typeof args[1] === "string") { logo.errorMsg(NANERRORMSG, blk); } else if (logo.inNoteBlock[turtle].length > 0) { - logo.embeddedGraphics[turtle][ - last(logo.inNoteBlock[turtle]) - ].push(blk); + tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk); } else { logo.cp1x[turtle] = args[0]; logo.cp1y[turtle] = args[1]; @@ -318,22 +308,18 @@ function setupGraphicsBlocks() { } flow(args, logo, turtle, blk) { + let tur = logo.turtles.ithTurtle(turtle); + if (args.length === 2) { - if ( - typeof args[0] === "string" || - typeof args[1] === "string" - ) { + if (typeof args[0] === "string" || typeof args[1] === "string") { logo.errorMsg(NANERRORMSG, blk); } else if (logo.inNoteBlock[turtle].length > 0) { - logo.embeddedGraphics[turtle][ - last(logo.inNoteBlock[turtle]) - ].push(blk); + tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk); } else { if (logo.suppressOutput[turtle]) { - let savedPenState = - logo.turtles.turtleList[turtle].painter.penState; - logo.turtles.turtleList[turtle].painter.penState = false; - logo.turtles.turtleList[turtle].painter.doBezier( + let savedPenState = tur.painter.penState; + tur.painter.penState = false; + tur.painter.doBezier( logo.cp1x[turtle], logo.cp1y[turtle], logo.cp2x[turtle], @@ -341,9 +327,9 @@ function setupGraphicsBlocks() { args[0], args[1] ); - logo.turtles.turtleList[turtle].painter.penState = savedPenState; + tur.painter.penState = savedPenState; } else { - logo.turtles.turtleList[turtle].painter.doBezier( + tur.painter.doBezier( logo.cp1x[turtle], logo.cp1y[turtle], logo.cp2x[turtle], @@ -380,11 +366,10 @@ function setupGraphicsBlocks() { } flow(args, logo, turtle, blk) { + let tur = logo.turtles.ithTurtle(turtle); + if (args.length === 2) { - if ( - typeof args[0] === "string" || - typeof args[1] === "string" - ) { + if (typeof args[0] === "string" || typeof args[1] === "string") { logo.errorMsg(NANERRORMSG, blk); } else if (logo.inMatrix) { logo.pitchTimeMatrix.addRowBlock(blk); @@ -396,18 +381,15 @@ function setupGraphicsBlocks() { ); logo.pitchTimeMatrix.rowArgs.push([args[0], args[1]]); } else if (logo.inNoteBlock[turtle].length > 0) { - logo.embeddedGraphics[turtle][ - last(logo.inNoteBlock[turtle]) - ].push(blk); + tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk); } else { if (logo.suppressOutput[turtle]) { - let savedPenState = - logo.turtles.turtleList[turtle].painter.penState; - logo.turtles.turtleList[turtle].painter.penState = false; - logo.turtles.turtleList[turtle].painter.doArc(args[0], args[1]); - logo.turtles.turtleList[turtle].painter.penState = savedPenState; + let savedPenState = tur.painter.penState; + tur.painter.penState = false; + tur.painter.doArc(args[0], args[1]); + tur.painter.penState = savedPenState; } else { - logo.turtles.turtleList[turtle].painter.doArc(args[0], args[1]); + tur.painter.doArc(args[0], args[1]); } } } @@ -432,6 +414,8 @@ function setupGraphicsBlocks() { } flow(args, logo, turtle, blk) { + let tur = logo.turtles.ithTurtle(turtle); + if (args.length === 1) { if (typeof args[0] === "string") { logo.errorMsg(NANERRORMSG, blk); @@ -445,11 +429,9 @@ function setupGraphicsBlocks() { ); logo.pitchTimeMatrix.rowArgs.push(args[0]); } else if (logo.inNoteBlock[turtle].length > 0) { - logo.embeddedGraphics[turtle][ - last(logo.inNoteBlock[turtle]) - ].push(blk); + tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk); } else { - logo.turtles.turtleList[turtle].painter.doSetHeading(args[0]); + tur.painter.doSetHeading(args[0]); } } } @@ -480,11 +462,10 @@ function setupGraphicsBlocks() { } flow(args, logo, turtle, blk) { + let tur = logo.turtles.ithTurtle(turtle); + if (args.length === 2) { - if ( - typeof args[0] === "string" || - typeof args[1] === "string" - ) { + if (typeof args[0] === "string" || typeof args[1] === "string") { logo.errorMsg(NANERRORMSG, blk); } else if (logo.inMatrix) { logo.pitchTimeMatrix.addRowBlock(blk); @@ -496,24 +477,15 @@ function setupGraphicsBlocks() { ); logo.pitchTimeMatrix.rowArgs.push([args[0], args[1]]); } else if (logo.inNoteBlock[turtle].length > 0) { - logo.embeddedGraphics[turtle][ - last(logo.inNoteBlock[turtle]) - ].push(blk); + tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk); } else { if (logo.suppressOutput[turtle]) { - let savedPenState = - logo.turtles.turtleList[turtle].painter.penState; - logo.turtles.turtleList[turtle].painter.penState = false; - logo.turtles.turtleList[turtle].painter.doSetXY( - args[0], - args[1] - ); - logo.turtles.turtleList[turtle].painter.penState = savedPenState; + let savedPenState = tur.painter.penState; + tur.painter.penState = false; + tur.painter.doSetXY(args[0], args[1]); + tur.painter.penState = savedPenState; } else { - logo.turtles.turtleList[turtle].painter.doSetXY( - args[0], - args[1] - ); + tur.painter.doSetXY(args[0], args[1]); } } } @@ -542,6 +514,8 @@ function setupGraphicsBlocks() { } flow(args, logo, turtle, blk) { + let tur = logo.turtles.ithTurtle(turtle); + if (args.length === 1) { if (typeof args[0] === "string") { logo.errorMsg(NANERRORMSG, blk); @@ -555,18 +529,15 @@ function setupGraphicsBlocks() { ); logo.pitchTimeMatrix.rowArgs.push(args[0]); } else if (logo.inNoteBlock[turtle].length > 0) { - logo.embeddedGraphics[turtle][ - last(logo.inNoteBlock[turtle]) - ].push(blk); + tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk); } else { if (logo.suppressOutput[turtle]) { - let savedPenState = - logo.turtles.turtleList[turtle].painter.penState; - logo.turtles.turtleList[turtle].painter.penState = false; - logo.turtles.turtleList[turtle].painter.doRight(args[0]); - logo.turtles.turtleList[turtle].painter.penState = savedPenState; + let savedPenState = tur.painter.penState; + tur.painter.penState = false; + tur.painter.doRight(args[0]); + tur.painter.penState = savedPenState; } else { - logo.turtles.turtleList[turtle].painter.doRight(args[0]); + tur.painter.doRight(args[0]); } } } @@ -595,6 +566,8 @@ function setupGraphicsBlocks() { } flow(args, logo, turtle, blk) { + let tur = logo.turtles.ithTurtle(turtle); + if (args.length === 1) { if (typeof args[0] === "string") { logo.errorMsg(NANERRORMSG, blk); @@ -608,18 +581,15 @@ function setupGraphicsBlocks() { ); logo.pitchTimeMatrix.rowArgs.push(args[0]); } else if (logo.inNoteBlock[turtle].length > 0) { - logo.embeddedGraphics[turtle][ - last(logo.inNoteBlock[turtle]) - ].push(blk); + tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk); } else { if (logo.suppressOutput[turtle]) { - let savedPenState = - logo.turtles.turtleList[turtle].painter.penState; - logo.turtles.turtleList[turtle].painter.penState = false; - logo.turtles.turtleList[turtle].painter.doRight(-args[0]); - logo.turtles.turtleList[turtle].painter.penState = savedPenState; + let savedPenState = tur.painter.penState; + tur.painter.penState = false; + tur.painter.doRight(-args[0]); + tur.painter.penState = savedPenState; } else { - logo.turtles.turtleList[turtle].painter.doRight(-args[0]); + tur.painter.doRight(-args[0]); } } } @@ -647,6 +617,8 @@ function setupGraphicsBlocks() { } flow(args, logo, turtle, blk) { + let tur = logo.turtles.ithTurtle(turtle); + if (args.length === 1) { if (typeof args[0] === "string") { logo.errorMsg(NANERRORMSG, blk); @@ -660,18 +632,15 @@ function setupGraphicsBlocks() { ); logo.pitchTimeMatrix.rowArgs.push(args[0]); } else if (logo.inNoteBlock[turtle].length > 0) { - logo.embeddedGraphics[turtle][ - last(logo.inNoteBlock[turtle]) - ].push(blk); + tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk); } else { if (logo.suppressOutput[turtle]) { - let savedPenState = - logo.turtles.turtleList[turtle].painter.penState; - logo.turtles.turtleList[turtle].painter.penState = false; - logo.turtles.turtleList[turtle].painter.doForward(-args[0]); - logo.turtles.turtleList[turtle].painter.penState = savedPenState; + let savedPenState = tur.painter.penState; + tur.painter.penState = false; + tur.painter.doForward(-args[0]); + tur.painter.penState = savedPenState; } else { - logo.turtles.turtleList[turtle].painter.doForward(-args[0]); + tur.painter.doForward(-args[0]); } } } @@ -699,6 +668,8 @@ function setupGraphicsBlocks() { } flow(args, logo, turtle, blk) { + let tur = logo.turtles.ithTurtle(turtle); + if (args.length === 1) { if (typeof args[0] === "string") { logo.errorMsg(NANERRORMSG, blk); @@ -712,18 +683,15 @@ function setupGraphicsBlocks() { ); logo.pitchTimeMatrix.rowArgs.push(args[0]); } else if (logo.inNoteBlock[turtle].length > 0) { - logo.embeddedGraphics[turtle][ - last(logo.inNoteBlock[turtle]) - ].push(blk); + tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk); } else { if (logo.suppressOutput[turtle]) { - let savedPenState = - logo.turtles.turtleList[turtle].painter.penState; - logo.turtles.turtleList[turtle].painter.penState = false; - logo.turtles.turtleList[turtle].painter.doForward(args[0]); - logo.turtles.turtleList[turtle].painter.penState = savedPenState; + let savedPenState = tur.painter.penState; + tur.painter.penState = false; + tur.painter.doForward(args[0]); + tur.painter.penState = savedPenState; } else { - logo.turtles.turtleList[turtle].painter.doForward(args[0]); + tur.painter.doForward(args[0]); } } } diff --git a/js/blocks/IntervalsBlocks.js b/js/blocks/IntervalsBlocks.js index 1e0f887f59..f13277602f 100644 --- a/js/blocks/IntervalsBlocks.js +++ b/js/blocks/IntervalsBlocks.js @@ -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 @@ -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; @@ -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, @@ -254,7 +255,7 @@ function setupIntervalsBlocks() { ); } - logo.notesPlayed[turtle] = saveNoteCount; + tur.singer.notesPlayed = saveNoteCount; // Restore previous state logo.boxes = JSON.parse(saveBoxes); @@ -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 @@ -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; @@ -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 && @@ -370,7 +365,7 @@ function setupIntervalsBlocks() { ); } - logo.notesPlayed[turtle] = saveNoteCount; + tur.singer.notesPlayed = saveNoteCount; // Restore previous state logo.boxes = JSON.parse(saveBoxes); @@ -507,13 +502,12 @@ function setupIntervalsBlocks() { arg = args[0]; } + let tur = logo.turtles.ithTurtle(turtle); + let i = arg > 0 ? Math.floor(arg) : Math.ceil(arg); if (i !== 0) { - logo.semitoneIntervals[turtle].push([ - i, - logo.noteDirection[turtle] - ]); - logo.noteDirection[turtle] = 0; + logo.semitoneIntervals[turtle].push([i, tur.singer.noteDirection]); + tur.singer.noteDirection = 0; let listenerName = "_semitone_interval_" + turtle; logo.setDispatchBlock(blk, turtle, listenerName); @@ -722,8 +716,10 @@ function setupIntervalsBlocks() { return; } - logo.inDefineMode[turtle] = true; - logo.defineMode[turtle] = []; + let tur = logo.turtles.ithTurtle(turtle); + + tur.singer.inDefineMode = true; + tur.singer.defineMode = []; let modeName; if (args[0] === null) { logo.errorMsg(NOINPUTERRORMSG, blk); @@ -737,12 +733,12 @@ function setupIntervalsBlocks() { let __listener = function(event) { MUSICALMODES[modeName] = []; - if (logo.defineMode[turtle].indexOf(0) === -1) { - logo.defineMode[turtle].push(0); + if (tur.singer.defineMode.indexOf(0) === -1) { + tur.singer.defineMode.push(0); logo.errorMsg(_("Adding missing pitch number 0.")); } - let pitchNumbers = logo.defineMode[turtle].sort(function(a, b) { + let pitchNumbers = tur.singer.defineMode.sort(function(a, b) { return a[0] - b[0]; }); @@ -775,7 +771,7 @@ function setupIntervalsBlocks() { logo.blocks.updateBlockText(cblk); } - logo.inDefineMode[turtle] = false; + tur.singer.inDefineMode = false; }; logo.setTurtleListener(turtle, listenerName, __listener); @@ -814,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]; } } } @@ -984,12 +980,13 @@ function setupIntervalsBlocks() { } } - // Check to see if there are any transpositions on the key. - if (turtle in logo.transposition) { + let tur = logo.turtles.ithTurtle(turtle); + // Check to see if there are any transpositions on the key + if (tur.singer.transposition !== 0) { let noteObj = getNote( args[0], 4, - logo.transposition[turtle], + tur.singer.transposition, logo.keySignature[turtle], false, null, diff --git a/js/blocks/MediaBlocks.js b/js/blocks/MediaBlocks.js index 34c019caaa..cb4ac74eb2 100644 --- a/js/blocks/MediaBlocks.js +++ b/js/blocks/MediaBlocks.js @@ -243,12 +243,12 @@ function setupMediaBlocks() { } flow(args, logo, turtle, blk) { + let tur = logo.turtles.ithTurtle(turtle); + if (args.length === 1) { if (logo.meSpeak !== null) { if (logo.inNoteBlock[turtle].length > 0) { - logo.embeddedGraphics[turtle][ - last(logo.inNoteBlock[turtle]) - ].push(blk); + tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk); } else { if (!logo.suppressOutput[turtle]) { logo.processSpeak(args[0]); @@ -385,6 +385,8 @@ function setupMediaBlocks() { } arg(logo, turtle, blk, receivedArg) { + let tur = logo.turtles.ithTurtle(turtle); + if (_THIS_IS_MUSIC_BLOCKS_) { let block = logo.blocks.blockList[blk]; let cblk1 = logo.blocks.blockList[blk].connections[1]; @@ -396,9 +398,9 @@ function setupMediaBlocks() { let note = logo.parseArg(logo, turtle, cblk1, blk, receivedArg); let octave = Math.floor( calcOctave( - logo.currentOctave[turtle], + tur.singer.currentOctave, logo.parseArg(logo, turtle, cblk2, blk, receivedArg), - logo.lastNotePlayed[turtle], + tur.singer.lastNotePlayed, note ) ); @@ -556,11 +558,11 @@ function setupMediaBlocks() { } flow(args, logo, turtle, blk) { + let tur = logo.turtles.ithTurtle(turtle); + if (args.length === 2) { if (logo.inNoteBlock[turtle].length > 0) { - logo.embeddedGraphics[turtle][ - last(logo.inNoteBlock[turtle]) - ].push(blk); + tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk); } else { if (!logo.suppressOutput[turtle]) { logo.processShow(turtle, blk, args[0], args[1]); diff --git a/js/blocks/MeterBlocks.js b/js/blocks/MeterBlocks.js index 060d489c40..4a4a1e3da3 100644 --- a/js/blocks/MeterBlocks.js +++ b/js/blocks/MeterBlocks.js @@ -43,7 +43,7 @@ function setupMeterBlocks() { } setter(logo, value, turtle, blk) { - logo.beatFactor[turtle] = value; + logo.turtles.ithTurtle(turtle).singer.beatFactor = value; } arg(logo, turtle, blk) { @@ -54,7 +54,7 @@ function setupMeterBlocks() { ) { logo.statusFields.push([blk, "beatfactor"]); } else { - return logo.beatFactor[turtle]; + return logo.turtles.ithTurtle(turtle).singer.beatFactor; } } } @@ -104,7 +104,7 @@ function setupMeterBlocks() { } else if (logo.bpm[turtle].length > 0) { return last(logo.bpm[turtle]); } else { - return logo._masterBPM; + return Singer.masterBPM; } } } @@ -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 ); } @@ -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; } } } @@ -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]; } } } @@ -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; } } } @@ -642,12 +634,9 @@ function setupMeterBlocks() { logo.parameterQueue[turtle] = []; logo.initTurtle(turtle); logo.setTurtleListener(turtle, eventName, __listener); - let duration ; - if (logo.bpm[orgTurtle].length > 0) { - duration = 60 / last(logo.bpm[orgTurtle]); - } else { - duration = 60 / logo._masterBPM; - } + let duration = + 60 / + logo.bpm[orgTurtle].length > 0 ? last(logo.bpm[orgTurtle]) : Singer.masterBPM; if (logo.turtles.turtleList[turtle].interval !== undefined) clearInterval(this.interval); logo.turtles.turtleList[turtle].interval = setInterval ( () => { @@ -780,7 +769,7 @@ function setupMeterBlocks() { target, blk ); - logo._masterBPM = 30; + Singer.masterBPM = 30; } else if (bpm > 1000) { obj = rationalToFraction(args[1]); target = (1000 * 0.25) / args[1]; @@ -796,13 +785,13 @@ function setupMeterBlocks() { target, blk ); - logo._masterBPM = 1000; + Singer.masterBPM = 1000; } else { - logo._masterBPM = bpm; + Singer.masterBPM = bpm; } logo.notation.notationTempo(turtle, args[0], args[1]); - logo.defaultBPMFactor = TONEBPM / logo._masterBPM; + Singer.defaultBPMFactor = TONEBPM / Singer.masterBPM; } if (logo.inTempo) { @@ -831,15 +820,15 @@ function setupMeterBlocks() { if (args.length === 1 && typeof args[0] === "number") { if (args[0] < 30) { logo.errorMsg(_("Beats per minute must be > 30."), blk); - logo._masterBPM = 30; + Singer.masterBPM = 30; } else if (args[0] > 1000) { logo.errorMsg(_("Maximum beats per minute is 1000."), blk); - logo._masterBPM = 1000; + Singer.masterBPM = 1000; } else { - logo._masterBPM = args[0]; + Singer.masterBPM = args[0]; } - logo.defaultBPMFactor = TONEBPM / logo._masterBPM; + Singer.defaultBPMFactor = TONEBPM / Singer.masterBPM; } if (logo.inTempo) { diff --git a/js/blocks/NumberBlocks.js b/js/blocks/NumberBlocks.js index 400039029d..bbb5960d5b 100644 --- a/js/blocks/NumberBlocks.js +++ b/js/blocks/NumberBlocks.js @@ -421,6 +421,8 @@ function setupNumberBlocks() { return 0; } } else { + let tur = logo.turtles.ithTurtle(turtle); + // We have a special case for certain keywords associated with octaves: // current, next, and previous. @@ -435,18 +437,18 @@ function setupNumberBlocks() { a = typeof logo.blocks.blockList[cblk1].value === "string" ? calcOctave( - logo.currentOctave[turtle], + tur.singer.currentOctave, logo.blocks.blockList[cblk1].value, - logo.lastNotePlayed[turtle], + tur.singer.lastNotePlayed, logo.blocks.blockList[noteBlock].value ) : logo.parseArg(logo, turtle, cblk1, blk, receivedArg); b = typeof logo.blocks.blockList[cblk2].value === "string" ? calcOctave( - logo.currentOctave[turtle], + tur.singer.currentOctave, logo.blocks.blockList[cblk2].value, - logo.lastNotePlayed[turtle], + tur.singer.lastNotePlayed, logo.blocks.blockList[noteBlock].value ) : logo.parseArg(logo, turtle, cblk2, blk, receivedArg); @@ -556,6 +558,8 @@ function setupNumberBlocks() { return 0; } } else { + let tur = logo.turtles.ithTurtle(turtle); + // We have a special case for certain keywords associated with octaves: // current, next, and previous. @@ -570,18 +574,18 @@ function setupNumberBlocks() { a = typeof logo.blocks.blockList[cblk1].value === "string" ? calcOctave( - logo.currentOctave[turtle], + tur.singer.currentOctave, logo.blocks.blockList[cblk1].value, - logo.lastNotePlayed[turtle], + tur.singer.lastNotePlayed, logo.blocks.blockList[noteBlock].value ) : logo.parseArg(logo, turtle, cblk1, blk, receivedArg); b = typeof logo.blocks.blockList[cblk2].value === "string" ? calcOctave( - logo.currentOctave[turtle], + tur.singer.currentOctave, logo.blocks.blockList[cblk2].value, - logo.lastNotePlayed[turtle], + tur.singer.lastNotePlayed, logo.blocks.blockList[noteBlock].value ) : logo.parseArg(logo, turtle, cblk2, blk, receivedArg); @@ -652,6 +656,8 @@ function setupNumberBlocks() { return 0; } } else { + let tur = logo.turtles.ithTurtle(turtle); + // We have a special case for certain keywords associated with octaves: // current, next, and previous. In the case of plus, since we use it // for string concatenation as well, we check to see if the block is @@ -660,26 +666,23 @@ function setupNumberBlocks() { let cblk0 = logo.blocks.blockList[blk].connections[0]; let a, b; - if ( - cblk0 !== null && - logo.blocks.blockList[cblk0].name === "pitch" - ) { + if (cblk0 !== null && logo.blocks.blockList[cblk0].name === "pitch") { let noteBlock = logo.blocks.blockList[cblk0].connections[1]; a = typeof logo.blocks.blockList[cblk1].value === "string" ? calcOctave( - logo.currentOctave[turtle], + tur.singer.currentOctave, logo.blocks.blockList[cblk1].value, - logo.lastNotePlayed[turtle], + tur.singer.lastNotePlayed, logo.blocks.blockList[noteBlock].value ) : logo.parseArg(logo, turtle, cblk1, blk, receivedArg); b = typeof logo.blocks.blockList[cblk2].value === "string" ? calcOctave( - logo.currentOctave[turtle], + tur.singer.currentOctave, logo.blocks.blockList[cblk2].value, - logo.lastNotePlayed[turtle], + tur.singer.lastNotePlayed, logo.blocks.blockList[noteBlock].value ) : logo.parseArg(logo, turtle, cblk2, blk, receivedArg); diff --git a/js/blocks/OrnamentBlocks.js b/js/blocks/OrnamentBlocks.js index 8254fa56aa..9829e953eb 100644 --- a/js/blocks/OrnamentBlocks.js +++ b/js/blocks/OrnamentBlocks.js @@ -87,17 +87,19 @@ function setupOrnamentBlocks() { return; } - logo.inNeighbor[turtle].push(blk); - logo.neighborStepPitch[turtle].push(args[0]); - logo.neighborNoteValue[turtle].push(args[1]); + let tur = logo.turtles.ithTurtle(turtle); + + tur.singer.inNeighbor.push(blk); + tur.singer.neighborStepPitch.push(args[0]); + tur.singer.neighborNoteValue.push(args[1]); let listenerName = "_neighbor_" + turtle + "_" + blk; logo.setDispatchBlock(blk, turtle, listenerName); - let __listener = function(event) { - logo.inNeighbor[turtle].pop(); - logo.neighborStepPitch[turtle].pop(); - logo.neighborNoteValue[turtle].pop(); + let __listener = event => { + tur.singer.inNeighbor.pop(); + tur.singer.neighborStepPitch.pop(); + tur.singer.neighborNoteValue.pop(); }; logo.setTurtleListener(turtle, listenerName, __listener); diff --git a/js/blocks/PenBlocks.js b/js/blocks/PenBlocks.js index b799576564..7357f2fb36 100644 --- a/js/blocks/PenBlocks.js +++ b/js/blocks/PenBlocks.js @@ -371,24 +371,22 @@ function setupPenBlocks() { return; } + let tur = logo.turtles.ithTurtle(turtle); + if (logo.inNoteBlock[turtle].length > 0) { - logo.embeddedGraphics[turtle][ - last(logo.inNoteBlock[turtle]) - ].push(blk); + tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk); } else { - logo.turtles.turtleList[turtle].painter.doStartHollowLine(); + tur.painter.doStartHollowLine(); } let listenerName = "_hollowline_" + turtle; logo.setDispatchBlock(blk, turtle, listenerName); - let __listener = function() { + let __listener = () => { if (logo.inNoteBlock[turtle].length > 0) { - logo.embeddedGraphics[turtle][ - last(logo.inNoteBlock[turtle]) - ].push(blk); + tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk); } else { - logo.turtles.turtleList[turtle].painter.doEndHollowLine(); + tur.painter.doEndHollowLine(); } }; @@ -428,39 +426,35 @@ function setupPenBlocks() { return; } + let tur = logo.turtles.ithTurtle(turtle); + if (logo.inNoteBlock[turtle].length > 0) { - logo.embeddedGraphics[turtle][ - last(logo.inNoteBlock[turtle]) - ].push(blk); + tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk); } else { if (logo.suppressOutput[turtle]) { - let savedPenState = - logo.turtles.turtleList[turtle].painter.penState; - logo.turtles.turtleList[turtle].painter.penState = false; - logo.turtles.turtleList[turtle].painter.doStartFill(); - logo.turtles.turtleList[turtle].painter.penState = savedPenState; + let savedPenState = tur.painter.penState; + tur.painter.penState = false; + tur.painter.doStartFill(); + tur.painter.penState = savedPenState; } else { - logo.turtles.turtleList[turtle].painter.doStartFill(); + tur.painter.doStartFill(); } } let listenerName = "_fill_" + turtle; logo.setDispatchBlock(blk, turtle, listenerName); - let __listener = function() { + let __listener = () => { if (logo.inNoteBlock[turtle].length > 0) { - logo.embeddedGraphics[turtle][ - last(logo.inNoteBlock[turtle]) - ].push(blk); + tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk); } else { if (logo.suppressOutput[turtle]) { - let savedPenState = - logo.turtles.turtleList[turtle].painter.penState; - logo.turtles.turtleList[turtle].painter.penState = false; - logo.turtles.turtleList[turtle].painter.doEndFill(); - logo.turtles.turtleList[turtle].painter.penState = savedPenState; + let savedPenState = tur.painter.penState; + tur.painter.penState = false; + tur.painter.doEndFill(); + tur.painter.penState = savedPenState; } else { - logo.turtles.turtleList[turtle].painter.doEndFill(); + tur.painter.doEndFill(); } } }; @@ -486,12 +480,12 @@ function setupPenBlocks() { } flow(args, logo, turtle, blk) { + let tur = logo.turtles.ithTurtle(turtle); + if (logo.inNoteBlock[turtle].length > 0) { - logo.embeddedGraphics[turtle][ - last(logo.inNoteBlock[turtle]) - ].push(blk); + tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk); } else { - logo.turtles.turtleList[turtle].painter.doPenUp(); + tur.painter.doPenUp(); } } } @@ -511,12 +505,12 @@ function setupPenBlocks() { } flow(args, logo, turtle, blk) { + let tur = logo.turtles.ithTurtle(turtle); + if (logo.inNoteBlock[turtle].length > 0) { - logo.embeddedGraphics[turtle][ - last(logo.inNoteBlock[turtle]) - ].push(blk); + tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk); } else { - logo.turtles.turtleList[turtle].painter.doPenDown(); + tur.painter.doPenDown(); } } } @@ -546,6 +540,8 @@ function setupPenBlocks() { return; } + let tur = logo.turtles.ithTurtle(turtle); + if (typeof args[0] === "string") { logo.errorMsg(NANERRORMSG, blk); } else if (logo.inMatrix) { @@ -559,11 +555,9 @@ function setupPenBlocks() { ); logo.pitchTimeMatrix.rowArgs.push(args[0]); } else if (logo.inNoteBlock[turtle].length > 0) { - logo.embeddedGraphics[turtle][ - last(logo.inNoteBlock[turtle]) - ].push(blk); + tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk); } else { - logo.turtles.turtleList[turtle].painter.doSetPensize(args[0]); + tur.painter.doSetPensize(args[0]); } } } @@ -591,6 +585,8 @@ function setupPenBlocks() { return; } + let tur = logo.turtles.ithTurtle(turtle); + if (typeof args[0] === "string") { logo.errorMsg(NANERRORMSG, blk); } else if (logo.inMatrix) { @@ -604,13 +600,11 @@ function setupPenBlocks() { ); logo.pitchTimeMatrix.rowArgs.push(args[0]); } else if (logo.inNoteBlock[turtle].length > 0) { - logo.embeddedGraphics[turtle][ - last(logo.inNoteBlock[turtle]) - ].push(blk); + tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk); } else { let arg = args[0] % 101; let alpha = 1.0 - arg / 100; - logo.turtles.turtleList[turtle].painter.doSetPenAlpha(alpha); + tur.painter.doSetPenAlpha(alpha); } } } @@ -637,6 +631,8 @@ function setupPenBlocks() { return; } + let tur = logo.turtles.ithTurtle(turtle); + if (typeof args[0] === "string") { logo.errorMsg(NANERRORMSG, blk); } else if (logo.inMatrix) { @@ -650,11 +646,9 @@ function setupPenBlocks() { ); logo.pitchTimeMatrix.rowArgs.push(args[0]); } else if (logo.inNoteBlock[turtle].length > 0) { - logo.embeddedGraphics[turtle][ - last(logo.inNoteBlock[turtle]) - ].push(blk); + tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk); } else { - logo.turtles.turtleList[turtle].painter.doSetHue(args[0]); + tur.painter.doSetHue(args[0]); } } } @@ -685,6 +679,8 @@ function setupPenBlocks() { return; } + let tur = logo.turtles.ithTurtle(turtle); + if (typeof args[0] === "string") { logo.errorMsg(NANERRORMSG, blk); } else if (logo.inMatrix) { @@ -698,11 +694,9 @@ function setupPenBlocks() { ); logo.pitchTimeMatrix.rowArgs.push(args[0]); } else if (logo.inNoteBlock[turtle].length > 0) { - logo.embeddedGraphics[turtle][ - last(logo.inNoteBlock[turtle]) - ].push(blk); + tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk); } else { - logo.turtles.turtleList[turtle].painter.doSetValue(args[0]); + tur.painter.doSetValue(args[0]); } } } @@ -730,6 +724,8 @@ function setupPenBlocks() { return; } + let tur = logo.turtles.ithTurtle(turtle); + if (typeof args[0] === "string") { logo.errorMsg(NANERRORMSG, blk); } else if (logo.inMatrix) { @@ -743,11 +739,9 @@ function setupPenBlocks() { ); logo.pitchTimeMatrix.rowArgs.push(args[0]); } else if (logo.inNoteBlock[turtle].length > 0) { - logo.embeddedGraphics[turtle][ - last(logo.inNoteBlock[turtle]) - ].push(blk); + tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk); } else { - logo.turtles.turtleList[turtle].painter.doSetChroma(args[0]); + tur.painter.doSetChroma(args[0]); } } } @@ -776,6 +770,8 @@ function setupPenBlocks() { return; } + let tur = logo.turtles.ithTurtle(turtle); + if (typeof args[0] === "string") { logo.errorMsg(NANERRORMSG, blk); } else if (logo.inMatrix) { @@ -789,11 +785,9 @@ function setupPenBlocks() { ); logo.pitchTimeMatrix.rowArgs.push(args[0]); } else if (logo.inNoteBlock[turtle].length > 0) { - logo.embeddedGraphics[turtle][ - last(logo.inNoteBlock[turtle]) - ].push(blk); + tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])].push(blk); } else { - logo.turtles.turtleList[turtle].painter.doSetColor(args[0]); + tur.painter.doSetColor(args[0]); } } } diff --git a/js/blocks/PitchBlocks.js b/js/blocks/PitchBlocks.js index 206311676a..e36aba39cd 100644 --- a/js/blocks/PitchBlocks.js +++ b/js/blocks/PitchBlocks.js @@ -129,7 +129,7 @@ function setupPitchBlocks() { ) { logo.statusFields.push([blk, "transposition"]); } else { - return logo.transposition[turtle]; + return logo.turtles.ithTurtle(turtle).singer.transposition; } } } @@ -154,11 +154,13 @@ function setupPitchBlocks() { } arg(logo, turtle) { - if (logo.lastNotePlayed[turtle] !== null) { - let len = logo.lastNotePlayed[turtle][0].length; + let tur = logo.turtles.ithTurtle(turtle); + + if (tur.singer.lastNotePlayed !== null) { + let len = tur.singer.lastNotePlayed[0].length; return getStepSizeDown( logo.keySignature[turtle], - logo.lastNotePlayed[turtle][0].slice(0, len - 1) + tur.singer.lastNotePlayed[0].slice(0, len - 1) ); } else { return getStepSizeDown(logo.keySignature[turtle], "G"); @@ -186,11 +188,13 @@ function setupPitchBlocks() { } arg(logo, turtle) { - if (logo.lastNotePlayed[turtle] !== null) { - let len = logo.lastNotePlayed[turtle][0].length; + let tur = logo.turtles.ithTurtle(turtle); + + if (tur.singer.lastNotePlayed !== null) { + let len = tur.singer.lastNotePlayed[0].length; return getStepSizeUp( logo.keySignature[turtle], - logo.lastNotePlayed[turtle][0].slice(0, len - 1) + tur.singer.lastNotePlayed[0].slice(0, len - 1) ); } else { return getStepSizeUp(logo.keySignature[turtle], "G"); @@ -219,34 +223,29 @@ function setupPitchBlocks() { } arg(logo, turtle, blk) { + let tur = logo.turtles.ithTurtle(turtle); + if ( logo.inStatusMatrix && logo.blocks.blockList[logo.blocks.blockList[blk].connections[0]] .name === "print" ) { logo.statusFields.push([blk, "mypitch"]); - } else if (logo.previousNotePlayed[turtle] == null) { + } else if (tur.singer.previousNotePlayed == null) { return 0; } else { - let len = logo.previousNotePlayed[turtle][0].length; - let pitch = logo.previousNotePlayed[turtle][0].slice( - 0, - len - 1 - ); - let octave = parseInt( - logo.previousNotePlayed[turtle][0].slice(len - 1) - ); + let len = tur.singer.previousNotePlayed[0].length; + let pitch = tur.singer.previousNotePlayed[0].slice(0, len - 1); + let octave = parseInt(tur.singer.previousNotePlayed[0].slice(len - 1)); let obj = [pitch, octave]; let previousValue = pitchToNumber( obj[0], obj[1], logo.keySignature[turtle] ); - len = logo.lastNotePlayed[turtle][0].length; - pitch = logo.lastNotePlayed[turtle][0].slice(0, len - 1); - octave = parseInt( - logo.lastNotePlayed[turtle][0].slice(len - 1) - ); + len = tur.singer.lastNotePlayed[0].length; + pitch = tur.singer.lastNotePlayed[0].slice(0, len - 1); + octave = parseInt(tur.singer.lastNotePlayed[0].slice(len - 1)); obj = [pitch, octave]; let delta = pitchToNumber(obj[0], obj[1], logo.keySignature[turtle]) - @@ -274,7 +273,7 @@ function setupPitchBlocks() { octave, nhalf, logo.keySignature[turtle], - logo.moveable[turtle], + tur.singer.moveable, null, logo.errorMsg, logo.synth.inTemperament @@ -303,7 +302,7 @@ function setupPitchBlocks() { octave, nhalf, logo.keySignature[turtle], - logo.moveable[turtle], + tur.singer.moveable, null, logo.errorMsg, logo.synth.inTemperament @@ -351,12 +350,11 @@ function setupPitchBlocks() { } setter(logo, value, turtle, blk) { - logo.previousNotePlayed[turtle] = logo.lastNotePlayed[turtle]; - let obj = numberToPitch(Math.floor(value) + logo.pitchNumberOffset[turtle]); - logo.lastNotePlayed[turtle] = [ - obj[0] + obj[1], - logo.lastNotePlayed[turtle][1] - ]; + let tur = logo.turtles.ithTurtle(turtle); + + tur.singer.previousNotePlayed = tur.singer.lastNotePlayed; + let obj = numberToPitch(Math.floor(value) + tur.singer.pitchNumberOffset); + tur.singer.lastNotePlayed = [obj[0] + obj[1], tur.singer.lastNotePlayed[1]]; } arg(logo, turtle, blk) { @@ -367,45 +365,38 @@ function setupPitchBlocks() { ) { logo.statusFields.push([blk, "mypitch"]); } else { + let tur = logo.turtles.ithTurtle(turtle); + let value = null; let obj; - if (logo.lastNotePlayed[turtle] !== null) { - if (typeof logo.lastNotePlayed[turtle][0] === "string") { - let len = logo.lastNotePlayed[turtle][0].length; - let pitch = logo.lastNotePlayed[turtle][0].slice( + if (tur.singer.lastNotePlayed !== null) { + if (typeof tur.singer.lastNotePlayed[0] === "string") { + let len = tur.singer.lastNotePlayed[0].length; + let pitch = tur.singer.lastNotePlayed[0].slice( 0, len - 1 ); - let octave = parseInt( - logo.lastNotePlayed[turtle][0].slice(len - 1) - ); + let octave = parseInt(tur.singer.lastNotePlayed[0].slice(len - 1)); obj = [pitch, octave]; } else { // Hertz? - obj = frequencyToPitch( - logo.lastNotePlayed[turtle][0] - ); + obj = frequencyToPitch(tur.singer.lastNotePlayed[0]); } } else if ( - logo.inNoteBlock[turtle] in logo.notePitches[turtle] && - logo.notePitches[turtle][last(logo.inNoteBlock[turtle])] - .length > 0 + logo.inNoteBlock[turtle] in tur.singer.notePitches && + tur.singer.notePitches[last(logo.inNoteBlock[turtle])].length > 0 ) { obj = getNote( - logo.notePitches[turtle][ - last(logo.inNoteBlock[turtle]) - ][0], - logo.noteOctaves[turtle][ - last(logo.inNoteBlock[turtle]) - ][0], + tur.singer.notePitches[last(logo.inNoteBlock[turtle])][0], + tur.singer.noteOctaves[last(logo.inNoteBlock[turtle])][0], 0, logo.keySignature[turtle], - logo.moveable[turtle], + tur.singer.moveable, null, logo.errorMsg ); } else { - if (logo.lastNotePlayed[turtle] !== null) { + if (tur.singer.lastNotePlayed !== null) { console.debug("Cannot find a note "); logo.errorMsg(INVALIDPITCH, blk); } @@ -415,7 +406,7 @@ function setupPitchBlocks() { value = pitchToNumber(obj[0], obj[1], logo.keySignature[turtle]) - - logo.pitchNumberOffset[turtle]; + tur.singer.pitchNumberOffset; return value; } } @@ -450,9 +441,11 @@ function setupPitchBlocks() { ) { logo.statusFields.push([blk, "pitchinhertz"]); } else { - if (logo.lastNotePlayed[turtle] !== null) { + let tur = logo.turtles.ithTurtle(turtle); + + if (tur.singer.lastNotePlayed !== null) { return logo.synth._getFrequency( - logo.lastNotePlayed[turtle][0], + tur.singer.lastNotePlayed[0], logo.synth.changeInTemperament ); } @@ -488,19 +481,21 @@ function setupPitchBlocks() { ) { logo.statusFields.push([blk, "outputtools"]); } else { - if (logo.noteStatus[turtle] !== null) { + let tur = logo.turtles.ithTurtle(turtle); + + if (tur.singer.noteStatus !== null) { let name = logo.blocks.blockList[blk].privateData; switch (name) { case "letter class": - let lc = logo.lastNotePlayed[turtle][0][0]; + let lc = tur.singer.lastNotePlayed[0][0]; return lc; case "solfege syllable": - let lc2 = logo.lastNotePlayed[turtle][0]; + let lc2 = tur.singer.lastNotePlayed[0]; lc2 = lc2.substr(0, lc2.length - 1); 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]; @@ -508,7 +503,7 @@ function setupPitchBlocks() { return SOLFEGENAMES[i]; } case "pitch class": - let note = logo.lastNotePlayed[turtle][0]; + let note = tur.singer.lastNotePlayed[0]; let num = pitchToNumber( note.substr(0, note.length - 1 ), note[note.length - 1], @@ -516,7 +511,7 @@ function setupPitchBlocks() { ); return (num - 3) % 12; case "scalar class": - let note2 = logo.lastNotePlayed[turtle][0]; + let note2 = tur.singer.lastNotePlayed[0]; note2 = note2.substr(0, note2.length - 1); note2 = note2 .replace("#", SHARP) @@ -524,12 +519,12 @@ function setupPitchBlocks() { let scalarClass = scaleDegreeToPitchMapping( logo.keySignature[turtle], null, - logo.moveable[turtle], + tur.singer.moveable, note2 ); return scalarClass[0]; case "scale degree": - let note3 = logo.lastNotePlayed[turtle][0]; + let note3 = tur.singer.lastNotePlayed[0]; note3 = note3.substr(0, note3.length - 1); note3 = note3 .replace("#", SHARP) @@ -537,12 +532,12 @@ function setupPitchBlocks() { let scalarClass1 = scaleDegreeToPitchMapping( logo.keySignature[turtle], null, - logo.moveable[turtle], + tur.singer.moveable, note3 ); return scalarClass1[0] + scalarClass1[1]; case "nth degree": - let note4 = logo.lastNotePlayed[turtle][0]; + let note4 = tur.singer.lastNotePlayed[0]; note4 = note4.substr(0, note4.length - 1); note4 = note4 .replace("#", SHARP) @@ -550,58 +545,48 @@ function setupPitchBlocks() { let scale = _buildScale(logo.keySignature[turtle])[0]; return scale.indexOf(note4); case "staff y": - if (logo.lastNotePlayed[turtle].length === 0) { + if (tur.singer.lastNotePlayed.length === 0) { return 0; } - let lc1 = logo.lastNotePlayed[turtle][0][0]; + let lc1 = tur.singer.lastNotePlayed[0][0]; let o1 = 4; - if (logo.lastNotePlayed[turtle][0].length === 2) { - o1 = logo.lastNotePlayed[turtle][0][1]; + if (tur.singer.lastNotePlayed[0].length === 2) { + o1 = tur.singer.lastNotePlayed[0][1]; } else { - o1 = logo.lastNotePlayed[turtle][0][2]; + o1 = tur.singer.lastNotePlayed[0][2]; } // these numbers are subject to staff artwork return ["C", "D", "E", "F", "G", "A", "B"].indexOf(lc1) * 12.5 + (o1 - 4) * 87.5; case "pitch number": let value = null; let obj; - if (logo.lastNotePlayed[turtle] !== null) { - if (typeof logo.lastNotePlayed[turtle][0] === "string") { - let len = logo.lastNotePlayed[turtle][0].length; - let pitch = logo.lastNotePlayed[turtle][0].slice( - 0, - len - 1 - ); + if (tur.singer.lastNotePlayed !== null) { + if (typeof tur.singer.lastNotePlayed[0] === "string") { + let len = tur.singer.lastNotePlayed[0].length; + let pitch = tur.singer.lastNotePlayed[0].slice(0, len - 1); let octave = parseInt( - logo.lastNotePlayed[turtle][0].slice(len - 1) + tur.singer.lastNotePlayed[0].slice(len - 1) ); obj = [pitch, octave]; } else { // Hertz? - obj = frequencyToPitch( - logo.lastNotePlayed[turtle][0] - ); + obj = frequencyToPitch(tur.singer.lastNotePlayed[0]); } } else if ( - logo.inNoteBlock[turtle] in logo.notePitches[turtle] && - logo.notePitches[turtle][last(logo.inNoteBlock[turtle])] - .length > 0 + logo.inNoteBlock[turtle] in tur.singer.notePitches && + tur.singer.notePitches[last(logo.inNoteBlock[turtle])].length > 0 ) { obj = getNote( - logo.notePitches[turtle][ - last(logo.inNoteBlock[turtle]) - ][0], - logo.noteOctaves[turtle][ - last(logo.inNoteBlock[turtle]) - ][0], + tur.singer.notePitches[last(logo.inNoteBlock[turtle])][0], + tur.singer.noteOctaves[last(logo.inNoteBlock[turtle])][0], 0, logo.keySignature[turtle], - logo.moveable[turtle], + tur.singer.moveable, null, logo.errorMsg ); } else { - if (logo.lastNotePlayed[turtle] !== null) { + if (tur.singer.lastNotePlayed !== null) { console.debug("Cannot find a note "); logo.errorMsg(INVALIDPITCH, blk); } @@ -611,11 +596,11 @@ function setupPitchBlocks() { value = pitchToNumber(obj[0], obj[1], logo.keySignature[turtle]) - - logo.pitchNumberOffset[turtle]; + tur.singer.pitchNumberOffset; return value; case "pitch in hertz": return logo.synth._getFrequency( - logo.lastNotePlayed[turtle][0], + tur.singer.lastNotePlayed[0], logo.synth.changeInTemperament ); default: @@ -688,19 +673,14 @@ function setupPitchBlocks() { arg1 = args[1]; } + let tur = logo.turtles.ithTurtle(turtle); + let octave = Math.floor( calcOctave( - logo.currentOctave[turtle], - arg1, - logo.lastNotePlayed[turtle], - arg0 + tur.singer.currentOctave, arg1, tur.singer.lastNotePlayed, arg0 ) ); - logo.pitchNumberOffset[turtle] = pitchToNumber( - arg0, - octave, - logo.keySignature[turtle] - ); + tur.singer.pitchNumberOffset = pitchToNumber(arg0, octave, logo.keySignature[turtle]); } } @@ -726,7 +706,9 @@ function setupPitchBlocks() { let cblk = logo.blocks.blockList[blk].connections[1]; let num = logo.parseArg(logo, turtle, cblk, blk, receivedArg); if (num != null && typeof num === "number") { - let obj = numberToPitch(Math.floor(num) + logo.pitchNumberOffset[turtle]); + let obj = + numberToPitch(Math.floor(num) + + logo.turtles.ithTurtle(turtle).singer.pitchNumberOffset); if (logo.blocks.blockList[blk].name === "number2pitch") { return obj[0]; } else { @@ -909,12 +891,11 @@ function setupPitchBlocks() { arg2 = "scalar"; } + let tur = logo.turtles.ithTurtle(turtle); + if (arg2 === "even" || arg2 === "odd" || arg2 === "scalar") { let octave = calcOctave( - logo.currentOctave[turtle], - arg1, - logo.lastNotePlayed[turtle], - arg0 + tur.singer.currentOctave, arg1, tur.singer.lastNotePlayed, arg0 ); logo.invertList[turtle].push([arg0, octave, arg2]); } @@ -1007,7 +988,7 @@ function setupPitchBlocks() { flow(args, logo, turtle) { if (args[0] !== null && typeof args[0] === "number") { - logo.register[turtle] = Math.floor(args[0]); + logo.turtles.ithTurtle(turtle).singer.register = Math.floor(args[0]); } } } @@ -1051,24 +1032,18 @@ function setupPitchBlocks() { if (args[0] !== null && typeof args[0] === "number") { let transValue = args[0]; - if (!(logo.invertList[turtle].length === 0)) { - logo.transposition[turtle] -= transValue; - } else { - logo.transposition[turtle] += transValue; - } - - logo.transpositionValues[turtle].push(transValue); + let tur = logo.turtles.ithTurtle(turtle); + tur.singer.transposition += + logo.invertList[turtle].length > 0 ? -transValue : transValue; + tur.singer.transpositionValues.push(transValue); let listenerName = "_transposition_" + turtle; logo.setDispatchBlock(blk, turtle, listenerName); let __listener = function(event) { - transValue = logo.transpositionValues[turtle].pop(); - if (!(logo.invertList[turtle].length === 0)) { - logo.transposition[turtle] += transValue; - } else { - logo.transposition[turtle] -= transValue; - } + transValue = tur.singer.transpositionValues.pop(); + tur.singer.transposition += + logo.invertList[turtle].length > 0 ? transValue : -transValue; }; logo.setTurtleListener(turtle, listenerName, __listener); @@ -1334,24 +1309,18 @@ function setupPitchBlocks() { transValue = args[0]; } - if (!(logo.invertList[turtle].length === 0)) { - logo.scalarTransposition[turtle] -= transValue; - } else { - logo.scalarTransposition[turtle] += transValue; - } - - logo.scalarTranspositionValues[turtle].push(transValue); + let tur = logo.turtles.ithTurtle(turtle); + tur.singer.scalarTransposition += + logo.invertList[turtle].length > 0 ? transValue : -transValue; + tur.singer.scalarTranspositionValues.push(transValue); let listenerName = "_scalar_transposition_" + turtle; logo.setDispatchBlock(blk, turtle, listenerName); - let __listener = function(event) { - transValue = logo.scalarTranspositionValues[turtle].pop(); - if (!(logo.invertList[turtle].length === 0)) { - logo.scalarTransposition[turtle] += transValue; - } else { - logo.scalarTransposition[turtle] -= transValue; - } + let __listener = event => { + transValue = tur.singer.scalarTranspositionValues.pop(); + tur.singer.scalarTransposition += + logo.invertList[turtle].length > 0 ? transValue : -transValue; }; logo.setTurtleListener(turtle, listenerName, __listener); @@ -1422,21 +1391,14 @@ function setupPitchBlocks() { value = ACCIDENTALVALUES[i]; } - if (!(logo.invertList[turtle].length === 0)) { - logo.transposition[turtle] -= value; - } else { - logo.transposition[turtle] += value; - } + let tur = logo.turtles.ithTurtle(turtle); + tur.singer.transposition += logo.invertList[turtle].length > 0 ? -value : value; let listenerName = "_accidental_" + turtle + "_" + blk; logo.setDispatchBlock(blk, turtle, listenerName); - let __listener = function(event) { - if (!(logo.invertList[turtle].length === 0)) { - logo.transposition[turtle] += value; - } else { - logo.transposition[turtle] -= value; - } + let __listener = event => { + tur.singer.transposition += logo.invertList[turtle].length > 0 ? value : -value; }; logo.setTurtleListener(turtle, listenerName, __listener); @@ -1468,26 +1430,17 @@ function setupPitchBlocks() { } flow(args, logo, turtle, blk) { - if (args[0] === undefined) { - // Nothing to do. + if (args[0] === undefined) return; - } - if (!(logo.invertList[turtle].length === 0)) { - logo.transposition[turtle] += 1; - } else { - logo.transposition[turtle] -= 1; - } + let tur = logo.turtles.ithTurtle(turtle); + tur.singer.transposition += logo.invertList[turtle].length > 0 ? 1 : -1; let listenerName = "_flat_" + turtle; logo.setDispatchBlock(blk, turtle, listenerName); - let __listener = function(event) { - if (!(logo.invertList[turtle].length === 0)) { - logo.transposition[turtle] -= 1; - } else { - logo.transposition[turtle] += 1; - } + let __listener = event => { + tur.singer.transposition += logo.invertList[turtle].length > 0 ? -1 : 1; }; logo.setTurtleListener(turtle, listenerName, __listener); @@ -1524,21 +1477,14 @@ function setupPitchBlocks() { return; } - if (!(logo.invertList[turtle].length === 0)) { - logo.transposition[turtle] -= 1; - } else { - logo.transposition[turtle] += 1; - } + let tur = logo.turtles.ithTurtle(turtle); + tur.singer.transposition += logo.invertList[turtle].length > 0 ? -1 : 1; let listenerName = "_sharp_" + turtle; logo.setDispatchBlock(blk, turtle, listenerName); - let __listener = function(event) { - if (!(logo.invertList[turtle].length === 0)) { - logo.transposition[turtle] += 1; - } else { - logo.transposition[turtle] -= 1; - } + let __listener = event => { + tur.singer.transposition += logo.invertList[turtle].length > 0 ? 1 : -1; }; logo.setTurtleListener(turtle, listenerName, __listener); @@ -1586,14 +1532,16 @@ function setupPitchBlocks() { let cents = obj[2]; let delta = 0; + let tur = logo.turtles.ithTurtle(turtle); + function addPitch(note, octave, cents, frequency, direction) { - let t = transposition + logo.register[turtle] * 12; + let t = transposition + tur.singer.register * 12; let noteObj = getNote( note, octave, t, logo.keySignature[turtle], - logo.moveable[turtle], + tur.singer.moveable, direction, logo.errorMsg, logo.synth.inTemperament @@ -1605,25 +1553,14 @@ function setupPitchBlocks() { ] = drumname; } - logo.notePitches[turtle][last(logo.inNoteBlock[turtle])].push( - noteObj[0] - ); - logo.noteOctaves[turtle][last(logo.inNoteBlock[turtle])].push( - noteObj[1] - ); - logo.noteCents[turtle][last(logo.inNoteBlock[turtle])].push( - cents - ); - logo.noteHertz[turtle][last(logo.inNoteBlock[turtle])].push( - frequency - ); + tur.singer.notePitches[last(logo.inNoteBlock[turtle])].push(noteObj[0]); + tur.singer.noteOctaves[last(logo.inNoteBlock[turtle])].push(noteObj[1]); + tur.singer.noteCents[last(logo.inNoteBlock[turtle])].push(cents); + tur.singer.noteHertz[last(logo.inNoteBlock[turtle])].push(frequency); return noteObj; } - let transposition = 2 * delta; - if (turtle in logo.transposition) { - transposition += logo.transposition[turtle]; - } + let transposition = 2 * delta + logo.turtles.ithTurtle(turtle).transposition; if (note === "?") { logo.errorMsg(INVALIDPITCH, blk); @@ -1635,7 +1572,7 @@ function setupPitchBlocks() { octave, 0, logo.keySignature[turtle], - logo.moveable[turtle], + tur.singer.moveable, null, logo.errorMsg ); @@ -1646,7 +1583,7 @@ function setupPitchBlocks() { noteObj[0], noteObj[1], logo.keySignature[turtle] - ) - logo.pitchNumberOffset[turtle]; + ) - tur.singer.pitchNumberOffset; if (logo.firstPitch[turtle].length < n) { logo.firstPitch[turtle].push(pitchNumber); } else if (logo.lastPitch[turtle].length < n) { @@ -1664,7 +1601,7 @@ function setupPitchBlocks() { logo.pitchTimeMatrix.rowArgs.push(arg); // convert hertz to note/octave let note = frequencyToPitch(arg); - logo.lastNotePlayed[turtle] = [note[0] + note[1], 4]; + tur.singer.lastNotePlayed = [note[0] + note[1], 4]; } else if (logo.inMusicKeyboard) { logo.musicKeyboard.instruments.push( last(logo.instrumentNames[turtle]) @@ -1674,7 +1611,7 @@ function setupPitchBlocks() { logo.musicKeyboard.addRowBlock(blk); // convert hertz to note/octave let note = frequencyToPitch(arg); - logo.lastNotePlayed[turtle] = [note[0] + note[1], 4]; + tur.singer.lastNotePlayed = [note[0] + note[1], 4]; } else if (logo.inNoteBlock[turtle].length > 0) { if (!(logo.invertList[turtle].length === 0)) { delta += Singer.calculateInvert(logo, turtle, note, octave); @@ -1698,7 +1635,7 @@ function setupPitchBlocks() { noteObj1[1], ii, logo.keySignature[turtle], - logo.moveable[turtle], + tur.singer.moveable, null, logo.errorMsg, logo.synth.inTemperament @@ -1721,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 @@ -1736,9 +1673,9 @@ function setupPitchBlocks() { } } - logo.noteBeatValues[turtle][ - last(logo.inNoteBlock[turtle]) - ].push(logo.beatFactor[turtle]); + tur.singer.noteBeatValues[last(logo.inNoteBlock[turtle])].push( + tur.singer.beatFactor + ); logo.pushedNote[turtle] = true; if (logo.runningLilypond) { logo.notation.notationMarkup(turtle, pitchToFrequency(noteObj1[0], noteObj1[1], cents, logo.keySignature[turtle])); @@ -1829,13 +1766,15 @@ function setupPitchBlocks() { // If arg0 is a float value then round-off to the nearest integer arg0 = Math.round(arg0); - if (logo.inDefineMode[turtle]) { - logo.defineMode[turtle].push(arg0); + let tur = logo.turtles.ithTurtle(turtle); + + if (tur.singer.inDefineMode) { + tur.singer.defineMode.push(arg0); return; } else { if ( isCustom(logo.synth.inTemperament) && - logo.scalarTransposition[turtle] + logo.transposition[turtle] !== 0 + tur.singer.scalarTransposition + tur.singer.transposition !== 0 ) { logo.errorMsg( _( @@ -1846,10 +1785,10 @@ function setupPitchBlocks() { // In number to pitch we assume A0 == 0, so add offset let obj = numberToPitch( - arg0 + logo.pitchNumberOffset[turtle], + arg0 + tur.singer.pitchNumberOffset, logo.synth.inTemperament, logo.synth.startingPitch, - logo.pitchNumberOffset[turtle] + tur.singer.pitchNumberOffset ); return Singer.processPitch(obj[0], obj[1], 0, logo, turtle, blk); @@ -1895,6 +1834,8 @@ function setupPitchBlocks() { } if (typeof arg0 === "number") { + let tur = logo.turtles.ithTurtle(turtle); + // (0, 4) --> ti 3; (-1, 4) --> la 3, (-6, 4) --> do 3 // (1, 4) --> do 4; ( 2, 4) --> re 4; ( 8, 4) --> do 5 @@ -1962,12 +1903,7 @@ function setupPitchBlocks() { let deltaSemi = isNegativeArg ? (semitones > ref ? 1 : 0) : (semitones < ref ? 1 : 0); let octave = ((isNegativeArg ? -1 : 1) * (deltaOctave + deltaSemi)) + Math.floor( - calcOctave( - logo.currentOctave[turtle], - arg1, - logo.lastNotePlayed[turtle], - note - ) + calcOctave(tur.singer.currentOctave, arg1, tur.singer.lastNotePlayed, note) ); return Singer.processPitch(note, octave, 0, logo, turtle, blk); @@ -2014,6 +1950,8 @@ function setupPitchBlocks() { } if (typeof arg0 === "number") { + let tur = logo.turtles.ithTurtle(turtle); + // (0, 4) --> ti 3; (-1, 4) --> la 3, (-6, 4) --> do 3 // (1, 4) --> do 4; ( 2, 4) --> re 4; ( 8, 4) --> do 5 @@ -2081,12 +2019,7 @@ function setupPitchBlocks() { let deltaSemi = isNegativeArg ? (semitones > ref ? 1 : 0) : (semitones < ref ? 1 : 0); let octave = ((isNegativeArg ? -1 : 1) * (deltaOctave + deltaSemi)) + Math.floor( - calcOctave( - logo.currentOctave[turtle], - arg1, - logo.lastNotePlayed[turtle], - note - ) + calcOctave(tur.singer.currentOctave, arg1, tur.singer.lastNotePlayed, note) ); return Singer.processPitch(note, octave, 0, logo, turtle, blk); @@ -2154,6 +2087,8 @@ function setupPitchBlocks() { } flow(args, logo, turtle, blk) { + let tur = logo.turtles.ithTurtle(turtle); + // Similar to pitch but calculated from previous note played. if ( !logo.inMatrix && @@ -2179,27 +2114,27 @@ function setupPitchBlocks() { // If we are just counting notes we don't care about the pitch. if ( logo.justCounting[turtle].length > 0 && - logo.lastNotePlayed[turtle] === null + tur.singer.lastNotePlayed === null ) { console.debug("Just counting, so spoofing last note played."); - logo.previousNotePlayed[turtle] = ["G4", 4]; - logo.lastNotePlayed[turtle] = ["G4", 4]; + tur.singer.previousNotePlayed = ["G4", 4]; + tur.singer.lastNotePlayed = ["G4", 4]; } - if (logo.lastNotePlayed[turtle] === null) { + if (tur.singer.lastNotePlayed === null) { logo.errorMsg( _( "The Scalar Step Block must be preceded by a Pitch Block." ), blk ); - logo.lastNotePlayed[turtle] = ["G4", 4]; + tur.singer.lastNotePlayed = ["G4", 4]; // logo.stopTurtle = true; // return; } function addPitch(note, octave, cents, direction) { - let t = transposition + logo.register[turtle] * 12; + let t = transposition + tur.singer.register * 12; let noteObj = getNote( note, octave, @@ -2225,43 +2160,30 @@ function setupPitchBlocks() { } if (!logo.inMatrix && !logo.inMusicKeyboard) { - logo.notePitches[turtle][ - last(logo.inNoteBlock[turtle]) - ].push(noteObj[0]); - logo.noteOctaves[turtle][ - last(logo.inNoteBlock[turtle]) - ].push(noteObj[1]); - logo.noteCents[turtle][last(logo.inNoteBlock[turtle])].push( - cents - ); + tur.singer.notePitches[last(logo.inNoteBlock[turtle])].push(noteObj[0]); + tur.singer.noteOctaves[last(logo.inNoteBlock[turtle])].push(noteObj[1]); + tur.singer.noteCents[last(logo.inNoteBlock[turtle])].push(cents); if (cents !== 0) { - logo.noteHertz[turtle][ - last(logo.inNoteBlock[turtle]) - ].push( + tur.singer.noteHertz[last(logo.inNoteBlock[turtle])].push( pitchToFrequency( - noteObj[0], - noteObj[1], - cents, - logo.keySignature[turtle] + noteObj[0], noteObj[1], cents, logo.keySignature[turtle] ) ); } else { - logo.noteHertz[turtle][ - last(logo.inNoteBlock[turtle]) - ].push(0); + tur.singer.noteHertz[last(logo.inNoteBlock[turtle])].push(0); } } return noteObj; } - let len = logo.lastNotePlayed[turtle][0].length; + let len = tur.singer.lastNotePlayed[0].length; let noteObj = Singer.addScalarTransposition( logo, turtle, - logo.lastNotePlayed[turtle][0].slice(0, len - 1), - parseInt(logo.lastNotePlayed[turtle][0].slice(len - 1)), + tur.singer.lastNotePlayed[0].slice(0, len - 1), + parseInt(tur.singer.lastNotePlayed[0].slice(len - 1)), args[0] ); @@ -2270,10 +2192,7 @@ function setupPitchBlocks() { delta += Singer.calculateInvert(logo, turtle, noteObj[0], noteObj[1]); } - let transposition = 2 * delta; - if (turtle in logo.transposition) { - transposition += logo.transposition[turtle]; - } + let transposition = 2 * delta + logo.turtles.ithTurtle(turtle).transposition; let noteObj1 = addPitch(noteObj[0], noteObj[1], 0); // Only apply the transposition to the base note of an interval @@ -2315,8 +2234,8 @@ function setupPitchBlocks() { logo.pitchTimeMatrix.rowArgs.push(noteObj1[1]); } - logo.previousNotePlayed[turtle] = logo.lastNotePlayed[turtle]; - logo.lastNotePlayed[turtle] = [noteObj1[0] + noteObj1[1], 4]; + tur.singer.previousNotePlayed = tur.singer.lastNotePlayed; + tur.singer.lastNotePlayed = [noteObj1[0] + noteObj1[1], 4]; } else if (logo.inMusicKeyboard) { if (logo.drumStyle[turtle].length === 0) { logo.musicKeyboard.instruments.push( @@ -2353,10 +2272,7 @@ function setupPitchBlocks() { } logo.musicKeyboard.addRowBlock(blk); - logo.lastNotePlayed[turtle] = [ - noteObj1[0] + noteObj1[1], - 4 - ]; + tur.singer.lastNotePlayed = [noteObj1[0] + noteObj1[1], 4]; } } @@ -2373,7 +2289,7 @@ function setupPitchBlocks() { noteObj1[1], ii, logo.keySignature[turtle], - logo.moveable[turtle], + tur.singer.moveable, null, logo.errorMsg, logo.synth.inTemperament @@ -2396,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 @@ -2411,9 +2327,9 @@ function setupPitchBlocks() { } if (logo.inNoteBlock[turtle].length > 0) { - logo.noteBeatValues[turtle][ - last(logo.inNoteBlock[turtle]) - ].push(logo.beatFactor[turtle]); + tur.singer.noteBeatValues[last(logo.inNoteBlock[turtle])].push( + tur.singer.beatFactor + ); } logo.pushedNote[turtle] = true; @@ -2467,6 +2383,8 @@ function setupPitchBlocks() { logo.errorMsg(NOINPUTERRORMSG, blk); } + let tur = logo.turtles.ithTurtle(turtle); + let note, octave, cents; if (typeof arg0 === "number" || !isNaN(Number(arg0))) { arg0 = Number(arg0); @@ -2485,9 +2403,7 @@ function setupPitchBlocks() { note = nthDegreeToPitch(logo.keySignature[turtle], Math.round(arg0)); octave = Math.floor( - calcOctave( - logo.currentOctave[turtle], arg1, logo.lastNotePlayed[turtle], note - ) + calcOctave(tur.singer.currentOctave, arg1, tur.singer.lastNotePlayed, note) ); cents = 0; } else { @@ -2523,15 +2439,12 @@ function setupPitchBlocks() { note = accSym !== NATURAL ? note + accSym : note; // add accidental octave = Math.floor( - calcOctave( - logo.currentOctave[turtle], arg1, logo.lastNotePlayed[turtle], note - ) + calcOctave(tur.singer.currentOctave, arg1, tur.singer.lastNotePlayed, note) ); cents = 0; } else { - octave = calcOctave( - logo.currentOctave[turtle], arg1, logo.lastNotePlayed[turtle], arg0 - ); + octave = + calcOctave(tur.singer.currentOctave, arg1, tur.singer.lastNotePlayed, arg0); // Octave must be an integer in [0, 9] [note, octave, cents] = diff --git a/js/blocks/RhythmBlockPaletteBlocks.js b/js/blocks/RhythmBlockPaletteBlocks.js index 19b1162426..d9ef9a507b 100644 --- a/js/blocks/RhythmBlockPaletteBlocks.js +++ b/js/blocks/RhythmBlockPaletteBlocks.js @@ -92,31 +92,24 @@ function setupRhythmBlockPaletteBlocks() { } } } else { + let tur = logo.turtles.ithTurtle(turtle); + if (logo.drumStyle[turtle].length > 0) { // Play rhythm block as if it were a drum. - logo.clearNoteParams(turtle, blk, logo.drumStyle[turtle]); + logo.clearNoteParams(tur, blk, logo.drumStyle[turtle]); logo.inNoteBlock[turtle].push(blk); } else { // Or use the current synth. - logo.clearNoteParams(turtle, blk, []); + logo.clearNoteParams(tur, blk, []); logo.inNoteBlock[turtle].push(blk); - logo.notePitches[turtle][last(logo.inNoteBlock[turtle])] = [ - "G" - ]; - logo.noteOctaves[turtle][last(logo.inNoteBlock[turtle])] = [ - 4 - ]; - logo.noteCents[turtle][last(logo.inNoteBlock[turtle])] = [ - 0 - ]; + tur.singer.notePitches[last(logo.inNoteBlock[turtle])] = ["G"]; + tur.singer.noteOctaves[last(logo.inNoteBlock[turtle])] = [4]; + tur.singer.noteCents[last(logo.inNoteBlock[turtle])] = [0]; } - let bpmFactor; - if (logo.bpm[turtle].length > 0) { - bpmFactor = TONEBPM / last(logo.bpm[turtle]); - } else { - bpmFactor = TONEBPM / logo._masterBPM; - } + let bpmFactor = + TONEBPM / + logo.bpm[turtle].length > 0 ? last(logo.bpm[turtle]) : Singer.masterBPM; let beatValue = bpmFactor / noteBeatValue; @@ -136,7 +129,7 @@ function setupRhythmBlockPaletteBlocks() { for (let i = 0; i < arg0; i++) { if (i === arg0 - 1) { __callback = function() { - delete logo.noteDrums[turtle][blk]; + delete tur.singer.noteDrums[blk]; let j = logo.inNoteBlock[turtle].indexOf(blk); logo.inNoteBlock[turtle].splice(j, 1); }; @@ -325,12 +318,12 @@ function setupRhythmBlockPaletteBlocks() { if (logo.blocks.blockList[blk].name === "tuplet3") { logo.tupletParams.push([ args[0], - (1 / args[1]) * logo.beatFactor[turtle] + (1 / args[1]) * logo.turtles.ithTurtle(turtle).singer.beatFactor ]); } else { logo.tupletParams.push([ args[0], - args[1] * logo.beatFactor[turtle] + args[1] * logo.turtles.ithTurtle(turtle).singer.beatFactor ]); } @@ -451,12 +444,16 @@ function setupRhythmBlockPaletteBlocks() { logo.tuplet = true; logo.addingNotesToTuplet = false; - logo.tupletParams.push([1, (1 / arg) * logo.beatFactor[turtle]]); + logo.tupletParams.push([ + 1, (1 / arg) * logo.turtles.ithTurtle(turtle).singer.beatFactor + ]); let listenerName = "_tuplet_" + turtle; logo.setDispatchBlock(blk, turtle, listenerName); - let __listener = function(event) { + let __listener = event => { + let tur = logo.turtles.ithTurtle(turtle); + logo.tuplet = false; logo.addingNotesToTuplet = false; if (!logo.inMatrix) { @@ -483,23 +480,16 @@ function setupRhythmBlockPaletteBlocks() { // Play rhythm block as if it were a drum. if (logo.drumStyle[turtle].length > 0) { - logo.clearNoteParams( - turtle, - blk, - logo.drumStyle[turtle] - ); + logo.clearNoteParams(tur, blk, logo.drumStyle[turtle]); } else { - logo.clearNoteParams(turtle, blk, [DEFAULTDRUM]); + logo.clearNoteParams(tur, blk, [DEFAULTDRUM]); } logo.inNoteBlock[turtle].push(blk); - let bpmFactor; - if (logo.bpm[turtle].length > 0) { - bpmFactor = TONEBPM / last(logo.bpm[turtle]); - } else { - bpmFactor = TONEBPM / logo._masterBPM; - } + let bpmFactor = + TONEBPM / + logo.bpm[turtle].length > 0 ? last(logo.bpm[turtle]) : Singer.masterBPM; let totalBeats = 0; @@ -522,7 +512,7 @@ function setupRhythmBlockPaletteBlocks() { if (i === beatValues.length - 1) { __callback = function() { - delete logo.noteDrums[turtle][blk]; + delete tur.singer.noteDrums[blk]; let j = logo.inNoteBlock[turtle].indexOf(blk); logo.inNoteBlock[turtle].splice(j, 1); }; @@ -661,7 +651,7 @@ function setupRhythmBlockPaletteBlocks() { arg1 = args[1]; } - let noteBeatValue = (1 / arg1) * logo.beatFactor[turtle]; + let noteBeatValue = (1 / arg1) * logo.turtles.ithTurtle(turtle).singer.beatFactor; if (logo.inMatrix || logo.tuplet) { logo.pitchTimeMatrix.addColBlock(blk, arg0); if (logo.tuplet) { @@ -678,26 +668,25 @@ function setupRhythmBlockPaletteBlocks() { logo.tupletParams.push([1, noteBeatValue]); let obj = ["simple", 0]; for (let i = 0; i < arg0; i++) { - obj.push((1 / arg1) * logo.beatFactor[turtle]); + obj.push((1 / arg1) * logo.turtles.ithTurtle(turtle).singer.beatFactor); } logo.tupletRhythms.push(obj); } } else { + let tur = logo.turtles.ithTurtle(turtle); + // Play rhythm block as if it were a drum. if (logo.drumStyle[turtle].length > 0) { - logo.clearNoteParams(turtle, blk, logo.drumStyle[turtle]); + logo.clearNoteParams(tur, blk, logo.drumStyle[turtle]); } else { - logo.clearNoteParams(turtle, blk, [DEFAULTDRUM]); + logo.clearNoteParams(tur, blk, [DEFAULTDRUM]); } logo.inNoteBlock[turtle].push(blk); - let bpmFactor; - if (logo.bpm[turtle].length > 0) { - bpmFactor = TONEBPM / last(logo.bpm[turtle]); - } else { - bpmFactor = TONEBPM / logo._masterBPM; - } + let bpmFactor = + TONEBPM / + logo.bpm[turtle].length > 0 ? last(logo.bpm[turtle]) : Singer.masterBPM; let beatValue = bpmFactor / noteBeatValue / arg0; @@ -716,7 +705,7 @@ function setupRhythmBlockPaletteBlocks() { for (let i = 0; i < arg0; i++) { if (i === arg0 - 1) { __callback = function() { - delete logo.noteDrums[turtle][blk]; + delete tur.singer.noteDrums[blk]; let j = logo.inNoteBlock[turtle].indexOf(blk); logo.inNoteBlock[turtle].splice(j, 1); }; diff --git a/js/blocks/RhythmBlocks.js b/js/blocks/RhythmBlocks.js index ba0dbafea9..d5a99e3a7a 100644 --- a/js/blocks/RhythmBlocks.js +++ b/js/blocks/RhythmBlocks.js @@ -23,41 +23,29 @@ function setupRhythmBlocks() { 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, "mynotevalue"]); } else { + let tur = logo.turtles.ithTurtle(turtle); + let value = 0; if ( - logo.noteValue[turtle][last(logo.inNoteBlock[turtle])] !== - null && - logo.noteValue[turtle][last(logo.inNoteBlock[turtle])] !== - undefined + tur.singer.noteValue[last(logo.inNoteBlock[turtle])] !== null && + tur.singer.noteValue[last(logo.inNoteBlock[turtle])] !== undefined ) { - if ( - logo.noteValue[turtle][ - last(logo.inNoteBlock[turtle]) - ] !== 0 - ) { - value = - 1 / - logo.noteValue[turtle][ - last(logo.inNoteBlock[turtle]) - ]; + if (tur.singer.noteValue[last(logo.inNoteBlock[turtle])] !== 0) { + value = 1 / tur.singer.noteValue[last(logo.inNoteBlock[turtle])]; } else { value = 0; } - } else if (logo.lastNotePlayed[turtle] !== null) { - value = logo.lastNotePlayed[turtle][1]; + } else if (tur.singer.lastNotePlayed !== null) { + value = tur.singer.lastNotePlayed[1]; } else if ( - logo.notePitches[turtle][last(logo.inNoteBlock[turtle])] !== - undefined && - logo.notePitches[turtle][last(logo.inNoteBlock[turtle])] - .length > 0 + tur.singer.notePitches[last(logo.inNoteBlock[turtle])] !== undefined && + tur.singer.notePitches[last(logo.inNoteBlock[turtle])].length > 0 ) { - value = - logo.noteBeat[turtle][last(logo.inNoteBlock[turtle])]; + value = tur.singer.noteBeat[last(logo.inNoteBlock[turtle])]; } else { console.debug("Cannot find a note for turtle " + turtle); value = 0; @@ -395,13 +383,13 @@ function setupRhythmBlocks() { factor = args[0]; } - logo.beatFactor[turtle] /= factor; + logo.turtles.ithTurtle(turtle).singer.beatFactor /= factor; let listenerName = "_multiplybeat_" + turtle; logo.setDispatchBlock(blk, turtle, listenerName); - let __listener = function(event) { - logo.beatFactor[turtle] *= factor; + let __listener = event => { + logo.turtles.ithTurtle(turtle).singer.beatFactor *= factor; }; logo.setTurtleListener(turtle, listenerName, __listener); @@ -437,10 +425,10 @@ function setupRhythmBlocks() { } flow(args, logo, turtle, blk, receivedArg, actionArgs, isflow) { - if (args[0] === undefined) { - // Nothing to do. + if (args[0] === undefined) return; - } + + let tur = logo.turtles.ithTurtle(turtle); // Tie notes together in pairs. logo.tie[turtle] = true; @@ -452,7 +440,7 @@ function setupRhythmBlocks() { let listenerName = "_tie_" + turtle; logo.setDispatchBlock(blk, turtle, listenerName); - let __listener = function(event) { + let __listener = event => { logo.tie[turtle] = false; // If tieCarryOver > 0, we have one more note to @@ -460,17 +448,11 @@ function setupRhythmBlocks() { if (logo.tieCarryOver[turtle] > 0) { if (logo.justCounting[turtle].length === 0) { let lastNote = last(logo.inNoteBlock[turtle]); - if ( - lastNote != null && - lastNote in logo.notePitches[turtle] - ) { + if (lastNote != null && lastNote in tur.singer.notePitches) { // Remove the note from the Lilypond list. for ( let i = 0; - i < - logo.notePitches[turtle][ - last(logo.inNoteBlock[turtle]) - ].length; + i < tur.singer.notePitches[last(logo.inNoteBlock[turtle])].length; i++ ) { logo.notation.notationRemoveTie(turtle); @@ -485,62 +467,46 @@ function setupRhythmBlocks() { logo.inNoteBlock[turtle].push(saveBlk); - logo.notePitches[turtle][saveBlk] = []; - logo.noteOctaves[turtle][saveBlk] = []; - logo.noteCents[turtle][saveBlk] = []; - logo.noteHertz[turtle][saveBlk] = []; + tur.singer.notePitches[saveBlk] = []; + tur.singer.noteOctaves[saveBlk] = []; + tur.singer.noteCents[saveBlk] = []; + tur.singer.noteHertz[saveBlk] = []; for ( let i = 0; i < logo.tieNotePitches[turtle].length; i++ ) { - logo.notePitches[turtle][saveBlk].push( - logo.tieNotePitches[turtle][i][0] - ); - logo.noteOctaves[turtle][saveBlk].push( - logo.tieNotePitches[turtle][i][1] - ); - logo.noteCents[turtle][saveBlk].push( - logo.tieNotePitches[turtle][i][2] - ); - logo.noteHertz[turtle][saveBlk].push( - logo.tieNotePitches[turtle][i][3] - ); + tur.singer.notePitches[saveBlk].push(logo.tieNotePitches[turtle][i][0]); + tur.singer.noteOctaves[saveBlk].push(logo.tieNotePitches[turtle][i][1]); + tur.singer.noteCents[saveBlk].push(logo.tieNotePitches[turtle][i][2]); + tur.singer.noteHertz[saveBlk].push(logo.tieNotePitches[turtle][i][3]); } - logo.oscList[turtle][saveBlk] = - logo.tieNoteExtras[turtle][1]; - logo.noteBeat[turtle][saveBlk] = - logo.tieNoteExtras[turtle][2]; - logo.noteBeatValues[turtle][saveBlk] = - logo.tieNoteExtras[turtle][3]; - logo.noteDrums[turtle][saveBlk] = - logo.tieNoteExtras[turtle][4]; - // Graphics will have already been rendered. - logo.embeddedGraphics[turtle][saveBlk] = []; + tur.singer.oscList[saveBlk] = logo.tieNoteExtras[turtle][1]; + tur.singer.noteBeat[saveBlk] = logo.tieNoteExtras[turtle][2]; + tur.singer.noteBeatValues[saveBlk] = logo.tieNoteExtras[turtle][3]; + tur.singer.noteDrums[saveBlk] = logo.tieNoteExtras[turtle][4]; + tur.singer.embeddedGraphics[saveBlk] = []; // graphics will have already been rendered Singer.processNote(logo, noteValue, saveBlk, turtle); - let bpmFactor; - if (logo.bpm[turtle].length > 0) { - bpmFactor = TONEBPM / last(logo.bpm[turtle]); - } else { - bpmFactor = TONEBPM / logo._masterBPM; - } + let bpmFactor = + TONEBPM / + logo.bpm[turtle].length > 0 ? last(logo.bpm[turtle]) : Singer.masterBPM; // Wait until this note is played before continuing. logo.doWait(turtle, bpmFactor / noteValue); logo.inNoteBlock[turtle].pop(); - delete logo.notePitches[turtle][saveBlk]; - delete logo.noteOctaves[turtle][saveBlk]; - delete logo.noteCents[turtle][saveBlk]; - delete logo.noteHertz[turtle][saveBlk]; - delete logo.oscList[turtle][saveBlk]; - delete logo.noteBeat[turtle][saveBlk]; - delete logo.noteBeatValues[turtle][saveBlk]; - delete logo.noteDrums[turtle][saveBlk]; - delete logo.embeddedGraphics[turtle][saveBlk]; + delete tur.singer.notePitches[saveBlk]; + delete tur.singer.noteOctaves[saveBlk]; + delete tur.singer.noteCents[saveBlk]; + delete tur.singer.noteHertz[saveBlk]; + delete tur.singer.oscList[saveBlk]; + delete tur.singer.noteBeat[saveBlk]; + delete tur.singer.noteBeatValues[saveBlk]; + delete tur.singer.noteDrums[saveBlk]; + delete tur.singer.embeddedGraphics[saveBlk]; // Remove duplicate note logo.notation.notationStaging[turtle].pop(); @@ -577,29 +543,30 @@ function setupRhythmBlocks() { if (args[0] === null) logo.errorMsg(NOINPUTERRORMSG, blk); let arg = 1; - let currentDotFactor = 2 - 1 / Math.pow(2, logo.dotCount[turtle]); - logo.beatFactor[turtle] *= currentDotFactor; + let tur = logo.turtles.ithTurtle(turtle); + let currentDotFactor = 2 - 1 / Math.pow(2, tur.singer.dotCount); + tur.singer.beatFactor *= currentDotFactor; if (arg >= 0) { - logo.dotCount[turtle] += arg; + tur.singer.dotCount += arg; } else if (arg === -1) { logo.errorMsg(_("An argument of -1 results in a note value of 0."), blk); arg = 0; } else { - logo.dotCount[turtle] += 1 / arg; + tur.singer.dotCount += 1 / arg; } - let newDotFactor = 2 - 1 / Math.pow(2, logo.dotCount[turtle]); - logo.beatFactor[turtle] /= newDotFactor; + let newDotFactor = 2 - 1 / Math.pow(2, tur.singer.dotCount); + tur.singer.beatFactor /= newDotFactor; let listenerName = "_dot_" + turtle; logo.setDispatchBlock(blk, turtle, listenerName); let __listener = event => { - let currentDotFactor = 2 - 1 / Math.pow(2, logo.dotCount[turtle]); - logo.beatFactor[turtle] *= currentDotFactor; - logo.dotCount[turtle] -= arg >= 0 ? arg : 1 / arg; - let newDotFactor = 2 - 1 / Math.pow(2, logo.dotCount[turtle]); - logo.beatFactor[turtle] /= newDotFactor; + let currentDotFactor = 2 - 1 / Math.pow(2, tur.singer.dotCount); + tur.singer.beatFactor *= currentDotFactor; + tur.singer.dotCount -= arg >= 0 ? arg : 1 / arg; + let newDotFactor = 2 - 1 / Math.pow(2, tur.singer.dotCount); + tur.singer.beatFactor /= newDotFactor; }; logo.setTurtleListener(turtle, listenerName, __listener); @@ -641,29 +608,30 @@ function setupRhythmBlocks() { if (args[0] === null) logo.errorMsg(NOINPUTERRORMSG, blk); let arg = args[0] === null ? 0 : args[0]; - let currentDotFactor = 2 - 1 / Math.pow(2, logo.dotCount[turtle]); - logo.beatFactor[turtle] *= currentDotFactor; + let tur = logo.turtles.ithTurtle(turtle); + let currentDotFactor = 2 - 1 / Math.pow(2, tur.singer.dotCount); + tur.singer.beatFactor *= currentDotFactor; if (arg >= 0) { - logo.dotCount[turtle] += arg; + tur.singer.dotCount += arg; } else if (arg === -1) { logo.errorMsg(_("An argument of -1 results in a note value of 0."), blk); arg = 0; } else { - logo.dotCount[turtle] += 1 / arg; + tur.singer.dotCount += 1 / arg; } - let newDotFactor = 2 - 1 / Math.pow(2, logo.dotCount[turtle]); - logo.beatFactor[turtle] /= newDotFactor; + let newDotFactor = 2 - 1 / Math.pow(2, tur.singer.dotCount); + tur.singer.beatFactor /= newDotFactor; let listenerName = "_dot_" + turtle; logo.setDispatchBlock(blk, turtle, listenerName); let __listener = event => { - let currentDotFactor = 2 - 1 / Math.pow(2, logo.dotCount[turtle]); - logo.beatFactor[turtle] *= currentDotFactor; - logo.dotCount[turtle] -= arg >= 0 ? arg : 1 / arg; - let newDotFactor = 2 - 1 / Math.pow(2, logo.dotCount[turtle]); - logo.beatFactor[turtle] /= newDotFactor; + let currentDotFactor = 2 - 1 / Math.pow(2, tur.singer.dotCount); + tur.singer.beatFactor *= currentDotFactor; + tur.singer.dotCount -= arg >= 0 ? arg : 1 / arg; + let newDotFactor = 2 - 1 / Math.pow(2, tur.singer.dotCount); + tur.singer.beatFactor /= newDotFactor; }; logo.setTurtleListener(turtle, listenerName, __listener); @@ -698,17 +666,16 @@ function setupRhythmBlocks() { } flow(args, logo, turtle) { + let tur = logo.turtles.ithTurtle(turtle); + if (logo.inNoteBlock[turtle].length > 0) { - logo.notePitches[turtle][last(logo.inNoteBlock[turtle])].push( - "rest" - ); - logo.noteOctaves[turtle][last(logo.inNoteBlock[turtle])].push( - 4 + tur.singer.notePitches[last(logo.inNoteBlock[turtle])].push("rest"); + tur.singer.noteOctaves[last(logo.inNoteBlock[turtle])].push(4); + tur.singer.noteCents[last(logo.inNoteBlock[turtle])].push(0); + tur.singer.noteHertz[last(logo.inNoteBlock[turtle])].push(0); + tur.singer.noteBeatValues[last(logo.inNoteBlock[turtle])].push( + tur.singer.beatFactor ); - logo.noteCents[turtle][last(logo.inNoteBlock[turtle])].push(0); - logo.noteHertz[turtle][last(logo.inNoteBlock[turtle])].push(0); - logo.noteBeatValues[turtle][last(logo.inNoteBlock[turtle])] - .push(logo.beatFactor[turtle]); logo.pushedNote[turtle] = true; } } diff --git a/js/blocks/ToneBlocks.js b/js/blocks/ToneBlocks.js index dd3c8e8f62..b0d560dc1e 100644 --- a/js/blocks/ToneBlocks.js +++ b/js/blocks/ToneBlocks.js @@ -293,9 +293,11 @@ function setupToneBlocks() { return; } - if (logo.inHarmonic[turtle].length > 0) { - let n = logo.inHarmonic[turtle].length - 1; - logo.partials[turtle][n].push(args[0]); + let tur = logo.turtles.ithTurtle(turtle); + + if (tur.singer.inHarmonic.length > 0) { + let n = tur.singer.inHarmonic.length - 1; + tur.singer.partials[n].push(args[0]); } else { //.TRANS: partials are weighted components in a harmonic series logo.errorMsg( @@ -335,15 +337,17 @@ function setupToneBlocks() { } flow(args, logo, turtle, blk) { - logo.inHarmonic[turtle].push(blk); - logo.partials[turtle].push([]); + let tur = logo.turtles.ithTurtle(turtle); + + tur.singer.inHarmonic.push(blk); + tur.singer.partials.push([]); let listenerName = "_harmonic_" + turtle + "_" + blk; logo.setDispatchBlock(blk, turtle, listenerName); - let __listener = function(event) { - logo.inHarmonic[turtle].pop(); - logo.partials[turtle].pop(); + let __listener = event => { + tur.singer.inHarmonic.pop(); + tur.singer.partials.pop(); }; logo.setTurtleListener(turtle, listenerName, __listener); @@ -385,23 +389,25 @@ function setupToneBlocks() { return; } - logo.inHarmonic[turtle].push(blk); - logo.partials[turtle].push([]); - let n = logo.partials[turtle].length - 1; + let tur = logo.turtles.ithTurtle(turtle); + + tur.singer.inHarmonic.push(blk); + tur.singer.partials.push([]); + let n = tur.singer.partials.length - 1; for (let i = 0; i < args[0]; i++) { - logo.partials[turtle][n].push(0); + tur.singer.partials[n].push(0); } - logo.partials[turtle][n].push(1); + tur.singer.partials[n].push(1); logo.notation.notationBeginHarmonics(turtle); let listenerName = "_harmonic_" + turtle + "_" + blk; logo.setDispatchBlock(blk, turtle, listenerName); - let __listener = function(event) { - logo.inHarmonic[turtle].pop(); - logo.partials[turtle].pop(); + let __listener = event => { + tur.singer.inHarmonic.pop(); + tur.singer.partials.pop(); logo.notation.notationEndHarmonics(turtle); }; diff --git a/js/logo.js b/js/logo.js index 78872eecbc..353af3cf68 100644 --- a/js/logo.js +++ b/js/logo.js @@ -74,6 +74,7 @@ class Logo { this._saveLocally = null; this.showBlocksAfterRun = false; + // Widgets this.pitchTimeMatrix = null; this.pitchDrumMatrix = null; this.rhythmRuler = null; @@ -122,35 +123,28 @@ class Logo { // When we leave a clamp block, we need to dispatch a signal this.endOfClampSignals = {}; - // Don't dispatch these signals (when exiting note counter or interval measure + // Don't dispatch these signals (when exiting note counter or interval measure) this.butNotThese = {}; - this.lastNoteTimeout = null; - this.alreadyRunning = false; - this.prematureRestart = false; - this.runningBlock = null; - this.ignoringBlock = null; + // Related to running programs + this._lastNoteTimeout = null; + this._alreadyRunning = false; + this._prematureRestart = false; + this._runningBlock = null; + this._ignoringBlock = null; // Used to halt runtime during input - this.delayTimeout = {}; - this.delayParameters = {}; + this._delayTimeout = {}; + this._delayParameters = {}; this.time = 0; this.firstNoteTime = null; - this.waitTimes = {}; + this._waitTimes = {}; this._turtleDelay = 0; this.sounds = []; this.cameraID = null; this.stopTurtle = false; this.lastKeyCode = null; - this.saveTimeout = 0; - - // Music-related attributes - this.notesPlayed = {}; - this.whichNoteToCount = {}; - - // Moveable solfege? - this.moveable = {}; // Widget-related attributes this.showPitchDrumMatrix = false; @@ -178,45 +172,6 @@ class Logo { this.inNoteBlock = []; this.multipleVoices = []; - // Parameters used by pitch - this.scalarTransposition = {}; - this.scalarTranspositionValues = {}; - this.transposition = {}; - this.transpositionValues = {}; - - // Parameters used by notes - this._masterBPM = TARGETBPM; - this.defaultBPMFactor = TONEBPM / this._masterBPM; - - this.register = {}; - this.beatFactor = {}; - this.dotCount = {}; - this.noteBeat = {}; - this.noteValue = {}; - this.oscList = {}; - this.noteDrums = {}; - this.notePitches = {}; - this.noteOctaves = {}; - this.noteCents = {}; - this.noteHertz = {}; - this.noteBeatValues = {}; - this.embeddedGraphics = {}; - this.lastNotePlayed = {}; - this.lastPitchPlayed = {}; // for a stand-alone pitch block - this.previousNotePlayed = {}; - this.noteStatus = {}; - this.noteDirection = {}; - this.pitchNumberOffset = []; // 39, C4 - this.currentOctave = {}; - this.currentCalculatedOctave = {}; // for a stand-alone pitch block - this.inHarmonic = {}; - this.partials = {}; - this.inNeighbor = []; - this.neighborStepPitch = {}; - this.neighborNoteValue = {}; - this.inDefineMode = {}; - this.defineMode = {}; - // Parameters used in time signature this.pickup = {}; this.beatsPerMeasure = {}; @@ -286,9 +241,6 @@ class Logo { this.lastPitch = {}; this.suppressOutput = {}; - // Scale factor for turtle graphics embedded in notes - this.dispatchFactor = {}; - // tuplet this.tuplet = false; this.tupletParams = []; @@ -305,15 +257,9 @@ class Logo { this.runningLilypond = false; this.runningAbc = false; this.runningMxml = false; - this.checkingCompletionState = false; + this._checkingCompletionState = false; this.compiling = false; this.recording = false; - this.lastNote = {}; - - // Variables for progress bar - this.progressBar = docById("myBar"); - this.progressBarWidth = 0; - this.progressBarDivision; this.temperamentSelected = []; this.customTemperamentDefined = false; @@ -333,8 +279,6 @@ class Logo { // Load the default synthesizer this.synth = new Synth(); this.synth.changeInTemperament = false; - } else { - this.turtleOscs = {}; } // Mode widget @@ -348,10 +292,9 @@ class Logo { this.updatingStatusMatrix = false; this.statusFields = []; - // When running in step-by-step mode, the next command to run is - // queued here + // When running in step-by-step mode, the next command to run is queued here this.stepQueue = {}; - this.unhighlightStepQueue = {}; + this._unhighlightStepQueue = {}; // Control points for bezier curves this.cp1x = {}; @@ -788,22 +731,22 @@ class Logo { /** * Clears note params. * - * @param turtle + * @param {Object} turtle - Turtle object * @param blk * @param drums * @returns {void} */ clearNoteParams(turtle, blk, drums) { - this.oscList[turtle][blk] = []; - this.noteBeat[turtle][blk] = []; - this.noteBeatValues[turtle][blk] = []; - this.noteValue[turtle][blk] = null; - this.notePitches[turtle][blk] = []; - this.noteOctaves[turtle][blk] = []; - this.noteCents[turtle][blk] = []; - this.noteHertz[turtle][blk] = []; - this.embeddedGraphics[turtle][blk] = []; - this.noteDrums[turtle][blk] = drums !== null ? drums : []; + turtle.singer.oscList[blk] = []; + turtle.singer.noteBeat[blk] = []; + turtle.singer.noteBeatValues[blk] = []; + turtle.singer.noteValue[blk] = null; + turtle.singer.notePitches[blk] = []; + turtle.singer.noteOctaves[blk] = []; + turtle.singer.noteCents[blk] = []; + turtle.singer.noteHertz[blk] = []; + turtle.singer.embeddedGraphics[blk] = []; + turtle.singer.noteDrums[blk] = drums !== null ? drums : []; } /** @@ -988,6 +931,8 @@ class Logo { * @returns {*} */ parseArg(logo, turtle, blk, parentBlk, receivedArg) { + let tur = logo.turtles.ithTurtle(turtle); + // Retrieve the value of a block if (blk == null) { logo.errorMsg(NOINPUTERRORMSG, parentBlk); @@ -1013,7 +958,7 @@ class Logo { if (logo.blocks.blockList[blk].name === "intervalname") { if (typeof logo.blocks.blockList[blk].value === "string") { - logo.noteDirection[turtle] = getIntervalDirection( + tur.singer.noteDirection = getIntervalDirection( logo.blocks.blockList[blk].value ); return getIntervalNumber(logo.blocks.blockList[blk].value); @@ -1105,12 +1050,14 @@ class Logo { // Don't split the note if we are already splitting the note if (split == undefined) split = true; + let tur = logo.turtles.ithTurtle(turtle); + // Check to see if this note straddles a measure boundary let durationTime = 1 / duration; let beatsIntoMeasure = ( ( - this.notesPlayed[turtle][0] / this.notesPlayed[turtle][1] - + tur.singer.notesPlayed[0] / tur.singer.notesPlayed[1] - this.pickup[turtle] - durationTime ) * this.noteValuePerBeat[turtle] @@ -1179,7 +1126,7 @@ class Logo { * @returns {void} */ doWait(turtle, secs) { - this.waitTimes[turtle] = Number(secs) * 1000; + this._waitTimes[turtle] = Number(secs) * 1000; } /** @@ -1189,15 +1136,15 @@ class Logo { * @returns {void} */ clearTurtleRun(turtle) { - if (this.delayTimeout[turtle] !== null) { - clearTimeout(this.delayTimeout[turtle]); - this.delayTimeout[turtle] = null; + if (this._delayTimeout[turtle] !== null) { + clearTimeout(this._delayTimeout[turtle]); + this._delayTimeout[turtle] = null; this.runFromBlockNow( this, turtle, - this.delayParameters[turtle]['blk'], - this.delayParameters[turtle]['flow'], - this.delayParameters[turtle]['arg'] + this._delayParameters[turtle]['blk'], + this._delayParameters[turtle]['flow'], + this._delayParameters[turtle]['arg'] ); } } @@ -1275,9 +1222,49 @@ class Logo { * @returns {void} */ initTurtle(turtle) { + let tur = this.turtles.ithTurtle(turtle); + + tur.singer.scalarTransposition = 0; + tur.singer.scalarTranspositionValues = []; + tur.singer.transposition = 0; + tur.singer.transpositionValues = []; + + tur.singer.register = 0; + tur.singer.beatFactor = 1; + tur.singer.dotCount = 0; + tur.singer.noteBeat = {}; + tur.singer.noteValue = {}; + tur.singer.oscList = {}; + tur.singer.noteDrums = {}; + tur.singer.notePitches = {}; + tur.singer.noteOctaves = {}; + tur.singer.noteCents = {}; + tur.singer.noteHertz = {}; + tur.singer.noteBeatValues = {}; + tur.singer.embeddedGraphics = {}; + tur.singer.lastNotePlayed = null; + tur.singer.previousNotePlayed = null; + tur.singer.noteStatus = null; + tur.singer.noteDirection = 0; + tur.singer.pitchNumberOffset = 39; + tur.singer.currentOctave = 4; + tur.singer.inHarmonic = []; + tur.singer.partials = []; + tur.singer.inNeighbor = []; + tur.singer.neighborStepPitch = []; + tur.singer.neighborNoteValue = []; + tur.singer.inDefineMode = false; + tur.singer.defineMode = []; + + tur.singer.notesPlayed = [0, 1]; + tur.singer.whichNoteToCount = 1; + tur.singer.moveable = false; + + tur.singer.dispatchFactor = 1; + this.previousTurtleTime[turtle] = 0; this.turtleTime[turtle] = 0; - this.waitTimes[turtle] = 0; + this._waitTimes[turtle] = 0; this.endOfClampSignals[turtle] = {}; this.butNotThese[turtle] = {}; this.cp1x[turtle] = 0; @@ -1286,28 +1273,7 @@ class Logo { this.cp2y[turtle] = 100; this.inNoteBlock[turtle] = []; this.multipleVoices[turtle] = false; - this.scalarTransposition[turtle] = 0; - this.scalarTranspositionValues[turtle] = []; - this.transposition[turtle] = 0; - this.transpositionValues[turtle] = []; - this.noteBeat[turtle] = {}; - this.noteValue[turtle] = {}; - this.noteCents[turtle] = {}; - this.noteHertz[turtle] = {}; - this.lastNotePlayed[turtle] = null; - this.previousNotePlayed[turtle] = null; - this.noteStatus[turtle] = null; - this.noteDirection[turtle] = 0; - this.noteDrums[turtle] = {}; - this.notePitches[turtle] = {}; - this.noteOctaves[turtle] = {}; - this.currentOctave[turtle] = 4; - this.register[turtle] = 0; - this.noteBeatValues[turtle] = {}; - this.embeddedGraphics[turtle] = {}; this.embeddedGraphicsFinished[turtle] = true; - this.beatFactor[turtle] = 1; - this.dotCount[turtle] = 0; this.invertList[turtle] = []; this.beatList[turtle] = []; this.factorList[turtle] = []; @@ -1319,11 +1285,8 @@ class Logo { this.inDuplicate[turtle] = false; this.skipFactor[turtle] = 1; this.skipIndex[turtle] = 0; - this.notesPlayed[turtle] = [0, 1]; - this.whichNoteToCount[turtle] = 1; this.keySignature[turtle] = "C " + "major"; this.pushedNote[turtle] = false; - this.oscList[turtle] = {}; this.bpm[turtle] = []; this.inSetTimbre[turtle] = false; this.instrumentNames[turtle] = ["electronic synth"]; @@ -1367,9 +1330,6 @@ class Logo { this.neighborArgNote2[turtle] = []; this.neighborArgBeat[turtle] = []; this.neighborArgCurrentBeat[turtle] = []; - this.inDefineMode[turtle] = false; - this.defineMode[turtle] = []; - this.dispatchFactor[turtle] = 1; this.pickup[turtle] = 0; this.beatsPerMeasure[turtle] = 4; // default is 4/4 time this.noteValuePerBeat[turtle] = 4; @@ -1383,15 +1343,8 @@ class Logo { this.notation.pickupPOW2[turtle] = false; this.firstPitch[turtle] = []; this.lastPitch[turtle] = []; - this.pitchNumberOffset[turtle] = 39; // C4 this.suppressOutput[turtle] = this.runningLilypond || this.runningAbc || this.runningMxml || this.compiling; - this.moveable[turtle] = false; - this.inNeighbor[turtle] = []; - this.neighborStepPitch[turtle] = []; - this.neighborNoteValue[turtle] = []; - this.inHarmonic[turtle] = []; - this.partials[turtle] = []; this.returns[turtle] = []; this.defaultStrongBeats[turtle] = false; @@ -1471,13 +1424,13 @@ class Logo { for (let turtle in this.stepQueue) { if (this.stepQueue[turtle].length > 0) { if ( - turtle in this.unhighlightStepQueue && - this.unhighlightStepQueue[turtle] != null + turtle in this._unhighlightStepQueue && + this._unhighlightStepQueue[turtle] != null ) { if (this.blocks.visible) { - this.blocks.unhighlight(this.unhighlightStepQueue[turtle]); + this.blocks.unhighlight(this._unhighlightStepQueue[turtle]); } - this.unhighlightStepQueue[turtle] = null; + this._unhighlightStepQueue[turtle] = null; } let blk = this.stepQueue[turtle].pop(); @@ -1496,18 +1449,18 @@ class Logo { * @returns {void} */ runLogoCommands(startHere, env) { - this.prematureRestart = this.alreadyRunning; - if (this.alreadyRunning && this.runningBlock !== null) { - this.ignoringBlock = this.runningBlock; - console.debug(this.alreadyRunning + " " + this.runningBlock); + this._prematureRestart = this._alreadyRunning; + if (this._alreadyRunning && this._runningBlock !== null) { + this._ignoringBlock = this._runningBlock; + console.debug(this._alreadyRunning + " " + this._runningBlock); } else { - this.ignoringBlock = null; + this._ignoringBlock = null; } - if (this.lastNoteTimeout != null) { + if (this._lastNoteTimeout != null) { console.debug("clearing lastNoteTimeout"); - clearTimeout(this.lastNoteTimeout); - this.lastNoteTimeout = null; + clearTimeout(this._lastNoteTimeout); + this._lastNoteTimeout = null; } this._restoreConnections(); // restore any broken connections @@ -1534,14 +1487,14 @@ class Logo { this.turtles.add(null); } - this._masterBPM = TARGETBPM; - this.defaultBPMFactor = TONEBPM / this._masterBPM; + Singer.masterBPM = TARGETBPM; + Singer.defaultBPMFactor = TONEBPM / TARGETBPM; this.masterVolume = [DEFAULTVOLUME]; if (_THIS_IS_MUSIC_BLOCKS_) { this.synth.changeInTemperament = false; } - this.checkingCompletionState = false; + this._checkingCompletionState = false; this.embeddedGraphicsFinished = {}; @@ -1772,7 +1725,7 @@ class Logo { if (this.suppressOutput[turtle] || this.suppressOutput[turtle] == undefined) { // this.errorMsg(NOACTIONERRORMSG, null, _('start')); this.suppressOutput[turtle] = false; - this.checkingCompletionState = false; + this._checkingCompletionState = false; // Reset cursor document.body.style.cursor = "default"; @@ -1793,13 +1746,13 @@ class Logo { * @returns {void} */ runFromBlock(logo, turtle, blk, isflow, receivedArg) { - this.runningBlock = blk; + this._runningBlock = blk; if (blk == null) return; this.receivedArg = receivedArg; - let delay = logo.turtleDelay + logo.waitTimes[turtle]; - logo.waitTimes[turtle] = 0; + let delay = logo.turtleDelay + logo._waitTimes[turtle]; + logo._waitTimes[turtle] = 0; if (!logo.stopTurtle) { if (logo.turtleDelay === TURTLESTEP) { @@ -1809,9 +1762,8 @@ class Logo { } logo.stepQueue[turtle].push(blk); } else { - logo.delayParameters[turtle] = - { 'blk': blk, 'flow': isflow, 'arg': receivedArg }; - logo.delayTimeout[turtle] = setTimeout(() => { + logo._delayParameters[turtle] = { 'blk': blk, 'flow': isflow, 'arg': receivedArg }; + logo._delayTimeout[turtle] = setTimeout(() => { logo.runFromBlockNow(logo, turtle, blk, isflow, receivedArg); }, delay); } @@ -1830,7 +1782,7 @@ class Logo { * @returns {void} */ runFromBlockNow(logo, turtle, blk, isflow, receivedArg, queueStart) { - this.alreadyRunning = true; + this._alreadyRunning = true; this.receivedArg = receivedArg; @@ -1973,7 +1925,7 @@ class Logo { =========================================================================== */ // Is the block in a queued clamp? - if (blk !== logo.ignoringBlock) { + if (blk !== logo._ignoringBlock) { if (blk in logo.endOfClampSignals[turtle]) { let n = logo.endOfClampSignals[turtle][blk].length; for (let i = 0; i < n; i++) { @@ -2036,10 +1988,10 @@ class Logo { if (nextBlock != null) { if (parentBlk !== blk) { - // The wait block waits waitTimes longer than other + // The wait block waits _waitTimes longer than other // blocks before it is unhighlighted if (logo.turtleDelay === TURTLESTEP) { - logo.unhighlightStepQueue[turtle] = blk; + logo._unhighlightStepQueue[turtle] = blk; } else { if ( !logo.suppressOutput[turtle] && @@ -2049,7 +2001,7 @@ class Logo { if (logo.blocks.visible) { logo.blocks.unhighlight(blk); } - }, logo.turtleDelay + logo.waitTimes[turtle]); + }, logo.turtleDelay + logo._waitTimes[turtle]); } } } @@ -2115,9 +2067,9 @@ class Logo { logo.runFromBlock(logo, turtle, nextBlock, isflow, passArg); } } else { - logo.alreadyRunning = false; + logo._alreadyRunning = false; - if (!logo.prematureRestart) { + if (!logo._prematureRestart) { // console.debug('Make sure any unissued signals are dispatched.'); for (let b in logo.endOfClampSignals[turtle]) { for (let i = 0; i < logo.endOfClampSignals[turtle][b].length; i++) { @@ -2204,16 +2156,16 @@ class Logo { " " + logo.suppressOutput[turtle] ); - logo.lastNoteTimeout = setTimeout(() => { + logo._lastNoteTimeout = setTimeout(() => { console.debug("LAST NOTE PLAYED"); - logo.lastNoteTimeout = null; + logo._lastNoteTimeout = null; if (logo.suppressOutput[turtle] && logo.recording) { logo.suppressOutput[turtle] = false; - logo.checkingCompletionState = false; + logo._checkingCompletionState = false; logo.saveLocally(); } else { logo.suppressOutput[turtle] = false; - logo.checkingCompletionState = false; + logo._checkingCompletionState = false; // Reset the cursor document.body.style.cursor = "default"; @@ -2232,8 +2184,8 @@ class Logo { queueStart === 0 && logo.justCounting[turtle].length === 0 ) { - if (!logo.checkingCompletionState) { - logo.checkingCompletionState = true; + if (!logo._checkingCompletionState) { + logo._checkingCompletionState = true; setTimeout(() => __checkCompletionState(), 250); } } @@ -2302,17 +2254,17 @@ class Logo { async dispatchTurtleSignals(turtle, beatValue, blk, delay) { // When turtle commands (forward, right, arc) are inside of notes, // they are run progressively over the course of the note duration - if (!turtle in this.embeddedGraphics) { - console.debug("Could not find turtle " + turtle + "in embeddedGraphics."); + + let tur = this.turtles.ithTurtle(turtle); + + if (tur.singer.embeddedGraphics === {}) return; - } - if (!blk in this.embeddedGraphics[turtle]) { - console.debug("Could not find blk " + blk + "in embeddedGraphics."); + if (!blk in tur.singer.embeddedGraphics) return; - } - if (this.embeddedGraphics[turtle][blk].length === 0) return; + if (tur.singer.embeddedGraphics[blk].length === 0) + return; // If the previous note's graphics are not complete, add a // slight delay before drawing any new graphics @@ -2328,28 +2280,28 @@ class Logo { let _penSwitch = name => { switch (name) { case "penup": - this.turtles.turtleList[turtle].painter.doPenUp(); + tur.painter.doPenUp(); break; case "pendown": - this.turtles.turtleList[turtle].painter.doPenDown(); + tur.painter.doPenDown(); break; case "setcolor": - this.turtles.turtleList[turtle].painter.doSetColor(arg); + tur.painter.doSetColor(arg); break; case "sethue": - this.turtles.turtleList[turtle].painter.doSetHue(arg); + tur.painter.doSetHue(arg); break; case "setshade": - this.turtles.turtleList[turtle].painter.doSetValue(arg); + tur.painter.doSetValue(arg); break; case "settranslucency": - this.turtles.turtleList[turtle].painter.doSetPenAlpha(arg); + tur.painter.doSetPenAlpha(arg); break; case "setgrey": - this.turtles.turtleList[turtle].painter.doSetChroma(arg); + tur.painter.doSetChroma(arg); break; case "setpensize": - this.turtles.turtleList[turtle].painter.doSetPensize(arg); + tur.painter.doSetPensize(arg); break; } }; @@ -2363,82 +2315,67 @@ class Logo { let __clear = (turtle, timeout) => { if (this.suppressOutput[turtle]) { - let savedPenState = this.turtles.turtleList[turtle].painter.penState; - this.turtles.turtleList[turtle].painter.penState = false; - this.turtles.turtleList[turtle].painter.doSetXY(0, 0); - this.turtles.turtleList[turtle].painter.doSetHeading(0); - this.turtles.turtleList[turtle].painter.penState = savedPenState; + let savedPenState = tur.painter.penState; + tur.painter.penState = false; + tur.painter.doSetXY(0, 0); + tur.painter.doSetHeading(0); + tur.painter.penState = savedPenState; this.svgBackground = true; } else { - this.turtles.turtleList[turtle].painter.penState = false; - this.turtles.turtleList[turtle].painter.doSetHeading(0); - this.turtles.turtleList[turtle].painter.doSetXY(0, 0); - this.turtles.turtleList[turtle].painter.penState = true; - // this.turtles.turtleList[turtle].painter.doClear(true, true, true); + tur.painter.penState = false; + tur.painter.doSetHeading(0); + tur.painter.doSetXY(0, 0); + tur.painter.penState = true; + // tur.painter.doClear(true, true, true); } }; let __right = (turtle, arg, timeout) => { if (suppressOutput) { - let savedPenState = this.turtles.turtleList[turtle].painter.penState; - this.turtles.turtleList[turtle].painter.penState = false; - this.turtles.turtleList[turtle].painter.doRight(arg); - this.turtles.turtleList[turtle].painter.penState = savedPenState; + let savedPenState = tur.painter.penState; + tur.painter.penState = false; + tur.painter.doRight(arg); + tur.painter.penState = savedPenState; } else { - setTimeout( - () => this.turtles.turtleList[turtle].painter.doRight(arg), - timeout - ); + setTimeout(() => tur.painter.doRight(arg), timeout); } }; let __setheading = (turtle, arg, timeout) => { if (suppressOutput) { - this.turtles.turtleList[turtle].painter.doSetHeading(arg); + tur.painter.doSetHeading(arg); } else { - setTimeout( - () => this.turtles.turtleList[turtle].painter.doSetHeading(arg), - timeout - ); + setTimeout(() => tur.painter.doSetHeading(arg), timeout); } }; let __forward = (turtle, arg, timeout) => { if (suppressOutput) { - let savedPenState = this.turtles.turtleList[turtle].painter.penState; - this.turtles.turtleList[turtle].painter.penState = false; - this.turtles.turtleList[turtle].painter.doForward(arg); - this.turtles.turtleList[turtle].painter.penState = savedPenState; + let savedPenState = tur.painter.penState; + tur.painter.penState = false; + tur.painter.doForward(arg); + tur.painter.penState = savedPenState; } else { - setTimeout( - () => this.turtles.turtleList[turtle].painter.doForward(arg), - timeout - ); + setTimeout(() => tur.painter.doForward(arg), timeout); } }; let __scrollxy = (turtle, arg1, arg2, timeout) => { if (suppressOutput) { - this.turtles.turtleList[turtle].painter.doScrollXY(arg1, arg2); + tur.painter.doScrollXY(arg1, arg2); } else { - setTimeout( - () => this.turtles.turtleList[turtle].painter.doScrollXY(arg1, arg2), - timeout - ); + setTimeout(() => tur.painter.doScrollXY(arg1, arg2), timeout); } }; let __setxy = (turtle, arg1, arg2, timeout) => { if (suppressOutput) { - let savedPenState = this.turtles.turtleList[turtle].painter.penState; - this.turtles.turtleList[turtle].painter.penState = false; - this.turtles.turtleList[turtle].painter.doSetXY(arg1, arg2); - this.turtles.turtleList[turtle].painter.penState = savedPenState; + let savedPenState = tur.painter.penState; + tur.painter.penState = false; + tur.painter.doSetXY(arg1, arg2); + tur.painter.penState = savedPenState; } else { - setTimeout( - () => this.turtles.turtleList[turtle].painter.doSetXY(arg1, arg2), - timeout - ); + setTimeout(() => tur.painter.doSetXY(arg1, arg2), timeout); } }; @@ -2465,15 +2402,12 @@ class Logo { let __arc = (turtle, arg1, arg2, timeout) => { if (suppressOutput) { - let savedPenState = this.turtles.turtleList[turtle].painter.penState; - this.turtles.turtleList[turtle].painter.penState = false; - this.turtles.turtleList[turtle].painter.doArc(arg1, arg2); - this.turtles.turtleList[turtle].painter.penState = savedPenState; + let savedPenState = tur.painter.penState; + tur.painter.penState = false; + tur.painter.doArc(arg1, arg2); + tur.painter.penState = savedPenState; } else { - setTimeout( - () => this.turtles.turtleList[turtle].painter.doArc(arg1, arg2), - timeout - ); + setTimeout(() => tur.painter.doArc(arg1, arg2), timeout); } }; @@ -2503,9 +2437,9 @@ class Logo { let __bezier = (turtle, arg1, arg2, timeout) => { if (suppressOutput) { - let savedPenState = this.turtles.turtleList[turtle].painter.penState; - this.turtles.turtleList[turtle].painter.penState = false; - this.turtles.turtleList[turtle].painter.doBezier( + let savedPenState = tur.painter.penState; + tur.painter.penState = false; + tur.painter.doBezier( this.cp1x[turtle], this.cp1y[turtle], this.cp2x[turtle], @@ -2513,10 +2447,10 @@ class Logo { arg1, arg2 ); - this.turtles.turtleList[turtle].painter.penState = savedPenState; + tur.painter.penState = savedPenState; } else { setTimeout(() => { - this.turtles.turtleList[turtle].painter.doBezier( + tur.painter.doBezier( this.cp1x[turtle], this.cp1y[turtle], this.cp2x[turtle], @@ -2531,24 +2465,23 @@ class Logo { let inFillClamp = false; let __fill = (turtle, timeout) => { if (suppressOutput) { - let savedPenState = this.turtles.turtleList[turtle].painter.penState; - this.turtles.turtleList[turtle].painter.penState = false; + let savedPenState = tur.painter.penState; + tur.painter.penState = false; if (inFillClamp) { - this.turtles.turtleList[turtle].painter.doEndFill(); + tur.painter.doEndFill(); inFillClamp = false; } else { - this.turtles.turtleList[turtle].painter.doStartFill(); + tur.painter.doStartFill(); inFillClamp = true; } - - this.turtles.turtleList[turtle].painter.penState = savedPenState; + tur.painter.penState = savedPenState; } else { setTimeout(() => { if (inFillClamp) { - this.turtles.turtleList[turtle].painter.doEndFill(); + tur.painter.doEndFill(); inFillClamp = false; } else { - this.turtles.turtleList[turtle].painter.doStartFill(); + tur.painter.doStartFill(); inFillClamp = true; } }, timeout); @@ -2559,19 +2492,19 @@ class Logo { let __hollowline = (turtle, timeout) => { if (suppressOutput) { if (inHollowLineClamp) { - this.turtles.turtleList[turtle].painter.doEndHollowLine(); + tur.painter.doEndHollowLine(); inHollowLineClamp = false; } else { - this.turtles.turtleList[turtle].painter.doStartHollowLine(); + tur.painter.doStartHollowLine(); inHollowLineClamp = true; } } else { setTimeout(() => { if (inHollowLineClamp) { - this.turtles.turtleList[turtle].painter.doEndHollowLine(); + tur.painter.doEndHollowLine(); inHollowLineClamp = false; } else { - this.turtles.turtleList[turtle].painter.doStartHollowLine(); + tur.painter.doStartHollowLine(); inHollowLineClamp = true; } }, timeout); @@ -2579,8 +2512,8 @@ class Logo { }; let extendedGraphicsCounter = 0; - for (let i = 0; i < this.embeddedGraphics[turtle][blk].length; i++) { - let b = this.embeddedGraphics[turtle][blk][i]; + for (let i = 0; i < tur.singer.embeddedGraphics[blk].length; i++) { + let b = tur.singer.embeddedGraphics[blk][i]; switch (this.blocks.blockList[b].name) { case "forward": case "back": @@ -2610,21 +2543,21 @@ class Logo { // Update the turtle graphics every 50ms within a note if (stepTime > 200) { - this.dispatchFactor[turtle] = NOTEDIV / 32; + tur.singer.dispatchFactor = NOTEDIV / 32; } else if (stepTime > 100) { - this.dispatchFactor[turtle] = NOTEDIV / 16; + tur.singer.dispatchFactor = NOTEDIV / 16; } else if (stepTime > 50) { - this.dispatchFactor[turtle] = NOTEDIV / 8; + tur.singer.dispatchFactor = NOTEDIV / 8; } else if (stepTime > 25) { - this.dispatchFactor[turtle] = NOTEDIV / 4; + tur.singer.dispatchFactor = NOTEDIV / 4; } else if (stepTime > 12.5) { - this.dispatchFactor[turtle] = NOTEDIV / 2; + tur.singer.dispatchFactor = NOTEDIV / 2; } else { - this.dispatchFactor[turtle] = NOTEDIV; + tur.singer.dispatchFactor = NOTEDIV; } - for (let i = 0; i < this.embeddedGraphics[turtle][blk].length; i++) { - let b = this.embeddedGraphics[turtle][blk][i]; + for (let i = 0; i < tur.singer.embeddedGraphics[blk].length; i++) { + let b = tur.singer.embeddedGraphics[blk][i]; let name = this.blocks.blockList[b].name; let arg, arg1, arg2; @@ -2743,16 +2676,9 @@ class Logo { this.receivedArg ); - for ( - let t = 0; - t < NOTEDIV / this.dispatchFactor[turtle]; - t++ - ) { - let deltaTime = - waitTime + - t * stepTime * this.dispatchFactor[turtle]; - let deltaArg = - arg / (NOTEDIV / this.dispatchFactor[turtle]); + for (let t = 0; t < NOTEDIV / tur.singer.dispatchFactor; t++) { + let deltaTime = waitTime + t * stepTime * tur.singer.dispatchFactor; + let deltaArg = arg / (NOTEDIV / tur.singer.dispatchFactor); __right(turtle, deltaArg, deltaTime); } @@ -2768,16 +2694,9 @@ class Logo { this.receivedArg ); - for ( - let t = 0; - t < NOTEDIV / this.dispatchFactor[turtle]; - t++ - ) { - let deltaTime = - waitTime + - t * stepTime * this.dispatchFactor[turtle]; - let deltaArg = - arg / (NOTEDIV / this.dispatchFactor[turtle]); + for (let t = 0; t < NOTEDIV / tur.singer.dispatchFactor; t++) { + let deltaTime = waitTime + t * stepTime * tur.singer.dispatchFactor; + let deltaArg = arg / (NOTEDIV / tur.singer.dispatchFactor); __right(turtle, -deltaArg, deltaTime); } @@ -2793,16 +2712,9 @@ class Logo { this.receivedArg ); - for ( - let t = 0; - t < NOTEDIV / this.dispatchFactor[turtle]; - t++ - ) { - let deltaTime = - waitTime + - t * stepTime * this.dispatchFactor[turtle]; - let deltaArg = - arg / (NOTEDIV / this.dispatchFactor[turtle]); + for (let t = 0; t < NOTEDIV / tur.singer.dispatchFactor; t++) { + let deltaTime = waitTime + t * stepTime * tur.singer.dispatchFactor; + let deltaArg = arg / (NOTEDIV / tur.singer.dispatchFactor); __forward(turtle, deltaArg, deltaTime); } @@ -2818,16 +2730,9 @@ class Logo { this.receivedArg ); - for ( - let t = 0; - t < NOTEDIV / this.dispatchFactor[turtle]; - t++ - ) { - let deltaTime = - waitTime + - t * stepTime * this.dispatchFactor[turtle]; - let deltaArg = - arg / (NOTEDIV / this.dispatchFactor[turtle]); + for (let t = 0; t < NOTEDIV / tur.singer.dispatchFactor; t++) { + let deltaTime = waitTime + t * stepTime * tur.singer.dispatchFactor; + let deltaArg = arg / (NOTEDIV / tur.singer.dispatchFactor); __forward(turtle, -deltaArg, deltaTime); } @@ -2926,16 +2831,9 @@ class Logo { this.receivedArg ); - for ( - let t = 0; - t < NOTEDIV / this.dispatchFactor[turtle]; - t++ - ) { - let deltaTime = - waitTime + - t * stepTime * this.dispatchFactor[turtle]; - let deltaArg = - arg1 / (NOTEDIV / this.dispatchFactor[turtle]); + for (let t = 0; t < NOTEDIV / tur.singer.dispatchFactor; t++) { + let deltaTime = waitTime + t * stepTime * tur.singer.dispatchFactor; + let deltaArg = arg1 / (NOTEDIV / tur.singer.dispatchFactor); __arc(turtle, deltaArg, arg2, deltaTime); } diff --git a/js/turtle-singer.js b/js/turtle-singer.js index 4466d52a2c..569dd01df5 100644 --- a/js/turtle-singer.js +++ b/js/turtle-singer.js @@ -41,10 +41,51 @@ class Singer { constructor(turtle) { this.turtle = turtle; this.turtles = turtle.turtles; + + // Parameters used by pitch + this.scalarTransposition = 0; + this.scalarTranspositionValues = []; + this.transposition = 0; + this.transpositionValues = []; + + // Parameters used by notes + this.register = 0; + this.beatFactor = 1; + this.dotCount = 0; + this.noteBeat = {}; + this.noteValue = {}; + this.noteDrums = {}; + this.notePitches = {}; + this.noteOctaves = {}; + this.noteCents = {}; + this.noteHertz = {}; + this.noteBeatValues = {}; + this.embeddedGraphics = {}; + this.lastNotePlayed = null; + this.lastPitchPlayed = {}; // for a stand-alone pitch block + this.previousNotePlayed = null; + this.noteStatus = null; + this.noteDirection = 0; + this.pitchNumberOffset = 39; // 39, C4 + this.currentOctave = 4; + this.currentCalculatedOctave = {}; // for a stand-alone pitch block + this.inHarmonic = []; + this.partials = []; + this.inNeighbor = []; + this.neighborStepPitch = []; + this.neighborNoteValue = []; + this.inDefineMode = false; + this.defineMode = []; + + // Music-related attributes + this.notesPlayed = [0, 1]; + this.whichNoteToCount = 1; + this.moveable = false; // moveable solfege? + + this.dispatchFactor = 1; // scale factor for turtle graphics embedded in notes } - // Deprecated - // ======================================================================== + // ========= Deprecated =================================================== /** * @deprecated @@ -69,32 +110,33 @@ class Singer { } else if (logo.inPitchSlider) { logo.pitchSlider.Sliders.push([args[0], 0, 0]); } else { - logo.oscList[turtle][last(logo.inNoteBlock[turtle])].push( + let tur = logo.turtles.ithTurtle(turtle); + + tur.singer.oscList[last(logo.inNoteBlock[turtle])].push( logo.blocks.blockList[blk].name ); // We keep track of pitch and octave for notation purposes. - logo.notePitches[turtle][last(logo.inNoteBlock[turtle])].push(obj[0]); - logo.noteOctaves[turtle][last(logo.inNoteBlock[turtle])].push(obj[1]); - logo.noteCents[turtle][last(logo.inNoteBlock[turtle])].push(obj[2]); + tur.singer.notePitches[last(logo.inNoteBlock[turtle])].push(obj[0]); + tur.singer.noteOctaves[last(logo.inNoteBlock[turtle])].push(obj[1]); + tur.singer.noteCents[last(logo.inNoteBlock[turtle])].push(obj[2]); if (obj[2] !== 0) { - logo.noteHertz[turtle][last(logo.inNoteBlock[turtle])].push( + tur.singer.noteHertz[last(logo.inNoteBlock[turtle])].push( pitchToFrequency(obj[0], obj[1], obj[2], logo.keySignature[turtle]) ); } else { - logo.noteHertz[turtle][last(logo.inNoteBlock[turtle])].push(0); + tur.singer.noteHertz[last(logo.inNoteBlock[turtle])].push(0); } - logo.noteBeatValues[turtle][last(logo.inNoteBlock[turtle])].push( - logo.beatFactor[turtle] + tur.singer.noteBeatValues[last(logo.inNoteBlock[turtle])].push( + tur.singer.beatFactor ); logo.pushedNote[turtle] = true; } } } - // Utilities - // ======================================================================== + // ========= Utilities ==================================================== /** * Shifts pitches by n steps relative to the provided scale. @@ -111,12 +153,14 @@ class Singer { if (steps === 0) return [note, octave]; + let tur = logo.turtles.ithTurtle(turtle); + let noteObj = getNote( note, octave, 0, logo.keySignature[turtle], - logo.moveable[turtle], + tur.singer.moveable, null, logo.errorMsg, logo.synth.inTemperament @@ -134,7 +178,7 @@ class Singer { logo.keySignature[turtle], noteObj[0], steps, logo.synth.inTemperament ), logo.keySignature[turtle], - logo.moveable[turtle], + tur.singer.moveable, null, logo.errorMsg, logo.synth.inTemperament @@ -148,7 +192,7 @@ class Singer { getStepSizeUp(logo.keySignature[turtle], noteObj[0]) : getStepSizeDown(logo.keySignature[turtle], noteObj[0]), logo.keySignature[turtle], - logo.moveable[turtle], + tur.singer.moveable, null, logo.errorMsg, logo.synth.inTemperament @@ -182,13 +226,15 @@ class Singer { positive = true; } - let noteObj = numberToPitch(lastNote + logo.pitchNumberOffset[turtle]); - let n = firstNote + logo.pitchNumberOffset[turtle]; + let tur = logo.turtles.ithTurtle(turtle); + + let noteObj = numberToPitch(lastNote + tur.singer.pitchNumberOffset); + let n = firstNote + tur.singer.pitchNumberOffset; let i = 0; while (i++ < 100) { n += getStepSizeUp(logo.keySignature[turtle], noteObj[0]); - if (n >= firstNote + logo.pitchNumberOffset[turtle]) + if (n >= firstNote + tur.singer.pitchNumberOffset) break; noteObj = numberToPitch(n); @@ -208,13 +254,15 @@ class Singer { * @returns {Number} inverted value */ static calculateInvert(logo, turtle, note, octave) { + let tur = logo.turtles.ithTurtle(turtle); + let delta = 0; let note1 = getNote( - note, octave, 0, logo.keySignature[turtle], logo.moveable[turtle], null, logo.errorMsg + note, octave, 0, logo.keySignature[turtle], tur.singer.moveable, null, logo.errorMsg ); let num1 = pitchToNumber(note1[0], note1[1], logo.keySignature[turtle]) - - logo.pitchNumberOffset[turtle]; + tur.singer.pitchNumberOffset; for (let i = logo.invertList[turtle].length - 1; i >= 0; i--) { let note2 = getNote( @@ -222,13 +270,13 @@ class Singer { logo.invertList[turtle][i][1], 0, logo.keySignature[turtle], - logo.moveable[turtle], + tur.singer.moveable, null, logo.errorMsg ); let num2 = pitchToNumber(note2[0], note2[1], logo.keySignature[turtle]) - - logo.pitchNumberOffset[turtle]; + tur.singer.pitchNumberOffset; if (logo.invertList[turtle][i][2] === "even") { delta += num2 - num1; @@ -244,7 +292,7 @@ class Singer { ); let num3 = pitchToNumber(note3[0], note3[1], logo.keySignature[turtle]) - - logo.pitchNumberOffset[turtle]; + tur.singer.pitchNumberOffset; delta += (num3 - num1) / 2; num1 = num3; @@ -267,23 +315,25 @@ class Singer { if (cblk === null) return 0; + let tur = logo.turtles.ithTurtle(turtle); + let saveSuppressStatus = logo.suppressOutput[turtle]; // We need to save the state of the boxes and heap although there is a potential of a boxes collision with other turtles 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 saveWhichNoteToCount = logo.whichNoteToCount[turtle]; + 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; + + let saveWhichNoteToCount = tur.singer.whichNoteToCount; let savePrevTurtleTime = logo.previousTurtleTime[turtle]; let saveTurtleTime = logo.turtleTime[turtle]; @@ -299,11 +349,11 @@ class Singer { } let actionArgs = []; - let saveNoteCount = logo.notesPlayed[turtle]; + let saveNoteCount = tur.singer.notesPlayed; logo.turtles.turtleList[turtle].running = true; if (logo.inNoteBlock[turtle]) { - logo.whichNoteToCount[turtle] += logo.inNoteBlock[turtle].length; + tur.singer.whichNoteToCount += logo.inNoteBlock[turtle].length; } logo.runFromBlockNow( @@ -311,9 +361,9 @@ class Singer { ); let returnValue = rationalSum( - logo.notesPlayed[turtle], [-saveNoteCount[0], saveNoteCount[1]] + tur.singer.notesPlayed, [-saveNoteCount[0], saveNoteCount[1]] ); - logo.notesPlayed[turtle] = saveNoteCount; + tur.singer.notesPlayed = saveNoteCount; // Restore previous state console.debug(saveBoxes); @@ -321,20 +371,20 @@ class Singer { console.debug(saveTurtleHeaps); logo.turtleHeaps[turtle] = JSON.parse(saveTurtleHeaps); - logo.turtles.turtleList[turtle].painter.doPenUp(); - logo.turtles.turtleList[turtle].painter.doSetXY(saveX, saveY); - logo.turtles.turtleList[turtle].painter.color = saveColor; - logo.turtles.turtleList[turtle].painter.value = saveValue; - logo.turtles.turtleList[turtle].painter.chroma = saveChroma; - logo.turtles.turtleList[turtle].painter.stroke = saveStroke; - logo.turtles.turtleList[turtle].painter.canvasAlpha = saveCanvasAlpha; - logo.turtles.turtleList[turtle].painter.doSetHeading(saveOrientation); - logo.turtles.turtleList[turtle].painter.penState = savePenState; + tur.painter.doPenUp(); + tur.painter.doSetXY(saveX, saveY); + tur.painter.color = saveColor; + tur.painter.value = saveValue; + tur.painter.chroma = saveChroma; + tur.painter.stroke = saveStroke; + tur.painter.canvasAlpha = saveCanvasAlpha; + tur.painter.doSetHeading(saveOrientation); + tur.painter.penState = savePenState; logo.previousTurtleTime[turtle] = savePrevTurtleTime; logo.turtleTime[turtle] = saveTurtleTime; - logo.whichNoteToCount[turtle] = saveWhichNoteToCount; + tur.singer.whichNoteToCount = saveWhichNoteToCount; logo.justCounting[turtle].pop(); logo.suppressOutput[turtle] = saveSuppressStatus; @@ -392,8 +442,7 @@ class Singer { } } - // Action - // ======================================================================== + // ========= Action ======================================================= /** * @static @@ -405,18 +454,20 @@ class Singer { * @param {Object} blk - corresponding Block object index in blocks.blockList */ static processPitch(note, octave, cents, logo, turtle, blk) { + let tur = logo.turtles.ithTurtle(turtle); + let noteObj = Singer.addScalarTransposition( - logo, turtle, note, octave, logo.scalarTransposition[turtle] + logo, turtle, note, octave, tur.singer.scalarTransposition ); [note, octave] = noteObj; - if (logo.inNeighbor[turtle].length > 0) { + if (tur.singer.inNeighbor.length > 0) { noteObj = getNote( note, octave, - logo.transposition[turtle], + tur.singer.transposition, logo.keySignature[turtle], - logo.moveable[turtle], + tur.singer.moveable, null, logo.errorMsg, logo.synth.inTemperament @@ -424,17 +475,17 @@ class Singer { logo.neighborArgNote1[turtle].push(noteObj[0] + noteObj[1]); let noteObj2; - if (logo.blocks.blockList[last(logo.inNeighbor[turtle])].name === "neighbor2") { + if (logo.blocks.blockList[last(tur.singer.inNeighbor)].name === "neighbor2") { noteObj2 = Singer.addScalarTransposition( - logo, turtle, note, octave, parseInt(logo.neighborStepPitch[turtle]) + logo, turtle, note, octave, parseInt(tur.singer.neighborStepPitch) ); - if (logo.transposition[turtle] !== 0) { + if (tur.singer.transposition !== 0) { noteObj2 = getNote( noteObj2[0], noteObj2[1], - logo.transposition[turtle], + tur.singer.transposition, logo.keySignature[turtle], - logo.moveable[turtle], + tur.singer.moveable, null, logo.errorMsg, logo.synth.inTemperament @@ -444,9 +495,9 @@ class Singer { noteObj2 = getNote( note, octave, - logo.transposition[turtle] + parseInt(logo.neighborStepPitch[turtle]), + tur.singer.transposition + parseInt(tur.singer.neighborStepPitch), logo.keySignature[turtle], - logo.moveable[turtle], + tur.singer.moveable, null, logo.errorMsg, logo.synth.inTemperament @@ -461,14 +512,14 @@ class Singer { Singer.calculateInvert(logo, turtle, note, octave) : 0; if (logo.justMeasuring[turtle].length > 0) { - let transposition = turtle in logo.transposition ? logo.transposition[turtle] : 0; + let transposition = tur.singer.transposition; noteObj = getNote( note, octave, transposition, logo.keySignature[turtle], - logo.moveable[turtle], + tur.singer.moveable, null, logo.errorMsg, logo.synth.inTemperament @@ -477,7 +528,7 @@ class Singer { let n = logo.justMeasuring[turtle].length; let pitchNumber = pitchToNumber(noteObj[0], noteObj[1], logo.keySignature[turtle]) - - logo.pitchNumberOffset[turtle]; + tur.singer.pitchNumberOffset; if (logo.firstPitch[turtle].length < n) { logo.firstPitch[turtle].push(pitchNumber); } else if (logo.lastPitch[turtle].length < n) { @@ -496,17 +547,14 @@ class Singer { for (let i = 0; i < duplicateFactor; i++) { // Apply transpositions - let transposition = 2 * delta; - if (turtle in logo.transposition) { - transposition += logo.transposition[turtle]; - } + let transposition = 2 * delta + tur.singer.transposition; let nnote = getNote( note, octave, transposition, logo.keySignature[turtle], - logo.moveable[turtle], + tur.singer.moveable, null, logo.errorMsg, logo.synth.inTemperament @@ -533,23 +581,20 @@ class Singer { for (let i = 0; i < duplicateFactor; i++) { // Apply transpositions - let transposition = 2 * delta; - if (turtle in logo.transposition) { - transposition += logo.transposition[turtle]; - } + let transposition = 2 * delta + tur.singer.transposition; let noteObj = getNote( note, octave, transposition, logo.keySignature[turtle], - logo.moveable[turtle], + tur.singer.moveable, null, logo.errorMsg, logo.synth.inTemperament ); - logo.previousNotePlayed[turtle] = logo.lastNotePlayed[turtle]; - logo.lastNotePlayed[turtle] = [noteObj[0] + noteObj[1], 4]; + tur.singer.previousNotePlayed = tur.singer.lastNotePlayed; + tur.singer.lastNotePlayed = [noteObj[0] + noteObj[1], 4]; if ( logo.keySignature[turtle][0] === "C" && @@ -586,9 +631,9 @@ class Singer { let noteObj = getNote( note, octave, - transposition + logo.register[turtle] * 12, + transposition + tur.singer.register * 12, logo.keySignature[turtle], - logo.moveable[turtle], + tur.singer.moveable, direction, logo.errorMsg, logo.synth.inTemperament @@ -599,15 +644,12 @@ class Singer { logo.pitchDrumTable[turtle][noteObj[0] + noteObj[1]] = drumname; } - logo.notePitches[turtle][last(logo.inNoteBlock[turtle])].push(noteObj[0]); - logo.noteOctaves[turtle][last(logo.inNoteBlock[turtle])].push(noteObj[1]); - logo.noteCents[turtle][last(logo.inNoteBlock[turtle])].push(cents); - logo.noteHertz[turtle][last(logo.inNoteBlock[turtle])].push( + tur.singer.notePitches[last(logo.inNoteBlock[turtle])].push(noteObj[0]); + tur.singer.noteOctaves[last(logo.inNoteBlock[turtle])].push(noteObj[1]); + tur.singer.noteCents[last(logo.inNoteBlock[turtle])].push(cents); + tur.singer.noteHertz[last(logo.inNoteBlock[turtle])].push( cents === 0 ? 0 : pitchToFrequency( - noteObj[0], - noteObj[1], - cents, - logo.keySignature[turtle] + noteObj[0], noteObj[1], cents, logo.keySignature[turtle] ) ); @@ -615,10 +657,7 @@ class Singer { } // Apply transpositions - let transposition = 2 * delta; - if (turtle in logo.transposition) { - transposition += logo.transposition[turtle]; - } + let transposition = 2 * delta + tur.singer.transposition; let noteObj1 = addPitch(note, octave, cents); @@ -633,7 +672,7 @@ class Singer { noteObj1[0] ), logo.keySignature[turtle], - logo.moveable[turtle], + tur.singer.moveable, null, logo.errorMsg, logo.synth.inTemperament @@ -649,7 +688,7 @@ class Singer { noteObj1[1], logo.semitoneIntervals[turtle][i][0], logo.keySignature[turtle], - logo.moveable[turtle], + tur.singer.moveable, null, logo.errorMsg, logo.synth.inTemperament @@ -661,22 +700,22 @@ class Singer { } if (logo.inNoteBlock[turtle].length > 0) { - logo.noteBeatValues[turtle][last(logo.inNoteBlock[turtle])].push( - logo.beatFactor[turtle] + tur.singer.noteBeatValues[last(logo.inNoteBlock[turtle])].push( + tur.singer.beatFactor ); } logo.pushedNote[turtle] = true; } else if (logo.drumStyle[turtle].length > 0) { let drumname = last(logo.drumStyle[turtle]); - let transposition = turtle in logo.transposition ? logo.transposition[turtle] : 0; + let transposition = tur.singer.transposition; let noteObj1 = getNote( note, octave, transposition, logo.keySignature[turtle], - logo.moveable[turtle], + tur.singer.moveable, null, logo.errorMsg ); @@ -688,7 +727,7 @@ class Singer { octave, 0, logo.keySignature[turtle], - logo.moveable[turtle], + tur.singer.moveable, null, logo.errorMsg ); @@ -716,17 +755,14 @@ class Singer { logo.pitchStaircase.stairPitchBlocks.push(blk); } else if (logo.inMusicKeyboard) { // Apply transpositions - let transposition = 2 * delta; - if (turtle in logo.transposition) { - transposition += logo.transposition[turtle]; - } + let transposition = 2 * delta + tur.singer.transposition; let nnote = getNote( note, octave, transposition, logo.keySignature[turtle], - logo.moveable[turtle], + tur.singer.moveable, null, logo.errorMsg ); @@ -737,13 +773,13 @@ class Singer { logo.musicKeyboard.noteNames.push(nnote[0]); logo.musicKeyboard.octaves.push(nnote[1]); logo.musicKeyboard.addRowBlock(blk); - logo.lastNotePlayed[turtle] = [noteObj[0] + noteObj[1], 4]; + tur.singer.lastNotePlayed = [noteObj[0] + noteObj[1], 4]; } } else { // Play a stand-alone pitch block as a quarter note. - logo.clearNoteParams(turtle, blk, []); - if (logo.currentCalculatedOctave[turtle] === undefined) { - logo.currentCalculatedOctave[turtle] = 4; + logo.clearNoteParams(tur, blk, []); + if (tur.singer.currentCalculatedOctave === undefined) { + tur.singer.currentCalculatedOctave = 4; } let noteObj = getNote( @@ -751,16 +787,16 @@ class Singer { octave, 0, logo.keySignature[turtle], - logo.moveable[turtle], + tur.singer.moveable, null, logo.errorMsg ); logo.inNoteBlock[turtle].push(blk); - logo.notePitches[turtle][last(logo.inNoteBlock[turtle])].push(noteObj[0]); - logo.noteOctaves[turtle][last(logo.inNoteBlock[turtle])].push(noteObj[1]); - logo.noteCents[turtle][last(logo.inNoteBlock[turtle])].push(cents); - logo.noteHertz[turtle][last(logo.inNoteBlock[turtle])].push( + tur.singer.notePitches[last(logo.inNoteBlock[turtle])].push(noteObj[0]); + tur.singer.noteOctaves[last(logo.inNoteBlock[turtle])].push(noteObj[1]); + tur.singer.noteCents[last(logo.inNoteBlock[turtle])].push(cents); + tur.singer.noteHertz[last(logo.inNoteBlock[turtle])].push( cents === 0 ? 0 : pitchToFrequency( noteObj[0], noteObj[1], cents, logo.keySignature[turtle] ) @@ -791,14 +827,16 @@ class Singer { * @todo We should consider the use of the global timer in Tone.js for more accuracy. */ + let tur = logo.turtles.ithTurtle(turtle); + // Use the outer most note when nesting to determine the beat and triggering if (logo.inNoteBlock[turtle].length === 0) { let beatValue, measureValue; - if (logo.notesPlayed[turtle][0] / logo.notesPlayed[turtle][1] < logo.pickup[turtle]) { + if (tur.singer.notesPlayed[0] / tur.singer.notesPlayed[1] < logo.pickup[turtle]) { beatValue = measureValue = 0; } else { let beat = logo.noteValuePerBeat[turtle] * ( - logo.notesPlayed[turtle][0] / logo.notesPlayed[turtle][1] - logo.pickup[turtle] + tur.singer.notesPlayed[0] / tur.singer.notesPlayed[1] - logo.pickup[turtle] ); beatValue = 1 + beat % logo.beatsPerMeasure[turtle]; measureValue = 1 + Math.floor(beat / logo.beatsPerMeasure[turtle]); @@ -841,7 +879,7 @@ class Singer { // A note can contain multiple pitch blocks to create a chord. The chord is accumuated in // arrays, which are used when we play the note - logo.clearNoteParams(turtle, blk, []); + logo.clearNoteParams(tur, blk, []); let noteBeatValue = logo.blocks.blockList[blk].name === "newnote" ? 1 / value : value; @@ -849,8 +887,8 @@ class Singer { logo.multipleVoices[turtle] = logo.inNoteBlock[turtle].length > 1 ? true : false; // Adjust the note value based on the beatFactor - logo.noteValue[turtle][last(logo.inNoteBlock[turtle])] = - 1 / (noteBeatValue * logo.beatFactor[turtle]); + tur.singer.noteValue[last(logo.inNoteBlock[turtle])] = + 1 / (noteBeatValue * tur.singer.beatFactor); let listenerName = "_playnote_" + turtle; logo.setDispatchBlock(blk, turtle, listenerName); @@ -861,36 +899,36 @@ class Singer { } if (logo.inNoteBlock[turtle].length > 0) { - if (logo.inNeighbor[turtle].length > 0) { - let neighborNoteValue = logo.neighborNoteValue[turtle]; + if (tur.singer.inNeighbor.length > 0) { + let neighborNoteValue = tur.singer.neighborNoteValue; logo.neighborArgBeat[turtle].push( - logo.beatFactor[turtle] * (1 / neighborNoteValue) + tur.singer.beatFactor * (1 / neighborNoteValue) ); - let nextBeat = 1 / noteBeatValue - 2 * logo.neighborNoteValue[turtle]; + let nextBeat = 1 / noteBeatValue - 2 * tur.singer.neighborNoteValue; logo.neighborArgCurrentBeat[turtle].push( - logo.beatFactor[turtle] * (1 / nextBeat) + tur.singer.beatFactor * (1 / nextBeat) ); } Singer.processNote( logo, - 1 / logo.noteValue[turtle][last(logo.inNoteBlock[turtle])], + 1 / tur.singer.noteValue[last(logo.inNoteBlock[turtle])], last(logo.inNoteBlock[turtle]), turtle ); } - delete logo.oscList[turtle][last(logo.inNoteBlock[turtle])]; - delete logo.noteBeat[turtle][last(logo.inNoteBlock[turtle])]; - delete logo.noteBeatValues[turtle][last(logo.inNoteBlock[turtle])]; - delete logo.noteValue[turtle][last(logo.inNoteBlock[turtle])]; - delete logo.notePitches[turtle][last(logo.inNoteBlock[turtle])]; - delete logo.noteOctaves[turtle][last(logo.inNoteBlock[turtle])]; - delete logo.noteCents[turtle][last(logo.inNoteBlock[turtle])]; - delete logo.noteHertz[turtle][last(logo.inNoteBlock[turtle])]; - delete logo.noteDrums[turtle][last(logo.inNoteBlock[turtle])]; - delete logo.embeddedGraphics[turtle][last(logo.inNoteBlock[turtle])]; + delete tur.singer.oscList[last(logo.inNoteBlock[turtle])]; + delete tur.singer.noteBeat[last(logo.inNoteBlock[turtle])]; + delete tur.singer.noteBeatValues[last(logo.inNoteBlock[turtle])]; + delete tur.singer.noteValue[last(logo.inNoteBlock[turtle])]; + delete tur.singer.notePitches[last(logo.inNoteBlock[turtle])]; + delete tur.singer.noteOctaves[last(logo.inNoteBlock[turtle])]; + delete tur.singer.noteCents[last(logo.inNoteBlock[turtle])]; + delete tur.singer.noteHertz[last(logo.inNoteBlock[turtle])]; + delete tur.singer.noteDrums[last(logo.inNoteBlock[turtle])]; + delete tur.singer.embeddedGraphics[last(logo.inNoteBlock[turtle])]; logo.inNoteBlock[turtle].splice(-1, 1); if (logo.multipleVoices[turtle] && logo.inNoteBlock[turtle].length === 0) { @@ -917,12 +955,10 @@ class Singer { * @param {Function} callback */ static processNote(logo, noteValue, blk, turtle, callback) { - let bpmFactor; - if (logo.bpm[turtle].length > 0) { - bpmFactor = TONEBPM / last(logo.bpm[turtle]); - } else { - bpmFactor = TONEBPM / logo._masterBPM; - } + let tur = logo.turtles.ithTurtle(turtle); + + let bpmFactor = + TONEBPM / (logo.bpm[turtle].length > 0 ? last(logo.bpm[turtle]) : Singer.masterBPM); let noteBeatValue; if (logo.blocks.blockList[blk].name === "osctime") { @@ -1042,7 +1078,7 @@ class Singer { } partials = [1]; - if (logo.inHarmonic[turtle].length > 0) { + if (tur.singer.inHarmonic.length > 0) { if (partials.length === 0) { //.TRANS: partials are weighted components in a harmonic series logo.errorMsg( @@ -1051,11 +1087,11 @@ class Singer { ) ); } else { - partials = last(logo.partials[turtle]); + partials = last(tur.singer.partials); } } - if (logo.inNeighbor[turtle].length > 0) { + if (tur.singer.inNeighbor.length > 0) { let len = logo.neighborArgNote1[turtle].length; for (let i = 0; i < len; i++) { neighborArgNote1.push(logo.neighborArgNote1[turtle].pop()); @@ -1109,11 +1145,11 @@ class Singer { if (logo.inTimbre) { let noteObj = getNote( - logo.notePitches[turtle][last(logo.inNoteBlock[turtle])][0], - logo.noteOctaves[turtle][last(logo.inNoteBlock[turtle])][0], + tur.singer.notePitches[last(logo.inNoteBlock[turtle])][0], + tur.singer.noteOctaves[last(logo.inNoteBlock[turtle])][0], 0, logo.keySignature[turtle], - logo.moveable[turtle], + tur.singer.moveable, null, logo.errorMsg ); @@ -1121,11 +1157,8 @@ class Singer { noteObj[0] + noteObj[1], 1 / noteBeatValue ]); - logo.previousNotePlayed[turtle] = logo.lastNotePlayed[turtle]; - logo.lastNotePlayed[turtle] = [ - noteObj[0] + noteObj[1], - noteBeatValue - ]; + tur.singer.previousNotePlayed = tur.singer.lastNotePlayed; + tur.singer.lastNotePlayed = [noteObj[0] + noteObj[1], noteBeatValue]; } else if (logo.inMatrix || logo.tuplet) { if (logo.inNoteBlock[turtle].length > 0) { logo.pitchTimeMatrix.addColBlock(blk, 1); @@ -1154,7 +1187,7 @@ class Singer { } } - noteBeatValue *= logo.beatFactor[turtle]; + noteBeatValue *= tur.singer.beatFactor; if (logo.tuplet) { if (logo.addingNotesToTuplet) { let i = logo.tupletRhythms.length - 1; @@ -1218,8 +1251,7 @@ class Singer { var match = true; if ( logo.tieNotePitches[turtle].length !== - logo.notePitches[turtle][last(logo.inNoteBlock[turtle])] - .length + tur.singer.notePitches[last(logo.inNoteBlock[turtle])].length ) { match = false; } else { @@ -1232,9 +1264,7 @@ class Singer { ) { if ( logo.tieNotePitches[turtle][i][0] != - logo.notePitches[turtle][ - last(logo.inNoteBlock[turtle]) - ][i] + tur.singer.notePitches[last(logo.inNoteBlock[turtle])][i] ) { match = false; break; @@ -1242,9 +1272,7 @@ class Singer { if ( logo.tieNotePitches[turtle][i][1] != - logo.noteOctaves[turtle][ - last(logo.inNoteBlock[turtle]) - ][i] + tur.singer.noteOctaves[last(logo.inNoteBlock[turtle])][i] ) { match = false; break; @@ -1266,81 +1294,56 @@ class Singer { var saveCurrentNote = []; var saveCurrentExtras = []; for ( - var i = 0; - i < - logo.notePitches[turtle][ - last(logo.inNoteBlock[turtle]) - ].length; + let i = 0; + i < tur.singer.notePitches[last(logo.inNoteBlock[turtle])].length; i++ ) { saveCurrentNote.push([ - logo.notePitches[turtle][saveBlk][i], - logo.noteOctaves[turtle][saveBlk][i], - logo.noteCents[turtle][saveBlk][i], - logo.noteHertz[turtle][saveBlk][i], + tur.singer.notePitches[saveBlk][i], + tur.singer.noteOctaves[saveBlk][i], + tur.singer.noteCents[saveBlk][i], + tur.singer.noteHertz[saveBlk][i], saveBlk ]); } saveCurrentExtras = [ saveBlk, - logo.oscList[turtle][saveBlk], - logo.noteBeat[turtle][saveBlk], - logo.noteBeatValues[turtle][saveBlk], - logo.noteDrums[turtle][saveBlk], - logo.embeddedGraphics[turtle][saveBlk] + tur.singer.oscList[saveBlk], + tur.singer.noteBeat[saveBlk], + tur.singer.noteBeatValues[saveBlk], + tur.singer.noteDrums[saveBlk], + tur.singer.embeddedGraphics[saveBlk] ]; // Swap in the previous note. saveBlk = logo.tieNoteExtras[turtle][0]; logo.inNoteBlock[turtle].push(saveBlk); - logo.notePitches[turtle][saveBlk] = []; - logo.noteOctaves[turtle][saveBlk] = []; - logo.noteCents[turtle][saveBlk] = []; - logo.noteHertz[turtle][saveBlk] = []; + tur.singer.notePitches[saveBlk] = []; + tur.singer.noteOctaves[saveBlk] = []; + tur.singer.noteCents[saveBlk] = []; + tur.singer.noteHertz[saveBlk] = []; for ( var i = 0; i < logo.tieNotePitches[turtle].length; i++ ) { - logo.notePitches[turtle][saveBlk].push( - logo.tieNotePitches[turtle][i][0] - ); - logo.noteOctaves[turtle][saveBlk].push( - logo.tieNotePitches[turtle][i][1] - ); - logo.noteCents[turtle][saveBlk].push( - logo.tieNotePitches[turtle][i][2] - ); - logo.noteHertz[turtle][saveBlk].push( - logo.tieNotePitches[turtle][i][3] - ); + tur.singer.notePitches[saveBlk].push(logo.tieNotePitches[turtle][i][0]); + tur.singer.noteOctaves[saveBlk].push(logo.tieNotePitches[turtle][i][1]); + tur.singer.noteCents[saveBlk].push(logo.tieNotePitches[turtle][i][2]); + tur.singer.noteHertz[saveBlk].push(logo.tieNotePitches[turtle][i][3]); } - logo.oscList[turtle][saveBlk] = logo.tieNoteExtras[ - turtle - ][1]; - logo.noteBeat[turtle][saveBlk] = logo.tieNoteExtras[ - turtle - ][2]; - logo.noteBeatValues[turtle][ - saveBlk - ] = logo.tieNoteExtras[turtle][3]; - logo.noteDrums[turtle][saveBlk] = logo.tieNoteExtras[ - turtle - ][4]; - logo.embeddedGraphics[turtle][ - saveBlk - ] = logo.tieNoteExtras[turtle][5]; + tur.singer.oscList[saveBlk] = logo.tieNoteExtras[turtle][1]; + tur.singer.noteBeat[saveBlk] = logo.tieNoteExtras[turtle][2]; + tur.singer.noteBeatValues[saveBlk] = logo.tieNoteExtras[turtle][3]; + tur.singer.noteDrums[saveBlk] = logo.tieNoteExtras[turtle][4]; + tur.singer.embeddedGraphics[saveBlk] = logo.tieNoteExtras[turtle][5]; if (logo.justCounting[turtle].length === 0) { // Remove the note from the Lilypond list. - for ( - var i = 0; - i < logo.notePitches[turtle][saveBlk].length; - i++ - ) { + for (let i = 0; i < tur.singer.notePitches[saveBlk].length; i++) { logo.notation.notationRemoveTie(turtle); } } @@ -1374,32 +1377,22 @@ class Singer { // Restore the current note. saveBlk = saveCurrentExtras[0]; - logo.notePitches[turtle][saveBlk] = []; - logo.noteOctaves[turtle][saveBlk] = []; - logo.noteCents[turtle][saveBlk] = []; - logo.noteHertz[turtle][saveBlk] = []; + tur.singer.notePitches[saveBlk] = []; + tur.singer.noteOctaves[saveBlk] = []; + tur.singer.noteCents[saveBlk] = []; + tur.singer.noteHertz[saveBlk] = []; for (let i = 0; i < saveCurrentNote.length; i++) { - logo.notePitches[turtle][saveBlk].push( - saveCurrentNote[i][0] - ); - logo.noteOctaves[turtle][saveBlk].push( - saveCurrentNote[i][1] - ); - logo.noteCents[turtle][saveBlk].push( - saveCurrentNote[i][2] - ); - logo.noteHertz[turtle][saveBlk].push( - saveCurrentNote[i][3] - ); + tur.singer.notePitches[saveBlk].push(saveCurrentNote[i][0]); + tur.singer.noteOctaves[saveBlk].push(saveCurrentNote[i][1]); + tur.singer.noteCents[saveBlk].push(saveCurrentNote[i][2]); + tur.singer.noteHertz[saveBlk].push(saveCurrentNote[i][3]); } - logo.oscList[turtle][saveBlk] = saveCurrentExtras[1]; - logo.noteBeat[turtle][saveBlk] = saveCurrentExtras[2]; - logo.noteBeatValues[turtle][saveBlk] = - saveCurrentExtras[3]; - logo.noteDrums[turtle][saveBlk] = saveCurrentExtras[4]; - logo.embeddedGraphics[turtle][saveBlk] = - saveCurrentExtras[5]; + tur.singer.oscList[saveBlk] = saveCurrentExtras[1]; + tur.singer.noteBeat[saveBlk] = saveCurrentExtras[2]; + tur.singer.noteBeatValues[saveBlk] = saveCurrentExtras[3]; + tur.singer.noteDrums[saveBlk] = saveCurrentExtras[4]; + tur.singer.embeddedGraphics[saveBlk] = saveCurrentExtras[5]; } } @@ -1408,33 +1401,27 @@ class Singer { logo.tieNotePitches[turtle] = []; logo.tieCarryOver[turtle] = noteBeatValue; - for ( - var i = 0; - i < logo.notePitches[turtle][saveBlk].length; - i++ - ) { + for (let i = 0; i < tur.singer.notePitches[saveBlk].length; i++) { logo.tieNotePitches[turtle].push([ - logo.notePitches[turtle][saveBlk][i], - logo.noteOctaves[turtle][saveBlk][i], - logo.noteCents[turtle][saveBlk][i], - logo.noteHertz[turtle][saveBlk][i] + tur.singer.notePitches[saveBlk][i], + tur.singer.noteOctaves[saveBlk][i], + tur.singer.noteCents[saveBlk][i], + tur.singer.noteHertz[saveBlk][i] ]); } logo.tieNoteExtras[turtle] = [ saveBlk, - logo.oscList[turtle][saveBlk], - logo.noteBeat[turtle][saveBlk], - logo.noteBeatValues[turtle][saveBlk], - logo.noteDrums[turtle][saveBlk], + tur.singer.oscList[saveBlk], + tur.singer.noteBeat[saveBlk], + tur.singer.noteBeatValues[saveBlk], + tur.singer.noteDrums[saveBlk], [] ]; // We play any drums in the first tied note along // with the drums in the second tied note. - logo.tieFirstDrums[turtle] = logo.noteDrums[turtle][ - saveBlk - ]; + logo.tieFirstDrums[turtle] = tur.singer.noteDrums[saveBlk]; noteBeatValue = 0; } else { carry = logo.tieCarryOver[turtle]; @@ -1524,53 +1511,41 @@ class Singer { let __playnote = () => { let thisBlk = last(logo.inNoteBlock[turtle]); - if (logo.notePitches[turtle][thisBlk] === undefined) { + if (tur.singer.notePitches[thisBlk] === undefined) { // Rest? // console.debug('no note found'); return; } // If there are multiple notes, remove the rests. - if (logo.notePitches[turtle][thisBlk].length > 1) { - while ( - logo.notePitches[turtle][thisBlk].indexOf("rest") !== -1 - ) { - logo.notePitches[turtle][thisBlk].splice( - logo.notePitches[turtle][thisBlk].indexOf("rest"), - 1 + if (tur.singer.notePitches[thisBlk].length > 1) { + while (tur.singer.notePitches[thisBlk].indexOf("rest") !== -1) { + tur.singer.notePitches[thisBlk].splice( + tur.singer.notePitches[thisBlk].indexOf("rest"), 1 ); } } // If there is no note, add a rest. - if (logo.notePitches[turtle][thisBlk].length === 0) { - logo.notePitches[turtle][ - logo.inNoteBlock[turtle][ - logo.inNoteBlock[turtle].length - 1 - ] + if (tur.singer.notePitches[thisBlk].length === 0) { + tur.singer.notePitches[ + logo.inNoteBlock[turtle][logo.inNoteBlock[turtle].length - 1] ].push("rest"); } // Stop playing notes if the stop button is pressed. if (logo.stopTurtle) return; - if ( - logo.inNoteBlock[turtle].length === - logo.whichNoteToCount[turtle] - ) { - logo.notesPlayed[turtle] = rationalSum( - logo.notesPlayed[turtle], - [1, noteValue] - ); + if (logo.inNoteBlock[turtle].length === tur.singer.whichNoteToCount) { + tur.singer.notesPlayed = rationalSum(tur.singer.notesPlayed, [1, noteValue]); } var notes = []; var drums = []; var insideChord = -1; if ( - logo.notePitches[turtle][thisBlk].length + - logo.oscList[turtle][thisBlk].length > - 1 + tur.singer.notePitches[thisBlk].length + + tur.singer.oscList[thisBlk].length > 1 ) { if ( turtle in logo.notation.notationStaging && @@ -1583,7 +1558,7 @@ class Singer { } } - logo.noteBeat[turtle][blk] = noteBeatValue; + tur.singer.noteBeat[blk] = noteBeatValue; // Do not process a note if its duration is equal // to infinity or NaN. @@ -1622,31 +1597,23 @@ class Singer { // e.g., are there any combinations of natural and // sharp or natural and flat notes? var courtesy = []; - for ( - var i = 0; - i < logo.notePitches[turtle][thisBlk].length; - i++ - ) { - var n = logo.notePitches[turtle][thisBlk][i]; + for (let i = 0; i < tur.singer.notePitches[thisBlk].length; i++) { + var n = tur.singer.notePitches[thisBlk][i]; var thisCourtesy = false; if (n.length === 1) { - for ( - let j = 0; - j < logo.notePitches[turtle][thisBlk].length; - j++ - ) { + for (let j = 0; j < tur.singer.notePitches[thisBlk].length; j++) { if ( i === j || - logo.noteOctaves[turtle][thisBlk][i] !== - logo.noteOctaves[turtle][thisBlk][j] + tur.singer.noteOctaves[thisBlk][i] !== + tur.singer.noteOctaves[thisBlk][j] ) { continue; } if ( n + "♯" === - logo.notePitches[turtle][thisBlk][j] || - n + "♭" === logo.notePitches[turtle][thisBlk][j] + tur.singer.notePitches[thisBlk][j] || + n + "♭" === tur.singer.notePitches[thisBlk][j] ) { thisCourtesy = true; } @@ -1657,43 +1624,33 @@ class Singer { } // Process pitches - if (logo.notePitches[turtle][thisBlk].length > 0) { - for ( - var i = 0; - i < logo.notePitches[turtle][thisBlk].length; - i++ - ) { - if ( - logo.notePitches[turtle][thisBlk][i] === "rest" || - forceSilence - ) { + if (tur.singer.notePitches[thisBlk].length > 0) { + for (let i = 0; i < tur.singer.notePitches[thisBlk].length; i++) { + if (tur.singer.notePitches[thisBlk][i] === "rest" || forceSilence) { note = "R"; - logo.previousNotePlayed[turtle] = - logo.lastNotePlayed[turtle]; + tur.singer.previousNotePlayed = tur.singer.lastNotePlayed; } else { var noteObj = getNote( - logo.notePitches[turtle][thisBlk][i], - logo.noteOctaves[turtle][thisBlk][i], + tur.singer.notePitches[thisBlk][i], + tur.singer.noteOctaves[thisBlk][i], 0, logo.keySignature[turtle], - logo.moveable[turtle], + tur.singer.moveable, null, logo.errorMsg, logo.synth.inTemperament ); - // If the cents for this note != 0, then - // we need to convert to frequency and add - // in the cents. - if (logo.noteCents[turtle][thisBlk][i] !== 0) { - if (logo.noteHertz[turtle][thisBlk][i] !== 0) { - var note = - logo.noteHertz[turtle][thisBlk][i]; + // If the cents for this note != 0, then we need to convert to frequency + // and add in the cents + if (tur.singer.noteCents[thisBlk][i] !== 0) { + if (tur.singer.noteHertz[thisBlk][i] !== 0) { + var note = tur.singer.noteHertz[thisBlk][i]; } else { var note = Math.floor( pitchToFrequency( noteObj[0], noteObj[1], - logo.noteCents[turtle][thisBlk][i], + tur.singer.noteCents[thisBlk][i], logo.keySignature[turtle] ) ); @@ -1734,21 +1691,15 @@ class Singer { } if (logo.justCounting[turtle].length === 0) { - if ( - logo.noteDrums[turtle][thisBlk].length > 0 - ) { + if (tur.singer.noteDrums[thisBlk].length > 0) { if (chordNotes.indexOf(note) === -1) { chordNotes.push(note); } if ( - chordDrums.indexOf( - logo.noteDrums[turtle][thisBlk][0] - ) === -1 + chordDrums.indexOf(tur.singer.noteDrums[thisBlk][0]) === -1 ) { - chordDrums.push( - logo.noteDrums[turtle][thisBlk][0] - ); + chordDrums.push(tur.singer.noteDrums[thisBlk][0]); } } else { if (courtesy[i]) { @@ -1779,10 +1730,7 @@ class Singer { } } - if ( - i === - logo.notePitches[turtle][thisBlk].length - 1 - ) { + if (i === tur.singer.notePitches[thisBlk].length - 1) { if (duration > 0) { if (carry > 0) { var d = 1 / (1 / duration - 1 / carry); @@ -1905,14 +1853,11 @@ class Singer { var len = notes[0].length; if (typeof notes[0] === "number") { var obj = frequencyToPitch(notes[0]); - logo.currentOctave[turtle] = obj[1]; + tur.singer.currentOctave = obj[1]; } else { - logo.currentOctave[turtle] = parseInt( - notes[0].slice(len - 1) - ); + tur.singer.currentOctave = parseInt(notes[0].slice(len - 1)); } - logo.currentCalculatedOctave[turtle] = - logo.currentOctave[turtle]; + tur.singer.currentCalculatedOctave = tur.singer.currentOctave; if (logo.turtles.turtleList[turtle].drum) { for (var i = 0; i < notes.length; i++) { @@ -2004,12 +1949,10 @@ class Singer { } } - if (logo.oscList[turtle][thisBlk].length > 0) { + if (tur.singer.oscList[thisBlk].length > 0) { if (notes.length > 1) { logo.errorMsg( - last( - logo.oscList[turtle][thisBlk] - ) + + last(tur.singer.oscList[thisBlk]) + ": " + _("synth cannot play chords."), blk @@ -2021,7 +1964,7 @@ class Singer { turtle, notes, beatValue, - last(logo.oscList[turtle][thisBlk]), + last(tur.singer.oscList[thisBlk]), paramsEffects, null, false @@ -2201,23 +2144,17 @@ class Singer { } } - logo.previousNotePlayed[turtle] = - logo.lastNotePlayed[turtle]; - logo.lastNotePlayed[turtle] = [notes[0], noteBeatValue]; - logo.noteStatus[turtle] = [notes, noteBeatValue]; - logo.lastPitchPlayed[turtle] = - logo.lastNotePlayed[turtle]; //For a stand-alone pitch block. + tur.singer.previousNotePlayed = tur.singer.lastNotePlayed; + tur.singer.lastNotePlayed = [notes[0], noteBeatValue]; + tur.singer.noteStatus = [notes, noteBeatValue]; + tur.singer.lastPitchPlayed = tur.singer.lastNotePlayed; // for a stand-alone pitch block } } // Process drums - if (logo.noteDrums[turtle][thisBlk].length > 0) { - for ( - var i = 0; - i < logo.noteDrums[turtle][thisBlk].length; - i++ - ) { - drums.push(logo.noteDrums[turtle][thisBlk][i]); + if (tur.singer.noteDrums[thisBlk].length > 0) { + for (let i = 0; i < tur.singer.noteDrums[thisBlk].length; i++) { + drums.push(tur.singer.noteDrums[thisBlk][i]); } for ( @@ -2234,7 +2171,7 @@ class Singer { // If it is > 0, we already counted this note // (e.g. pitch & drum combination). - if (logo.notePitches[turtle][thisBlk].length === 0) { + if (tur.singer.notePitches[thisBlk].length === 0) { var obj = rationalToFraction(1 / noteBeatValue); if (obj[0] > 0) { if (logo.justCounting[turtle].length === 0) { @@ -2352,8 +2289,8 @@ class Singer { } } - // After the note plays, clear the embedded graphics queue. - logo.embeddedGraphics[turtle][blk] = []; + // After the note plays, clear the embedded graphics queue + tur.singer.embeddedGraphics[blk] = []; // Ensure note value block unhighlights after note plays. setTimeout(function () { @@ -2383,3 +2320,8 @@ class Singer { stage.update(event); } } + +// ========= Static variables ============================================= +// Parameters used by notes +Singer.masterBPM = TARGETBPM; +Singer.defaultBPMFactor = TONEBPM / TARGETBPM; diff --git a/js/turtles.js b/js/turtles.js index 11529afadb..ad3125b374 100644 --- a/js/turtles.js +++ b/js/turtles.js @@ -476,6 +476,14 @@ Turtles.TurtlesModel = class { } return false; } + + /** + * @param {Number} i - index number + * @returns {Object} ith Turtle object + */ + ithTurtle(i) { + return this._turtleList[Number(i)]; + } }; /** diff --git a/js/widgets/meterwidget.js b/js/widgets/meterwidget.js index dc923dcb5f..0478632973 100644 --- a/js/widgets/meterwidget.js +++ b/js/widgets/meterwidget.js @@ -145,12 +145,7 @@ function MeterWidget() { this.__playDrum = function(drum) { this._logo.synth.trigger( - 0, - "C4", - this._logo.defaultBPMFactor * this._beatValue, - drum, - null, - null + 0, "C4", Singer.defaultBPMFactor * this._beatValue, drum, null, null ); }; @@ -192,12 +187,8 @@ function MeterWidget() { }; this._playBeat = function() { - let bpmFactor; - if (this._logo.bpm[0].length > 0) { - bpmFactor = TONEBPM / last(this._logo.bpm[0]); - } else { - bpmFactor = TONEBPM / this._logo._masterBPM; - } + let bpmFactor = + TONEBPM / this._logo.bpm[0].length > 0 ? last(this._logo.bpm[0]) : Singer.masterBPM; for (let i = 0; i < this._strongBeats.length; i++) { this._playWheel.navItems[i].navItem.hide(); diff --git a/js/widgets/pitchdrummatrix.js b/js/widgets/pitchdrummatrix.js index 28488735b9..24b60adac4 100644 --- a/js/widgets/pitchdrummatrix.js +++ b/js/widgets/pitchdrummatrix.js @@ -632,14 +632,9 @@ function PitchDrumMatrix() { var note = noteObj[0] + noteObj[1]; if (playNote) { - var waitTime = this._logo.defaultBPMFactor * 1000 * 0.25; + var waitTime = Singer.defaultBPMFactor * 1000 * 0.25; this._logo.synth.trigger( - 0, - note.replace(/♭/g, "b").replace(/♯/g, "#"), - 0.125, - "default", - null, - null + 0, note.replace(/♭/g, "b").replace(/♯/g, "#"), 0.125, "default", null, null ); var that = this; diff --git a/js/widgets/pitchtimematrix.js b/js/widgets/pitchtimematrix.js index bba95adf1e..3d022cc01b 100644 --- a/js/widgets/pitchtimematrix.js +++ b/js/widgets/pitchtimematrix.js @@ -4218,18 +4218,14 @@ function PitchTimeMatrix() { } if (note[0] !== "R" && pitchNotes.length > 0) { - this._playChord( - pitchNotes, - this._logo.defaultBPMFactor / noteValue - ); - // this._logo.synth.trigger(0, pitchNotes[0], this._logo.defaultBPMFactor / noteValue, this._instrumentName, null, null); + this._playChord(pitchNotes, Singer.defaultBPMFactor / noteValue); } for (var i = 0; i < synthNotes.length; i++) { this._logo.synth.trigger( 0, [Number(synthNotes[i])], - this._logo.defaultBPMFactor / noteValue, + Singer.defaultBPMFactor / noteValue, this._instrumentName, null, null @@ -4238,12 +4234,7 @@ function PitchTimeMatrix() { for (var i = 0; i < drumNotes.length; i++) { this._logo.synth.trigger( - 0, - "C2", - this._logo.defaultBPMFactor / noteValue, - drumNotes[i], - null, - null + 0, "C2", Singer.defaultBPMFactor / noteValue, drumNotes[i], null, null ); } @@ -4421,18 +4412,14 @@ function PitchTimeMatrix() { } if (note[0] !== "R" && pitchNotes.length > 0) { - that._playChord( - pitchNotes, - that._logo.defaultBPMFactor / noteValue - ); - // that._logo.synth.trigger(0, pitchNotes[0], that._logo.defaultBPMFactor / noteValue, that._instrumentName, null, null); + that._playChord(pitchNotes, Singer.defaultBPMFactor / noteValue); } for (var i = 0; i < synthNotes.length; i++) { that._logo.synth.trigger( 0, [Number(synthNotes[i])], - that._logo.defaultBPMFactor / noteValue, + Singer.defaultBPMFactor / noteValue, that._instrumentName, null, null @@ -4441,12 +4428,7 @@ function PitchTimeMatrix() { for (var i = 0; i < drumNotes.length; i++) { that._logo.synth.trigger( - 0, - ["C2"], - that._logo.defaultBPMFactor / noteValue, - drumNotes[i], - null, - null + 0, ["C2"], Singer.defaultBPMFactor / noteValue, drumNotes[i], null, null ); } } @@ -4479,7 +4461,7 @@ function PitchTimeMatrix() { ); } } - }, that._logo.defaultBPMFactor * 1000 * time + that._logo.turtleDelay); + }, Singer.defaultBPMFactor * 1000 * time + that._logo.turtleDelay); }; this._playChord = function(notes, noteValue) { @@ -4632,7 +4614,7 @@ function PitchTimeMatrix() { var cell = row.cells[colIndex]; // Using the alt attribute to store the note value - var noteValue = cell.getAttribute("alt") * this._logo.defaultBPMFactor; + var noteValue = cell.getAttribute("alt") * Singer.defaultBPMFactor; if (obj.length === 1) { if (playNote) { diff --git a/js/widgets/rhythmruler.js b/js/widgets/rhythmruler.js index 8e9659ffbf..662245146a 100644 --- a/js/widgets/rhythmruler.js +++ b/js/widgets/rhythmruler.js @@ -172,12 +172,7 @@ function RhythmRuler() { for (var i = 0; i < 4; i++) { setTimeout(function() { that._logo.synth.trigger( - 0, - "C4", - that._logo.defaultBPMFactor / 16, - drum, - null, - null + 0, "C4", Singer.defaultBPMFactor / 16, drum, null, null ); }, (interval * i) / 4); } @@ -1145,25 +1140,13 @@ function RhythmRuler() { if (that._playing) { // Play the current note. if (noteValue > 0) { - // console.debug(0 + ' C4 ' + that._logo.defaultBPMFactor / noteValue + ' ' + drum); if (foundVoice) { that._logo.synth.trigger( - 0, - "C4", - that._logo.defaultBPMFactor / noteValue, - drum, - null, - null, - false + 0, "C4", Singer.defaultBPMFactor / noteValue, drum, null, null, false ); } else if (foundDrum) { that._logo.synth.trigger( - 0, - ["C4"], - that._logo.defaultBPMFactor / noteValue, - drum, - null, - null + 0, ["C4"], Singer.defaultBPMFactor / noteValue, drum, null, null ); } } @@ -1186,11 +1169,9 @@ function RhythmRuler() { if (that._playing) { that.__loop(noteTime, rulerNo, colIndex); } - }, this._logo.defaultBPMFactor * 1000 * noteTime - - this._offsets[rulerNo]); + }, Singer.defaultBPMFactor * 1000 * noteTime - this._offsets[rulerNo]); - this._elapsedTimes[rulerNo] += - this._logo.defaultBPMFactor * 1000 * noteTime; + this._elapsedTimes[rulerNo] += Singer.defaultBPMFactor * 1000 * noteTime; }; this._save = function(selectedRuler) { @@ -2315,7 +2296,7 @@ function RhythmRuler() { console.debug("init RhythmRuler"); this._logo = logo; - this._bpmFactor = (1000 * TONEBPM) / this._logo._masterBPM; + this._bpmFactor = (1000 * TONEBPM) / Singer.masterBPM; this._playing = false; this._playingOne = false; diff --git a/js/widgets/status.js b/js/widgets/status.js index e27689d7e9..b2bf497a9f 100644 --- a/js/widgets/status.js +++ b/js/widgets/status.js @@ -221,6 +221,8 @@ function StatusMatrix() { turtle < this._logo.turtles.turtleList.length; turtle++ ) { + let tur = this._logo.turtles.ithTurtle(turtle); + if (this._logo.turtles.turtleList[turtle].inTrash) { continue; } @@ -297,8 +299,8 @@ function StatusMatrix() { break; case "pitchinhertz": var value = ""; - if (this._logo.noteStatus[turtle] != null) { - var notes = this._logo.noteStatus[turtle][0]; + if (tur.singer.noteStatus != null) { + var notes = tur.singer.noteStatus[0]; for (var j = 0; j < notes.length; j++) { if (j > 0) { value += " "; @@ -338,8 +340,8 @@ function StatusMatrix() { if (_THIS_IS_MUSIC_BLOCKS_) { var note = ""; var value = ""; - if (this._logo.noteStatus[turtle] != null) { - var notes = this._logo.noteStatus[turtle][0]; + if (tur.singer.noteStatus != null) { + var notes = tur.singer.noteStatus[0]; for (var j = 0; j < notes.length; j++) { if (typeof notes[j] === "number") { note += toFixed2(notes[j]); @@ -349,7 +351,7 @@ function StatusMatrix() { note += " "; } } - var value = this._logo.noteStatus[turtle][1]; + var value = tur.singer.noteStatus[1]; var obj = rationalToFraction(value); note += obj[1] + "/" + obj[0]; diff --git a/js/widgets/temperament.js b/js/widgets/temperament.js index 9c8ac65831..055cc91d6b 100644 --- a/js/widgets/temperament.js +++ b/js/widgets/temperament.js @@ -406,12 +406,7 @@ function TemperamentWidget() { that.temporaryRatios[i] = ratio; that._logo.resetSynth(0); that._logo.synth.trigger( - 0, - frequency, - that._logo.defaultBPMFactor * 0.01, - "electronic synth", - null, - null + 0, frequency, Singer.defaultBPMFactor * 0.01, "electronic synth", null, null ); that.createMainWheel(that.temporaryRatios); }; @@ -1374,12 +1369,7 @@ function TemperamentWidget() { var pitchNumber = this.tempRatios.length - 1; this._logo.resetSynth(0); this._logo.synth.trigger( - 0, - frequency, - this._logo.defaultBPMFactor * 0.01, - "electronic synth", - null, - null + 0, frequency, Singer.defaultBPMFactor * 0.01, "electronic synth", null, null ); this._createInnerWheel(this.tempRatios, pitchNumber); }; @@ -1837,12 +1827,7 @@ function TemperamentWidget() { } this._logo.synth.trigger( - 0, - notes, - this._logo.defaultBPMFactor * duration, - "electronic synth", - null, - null + 0, notes, Singer.defaultBPMFactor * duration, "electronic synth", null, null ); }; @@ -1913,7 +1898,7 @@ function TemperamentWidget() { that._logo.synth.trigger( 0, startPitch, - that._logo.defaultBPMFactor * duration, + Singer.defaultBPMFactor * duration, "electronic synth", null, null @@ -2041,7 +2026,7 @@ function TemperamentWidget() { if (i <= pitchNumber && i >= 0 && that._playing && p < 2) { setTimeout(function() { __playLoop(i); - }, that._logo.defaultBPMFactor * 1000 * duration); + }, Singer.defaultBPMFactor * 1000 * duration); } else { cell.innerHTML = '