From 4a9cbcdef1d13d41151ec2d478ffa85b63e3e3de Mon Sep 17 00:00:00 2001 From: 3dtours Date: Mon, 27 Jul 2026 20:04:56 +0700 Subject: [PATCH] fix: per-track instrument + ghost note visibility soundfontPlayer.js: - selectInstrument: respect passed channel (don't allocate new one) - _playNoteFluid: only use _engineChMap when channel is undefined ghostNoteExtractor.js: - Include ALL notes from overlapping items (not clipped) - relative_start_beat can be negative (notes before window) - Keep original duration instead of clamping --- app/static/js/services/ghostNoteExtractor.js | 10 +++----- app/static/js/services/soundfontPlayer.js | 24 ++++++++++++-------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/app/static/js/services/ghostNoteExtractor.js b/app/static/js/services/ghostNoteExtractor.js index bf02e01..38a416e 100644 --- a/app/static/js/services/ghostNoteExtractor.js +++ b/app/static/js/services/ghostNoteExtractor.js @@ -40,17 +40,13 @@ var noteAbsStart = itemStartBeat + (note.start_beat || 0); var noteAbsEnd = noteAbsStart + (note.duration_beats || 1); - if (noteAbsStart >= windowEndBeat || noteAbsEnd < windowStartBeat) continue; - - var clampedStart = Math.max(noteAbsStart, windowStartBeat); - var clampedEnd = Math.min(noteAbsEnd, windowEndBeat); - var clampedDur = clampedEnd - clampedStart; + if (noteAbsStart >= windowEndBeat) continue; trackGhostNotes.push({ id: 'ghost_' + (note.id || Math.random().toString(36).substr(2, 9)), pitch: note.pitch, - relative_start_beat: clampedStart - windowStartBeat, - duration_beats: clampedDur, + relative_start_beat: noteAbsStart - windowStartBeat, + duration_beats: (note.duration_beats || 1), velocity: note.velocity, original_track_name: track.name, original_track_color: track.color || '#888888' diff --git a/app/static/js/services/soundfontPlayer.js b/app/static/js/services/soundfontPlayer.js index 08812bb..4edc156 100644 --- a/app/static/js/services/soundfontPlayer.js +++ b/app/static/js/services/soundfontPlayer.js @@ -233,9 +233,13 @@ } var engKey = (sfId || '') + ':' + bank + ':' + program; if (!_engineChMap[engKey]) { - var allocCh = this.allocateChannel(bank); - _engineChMap[engKey] = allocCh; - channel = allocCh; + if (channel === undefined || channel === null) { + var allocCh = this.allocateChannel(bank); + _engineChMap[engKey] = allocCh; + channel = allocCh; + } else { + _engineChMap[engKey] = channel; + } } else { channel = _engineChMap[engKey]; } @@ -363,12 +367,14 @@ if (synthEngine) { usedBank = synthEngine.soundfont_bank || 0; usedProg = synthEngine.soundfont_program || 0; - var engKey = (synthEngine.soundfont_id || '') + ':' + usedBank + ':' + usedProg; - var mappedCh = _engineChMap[engKey]; - if (mappedCh !== undefined) { - ch = mappedCh; - } else if (ch === undefined) { - ch = usedBank === 128 ? 9 : 0; + if (ch === undefined) { + var engKey = (synthEngine.soundfont_id || '') + ':' + usedBank + ':' + usedProg; + var mappedCh = _engineChMap[engKey]; + if (mappedCh !== undefined) { + ch = mappedCh; + } else { + ch = usedBank === 128 ? 9 : 0; + } } if (ch === undefined) ch = (usedBank === 128 ? 9 : 0); var sfHandle = synthEngine.soundfont_id ? _sfHandleMap.get(synthEngine.soundfont_id) : undefined;