Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

js/turtleactions: refactor, lint & prettify #2813

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions js/turtleactions/DrumActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,29 @@
*
* Utility methods are in PascalCase.
* Action methods are in camelCase.
*/

/* global Singer,DEFAULTDRUM,DRUMNAMES,last,DEFAULTVOLUME,logo,blocks,MusicBlocks,Mouse,NOISENAMES,_ */
/*
Global Locations
js/utils/utils.js
_
js/turtle-singer.js
Singer
js/activity.js
logo
js/utils/synthutils.js
DRUMNAMES,NOISENAMES
js/utils/musicutils.js
DEFAULTDRUM
js/logo.js/
DEFAULTVOLUME
js/blocks.js
blocks
js/js-export/export.js
MusicBlocks, Mouse
*/
/* exported setupDrumActions */

/**
* Sets up all the methods related to different actions for each block in Drum palette.
Expand Down Expand Up @@ -121,7 +143,7 @@ function setupDrumActions() {
mouse.MB.listeners.push(listenerName);
}

const __listener = event => {
const __listener = () => {
tur.singer.drumStyle.pop();
tur.singer.pitchDrumTable = {};
};
Expand Down Expand Up @@ -164,7 +186,7 @@ function setupDrumActions() {
mouse.MB.listeners.push(listenerName);
}

const __listener = event => tur.singer.drumStyle.pop();
const __listener = () => tur.singer.drumStyle.pop();

logo.setTurtleListener(turtle, listenerName, __listener);
if (logo.inRhythmRuler) {
Expand Down
2 changes: 1 addition & 1 deletion js/turtleactions/IntervalsActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,4 @@ function setupIntervalsActions() {
}
}
};
}
}
45 changes: 34 additions & 11 deletions js/turtleactions/MeterActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,31 @@
* You should have received a copy of the GNU Affero General Public License along with this
* library; if not, write to the Free Software Foundation, 51 Franklin Street, Suite 500 Boston,
* MA 02110-1335 USA.
*/

/* global _,logo,Singer,rationalToFraction,TONEBPM,Queue,turtles,last,MusicBlocks,blocks,Mouse */
/*
Global Locations
js/utils/utils.js
_,rationalToFraction
js/turtle-singer.js
Singer
js/activity.js
logo
js/utils/synthutils.js
DRUMNAMES,NOISENAMES
js/utils/musicutils.js
DEFAULTDRUM
js/logo.js
DEFAULTVOLUME,TONEBPM
js/blocks.js
blocks
js/activity.js
turtles
js/js-export/export.js
MusicBlocks, Mouse
*/
/* exported setupMeterActions */

/**
* Sets up all the methods related to different actions for each block in Meter palette.
Expand Down Expand Up @@ -77,8 +101,7 @@ function setupMeterActions() {
" " +
_("beats per minute must be greater than") +
" " +
target,
blk
target
);
_bpm = 30;
} else if (_bpm > 1000) {
Expand All @@ -93,8 +116,7 @@ function setupMeterActions() {
" " +
_("beats per minute is") +
" " +
target,
_blk
target
);
_bpm = 1000;
}
Expand Down Expand Up @@ -145,7 +167,7 @@ function setupMeterActions() {
static onEveryNoteDo(action, isflow, receivedArg, turtle, blk) {
const tur = logo.turtles.ithTurtle(turtle);

const __listener = event => {
const __listener = () => {
if (tur.running) {
const queueBlock = new Queue(logo.actions[action], 1, blk);
tur.parentFlowQueue.push(blk);
Expand All @@ -172,19 +194,19 @@ function setupMeterActions() {
static onEveryBeatDo(action, isflow, receivedArg, turtle, blk) {
// Set up a listener for every beat for this turtle.
const orgTurtle = turtle;
console.debug("used from: ", orgTurtle);
// console.debug("used from: ", orgTurtle);
if (!turtles.turtleList[orgTurtle].companionTurtle){
turtle = logo.turtles.turtleList.length;
turtles.turtleList[orgTurtle].companionTurtle = turtle;
logo.turtles.addTurtle(logo.blocks.blockList[blk], {});
logo.prepSynths();
console.debug("beat Turtle: ", turtle);
// console.debug("beat Turtle: ", turtle);
}
turtle = turtles.turtleList[orgTurtle].companionTurtle;

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

const __listener = event => {
const __listener = () => {
if (tur.running) {
const queueBlock = new Queue(logo.actions[action], 1, blk);
tur.parentFlowQueue.push(blk);
Expand Down Expand Up @@ -225,7 +247,7 @@ function setupMeterActions() {
const tur = logo.turtles.ithTurtle(turtle);

// Set up a listener for this turtle/onbeat combo.
const __listener = event => {
const __listener = () => {
if (tur.running) {
const queueBlock = new Queue(logo.actions[action], 1, blk);
tur.parentFlowQueue.push(blk);
Expand Down Expand Up @@ -270,7 +292,7 @@ function setupMeterActions() {
const tur = logo.turtles.ithTurtle(turtle);

// Set up a listener for this turtle/offbeat combo
const __listener = event => {
const __listener = () => {
if (tur.running) {
const queueBlock = new Queue(logo.actions[action], 1, blk);
tur.parentFlowQueue.push(blk);
Expand Down Expand Up @@ -308,7 +330,7 @@ function setupMeterActions() {
mouse.MB.listeners.push(listenerName);
}

const __listener = event => {
const __listener = () => {
if (tur.singer.drift > 0)
tur.singer.drift--;
};
Expand Down Expand Up @@ -373,6 +395,7 @@ function setupMeterActions() {
}

static getBeatFactor(turtle) {

return Singer.RhythmActions.getNoteValue(turtle) * logo.turtles.ithTurtle(turtle).singer.noteValuePerBeat;
}

Expand Down
18 changes: 15 additions & 3 deletions js/turtleactions/OrnamentActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,19 @@
* You should have received a copy of the GNU Affero General Public License along with this
* library; if not, write to the Free Software Foundation, 51 Franklin Street, Suite 500 Boston,
* MA 02110-1335 USA.
*/

