FIX: sửa lỗi cnnot move items
This commit is contained in:
+43
-13
@@ -9134,10 +9134,37 @@ const App = () => {
|
||||
const applyTrackState = (trackId, state) => {
|
||||
updateActiveTracks(prev => prev.map(t => {
|
||||
if (t.id !== trackId) return t;
|
||||
return {
|
||||
...t,
|
||||
...state
|
||||
};
|
||||
var updated = { ...t, ...state };
|
||||
if (state.sections) {
|
||||
updated.sections = t.sections ? t.sections.map(function(s) {
|
||||
var match = state.sections.find(function(ss) { return ss.id === s.id; });
|
||||
return match ? { ...s, start: match.start, duration: match.duration } : s;
|
||||
}) : state.sections;
|
||||
state.sections.forEach(function(ss) {
|
||||
if (!updated.sections.find(function(s) { return s.id === ss.id; })) {
|
||||
updated.sections.push(ss);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (state.midiItems) {
|
||||
updated.midiItems = t.midiItems ? t.midiItems.map(function(m) {
|
||||
var match = state.midiItems.find(function(sm) { return sm.id === m.id; });
|
||||
return match ? { ...m, startTime: match.startTime, duration: match.duration } : m;
|
||||
}) : state.midiItems;
|
||||
state.midiItems.forEach(function(sm) {
|
||||
if (!updated.midiItems.find(function(m) { return m.id === sm.id; })) {
|
||||
updated.midiItems.push(sm);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (state.clips) {
|
||||
updated.clips = t.clips ? t.clips.map(function(c) {
|
||||
var cid = c.id === 'default' ? 'default_' + t.id : c.id;
|
||||
var match = state.clips.find(function(sc) { return sc.id === cid; });
|
||||
return match ? { ...c, startTime: match.startTime } : c;
|
||||
}) : state.clips;
|
||||
}
|
||||
return updated;
|
||||
}));
|
||||
};
|
||||
const getSelectedMidiItemInfo = () => {
|
||||
@@ -9166,7 +9193,9 @@ const App = () => {
|
||||
buffer: c.buffer,
|
||||
startTime: c.startTime,
|
||||
name: c.name
|
||||
})) : null
|
||||
})) : null,
|
||||
sections: track.sections ? track.sections.map(function(s) { return { id: s.id, start: s.start, duration: s.duration, name: s.name, color: s.color, notes: s.notes ? s.notes.map(function(n) { return { id: n.id, pitch: n.pitch, start_beat: n.start_beat, duration_beats: n.duration_beats, velocity: n.velocity }; }) : null, tracks: s.tracks ? s.tracks.map(function(st) { return { id: st.id, name: st.name, color: st.color, clips: st.clips ? st.clips.map(function(c) { return { id: c.id, startTime: c.startTime, name: c.name, speed: c.speed, buffer: c.buffer }; }) : null, midiItems: st.midiItems ? st.midiItems.map(function(m) { return { id: m.id, startTime: m.startTime, duration: m.duration, name: m.name, notes: m.notes ? m.notes.map(function(n) { return { id: n.id, pitch: n.pitch, start_beat: n.start_beat, duration_beats: n.duration_beats, velocity: n.velocity }; }) : null }; }) : null }; }) : null }; }) : null,
|
||||
midiItems: track.midiItems ? track.midiItems.map(function(m) { return { id: m.id, startTime: m.startTime, duration: m.duration, name: m.name, notes: m.notes ? m.notes.map(function(n) { return { id: n.id, pitch: n.pitch, start_beat: n.start_beat, duration_beats: n.duration_beats, velocity: n.velocity }; }) : null }; }) : null
|
||||
};
|
||||
};
|
||||
|
||||
@@ -14076,6 +14105,7 @@ const App = () => {
|
||||
if (!track) return;
|
||||
if (multiIds) {
|
||||
var newOriginals = {};
|
||||
var dupBeforeSnap = captureTrackSnapshot(trackId);
|
||||
updateActiveTracks(function(prev) {
|
||||
return prev.map(function(t) {
|
||||
var updatedSections = t.sections ? t.sections.slice() : [];
|
||||
@@ -14111,13 +14141,14 @@ const App = () => {
|
||||
});
|
||||
var newItemId = Object.keys(newOriginals)[0] || itemId;
|
||||
var origPos = newOriginals[newItemId] || { start: 0 };
|
||||
setDraggedSectionItem({ trackId, itemType, itemId: newItemId, clickOffset, multiIds: newOriginals, originalPositions: { [newItemId]: origPos.start } });
|
||||
setDraggedSectionItem({ trackId, itemType, itemId: newItemId, clickOffset, multiIds: newOriginals, originalPositions: { [newItemId]: origPos.start }, beforeSnap: dupBeforeSnap });
|
||||
} else {
|
||||
var items = itemType === 'section' ? (track.sections || []) : (track.midiItems || []);
|
||||
var item = items.find(function(it) { return it.id === itemId; });
|
||||
if (!item) return;
|
||||
var rearrangeNewId = itemType + '_dup_' + Date.now();
|
||||
var newItem = { ...item, id: rearrangeNewId, name: item.name + ' (Copy)' };
|
||||
var singleDupBeforeSnap = captureTrackSnapshot(trackId);
|
||||
updateActiveTracks(function(prev) {
|
||||
return prev.map(function(t) {
|
||||
if (t.id !== trackId) return t;
|
||||
@@ -14125,14 +14156,15 @@ const App = () => {
|
||||
return itemType === 'section' ? { ...t, sections: updated } : { ...t, midiItems: updated };
|
||||
});
|
||||
});
|
||||
setDraggedSectionItem({ trackId, itemType, itemId: rearrangeNewId, clickOffset, isDuplicate: false, originalPositions: { [rearrangeNewId]: itemType === 'section' ? item.start : item.startTime } });
|
||||
setDraggedSectionItem({ trackId, itemType, itemId: rearrangeNewId, clickOffset, isDuplicate: false, originalPositions: { [rearrangeNewId]: itemType === 'section' ? item.start : item.startTime }, beforeSnap: singleDupBeforeSnap });
|
||||
}
|
||||
} else {
|
||||
var curTrk = activeTracksRef.current ? activeTracksRef.current.find(t => t.id === trackId) : null;
|
||||
var its = itemType === 'section' ? (curTrk?.sections || []) : (curTrk?.midiItems || []);
|
||||
var it = its.find(function(x) { return x.id === itemId; });
|
||||
var origPos = it ? (itemType === 'section' ? it.start : it.startTime) : 0;
|
||||
setDraggedSectionItem({ trackId, itemType, itemId, clickOffset, multiIds, originalPositions: { [itemId]: origPos } });
|
||||
var beforeSnap = captureTrackSnapshot(trackId);
|
||||
setDraggedSectionItem({ trackId, itemType, itemId, clickOffset, multiIds, originalPositions: { [itemId]: origPos }, beforeSnap });
|
||||
}
|
||||
};
|
||||
handleSectionItemDragStartRef.current = handleSectionItemDragStart;
|
||||
@@ -14288,7 +14320,7 @@ const App = () => {
|
||||
if (!drag) return;
|
||||
var changed = false;
|
||||
var trackId = drag.trackId;
|
||||
var beforeSnap = captureTrackSnapshot(trackId);
|
||||
var beforeSnap = drag.beforeSnap;
|
||||
var origs = drag.originalPositions || {};
|
||||
updateActiveTracks(function(prev) {
|
||||
return prev.map(function(t) {
|
||||
@@ -14308,8 +14340,6 @@ const App = () => {
|
||||
if (Math.abs(curStart - origStart) > 0.001) {
|
||||
hasChange = true;
|
||||
changed = true;
|
||||
if (sec) item.start = origStart;
|
||||
if (mid) item.startTime = origStart;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14318,9 +14348,9 @@ const App = () => {
|
||||
return { ...t, sections: updatedSections, midiItems: updatedMidi };
|
||||
});
|
||||
});
|
||||
if (changed) {
|
||||
if (changed || drag.beforeSnap) {
|
||||
var afterSnap = captureTrackSnapshot(trackId);
|
||||
pushAction('MOVE_ITEM', trackId, beforeSnap, afterSnap);
|
||||
pushAction('MOVE_ITEM', trackId, drag.beforeSnap || beforeSnap, afterSnap);
|
||||
}
|
||||
if (drag.itemType === 'midiItem') {
|
||||
let finalTrackId = null;
|
||||
|
||||
Reference in New Issue
Block a user