Skip to content
Open
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
87 changes: 37 additions & 50 deletions js/blocks/RhythmBlockPaletteBlocks.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019 Bottersnike
// Copyright (c) 2019 Bottersnike
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the The GNU Affero General Public
Expand Down Expand Up @@ -26,6 +26,22 @@ if (_THIS_IS_TURTLE_BLOCKS_) {
}

function setupRhythmBlockPaletteBlocks(activity) {
/**
* Schedules a note to be played after a timeout.
* @param {object} activity - The activity object.
* @param {number} beat - The beat value.
* @param {string} blk - The block ID.
* @param {string} turtle - The turtle ID.
* @param {function} callback - The callback function.
* @param {number} timeout - The timeout in milliseconds.
*/
const scheduleNote = (activity, beat, blk, turtle, callback, timeout) => {
setTimeout(
() => Singer.processNote(activity, beat, false, blk, turtle, callback),
timeout
);
};

/**
* Represents a block for handling rhythms.
* @extends {FlowBlock}
Expand All @@ -47,9 +63,9 @@ function setupRhythmBlockPaletteBlocks(activity) {
name:
this.lang === "ja"
? //.TRANS: rhythm block
_("rhythm1")
_("rhythm1")
: //.TRANS: an arrangement of notes based on duration
_("rhythm"),
_("rhythm"),

/**
* @type {number}
Expand Down Expand Up @@ -113,7 +129,7 @@ function setupRhythmBlockPaletteBlocks(activity) {
if (logo.inMatrix) {
logo.phraseMaker.addColBlock(blk, arg0);

// Add individual entries for each beat to avoid extra × blocks
// Add individual entries for each beat to avoid extra × blocks
for (let i = 0; i < arg0; i++) {
logo.tupletRhythms.push(["individual", 1, noteBeatValue]);
}
Expand Down Expand Up @@ -171,21 +187,6 @@ function setupRhythmBlockPaletteBlocks(activity) {

const beatValue = bpmFactor == null ? 1 : bpmFactor / noteBeatValue;

/**
* Plays a note in the rhythm.
*
* @param {number} thisBeat - Beat value for the note.
* @param {string} blk - Block identifier.
* @param {string} turtle - Turtle identifier.
* @param {Function} callback - Callback function.
* @param {number} timeout - Timeout value.
*/
const __rhythmPlayNote = (thisBeat, blk, turtle, callback, timeout) => {
setTimeout(
() => Singer.processNote(activity, thisBeat, false, blk, turtle, callback),
timeout
);
};
let __callback;

for (let i = 0; i < arg0; i++) {
Expand All @@ -198,9 +199,11 @@ function setupRhythmBlockPaletteBlocks(activity) {
__callback = null;
}

__rhythmPlayNote(noteBeatValue, blk, turtle, __callback, i * beatValue * 1000);
scheduleNote(activity, noteBeatValue, blk, turtle, __callback, i * beatValue * 1000);
}



tur.doWait((arg0 - 1) * beatValue);
}
}
Expand Down Expand Up @@ -234,7 +237,7 @@ function setupRhythmBlockPaletteBlocks(activity) {
name:
this.lang === "ja"
? //.TRANS: translate "rhythm1" as rhythm
_("rhythm1")
_("rhythm1")
: _("rhythm"),

/**
Expand Down Expand Up @@ -287,7 +290,7 @@ function setupRhythmBlockPaletteBlocks(activity) {
this.appleNoteBlock();
} else {
// TRANS: Do not modify the following line
super("sixtyfourthNote", _("1/64 note") + " 𝅘𝅥𝅱");
super("sixtyfourthNote", _("1/64 note") + " 𝅘𝅥𝅱");
}

this.setPalette(rhythmBlockPalette, activity);
Expand Down Expand Up @@ -318,7 +321,7 @@ function setupRhythmBlockPaletteBlocks(activity) {
this.appleNoteBlock();
} else {
// TRANS: Do not modify the following line
super("thirtysecondNote", _("1/32 note") + " 𝅘𝅥𝅰");
super("thirtysecondNote", _("1/32 note") + " 𝅘𝅥𝅰");
}

// Set the palette and activity for the block
Expand Down Expand Up @@ -352,7 +355,7 @@ function setupRhythmBlockPaletteBlocks(activity) {
this.appleNoteBlock();
} else {
// TRANS: Do not modify the following line
super("sixteenthNote", _("1/16 note") + " 𝅘𝅥𝅯");
super("sixteenthNote", _("1/16 note") + " 𝅘𝅥𝅯");
}

// Set the palette and activity for the block
Expand Down Expand Up @@ -381,7 +384,7 @@ function setupRhythmBlockPaletteBlocks(activity) {
*/
constructor() {
// TRANS: Do not modify the following line
super("eighthNote", _("eighth note") + " ");
super("eighthNote", _("eighth note") + " ΓÖ¬");

// Set the palette and activity for the block
this.setPalette(rhythmBlockPalette, activity);
Expand Down Expand Up @@ -409,7 +412,7 @@ function setupRhythmBlockPaletteBlocks(activity) {
*/
constructor() {
// TRANS: Do not modify the following line
super("quarterNote", _("quarter note") + " ");
super("quarterNote", _("quarter note") + " ΓÖ⌐");

// Set the palette and activity for the block
this.setPalette(rhythmBlockPalette, activity);
Expand Down Expand Up @@ -442,7 +445,7 @@ function setupRhythmBlockPaletteBlocks(activity) {
this.appleNoteBlock();
} else {
// TRANS: Do not modify the following line
super("halfNote", _("half note") + " 𝅗𝅥");
super("halfNote", _("half note") + " 𝅗𝅥");
}

// Set the palette and activity for the block
Expand Down Expand Up @@ -476,7 +479,7 @@ function setupRhythmBlockPaletteBlocks(activity) {
this.appleNoteBlock();
} else {
// TRANS: Do not modify the following line
super("wholeNote", _("whole note") + " 𝅝");
super("wholeNote", _("whole note") + " 𝅝");
}

// Set the palette and activity for the block
Expand Down Expand Up @@ -739,23 +742,6 @@ function setupRhythmBlockPaletteBlocks(activity) {
? last(tur.singer.bpm)
: Singer.masterBPM;

let totalBeats = 0;

const __tupletPlayNote = (thisBeat, blk, turtle, callback, timeout) => {
setTimeout(
() =>
Singer.processNote(
activity,
thisBeat,
false,
blk,
turtle,
callback
),
timeout
);
};

let timeout = 0;
let beatValue;
let __callback = null;
Expand All @@ -775,12 +761,13 @@ function setupRhythmBlockPaletteBlocks(activity) {
__callback = null;
}

__tupletPlayNote(thisBeat, blk, turtle, __callback, timeout);
scheduleNote(activity, thisBeat, blk, turtle, __callback, timeout);

timeout += beatValue * 1000;
totalBeats += beatValue;
}


tur.doWait(totalBeats - beatValue);
}
};
Expand Down Expand Up @@ -895,10 +882,10 @@ function setupRhythmBlockPaletteBlocks(activity) {
// Set the help string for the block
this.setHelpString([
_("Tuplets are a collection of notes that get scaled to a specific duration.") +
" " +
_(
"Using tuplets makes it easy to create groups of notes that are not based on a power of 2."
),
" " +
_(
"Using tuplets makes it easy to create groups of notes that are not based on a power of 2."
),
"documentation",
null,
"matrix"
Expand Down
Loading