fix: AI tracks auto-align to end of last existing item

- Replace currentTime with auto-calculated maxEnd from existing items
- Each AI generation starts right after the previous one
- Ensures tracks from different generations align in bar columns
This commit is contained in:
2026-07-26 22:14:02 +07:00
parent e4dadb3158
commit 1764fc29b5
2 changed files with 13 additions and 2 deletions
+11 -1
View File
@@ -13854,7 +13854,17 @@ const App = () => {
}; };
updatedTracks.push(targetTrack); updatedTracks.push(targetTrack);
} }
const itemStartTimeSec = currentTime; const itemStartTimeSec = (() => {
// Auto-align: place new AI tracks right after the last existing item
let maxEnd = 0;
updatedTracks.forEach(t => {
(t.midiItems || []).forEach(mi => {
const miEnd = (mi.startTime || 0) + (mi.duration || 0);
if (miEnd > maxEnd) maxEnd = miEnd;
});
});
return maxEnd > 0 ? maxEnd : 0;
})();
const newMidiItem = { const newMidiItem = {
id: 'item_ai_' + Date.now() + '_' + Math.random().toString(36).substr(2, 5), id: 'item_ai_' + Date.now() + '_' + Math.random().toString(36).substr(2, 5),
name: `${composition_title || 'AI Theme'} - ${aiTrack.track_name}`, name: `${composition_title || 'AI Theme'} - ${aiTrack.track_name}`,
File diff suppressed because one or more lines are too long