fix: store midiChannel on track object for consistent per-track playback
- setTrackInstrumentWithProgram stores midiChannel on the track - schedulePianoRollMidi reads track.midiChannel instead of recomputing from index (can be inconsistent across calls) - selectInstrument also stores midiChannel if not already set
This commit is contained in:
+12
-5
@@ -6775,7 +6775,12 @@ const App = () => {
|
||||
soundfont_program: sfProg !== undefined ? sfProg : 0,
|
||||
soundfont_id: isSfInstrument ? instrumentId.replace('sf_', '') : ''
|
||||
} : undefined;
|
||||
return { ...t, instrumentId, instrumentProgram: sfProg, instrumentName: displayName, soundfont_bank: sfBank, soundfont_program: sfProg, synth_engine: synthEngine, type: hasInstrument ? 'MIDI' : (t.type === 'MIDI' ? 'audio' : t.type) };
|
||||
var mt = activeTracksRef.current || tracks;
|
||||
var midx = 0;
|
||||
for (var mi = 0; mi < mt.length; mi++) { if (mt[mi].id === trackId) { midx = mi; break; } }
|
||||
var mch = sfBank === 128 ? 9 : (midx >= 9 ? midx + 1 : midx);
|
||||
if (mch >= 16) mch = 0;
|
||||
return { ...t, midiChannel: mch, instrumentId, instrumentProgram: sfProg, instrumentName: displayName, soundfont_bank: sfBank, soundfont_program: sfProg, synth_engine: synthEngine, type: hasInstrument ? 'MIDI' : (t.type === 'MIDI' ? 'audio' : t.type) };
|
||||
}));
|
||||
setInstrumentDropdownTrackId(null);
|
||||
setInstrumentDropdownBtnRect(null);
|
||||
@@ -6790,6 +6795,10 @@ const App = () => {
|
||||
for (var i = 0; i < allTracks.length; i++) { if (allTracks[i].id === trackId) { tidx = i; break; } }
|
||||
var ch = sfBank === 128 ? 9 : (tidx >= 9 ? tidx + 1 : tidx);
|
||||
if (ch >= 16) ch = 0;
|
||||
// Store channel for consistent per-track instrument playback
|
||||
if (!allTracks[tidx] || allTracks[tidx].midiChannel === undefined) {
|
||||
updateActiveTracks(prev => prev.map(t => t.id === trackId ? { ...t, midiChannel: ch } : t));
|
||||
}
|
||||
window.SonicSF.selectInstrument(ch, sfBank || 0, sfProg || 0, sfId);
|
||||
}
|
||||
setSubTabs(prev => prev.map(s => {
|
||||
@@ -10398,8 +10407,7 @@ const App = () => {
|
||||
const instrumentProgram = track ? track.instrumentProgram : undefined;
|
||||
const synthEngine = track ? track.synth_engine : undefined;
|
||||
var allTracks = activeTracksRef.current || [];
|
||||
var mainCh = 0;
|
||||
for (var i = 0; i < allTracks.length; i++) { if (allTracks[i].id === st.trackId) { mainCh = i >= 9 ? i + 1 : i; if (mainCh >= 16) mainCh = 0; break; } }
|
||||
var mainCh = track ? (track.midiChannel !== undefined ? track.midiChannel : 0) : 0;
|
||||
// Compute session beat offset from target item
|
||||
var sessionBeatOffset = 0;
|
||||
var targetTrk = allTracks.find(function(t) { return t.id === st.trackId; });
|
||||
@@ -10430,8 +10438,7 @@ const App = () => {
|
||||
var ghostSynth = layer.synthEngine || (ghostTrack ? ghostTrack.synth_engine : undefined);
|
||||
if (ghostProg === undefined && !ghostSynth) return;
|
||||
var ghostDest = getOrCreateTrackNode(ghostTrack, context);
|
||||
var ghostCh = 0;
|
||||
for (var i = 0; i < allTracks.length; i++) { if (allTracks[i].id === layer.trackId) { ghostCh = i >= 9 ? i + 1 : i; if (ghostCh >= 16) ghostCh = 0; break; } }
|
||||
var ghostCh = ghostTrack ? (ghostTrack.midiChannel !== undefined ? ghostTrack.midiChannel : 0) : 0;
|
||||
layer.notes.forEach(function(note) {
|
||||
var beat = (note.start_beat || 0) + sessionBeatOffset;
|
||||
var dur = note.duration_beats || 1;
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user