From 8d3db900d4648abfec96fe512f594a63b77e9f1d Mon Sep 17 00:00:00 2001 From: Ajeet Pratap Singh Date: Tue, 2 Jan 2024 22:25:39 +0530 Subject: [PATCH] Fix duplicate pitches in phrase maker (#3507) --- js/widgets/phrasemaker.js | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/js/widgets/phrasemaker.js b/js/widgets/phrasemaker.js index a85b5ff192..6c8d41fc0b 100644 --- a/js/widgets/phrasemaker.js +++ b/js/widgets/phrasemaker.js @@ -2128,7 +2128,8 @@ class PhraseMaker { } this._markedColsInRow.push(thisRow); } - + // create a 'Set' object that contains only unique values + const uniqueFrequencies = new Set(); const sortableList = []; let drumName; // Make a list to sort, skipping drums and graphics. @@ -2148,26 +2149,21 @@ class PhraseMaker { } // We want to sort based on frequency, so we convert all notes to frequency. - if (MATRIXSYNTHS.indexOf(this.rowLabels[i]) !== -1) { - // Deprecated - sortableList.push([ - this.rowArgs[i], - this.rowLabels[i], - this.rowArgs[i], - i, - this._noteStored[i] - ]); - } else { + const frequencyKey = noteToFrequency( + this.rowLabels[i] + this.rowArgs[i], + this.activity.turtles.ithTurtle(0).singer.keySignature + ); + + if (!uniqueFrequencies.has(frequencyKey)) { sortableList.push([ - noteToFrequency( - this.rowLabels[i] + this.rowArgs[i], - this.activity.turtles.ithTurtle(0).singer.keySignature - ), + frequencyKey, this.rowLabels[i], this.rowArgs[i], i, this._noteStored[i] ]); + + uniqueFrequencies.add(frequencyKey); } }