Skip to content

Commit 24b6140

Browse files
authored
FIX: Timbre (effects) (#4623)
* bug fixes * coment * singer fix * max value 1000 for base frequency
1 parent 86bec6b commit 24b6140

File tree

2 files changed

+30
-22
lines changed

2 files changed

+30
-22
lines changed

js/blocks/ToneBlocks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ function setupToneBlocks(activity) {
589589
instrumentsEffects[turtle][logo.timbre.instrumentName]["rate"] = args[0];
590590
logo.timbre.phaserParams.push(last(tur.singer.octaves));
591591
instrumentsEffects[turtle][logo.timbre.instrumentName]["octaves"] = args[1];
592-
logo.timbre.phaserParams.push(last(tur.signer.baseFrequency));
592+
logo.timbre.phaserParams.push(last(tur.singer.baseFrequency));
593593
instrumentsEffects[turtle][logo.timbre.instrumentName]["baseFrequency"] = args[2];
594594
}
595595

js/widgets/timbre.js

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2134,12 +2134,15 @@ class TimbreWidget {
21342134
_effects = () => {
21352135
let blockValue = 0;
21362136

2137-
this.timbreTableDiv.style.display = "inline";
2138-
this.timbreTableDiv.style.visibility = "visible";
2139-
this.timbreTableDiv.style.border = "0px";
2140-
this.timbreTableDiv.style.overflow = "auto";
2141-
this.timbreTableDiv.style.backgroundColor = "white";
2142-
this.timbreTableDiv.style.height = "300px";
2137+
Object.assign(this.timbreTableDiv.style, {
2138+
display: "inline",
2139+
visibility: "visible",
2140+
border: "0px",
2141+
overflow: "auto",
2142+
backgroundColor: "white",
2143+
height: "300px"
2144+
});
2145+
21432146
this.timbreTableDiv.innerHTML = '<div id="timbreTable"></div>';
21442147

21452148
const env = docById("timbreTable");
@@ -2158,14 +2161,13 @@ class TimbreWidget {
21582161
env.append(envAppend);
21592162

21602163
const mainDiv = docById("effect0");
2161-
mainDiv.innerHTML =
2162-
`<p>
2163-
<input type="radio" name="effectsName" value="Tremolo"/>${_("tremolo")}<br>
2164-
<input type="radio" name="effectsName" value="Vibrato"/>${_("vibrato")}<br>
2165-
<input type="radio" name="effectsName" value="Chorus"/>${_("chorus")}<br>
2166-
<input type="radio" name="effectsName" value="Phaser"/>${_("phaser")}<br>
2167-
<input type="radio" name="effectsName" value="Distortion"/>${_("distortion")}<br>
2168-
</p>`;
2164+
const effects = ["Tremolo", "Vibrato", "Chorus", "Phaser", "Distortion"];
2165+
const effectsHtml = effects
2166+
.map(effect =>
2167+
`<input type="radio" name="effectsName" value="${effect}"/>${_(effect.toLowerCase())}<br>`
2168+
)
2169+
.join("");
2170+
mainDiv.innerHTML = `<p>${effectsHtml}</p>`;
21692171

21702172
const subDiv = docById("effect1");
21712173
const effectsName = docByName("effectsName");
@@ -2184,7 +2186,7 @@ class TimbreWidget {
21842186

21852187
instrumentsEffects[0][this.instrumentName]["tremoloActive"] = true;
21862188

2187-
for (let j = 0; j < 2; i++) {
2189+
for (let j = 0; j < 2; j++) {
21882190
subHtmlElements +=
21892191
'<div id="wrapperFx' +
21902192
j +
@@ -2257,7 +2259,7 @@ class TimbreWidget {
22572259
parseFloat(elem.value) / 100;
22582260
}
22592261

2260-
this._update(blockValue, elem.value, Number(m));
2262+
this._update(blockValue, parseFloat(elem.value), Number(m));
22612263
this._playNote("G4", 1 / 8);
22622264
});
22632265
}
@@ -2465,6 +2467,12 @@ class TimbreWidget {
24652467

24662468
instrumentsEffects[0][this.instrumentName]["phaserActive"] = true;
24672469

2470+
// Default values
2471+
instrumentsEffects[0][this.instrumentName]["rate"] = 5;
2472+
instrumentsEffects[0][this.instrumentName]["octaves"] = 3;
2473+
instrumentsEffects[0][this.instrumentName]["baseFrequency"] = 100;
2474+
2475+
24682476
for (let i = 0; i < 3; i++) {
24692477
subHtmlElements +=
24702478
'<div id="wrapperFx' +
@@ -2473,7 +2481,7 @@ class TimbreWidget {
24732481
i +
24742482
'"><span></span></div><div class="insideDivEffects"><input type="range" id="myRangeFx' +
24752483
i +
2476-
'" class="sliders" style="margin-top:20px" value="2"><span id="myspanFx' +
2484+
'" class="sliders" style="margin-top:20px" min="0" max="1000" value="2"><span id="myspanFx' +
24772485
i +
24782486
'" class="rangeslidervalue">2</span></div></div>';
24792487
}
@@ -2486,8 +2494,8 @@ class TimbreWidget {
24862494
docById("myRangeFx1").value = 3;
24872495
docById("myspanFx1").textContent = "3";
24882496
docById("sFx2").textContent = _("base frequency");
2489-
docById("myRangeFx2").value = 350;
2490-
docById("myspanFx2").textContent = "350";
2497+
docById("myRangeFx2").value = 1000;
2498+
docById("myspanFx2").textContent = "1000";
24912499

24922500
if (this.phaserEffect.length !== 0) {
24932501
blockValue = this.phaserEffect.length - 1;
@@ -2507,7 +2515,7 @@ class TimbreWidget {
25072515
[0, ["phaser", {}], 0, 0, [null, 1, 2, 3, null, 4]],
25082516
[1, ["number", { value: 5 }], 0, 0, [0]],
25092517
[2, ["number", { value: 3 }], 0, 0, [0]],
2510-
[3, ["number", { value: 350 }], 0, 0, [0]],
2518+
[3, ["number", { value: 100 }], 0, 0, [0]],
25112519
[4, "hidden", 0, 0, [0, null]]
25122520
];
25132521
this.activity.blocks.loadNewBlocks(PHASEROBJ);
@@ -2548,7 +2556,7 @@ class TimbreWidget {
25482556
] = parseFloat(elem.value);
25492557
}
25502558

2551-
this._update(blockValue, elem.value, Number(m));
2559+
this._update(blockValue, parseFloat(elem.value), Number(m));
25522560
this._playNote("G4", 1 / 8);
25532561
});
25542562
}

0 commit comments

Comments
 (0)