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

pitchstairecase Bug Fix: Sound keeps playing even after closing the widget. #2837

Merged
merged 6 commits into from
Feb 15, 2021
Merged
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
18 changes: 13 additions & 5 deletions js/widgets/pitchstaircase.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ class PitchStaircase {
static ICONSIZE = 32;
static DEFAULTFREQUENCY = 220.0;

/**
* @constructor
*/
constructor() {
this.Stairs = [];
this.stairPitchBlocks = [];

this._stepTables = [];
this._musicRatio1 = null;
this._musicRatio2 = null;
Expand Down Expand Up @@ -119,7 +121,7 @@ class PitchStaircase {
);
playCell.className = "headcol"; // This cell is fixed horizontally.
playCell.setAttribute("id", i);

playCell.style.cursor = "pointer";
const stepCell = stepTableRow.insertCell();
stepCell.setAttribute("id", frequency);
stepCell.style.width =
Expand Down Expand Up @@ -172,7 +174,6 @@ class PitchStaircase {
*/
_undo() {
if (this._history.length === 0) {
// console.debug("nothing for undo to undo");
return false;
}

Expand Down Expand Up @@ -224,7 +225,6 @@ class PitchStaircase {
}

if (n === this.Stairs.length) {
// console.debug("DID NOT FIND A MATCH " + frequency);
return;
}

Expand Down Expand Up @@ -351,6 +351,8 @@ class PitchStaircase {
* @returns {void}
*/
_playNext(index, next) {
if (this.closed) return;

if (index === this.Stairs.length) {
setTimeout(() => {
for (let i = 0; i < this.Stairs.length; i++) {
Expand Down Expand Up @@ -436,7 +438,6 @@ class PitchStaircase {
let previousBlock = 0;

for (let i = 0; i < this.Stairs.length; i++) {
// console.debug(this.Stairs[i][5] + "x" + this.Stairs[i][4] + "/" + this.Stairs[i][3]);
const frequency = this.Stairs[i][2];
const pitch = frequencyToPitch(frequency);

Expand Down Expand Up @@ -608,6 +609,13 @@ class PitchStaircase {
this.widgetWindow = widgetWindow;
widgetWindow.clear();
widgetWindow.show();
widgetWindow.onclose = () => {
logo.synth.setMasterVolume(0);
this.closed = true;
widgetWindow.destroy();
};

this.closed = false;

widgetWindow.addButton(
"play-chord.svg",
Expand Down