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 1 commit
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
6 changes: 5 additions & 1 deletion js/turtleactions/DictActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
* Action methods are in camelCase.
*/

/*exported setupDictActions*/

/* global Turtle, _, turtles, Singer, getNote, logo, INVALIDPITCH, blk, pitchToNumber, getTargetTurtle*/

/**
* Sets up all the methods related to different actions for each block in Dictionary palette.
*
Expand Down Expand Up @@ -81,7 +85,7 @@ function setupDictActions() {
logo.synth.inTemperament
);
} else {
console.debug("Cannot find a note for mouse " + target);
// console.debug("Cannot find a note for mouse " + target);
logo.errorMsg(INVALIDPITCH, blk);
obj = ["G", 4];
}
Expand Down
10 changes: 8 additions & 2 deletions js/turtleactions/DrumActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
* Action methods are in camelCase.
*/

/*exported setupDrumActions*/

/* global DEFAULTDRUM, _, DRUMNAMES, Singer, last, logo, DEFAULTVOLUME, blocks,
MusicBlocks, Mouse, NOISENAMES
*/

/**
* Sets up all the methods related to different actions for each block in Drum palette.
*
Expand Down Expand Up @@ -121,7 +127,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 +170,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
10 changes: 8 additions & 2 deletions js/turtleactions/IntervalsActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
* Action methods are in camelCase.
*/

/*exported setupIntervalsActions*/

/* global MUSICALMODES, _, getNote, Singer, getModeLength, logo, NOINPUTERRORMSG, blocks,
MusicBlocks, Mouse, args
ricknjacky marked this conversation as resolved.
Show resolved Hide resolved
*/

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

const __listener = event => {
const __listener = () => {
MUSICALMODES[modeName] = [];
if (tur.singer.defineMode.indexOf(0) === -1) {
tur.singer.defineMode.push(0);
Expand Down Expand Up @@ -232,7 +238,7 @@ function setupIntervalsActions() {
mouse.MB.listeners.push(listenerName);
}

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

logo.setTurtleListener(turtle, listenerName, __listener);
}
Expand Down
21 changes: 14 additions & 7 deletions js/turtleactions/MeterActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
* MA 02110-1335 USA.
*/

/*exported setupMeterActions*/

/* global rationalToFraction, _, blk, Singer, _blk, logo, TONEBPM, blocks,
ricknjacky marked this conversation as resolved.
Show resolved Hide resolved
MusicBlocks, Mouse, Queue, turtles, last
*/

/**
* Sets up all the methods related to different actions for each block in Meter palette.
*
Expand Down Expand Up @@ -145,7 +151,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 +178,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 +231,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 +276,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 +314,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 +379,7 @@ function setupMeterActions() {
}

static getBeatFactor(turtle) {
// eslint-disable-next-line max-len
ricknjacky marked this conversation as resolved.
Show resolved Hide resolved
return Singer.RhythmActions.getNoteValue(turtle) * logo.turtles.ithTurtle(turtle).singer.noteValuePerBeat;
}

Expand Down
10 changes: 7 additions & 3 deletions js/turtleactions/OrnamentActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
* MA 02110-1335 USA.
*/

/*exported setupOrnamentActions*/

/* global Singer, logo, blocks, MusicBlocks, Mouse */

/**
* Sets up all the methods related to different actions for each block in Ornament palette.
*
Expand Down Expand Up @@ -45,7 +49,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 +80,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 +115,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
16 changes: 10 additions & 6 deletions js/turtleactions/RhythmActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
* MA 02110-1335 USA.
*/

/*exported setupRhythmActions*/

/* global Singer, logo, blocks, MusicBlocks, Mouse, last, _, TONEBPM, turtles */

/**
* Sets up all the methods related to different actions for each block in Rhythm palette.
*
Expand Down Expand Up @@ -118,7 +122,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 +228,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 +266,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 +365,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 +402,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 +440,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
18 changes: 11 additions & 7 deletions js/turtleactions/ToneActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
* MA 02110-1335 USA.
*/

/*exported setupToneActions*/

/* global Singer, logo, blocks, MusicBlocks, Mouse, last, _, VOICENAMES, instrumentsEffects, NOINPUTERRORMSG, arg */
ricknjacky marked this conversation as resolved.
Show resolved Hide resolved

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

const __listener = event => {
const __listener = () => {
tur.inSetTimbre = false;
tur.singer.instrumentNames.pop();
};
Expand Down Expand Up @@ -115,7 +119,7 @@ function setupToneActions() {
mouse.MB.listeners.push(listenerName);
}

const __listener = event => {
const __listener = () => {
tur.singer.vibratoIntensity.pop();
tur.singer.vibratoRate.pop();
};
Expand Down Expand Up @@ -165,7 +169,7 @@ function setupToneActions() {
mouse.MB.listeners.push(listenerName);
}

const __listener = event => {
const __listener = () => {
tur.singer.chorusRate.pop();
tur.singer.delayTime.pop();
tur.singer.chorusDepth.pop();
Expand Down Expand Up @@ -199,7 +203,7 @@ function setupToneActions() {
mouse.MB.listeners.push(listenerName);
}

const __listener = event => {
const __listener = () => {
tur.singer.rate.pop();
tur.singer.octaves.pop();
tur.singer.baseFrequency.pop();
Expand Down Expand Up @@ -239,7 +243,7 @@ function setupToneActions() {
mouse.MB.listeners.push(listenerName);
}

const __listener = event => {
const __listener = () => {
tur.singer.tremoloFrequency.pop();
tur.singer.tremoloDepth.pop();
};
Expand Down Expand Up @@ -276,7 +280,7 @@ function setupToneActions() {
}

logo.setTurtleListener(
turtle, listenerName, event => tur.singer.distortionAmount.pop()
turtle, listenerName, () => tur.singer.distortionAmount.pop()
);
}

Expand Down Expand Up @@ -317,7 +321,7 @@ function setupToneActions() {
mouse.MB.listeners.push(listenerName);
}

const __listener = event => {
const __listener = () => {
tur.singer.inHarmonic.pop();
tur.singer.partials.pop();
logo.notation.notationEndHarmonics(turtle);
Expand Down
9 changes: 7 additions & 2 deletions js/turtleactions/VolumeActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
* MA 02110-1335 USA.
*/

/*exported setupVolumeActions*/

/* global Singer, logo, blocks, MusicBlocks, Mouse, last, _, VOICENAMES, Tone,
_THIS_IS_MUSIC_BLOCKS_, instruments, DRUMNAMES, DEFAULTVOLUME*/

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

const __listener = event => {
const __listener = () => {
if (tur.singer.justCounting.length === 0) {
logo.notation.notationEndCrescendo(turtle, last(tur.singer.crescendoDelta));
}
Expand Down Expand Up @@ -115,7 +120,7 @@ function setupVolumeActions() {
mouse.MB.listeners.push(listenerName);
}

const __listener = event => {
const __listener = () => {
for (const synth in tur.singer.synthVolume) {
tur.singer.synthVolume[synth].pop();
Singer.setSynthVolume(logo, turtle, synth, last(tur.singer.synthVolume[synth]));
Expand Down