Skip to content

Commit

Permalink
fix tie playback over measure boundaries
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronDavidNewman committed Dec 19, 2023
1 parent beb9920 commit 77bc22e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
10 changes: 8 additions & 2 deletions release/smoosic.js
Original file line number Diff line number Diff line change
Expand Up @@ -5169,7 +5169,7 @@ class SuiAudioPlayer {
selector.tick = tickIx;
let ties = [];
const tieIx = '' + staffIx + '-' + measureIndex + '-' + voiceIx;
let tiedNote = false;
const prevMeasureIx = '' + staffIx + '-' + (measureIndex - 1) + '-' + voiceIx;
if (smoNote.noteType === 'n' && !smoNote.isHidden()) {
ties = staff.getTiesStartingAt(selector);
smoNote.pitches.forEach((pitch, pitchIx) => {
Expand Down Expand Up @@ -5209,7 +5209,13 @@ class SuiAudioPlayer {
measureNotes[curTick].push(soundData);
};
// If this is continuation of tied note, just change duration
if (this.openTies[tieIx]) {
if (this.openTies[prevMeasureIx]) {
this.openTies[prevMeasureIx].duration += duration;
if (ties.length === 0) {
this.openTies[prevMeasureIx] = null;
}
}
else if (this.openTies[tieIx]) {
this.openTies[tieIx].duration += duration;
if (ties.length === 0) {
this.openTies[tieIx] = null;
Expand Down
2 changes: 1 addition & 1 deletion release/smoosic.js.map

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions src/render/audio/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export class SuiAudioPlayer {
selector.tick = tickIx;
let ties: SmoTie[] = [];
const tieIx = '' + staffIx + '-' + measureIndex + '-' + voiceIx;
let tiedNote = false;
const prevMeasureIx = '' + staffIx + '-' + (measureIndex - 1) + '-' + voiceIx;
if (smoNote.noteType === 'n' && !smoNote.isHidden()) {
ties = staff.getTiesStartingAt(selector);
smoNote.pitches.forEach((pitch, pitchIx) => {
Expand Down Expand Up @@ -228,7 +228,13 @@ export class SuiAudioPlayer {
measureNotes[curTick].push(soundData);
}
// If this is continuation of tied note, just change duration
if (this.openTies[tieIx]) {
if (this.openTies[prevMeasureIx]) {
this.openTies[prevMeasureIx]!.duration += duration;
if (ties.length === 0) {
this.openTies[prevMeasureIx] = null;
}
}
else if (this.openTies[tieIx]) {
this.openTies[tieIx]!.duration += duration;
if (ties.length === 0) {
this.openTies[tieIx] = null;
Expand Down

0 comments on commit 77bc22e

Please sign in to comment.