Skip to content
Open
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
68 changes: 43 additions & 25 deletions js/widgets/tempo.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@

/*
global
_, getDrumSynthName
_, getDrumSynthName, Singer, TONEBPM
*/

/*
Global locations
js/utils/musicutils.js
getDrumSynthName
js/turtle-singer.js
Singer
js/utils/utils.js
_
js/logoconstants.js
TONEBPM
*/

/* exported Tempo */
Expand Down Expand Up @@ -103,19 +107,15 @@ class Tempo {
};

this._save_lock = false;
widgetWindow.addButton(
"export-chunk.svg",
Tempo.ICONSIZE,
_("Save tempo"),
""
).onclick = () => {
// Debounce button
if (!this._get_save_lock()) {
this._save_lock = true;
this._saveTempo();
setTimeout(() => (this._save_lock = false), 1000);
}
};
widgetWindow.addButton("export-chunk.svg", Tempo.ICONSIZE, _("Save tempo"), "").onclick =
() => {
// Debounce button
if (!this._get_save_lock()) {
this._save_lock = true;
this._saveTempo();
setTimeout(() => (this._save_lock = false), 1000);
}
};

this.bodyTable = document.createElement("table");
this.widgetWindow.getWidgetBody().appendChild(this.bodyTable);
Expand All @@ -139,13 +139,19 @@ class Tempo {
Tempo.ICONSIZE,
_("speed up"),
r1.insertCell()
).onclick = (i => () => this.speedUp(i))(i);
).onclick = (
i => () =>
this.speedUp(i)
)(i);
widgetWindow.addButton(
"down.svg",
Tempo.ICONSIZE,
_("slow down"),
r2.insertCell()
).onclick = (i => () => this.slowDown(i))(i);
).onclick = (
i => () =>
this.slowDown(i)
)(i);

this.BPMInputs[i] = widgetWindow.addInputButton(this.BPMs[i], r3.insertCell());
this.tempoCanvases[i] = document.createElement("canvas");
Expand Down Expand Up @@ -201,15 +207,27 @@ class Tempo {
_updateBPM(i) {
this._intervals[i] = (60 / this.BPMs[i]) * 1000;

let blockNumber;
if (this.BPMBlocks[i] != null) {
blockNumber = this.activity.blocks.blockList[this.BPMBlocks[i]].connections[1];
if (blockNumber != null) {
this.activity.blocks.blockList[blockNumber].value = parseFloat(this.BPMs[i]);
this.activity.blocks.blockList[blockNumber].text.text = this.BPMs[i];
this.activity.blocks.blockList[blockNumber].updateCache();
this.activity.refreshCanvas();
this.activity.saveLocally();
if (this.BPMBlocks[i] == null) return;

const bpmBlock = this.activity.blocks.blockList[this.BPMBlocks[i]];
const blockNumber = bpmBlock.connections[1];
if (blockNumber != null) {
this.activity.blocks.blockList[blockNumber].value = parseFloat(this.BPMs[i]);
this.activity.blocks.blockList[blockNumber].text.text = this.BPMs[i];
this.activity.blocks.blockList[blockNumber].updateCache();
this.activity.refreshCanvas();
this.activity.saveLocally();
}

const bpmValue = parseFloat(this.BPMs[i]);
if (bpmBlock.name === "setmasterbpm2" || bpmBlock.name === "setmasterbpm") {
Singer.masterBPM = bpmValue;
Singer.defaultBPMFactor = TONEBPM / bpmValue;
} else if (bpmBlock.name === "setbpm3" || bpmBlock.name === "setbpm2") {
for (const tur of this.activity.turtles.turtleList) {
if (tur.singer.bpm.length > 0) {
tur.singer.bpm[tur.singer.bpm.length - 1] = bpmValue;
}
}
}
}
Expand Down
Loading
Loading