Skip to content

Commit

Permalink
FIXED: Fixed slowdown caused when the app receives a flood of midi si…
Browse files Browse the repository at this point in the history
…gnals.

When a flood of midi signals (e.g., hard note-off) was received the app was slowing down. Problem occurred with Musescore.
  • Loading branch information
IndustrieCreative committed Jul 7, 2022
1 parent f5baee6 commit d9f2061
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 40 deletions.
74 changes: 40 additions & 34 deletions assets/js/dhc.js
Original file line number Diff line number Diff line change
Expand Up @@ -867,38 +867,41 @@ HUM.DHC = class {
// Search the FT number in the playQueue array
let position = this.playQueue.ft.findIndex(qt => qt.xtNum === dhcMsg.xtNum);
// If the FTn exist
if (position > -1) {
if (position !== -1) {
// Remove the FTn from the playQueue array
this.playQueue.ft.splice(position, 1);
// If the FTn does not exist
} else {
if (dhcMsg.panic === false) {
console.log("STRANGE: there is NOT a FT pressed key #:", dhcMsg.xtNum);
}
}

this.sendMessageToApps(dhcMsg);

// If there are other notes, read and play the next note on the playQueue array
if (this.playQueue.ft.length > 0) {
// Read the next FT
let nextIndex = this.playQueue.ft.length - 1;
let nextTone = this.playQueue.ft[nextIndex];
// If the next tone is NOT the active one
if (nextTone.xtNum !== this.settings.ht.curr_ft) {

// Recalculate the ht table passing the frequency (Hz)
this.createHTtable(this.tables.ft[nextTone.xtNum].hz);
// Store the current FT into the global slot for future HT table re-computations and UI monitor updates
this.settings.ht.curr_ft = nextTone.xtNum;

this.sendMessageToApps(nextTone);

// Update the UI
this.dhcMonitor("ft", nextTone.xtNum);
this.sendMessageToApps(dhcMsg);

// If there are other notes, read and play the next note on the playQueue array
if (this.playQueue.ft.length > 0) {
// Read the next FT
let nextIndex = this.playQueue.ft.length - 1;
let nextTone = this.playQueue.ft[nextIndex];
// If the next tone is NOT the active one
if (nextTone.xtNum !== this.settings.ht.curr_ft) {
// Recalculate the ht table passing the frequency (Hz)
this.createHTtable(this.tables.ft[nextTone.xtNum].hz);
// Store the current FT into the global slot for future HT table re-computations and UI monitor updates
this.settings.ht.curr_ft = nextTone.xtNum;
this.sendMessageToApps(nextTone);

// Update the UI
this.dhcMonitor("ft", nextTone.xtNum);

}
}

// If the FTn does not exist
}
// else {
// // if (dhcMsg.panic === false) {
// // console.log("STRANGE: there is NOT a FT pressed key #:", dhcMsg.xtNum);
// // }
// }

}

/**
Expand Down Expand Up @@ -981,27 +984,30 @@ HUM.DHC = class {
// Search the HT number in the queue array
let position = this.playQueue.ht.findIndex(qt => qt.xtNum === dhcMsg.xtNum);
// If the HTn exist
if (position > -1) {
if (position !== -1) {
// Remove the HTn from the queue array
this.playQueue.ht.splice(position, 1);
// Update the curr_ht
if (this.playQueue.ht.length > 0) {
this.settings.ht.curr_ht = this.playQueue.ht[this.playQueue.ht.length-1].xtNum;
}

this.sendMessageToApps(dhcMsg);

// If the FTn does not exist
} else {
if (dhcMsg.panic === false) {
console.log("STRANGE: there is NOT a HT pressed key #:", dhcMsg.xtNum);
}
}
}
// else {
// // if (dhcMsg.panic === false) {
// // console.log("STRANGE: there is NOT a HT pressed key #:", dhcMsg.xtNum);
// // }
// }

// If HT0 is pressed, it's the Piper feature
} else if (dhcMsg.xtNum === 0 && dhcMsg.panic === false) {
// Note OFF the active piped HT
this.piping(0);
this.sendMessageToApps(dhcMsg);
}

this.sendMessageToApps(dhcMsg);

}

Expand Down
11 changes: 6 additions & 5 deletions assets/js/synth.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,18 +397,19 @@ HUM.Synth = class {
// Mute the voice only in there are no more HT tones with the same number
// (in order to manage the pressure of multiple copy of the same HT on the controller eg. HT 8)
let sameTones = this.dhc.playQueue.ht.findIndex(qt => qt.xtNum === toneID);
if (sameTones < 0) {
if (sameTones === -1) {
// If there is an active voice with ctrlNoteNumber ID
if (this.voices.ht[toneID]) {
// Shut off the note playing and clear it
this.voices.ht[toneID].voiceMute();
this.voices.ht[toneID] = null;
delete this.voices.ht[toneID];
} else {
if (panic === false) {
console.log("STRANGE: there is NOT an HT active voice with ID:", toneID);
}
}
// else {
// // if (panic === false) {
// // console.log("STRANGE: there is NOT an HT active voice with ID:", toneID);
// // }
// }
}

// **FT**
Expand Down
2 changes: 1 addition & 1 deletion assets/js/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ HUM.tmpl = {
<h2>License</h2>
<h3 style="margin-bottom: 0;">Harmonicarium</h2>
<p style="margin-top: 0; margin-bottom: 0;">a Dynamic Harmonics Calculator</p>
<p style="margin-top: 0;"><span class="monospace">ver. 0.7.0 (Kepler)</span></p>
<p style="margin-top: 0;"><span class="monospace">ver. 0.7.1 (Kepler)</span></p>
<h3>Copyright (C) 2017-2022 by Walter Mantovani</h3>
<p>This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.</p>
<p>This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.</p>
Expand Down

0 comments on commit d9f2061

Please sign in to comment.