/* global Singer,logo,MusicBlocks,blocks,Mouse */
/*
Global Locations
js/turtle-singer.js
Singer
js/activity.js
logo
js/js-export/export.js
MusicBlocks, Mouse
*/
/* exported setupOrnamentActions */

/**
* Sets up all the methods related to different actions for each block in Ornament palette.
Expand Down Expand Up @@ -45,7 +57,7 @@ function setupOrnamentActions() {
mouse.MB.listeners.push(listenerName);
}

const __listener = event => tur.singer.staccato.pop();
const __listener = () => tur.singer.staccato.pop();

logo.setTurtleListener(turtle, listenerName, __listener);
}
Expand Down Expand Up @@ -76,7 +88,7 @@ function setupOrnamentActions() {
mouse.MB.listeners.push(listenerName);
}

const __listener = event => {
const __listener = () => {
tur.singer.staccato.pop();
if (tur.singer.justCounting.length === 0) {
logo.notation.notationEndSlur(turtle);
Expand Down Expand Up @@ -111,7 +123,7 @@ function setupOrnamentActions() {
mouse.MB.listeners.push(listenerName);
}

const __listener = event => {
const __listener = () => {
tur.singer.inNeighbor.pop();
tur.singer.neighborStepPitch.pop();
tur.singer.neighborNoteValue.pop();
Expand Down
32 changes: 26 additions & 6 deletions js/turtleactions/RhythmActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,27 @@
* You should have received a copy of the GNU Affero General Public License along with this
* library; if not, write to the Free Software Foundation, 51 Franklin Street, Suite 500 Boston,
* MA 02110-1335 USA.
*/

/* global _,Singer,logo,MusicBlocks,blocks,Mouse,last,turtles,TONEBPM */
/*
Global Locations
js/utils/utils.js
_
js/turtle-singer.js
Singer
js/activity.js
logo
js/activity.js
turtles
js/logo.js
TONEBPM
js/blocks.js
blocks
js/js-export/export.js
MusicBlocks, Mouse
*/
/* exported setupRhythmActions */

/**
* Sets up all the methods related to different actions for each block in Rhythm palette.
Expand Down Expand Up @@ -118,7 +138,7 @@ function setupRhythmActions() {
mouse.MB.listeners.push(listenerName);
}

const __listener = event => {
const __listener = () => {
if (tur.singer.multipleVoices) {
logo.notation.notationVoices(turtle, tur.singer.inNoteBlock.length);
}
Expand Down Expand Up @@ -224,7 +244,7 @@ function setupRhythmActions() {
mouse.MB.listeners.push(listenerName);
}

const __listener = event => {
const __listener = () => {
const currentDotFactor = 2 - 1 / Math.pow(2, tur.singer.dotCount);
tur.singer.beatFactor *= currentDotFactor;
tur.singer.dotCount -= value >= 0 ? value : 1 / value;
Expand Down Expand Up @@ -262,7 +282,7 @@ function setupRhythmActions() {
mouse.MB.listeners.push(listenerName);
}

const __listener = event => {
const __listener = () => {
tur.singer.tie = false;

// If tieCarryOver > 0, we have one more note to play
Expand Down Expand Up @@ -361,7 +381,7 @@ function setupRhythmActions() {
mouse.MB.listeners.push(listenerName);
}

const __listener = event => tur.singer.beatFactor *= factor;
const __listener = () => tur.singer.beatFactor *= factor;

logo.setTurtleListener(turtle, listenerName, __listener);
}
Expand Down Expand Up @@ -398,7 +418,7 @@ function setupRhythmActions() {
mouse.MB.listeners.push(listenerName);
}

const __listener = event => {
const __listener = () => {
if (!tur.singer.suppressOutput) {
tur.singer.swingTarget.pop();
tur.singer.swing.pop();
Expand Down Expand Up @@ -436,7 +456,7 @@ function setupRhythmActions() {
) {
value = tur.singer.noteBeat[last(tur.singer.inNoteBlock)];
} else {
console.debug("Cannot find a note for turtle " + turtle);
// console.debug("Cannot find a note for turtle " + turtle);
value = 0;
}

Expand Down
Loading