@nodetool-ai/timeline 0.8.19 → 0.8.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.nodetool-build-stamp +1 -1
- package/dist/autoCrossfade.d.ts +30 -0
- package/dist/autoCrossfade.d.ts.map +1 -0
- package/dist/autoCrossfade.js +130 -0
- package/dist/autoCrossfade.js.map +1 -0
- package/dist/automation.d.ts +32 -1
- package/dist/automation.d.ts.map +1 -1
- package/dist/automation.js +78 -1
- package/dist/automation.js.map +1 -1
- package/dist/automationRanges.d.ts +375 -0
- package/dist/automationRanges.d.ts.map +1 -0
- package/dist/automationRanges.js +375 -0
- package/dist/automationRanges.js.map +1 -0
- package/dist/clipAudio.d.ts +3 -1
- package/dist/clipAudio.d.ts.map +1 -1
- package/dist/clipAudio.js.map +1 -1
- package/dist/clipLoop.d.ts +67 -0
- package/dist/clipLoop.d.ts.map +1 -0
- package/dist/clipLoop.js +339 -0
- package/dist/clipLoop.js.map +1 -0
- package/dist/clipSpeed.d.ts.map +1 -1
- package/dist/clipSpeed.js +7 -0
- package/dist/clipSpeed.js.map +1 -1
- package/dist/defaults.d.ts.map +1 -1
- package/dist/defaults.js +9 -0
- package/dist/defaults.js.map +1 -1
- package/dist/dropResolve.d.ts.map +1 -1
- package/dist/dropResolve.js +56 -17
- package/dist/dropResolve.js.map +1 -1
- package/dist/harmony/chordChart.d.ts +25 -0
- package/dist/harmony/chordChart.d.ts.map +1 -0
- package/dist/harmony/chordChart.js +99 -0
- package/dist/harmony/chordChart.js.map +1 -0
- package/dist/harmony/chordRange.d.ts +9 -0
- package/dist/harmony/chordRange.d.ts.map +1 -0
- package/dist/harmony/chordRange.js +32 -0
- package/dist/harmony/chordRange.js.map +1 -0
- package/dist/harmony/chordSymbols.d.ts +28 -0
- package/dist/harmony/chordSymbols.d.ts.map +1 -0
- package/dist/harmony/chordSymbols.js +147 -0
- package/dist/harmony/chordSymbols.js.map +1 -0
- package/dist/harmony/chordTrack.d.ts +13 -0
- package/dist/harmony/chordTrack.d.ts.map +1 -0
- package/dist/harmony/chordTrack.js +11 -0
- package/dist/harmony/chordTrack.js.map +1 -0
- package/dist/harmony/detect.d.ts +35 -0
- package/dist/harmony/detect.d.ts.map +1 -0
- package/dist/harmony/detect.js +138 -0
- package/dist/harmony/detect.js.map +1 -0
- package/dist/harmony/detectAudio.d.ts +62 -0
- package/dist/harmony/detectAudio.d.ts.map +1 -0
- package/dist/harmony/detectAudio.js +226 -0
- package/dist/harmony/detectAudio.js.map +1 -0
- package/dist/harmony/expand.d.ts +7 -12
- package/dist/harmony/expand.d.ts.map +1 -1
- package/dist/harmony/expand.js +63 -11
- package/dist/harmony/expand.js.map +1 -1
- package/dist/harmony/index.d.ts +7 -0
- package/dist/harmony/index.d.ts.map +1 -1
- package/dist/harmony/index.js +7 -0
- package/dist/harmony/index.js.map +1 -1
- package/dist/harmony/progressionLibrary.d.ts +33 -0
- package/dist/harmony/progressionLibrary.d.ts.map +1 -0
- package/dist/harmony/progressionLibrary.js +71 -0
- package/dist/harmony/progressionLibrary.js.map +1 -0
- package/dist/harmony/summary.d.ts +4 -0
- package/dist/harmony/summary.d.ts.map +1 -0
- package/dist/harmony/summary.js +22 -0
- package/dist/harmony/summary.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/interchange.d.ts.map +1 -1
- package/dist/interchange.js +72 -12
- package/dist/interchange.js.map +1 -1
- package/dist/loopWindow.d.ts +17 -0
- package/dist/loopWindow.d.ts.map +1 -0
- package/dist/loopWindow.js +34 -0
- package/dist/loopWindow.js.map +1 -0
- package/dist/midi/cacheKey.d.ts +11 -2
- package/dist/midi/cacheKey.d.ts.map +1 -1
- package/dist/midi/cacheKey.js +69 -9
- package/dist/midi/cacheKey.js.map +1 -1
- package/dist/midi/controllerEdit.d.ts +35 -0
- package/dist/midi/controllerEdit.d.ts.map +1 -0
- package/dist/midi/controllerEdit.js +94 -0
- package/dist/midi/controllerEdit.js.map +1 -0
- package/dist/midi/controllerRange.d.ts +13 -0
- package/dist/midi/controllerRange.d.ts.map +1 -0
- package/dist/midi/controllerRange.js +13 -0
- package/dist/midi/controllerRange.js.map +1 -0
- package/dist/midi/controllers.d.ts +95 -0
- package/dist/midi/controllers.d.ts.map +1 -0
- package/dist/midi/controllers.js +421 -0
- package/dist/midi/controllers.js.map +1 -0
- package/dist/midi/curveCut.d.ts +17 -0
- package/dist/midi/curveCut.d.ts.map +1 -0
- package/dist/midi/curveCut.js +45 -0
- package/dist/midi/curveCut.js.map +1 -0
- package/dist/midi/edit.d.ts +13 -1
- package/dist/midi/edit.d.ts.map +1 -1
- package/dist/midi/edit.js +19 -3
- package/dist/midi/edit.js.map +1 -1
- package/dist/midi/engines/bl1.d.ts +10 -1
- package/dist/midi/engines/bl1.d.ts.map +1 -1
- package/dist/midi/engines/bl1.js +26 -6
- package/dist/midi/engines/bl1.js.map +1 -1
- package/dist/midi/engines/dr1.d.ts +11 -1
- package/dist/midi/engines/dr1.d.ts.map +1 -1
- package/dist/midi/engines/dr1.js +21 -3
- package/dist/midi/engines/dr1.js.map +1 -1
- package/dist/midi/engines/dsp.d.ts +1 -1
- package/dist/midi/engines/dsp.d.ts.map +1 -1
- package/dist/midi/engines/dsp.js +10 -2
- package/dist/midi/engines/dsp.js.map +1 -1
- package/dist/midi/engines/wt1.d.ts +10 -1
- package/dist/midi/engines/wt1.d.ts.map +1 -1
- package/dist/midi/engines/wt1.js +28 -5
- package/dist/midi/engines/wt1.js.map +1 -1
- package/dist/midi/events.d.ts +13 -4
- package/dist/midi/events.d.ts.map +1 -1
- package/dist/midi/events.js +33 -6
- package/dist/midi/events.js.map +1 -1
- package/dist/midi/expression.d.ts +25 -0
- package/dist/midi/expression.d.ts.map +1 -0
- package/dist/midi/expression.js +69 -0
- package/dist/midi/expression.js.map +1 -0
- package/dist/midi/index.d.ts +8 -0
- package/dist/midi/index.d.ts.map +1 -1
- package/dist/midi/index.js +8 -0
- package/dist/midi/index.js.map +1 -1
- package/dist/midi/instrument.d.ts.map +1 -1
- package/dist/midi/instrument.js +4 -0
- package/dist/midi/instrument.js.map +1 -1
- package/dist/midi/noteFunctions.d.ts +29 -0
- package/dist/midi/noteFunctions.d.ts.map +1 -0
- package/dist/midi/noteFunctions.js +213 -0
- package/dist/midi/noteFunctions.js.map +1 -0
- package/dist/midi/notes.d.ts +7 -1
- package/dist/midi/notes.d.ts.map +1 -1
- package/dist/midi/notes.js +43 -1
- package/dist/midi/notes.js.map +1 -1
- package/dist/midi/notesEdit.d.ts +13 -0
- package/dist/midi/notesEdit.d.ts.map +1 -1
- package/dist/midi/notesEdit.js +73 -2
- package/dist/midi/notesEdit.js.map +1 -1
- package/dist/midi/presets.d.ts +1 -1
- package/dist/midi/regionParams.d.ts +41 -0
- package/dist/midi/regionParams.d.ts.map +1 -0
- package/dist/midi/regionParams.js +164 -0
- package/dist/midi/regionParams.js.map +1 -0
- package/dist/midi/sampler.d.ts +2 -2
- package/dist/midi/sampler.d.ts.map +1 -1
- package/dist/midi/sampler.js +99 -21
- package/dist/midi/sampler.js.map +1 -1
- package/dist/midi/stepEditor.d.ts +50 -0
- package/dist/midi/stepEditor.d.ts.map +1 -0
- package/dist/midi/stepEditor.js +118 -0
- package/dist/midi/stepEditor.js.map +1 -0
- package/dist/midi/stepPattern.d.ts +173 -0
- package/dist/midi/stepPattern.d.ts.map +1 -0
- package/dist/midi/stepPattern.js +1390 -0
- package/dist/midi/stepPattern.js.map +1 -0
- package/dist/midi/stepPatternExpand.d.ts +149 -0
- package/dist/midi/stepPatternExpand.d.ts.map +1 -0
- package/dist/midi/stepPatternExpand.js +1068 -0
- package/dist/midi/stepPatternExpand.js.map +1 -0
- package/dist/midi/stepPatternLibrary.d.ts +65 -0
- package/dist/midi/stepPatternLibrary.d.ts.map +1 -0
- package/dist/midi/stepPatternLibrary.js +640 -0
- package/dist/midi/stepPatternLibrary.js.map +1 -0
- package/dist/midi/tempo.d.ts.map +1 -1
- package/dist/midi/tempo.js +3 -0
- package/dist/midi/tempo.js.map +1 -1
- package/dist/midi/voice.d.ts +51 -5
- package/dist/midi/voice.d.ts.map +1 -1
- package/dist/midi/voice.js +191 -21
- package/dist/midi/voice.js.map +1 -1
- package/dist/model3dBake.d.ts +13 -0
- package/dist/model3dBake.d.ts.map +1 -1
- package/dist/model3dBake.js +25 -0
- package/dist/model3dBake.js.map +1 -1
- package/dist/model3dCameraDescription.d.ts +11 -6
- package/dist/model3dCameraDescription.d.ts.map +1 -1
- package/dist/model3dCameraDescription.js +112 -30
- package/dist/model3dCameraDescription.js.map +1 -1
- package/dist/model3dReference.d.ts +25 -4
- package/dist/model3dReference.d.ts.map +1 -1
- package/dist/model3dReference.js +19 -6
- package/dist/model3dReference.js.map +1 -1
- package/dist/music/align.d.ts +111 -0
- package/dist/music/align.d.ts.map +1 -0
- package/dist/music/align.js +282 -0
- package/dist/music/align.js.map +1 -0
- package/dist/music/cut.d.ts +33 -0
- package/dist/music/cut.d.ts.map +1 -0
- package/dist/music/cut.js +50 -0
- package/dist/music/cut.js.map +1 -0
- package/dist/music/frames.d.ts +51 -0
- package/dist/music/frames.d.ts.map +1 -0
- package/dist/music/frames.js +110 -0
- package/dist/music/frames.js.map +1 -0
- package/dist/music/gain.d.ts +24 -0
- package/dist/music/gain.d.ts.map +1 -0
- package/dist/music/gain.js +38 -0
- package/dist/music/gain.js.map +1 -0
- package/dist/music/index.d.ts +9 -0
- package/dist/music/index.d.ts.map +1 -0
- package/dist/music/index.js +9 -0
- package/dist/music/index.js.map +1 -0
- package/dist/music/plan.d.ts +104 -0
- package/dist/music/plan.d.ts.map +1 -0
- package/dist/music/plan.js +300 -0
- package/dist/music/plan.js.map +1 -0
- package/dist/music/process.d.ts +9 -0
- package/dist/music/process.d.ts.map +1 -0
- package/dist/music/process.js +9 -0
- package/dist/music/process.js.map +1 -0
- package/dist/music/roles.d.ts +14 -0
- package/dist/music/roles.d.ts.map +1 -0
- package/dist/music/roles.js +30 -0
- package/dist/music/roles.js.map +1 -0
- package/dist/music/splice.d.ts +37 -0
- package/dist/music/splice.d.ts.map +1 -0
- package/dist/music/splice.js +67 -0
- package/dist/music/splice.js.map +1 -0
- package/dist/music/tempoRules.d.ts +41 -0
- package/dist/music/tempoRules.d.ts.map +1 -0
- package/dist/music/tempoRules.js +59 -0
- package/dist/music/tempoRules.js.map +1 -0
- package/dist/ops/apply.d.ts.map +1 -1
- package/dist/ops/apply.js +856 -234
- package/dist/ops/apply.js.map +1 -1
- package/dist/ops/automation.d.ts +6 -0
- package/dist/ops/automation.d.ts.map +1 -0
- package/dist/ops/automation.js +217 -0
- package/dist/ops/automation.js.map +1 -0
- package/dist/ops/barTime.d.ts +14 -0
- package/dist/ops/barTime.d.ts.map +1 -0
- package/dist/ops/barTime.js +33 -0
- package/dist/ops/barTime.js.map +1 -0
- package/dist/ops/chords.d.ts +43 -0
- package/dist/ops/chords.d.ts.map +1 -0
- package/dist/ops/chords.js +691 -0
- package/dist/ops/chords.js.map +1 -0
- package/dist/ops/groupBake.d.ts +24 -0
- package/dist/ops/groupBake.d.ts.map +1 -0
- package/dist/ops/groupBake.js +81 -0
- package/dist/ops/groupBake.js.map +1 -0
- package/dist/ops/index.d.ts +7 -0
- package/dist/ops/index.d.ts.map +1 -1
- package/dist/ops/index.js +5 -0
- package/dist/ops/index.js.map +1 -1
- package/dist/ops/join.d.ts +20 -0
- package/dist/ops/join.d.ts.map +1 -0
- package/dist/ops/join.js +265 -0
- package/dist/ops/join.js.map +1 -0
- package/dist/ops/loop.d.ts +29 -0
- package/dist/ops/loop.d.ts.map +1 -0
- package/dist/ops/loop.js +107 -0
- package/dist/ops/loop.js.map +1 -0
- package/dist/ops/midiMix.d.ts +41 -0
- package/dist/ops/midiMix.d.ts.map +1 -0
- package/dist/ops/midiMix.js +522 -0
- package/dist/ops/midiMix.js.map +1 -0
- package/dist/ops/op.d.ts +61 -11
- package/dist/ops/op.d.ts.map +1 -1
- package/dist/ops/op.js +60 -1
- package/dist/ops/op.js.map +1 -1
- package/dist/ops/parse.d.ts.map +1 -1
- package/dist/ops/parse.js +308 -4
- package/dist/ops/parse.js.map +1 -1
- package/dist/ops/pasteRange.d.ts +46 -0
- package/dist/ops/pasteRange.d.ts.map +1 -0
- package/dist/ops/pasteRange.js +276 -0
- package/dist/ops/pasteRange.js.map +1 -0
- package/dist/ops/plugin.d.ts +57 -0
- package/dist/ops/plugin.d.ts.map +1 -0
- package/dist/ops/plugin.js +875 -0
- package/dist/ops/plugin.js.map +1 -0
- package/dist/ops/sections.d.ts +98 -0
- package/dist/ops/sections.d.ts.map +1 -0
- package/dist/ops/sections.js +930 -0
- package/dist/ops/sections.js.map +1 -0
- package/dist/ops/serialize.d.ts +79 -1
- package/dist/ops/serialize.d.ts.map +1 -1
- package/dist/ops/serialize.js +85 -3
- package/dist/ops/serialize.js.map +1 -1
- package/dist/ops/stepPattern.d.ts +44 -0
- package/dist/ops/stepPattern.d.ts.map +1 -0
- package/dist/ops/stepPattern.js +2106 -0
- package/dist/ops/stepPattern.js.map +1 -0
- package/dist/ops/stepPatternFolders.d.ts +54 -0
- package/dist/ops/stepPatternFolders.d.ts.map +1 -0
- package/dist/ops/stepPatternFolders.js +299 -0
- package/dist/ops/stepPatternFolders.js.map +1 -0
- package/dist/ops/types.d.ts +238 -2
- package/dist/ops/types.d.ts.map +1 -1
- package/dist/rippleEdit.d.ts +5 -1
- package/dist/rippleEdit.d.ts.map +1 -1
- package/dist/rippleEdit.js +24 -9
- package/dist/rippleEdit.js.map +1 -1
- package/dist/script.d.ts +2 -1
- package/dist/script.d.ts.map +1 -1
- package/dist/script.js +3 -2
- package/dist/script.js.map +1 -1
- package/dist/splitClip.d.ts +29 -1
- package/dist/splitClip.d.ts.map +1 -1
- package/dist/splitClip.js +231 -1
- package/dist/splitClip.js.map +1 -1
- package/dist/storyboard.d.ts +14 -0
- package/dist/storyboard.d.ts.map +1 -1
- package/dist/storyboard.js +31 -0
- package/dist/storyboard.js.map +1 -1
- package/dist/testing/host-ops.js +3 -3
- package/dist/testing/host-ops.js.map +1 -1
- package/dist/testing/ops.d.ts +6 -1
- package/dist/testing/ops.d.ts.map +1 -1
- package/dist/testing/ops.js +823 -11
- package/dist/testing/ops.js.map +1 -1
- package/dist/timeRemap.d.ts +2 -2
- package/dist/timeRemap.d.ts.map +1 -1
- package/dist/timeRemap.js +18 -0
- package/dist/timeRemap.js.map +1 -1
- package/dist/trimClip.d.ts +1 -1
- package/dist/trimClip.d.ts.map +1 -1
- package/dist/trimClip.js +41 -7
- package/dist/trimClip.js.map +1 -1
- package/dist/types.d.ts +307 -16
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +11 -5
- package/dist/render/curveFitting.d.ts +0 -28
- package/dist/render/curveFitting.d.ts.map +0 -1
- package/dist/render/curveFitting.js +0 -94
- package/dist/render/curveFitting.js.map +0 -1
|
@@ -0,0 +1,930 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Section edits across tracks (CE4, D48): `insert_time`, `delete_time` and
|
|
3
|
+
* `duplicate_range`. They shift clips on every track and also move the chords
|
|
4
|
+
* of chord tracks, automation points, and (without `trackIds`) markers.
|
|
5
|
+
*
|
|
6
|
+
* The document has one tempo, with no tempo or signature events, so there is
|
|
7
|
+
* nothing of that kind to move.
|
|
8
|
+
*/
|
|
9
|
+
import { ease } from "../animation/easing.js";
|
|
10
|
+
import { automationValueAt } from "../automation.js";
|
|
11
|
+
import { activeLoopMs, unrollLoopedClip } from "../clipLoop.js";
|
|
12
|
+
import { clipSourceWindowMs } from "../generatedMatte.js";
|
|
13
|
+
import { resliceMediaTrackSamples, splitClipMediaTracks } from "../mediaTrack.js";
|
|
14
|
+
import { sliceParamCurves } from "../paramCurves.js";
|
|
15
|
+
import { barStartMs } from "../midi/grid.js";
|
|
16
|
+
import { msToTicks } from "../midi/ticks.js";
|
|
17
|
+
import { resolveTempo } from "../midi/tempo.js";
|
|
18
|
+
import { animationsForWindow, splitClip } from "../splitClip.js";
|
|
19
|
+
import { resolveBarTime } from "./barTime.js";
|
|
20
|
+
import { bakeGroupInto, groupBakeProblem } from "./groupBake.js";
|
|
21
|
+
import { unrollLoopedInScope } from "./loop.js";
|
|
22
|
+
const EPS = 1e-6;
|
|
23
|
+
export const newStats = () => ({
|
|
24
|
+
splitClips: 0,
|
|
25
|
+
removedClips: [],
|
|
26
|
+
movedClips: 0,
|
|
27
|
+
copiedClips: 0,
|
|
28
|
+
movedMarkers: 0,
|
|
29
|
+
changedChords: 0,
|
|
30
|
+
movedAutomationPoints: 0,
|
|
31
|
+
links: new Set()
|
|
32
|
+
});
|
|
33
|
+
const endOf = (c) => c.startMs + c.durationMs;
|
|
34
|
+
/** A link id kept by one clip only links nothing. Drop it from the survivor. */
|
|
35
|
+
export function pruneSingletonLinks(scope, ids) {
|
|
36
|
+
if (ids.size === 0)
|
|
37
|
+
return;
|
|
38
|
+
const counts = new Map();
|
|
39
|
+
for (const c of scope.clips) {
|
|
40
|
+
if (c.linkId !== undefined && ids.has(c.linkId)) {
|
|
41
|
+
counts.set(c.linkId, (counts.get(c.linkId) ?? 0) + 1);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
for (const c of scope.clips) {
|
|
45
|
+
if (c.linkId !== undefined && counts.get(c.linkId) === 1) {
|
|
46
|
+
delete c.linkId;
|
|
47
|
+
scope.touch(c.id);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/** Split a clip, and name it when it cannot be split (a time remap). */
|
|
52
|
+
function splitNamed(clip, at, bpm, gridOffsetMs = 0) {
|
|
53
|
+
try {
|
|
54
|
+
return splitClip(clip, at, { bpm, gridOffsetMs });
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
58
|
+
throw new Error(`Clip "${clip.name}" (${clip.id}) cannot be cut at ${at} ms: ${reason} Choose \`trackIds\` that avoid it.`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Refuse an edit point that a locked clip (or a clip on a locked track)
|
|
63
|
+
* strictly crosses. Cutting it would change the clip (D48).
|
|
64
|
+
*/
|
|
65
|
+
export function assertNoLockedCrossing(scope, at, tracks) {
|
|
66
|
+
const lockedTracks = new Set(scope.tracks.filter((t) => t.locked).map((t) => t.id));
|
|
67
|
+
const crossing = scope.clips.filter((c) => onTracks(c, tracks) &&
|
|
68
|
+
(c.locked || lockedTracks.has(c.trackId)) &&
|
|
69
|
+
at > c.startMs + EPS &&
|
|
70
|
+
at < endOf(c) - EPS);
|
|
71
|
+
if (crossing.length > 0) {
|
|
72
|
+
const names = crossing.map((c) => `"${c.name}" (${c.id})`).join(", ");
|
|
73
|
+
throw new Error(`The point ${at} ms cuts locked clips: ${names}. Unlock them first, or choose a point that avoids them.`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/** Groups whose direct children all lie inside the group window now. */
|
|
77
|
+
export function enclosingGroups(scope) {
|
|
78
|
+
const out = new Set();
|
|
79
|
+
for (const g of scope.clips) {
|
|
80
|
+
if (g.mediaType !== "group")
|
|
81
|
+
continue;
|
|
82
|
+
const kids = scope.clips.filter((c) => c.parentId === g.id);
|
|
83
|
+
if (kids.every((k) => k.startMs >= g.startMs - EPS && endOf(k) <= endOf(g) + EPS)) {
|
|
84
|
+
out.add(g.id);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Grow each group in `enclosing` until its window holds its children again. An
|
|
91
|
+
* edit on the children's tracks alone moves them past a group on another track.
|
|
92
|
+
*/
|
|
93
|
+
export function reencloseGroups(scope, enclosing) {
|
|
94
|
+
for (let pass = 0; pass <= scope.clips.length; pass += 1) {
|
|
95
|
+
let changed = false;
|
|
96
|
+
for (const g of scope.clips) {
|
|
97
|
+
if (!enclosing.has(g.id))
|
|
98
|
+
continue;
|
|
99
|
+
let start = g.startMs;
|
|
100
|
+
let end = endOf(g);
|
|
101
|
+
for (const k of scope.clips) {
|
|
102
|
+
if (k.parentId !== g.id)
|
|
103
|
+
continue;
|
|
104
|
+
start = Math.min(start, k.startMs);
|
|
105
|
+
end = Math.max(end, endOf(k));
|
|
106
|
+
}
|
|
107
|
+
if (start < g.startMs - EPS || end > endOf(g) + EPS) {
|
|
108
|
+
g.startMs = Math.max(0, start);
|
|
109
|
+
g.durationMs = end - g.startMs;
|
|
110
|
+
scope.touch(g.id);
|
|
111
|
+
changed = true;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (!changed)
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/** The tracks an op acts on. `null` means every track, and the markers. */
|
|
119
|
+
export function resolveTargetTracks(scope, trackIds) {
|
|
120
|
+
if (trackIds === undefined)
|
|
121
|
+
return null;
|
|
122
|
+
return new Set(trackIds.map((ref) => scope.resolveTrack(ref).id));
|
|
123
|
+
}
|
|
124
|
+
export const onTracks = (c, set) => set === null || set.has(c.trackId);
|
|
125
|
+
function barLengthMs(scope) {
|
|
126
|
+
const tempo = resolveTempo(scope.state);
|
|
127
|
+
return barStartMs(2, tempo) - barStartMs(1, tempo);
|
|
128
|
+
}
|
|
129
|
+
function resolveRange(scope, op) {
|
|
130
|
+
const bars = op.fromBar !== undefined || op.toBar !== undefined;
|
|
131
|
+
const ms = op.fromMs !== undefined || op.toMs !== undefined;
|
|
132
|
+
if (bars && ms) {
|
|
133
|
+
throw new Error("Send `fromBar` and `toBar`, or `fromMs` and `toMs`, not both.");
|
|
134
|
+
}
|
|
135
|
+
let from;
|
|
136
|
+
let to;
|
|
137
|
+
if (bars) {
|
|
138
|
+
if (op.fromBar === undefined || op.toBar === undefined) {
|
|
139
|
+
throw new Error("Send both `fromBar` and `toBar`.");
|
|
140
|
+
}
|
|
141
|
+
const tempo = resolveTempo(scope.state);
|
|
142
|
+
from = barStartMs(op.fromBar, tempo);
|
|
143
|
+
to = barStartMs(op.toBar, tempo);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
from = op.fromMs;
|
|
147
|
+
to = op.toMs;
|
|
148
|
+
}
|
|
149
|
+
if (from === undefined || to === undefined) {
|
|
150
|
+
throw new Error("Send `fromBar` and `toBar`, or `fromMs` and `toMs`.");
|
|
151
|
+
}
|
|
152
|
+
if (!(to > from + EPS)) {
|
|
153
|
+
throw new Error(`The range must end after it starts. Got ${from} ms to ${to} ms.`);
|
|
154
|
+
}
|
|
155
|
+
return { from, to };
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Cut `clip` in the document at `at`. A looped clip is written out as plain
|
|
159
|
+
* copies first (CE3). Groups are never cut: their children carry the time.
|
|
160
|
+
*/
|
|
161
|
+
function cutInDoc(scope, clip, at, stats, linkMap) {
|
|
162
|
+
if (clip.mediaType === "group")
|
|
163
|
+
return;
|
|
164
|
+
if (!(at > clip.startMs + EPS && at < endOf(clip) - EPS))
|
|
165
|
+
return;
|
|
166
|
+
// An unroll leaves the link on the first repeat only, so prune it afterwards.
|
|
167
|
+
if (clip.linkId !== undefined)
|
|
168
|
+
stats.links.add(clip.linkId);
|
|
169
|
+
const pieces = activeLoopMs(clip) !== undefined ? unrollLoopedInScope(scope, clip) : [clip];
|
|
170
|
+
const { bpm, offsetMs } = resolveTempo(scope.state);
|
|
171
|
+
for (const piece of pieces) {
|
|
172
|
+
if (!(at > piece.startMs + EPS && at < endOf(piece) - EPS))
|
|
173
|
+
continue;
|
|
174
|
+
const [cutLeft, cutRight] = splitNamed(piece, at, bpm, offsetMs);
|
|
175
|
+
cutLeft.id = scope.ctx.newId("clip");
|
|
176
|
+
cutRight.id = scope.ctx.newId("clip");
|
|
177
|
+
if (piece.linkId !== undefined) {
|
|
178
|
+
stats.links.add(piece.linkId);
|
|
179
|
+
let fresh = linkMap.get(piece.linkId);
|
|
180
|
+
if (fresh === undefined) {
|
|
181
|
+
fresh = scope.ctx.newId("link");
|
|
182
|
+
linkMap.set(piece.linkId, fresh);
|
|
183
|
+
stats.links.add(fresh);
|
|
184
|
+
}
|
|
185
|
+
cutRight.linkId = fresh;
|
|
186
|
+
}
|
|
187
|
+
const split = splitClipMediaTracks(scope.mediaTracks, piece.id, cutLeft, cutRight, () => scope.ctx.newId("track"));
|
|
188
|
+
scope.mediaTracks = split.mediaTracks;
|
|
189
|
+
const index = scope.clips.findIndex((c) => c.id === piece.id);
|
|
190
|
+
scope.clips.splice(index, 1, split.left, split.right);
|
|
191
|
+
scope.state.selectedClipIds = scope.state.selectedClipIds.filter((id) => id !== piece.id);
|
|
192
|
+
scope.touch(piece.id, split.left.id, split.right.id);
|
|
193
|
+
stats.splitClips += 1;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
export function cutAllCrossing(scope, at, tracks, stats) {
|
|
197
|
+
const linkMap = new Map();
|
|
198
|
+
for (const clip of [...scope.clips]) {
|
|
199
|
+
if (onTracks(clip, tracks))
|
|
200
|
+
cutInDoc(scope, clip, at, stats, linkMap);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
export function newChordId(used) {
|
|
204
|
+
let n = 0;
|
|
205
|
+
let id;
|
|
206
|
+
do {
|
|
207
|
+
id = `chord_${(++n).toString(36)}`;
|
|
208
|
+
} while (used.has(id));
|
|
209
|
+
used.add(id);
|
|
210
|
+
return id;
|
|
211
|
+
}
|
|
212
|
+
export function chordTicks(scope, ms) {
|
|
213
|
+
const tempo = resolveTempo(scope.state);
|
|
214
|
+
return Math.round(msToTicks(ms - tempo.offsetMs, tempo.bpm));
|
|
215
|
+
}
|
|
216
|
+
export function lengthTicks(scope, ms) {
|
|
217
|
+
return Math.max(1, Math.round(msToTicks(ms, resolveTempo(scope.state).bpm)));
|
|
218
|
+
}
|
|
219
|
+
export const byTime = (a, b) => a.timeMs - b.timeMs;
|
|
220
|
+
/** Linear sub-points that stand in for a slice of an eased segment. */
|
|
221
|
+
const SLICE_SAMPLES = 16;
|
|
222
|
+
/**
|
|
223
|
+
* The easing that a slice `[u0, u1]` of an eased segment keeps exactly, or
|
|
224
|
+
* `null` when only samples can follow it. Linear and `hold` slice to
|
|
225
|
+
* themselves. A cubic ease-in keeps its shape on a slice that starts at the
|
|
226
|
+
* segment start, and a cubic ease-out on one that ends at the segment end.
|
|
227
|
+
*/
|
|
228
|
+
function sliceEasing(easing, u0, u1) {
|
|
229
|
+
const id = easing ?? "linear";
|
|
230
|
+
if (id === "linear")
|
|
231
|
+
return undefined;
|
|
232
|
+
if (u0 <= EPS && u1 >= 1 - EPS)
|
|
233
|
+
return easing;
|
|
234
|
+
if (id === "hold")
|
|
235
|
+
return u1 >= 1 - EPS ? "hold" : undefined;
|
|
236
|
+
if (id === "easeIn" && u0 <= EPS)
|
|
237
|
+
return "easeIn";
|
|
238
|
+
if (id === "easeOut" && u1 >= 1 - EPS)
|
|
239
|
+
return "easeOut";
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* The points of the slice `[u0, u1]` of segment `a`→`b`, without the start
|
|
244
|
+
* point. The last point sits at `u1` and carries the easing that makes the slice
|
|
245
|
+
* draw what the segment drew there.
|
|
246
|
+
*/
|
|
247
|
+
function slicePoints(a, b, u0, u1) {
|
|
248
|
+
const span = b.timeMs - a.timeMs;
|
|
249
|
+
const at = (u) => u >= 1 - EPS ? b.value : a.value + (b.value - a.value) * ease(b.easing ?? "linear", u);
|
|
250
|
+
const kept = sliceEasing(b.easing, u0, u1);
|
|
251
|
+
const out = [];
|
|
252
|
+
if (kept === null) {
|
|
253
|
+
for (let k = 1; k < SLICE_SAMPLES; k += 1) {
|
|
254
|
+
const u = u0 + ((u1 - u0) * k) / SLICE_SAMPLES;
|
|
255
|
+
out.push({ timeMs: a.timeMs + u * span, value: at(u) });
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
const end = { timeMs: a.timeMs + u1 * span, value: at(u1) };
|
|
259
|
+
if (kept !== null && kept !== undefined)
|
|
260
|
+
end.easing = kept;
|
|
261
|
+
out.push(end);
|
|
262
|
+
return out;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* The part of a lane between `from` and `to`, as points: the first sits at
|
|
266
|
+
* `from` and the last at `to`, and the curve between them is the lane's own,
|
|
267
|
+
* easing kept (D60). `points` is sorted and not empty.
|
|
268
|
+
*/
|
|
269
|
+
export function lanePiece(points, from, to) {
|
|
270
|
+
const out = [{ timeMs: from, value: automationValueAt(points, from) }];
|
|
271
|
+
const first = points[0];
|
|
272
|
+
if (first.timeMs > from + EPS && first.timeMs <= to + EPS) {
|
|
273
|
+
out.push({ timeMs: first.timeMs, value: first.value });
|
|
274
|
+
}
|
|
275
|
+
for (let i = 0; i + 1 < points.length; i += 1) {
|
|
276
|
+
const a = points[i];
|
|
277
|
+
const b = points[i + 1];
|
|
278
|
+
const span = b.timeMs - a.timeMs;
|
|
279
|
+
if (span <= EPS)
|
|
280
|
+
continue;
|
|
281
|
+
const lo = Math.max(a.timeMs, from);
|
|
282
|
+
const hi = Math.min(b.timeMs, to);
|
|
283
|
+
if (hi <= lo + EPS)
|
|
284
|
+
continue;
|
|
285
|
+
out.push(...slicePoints(a, b, (lo - a.timeMs) / span, (hi - a.timeMs) / span));
|
|
286
|
+
}
|
|
287
|
+
if (out[out.length - 1].timeMs < to - EPS) {
|
|
288
|
+
out.push({ timeMs: to, value: automationValueAt(points, to) });
|
|
289
|
+
}
|
|
290
|
+
return out;
|
|
291
|
+
}
|
|
292
|
+
export const shiftPoints = (points, by) => points.map((p) => ({ ...p, timeMs: Math.max(0, p.timeMs + by) }));
|
|
293
|
+
/**
|
|
294
|
+
* A lane after time `len` opens at `at`. Points at or after `at` move later.
|
|
295
|
+
* A segment that crosses `at` would stretch, so the lane holds the value it has
|
|
296
|
+
* at `at` across the gap, and nothing before `at` changes (D60). Each side of
|
|
297
|
+
* a cut segment keeps its easing.
|
|
298
|
+
*/
|
|
299
|
+
export function laneAfterInsert(points, at, len) {
|
|
300
|
+
const sorted = [...points].sort(byTime);
|
|
301
|
+
const crosses = sorted.some((p) => p.timeMs < at - EPS) && sorted.some((p) => p.timeMs >= at - EPS);
|
|
302
|
+
if (!crosses) {
|
|
303
|
+
return sorted.map((p) => (p.timeMs >= at - EPS ? { ...p, timeMs: p.timeMs + len } : p));
|
|
304
|
+
}
|
|
305
|
+
const left = lanePiece(sorted, sorted[0].timeMs, at);
|
|
306
|
+
const right = lanePiece(sorted, at, Math.max(at, sorted[sorted.length - 1].timeMs));
|
|
307
|
+
return [...left, ...shiftPoints(right, len)];
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* A lane after `[from, to)` closes. Points inside go. A lane that crosses or
|
|
311
|
+
* holds the range joins the value at `from` to the value at `to`, so nothing
|
|
312
|
+
* outside the range changes (D60). Each side keeps the easing of a cut segment.
|
|
313
|
+
*/
|
|
314
|
+
function laneAfterDelete(points, from, to) {
|
|
315
|
+
const len = to - from;
|
|
316
|
+
const sorted = [...points].sort(byTime);
|
|
317
|
+
const touches = sorted.some((p) => p.timeMs < to - EPS) && sorted.some((p) => p.timeMs >= from - EPS);
|
|
318
|
+
if (!touches) {
|
|
319
|
+
const kept = [];
|
|
320
|
+
for (const p of sorted) {
|
|
321
|
+
if (p.timeMs < from - EPS)
|
|
322
|
+
kept.push(p);
|
|
323
|
+
else if (p.timeMs >= to - EPS)
|
|
324
|
+
kept.push({ ...p, timeMs: Math.max(0, p.timeMs - len) });
|
|
325
|
+
}
|
|
326
|
+
return kept;
|
|
327
|
+
}
|
|
328
|
+
const first = sorted[0].timeMs;
|
|
329
|
+
const last = sorted[sorted.length - 1].timeMs;
|
|
330
|
+
const vFrom = automationValueAt(sorted, from);
|
|
331
|
+
const vTo = automationValueAt(sorted, to);
|
|
332
|
+
const left = from > first + EPS
|
|
333
|
+
? lanePiece(sorted, first, from)
|
|
334
|
+
: [{ timeMs: from, value: vFrom }];
|
|
335
|
+
const same = Math.abs(vFrom - vTo) <= 1e-9;
|
|
336
|
+
if (to <= last + EPS) {
|
|
337
|
+
const right = shiftPoints(lanePiece(sorted, to, last), -len);
|
|
338
|
+
// A stable order keeps the join pair, `vFrom` first.
|
|
339
|
+
return [...left, ...(same ? right.slice(1) : right)];
|
|
340
|
+
}
|
|
341
|
+
if (!same)
|
|
342
|
+
left.push({ timeMs: from, value: vTo });
|
|
343
|
+
return left;
|
|
344
|
+
}
|
|
345
|
+
/** The lane for a copy of `[from, to)` that goes in at `to` (D60). */
|
|
346
|
+
function laneAfterDuplicate(points, from, to) {
|
|
347
|
+
const len = to - from;
|
|
348
|
+
const sorted = [...points].sort(byTime);
|
|
349
|
+
const crosses = sorted.some((p) => p.timeMs < to - EPS) && sorted.some((p) => p.timeMs >= from - EPS);
|
|
350
|
+
if (!crosses) {
|
|
351
|
+
return sorted.map((p) => (p.timeMs >= to - EPS ? { ...p, timeMs: p.timeMs + len } : p));
|
|
352
|
+
}
|
|
353
|
+
const last = sorted[sorted.length - 1].timeMs;
|
|
354
|
+
const head = lanePiece(sorted, sorted[0].timeMs, to);
|
|
355
|
+
const copy = shiftPoints(lanePiece(sorted, from, to), len);
|
|
356
|
+
const tail = last >= to - EPS ? shiftPoints(lanePiece(sorted, to, last), len) : [];
|
|
357
|
+
const joined = Math.abs(copy[0].value - head[head.length - 1].value) <= 1e-9;
|
|
358
|
+
return [...head, ...(joined ? copy.slice(1) : copy), ...tail.slice(1)];
|
|
359
|
+
}
|
|
360
|
+
export function insertGap(scope, at, len, tracks, stats, atTickOverride, skipAutomation = false) {
|
|
361
|
+
cutAllCrossing(scope, at, tracks, stats);
|
|
362
|
+
for (const clip of scope.clips) {
|
|
363
|
+
// A group is never cut. It grows so its children stay inside its window.
|
|
364
|
+
if (clip.mediaType === "group" &&
|
|
365
|
+
onTracks(clip, tracks) &&
|
|
366
|
+
clip.startMs < at - EPS &&
|
|
367
|
+
endOf(clip) > at + EPS) {
|
|
368
|
+
clip.durationMs += len;
|
|
369
|
+
scope.touch(clip.id);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
for (const clip of scope.clips) {
|
|
373
|
+
if (onTracks(clip, tracks) && clip.startMs >= at - EPS) {
|
|
374
|
+
clip.startMs += len;
|
|
375
|
+
scope.touch(clip.id);
|
|
376
|
+
stats.movedClips += 1;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
if (tracks === null) {
|
|
380
|
+
for (const marker of scope.state.markers) {
|
|
381
|
+
const duration = marker.durationMs ?? 0;
|
|
382
|
+
if (marker.timeMs >= at - EPS) {
|
|
383
|
+
marker.timeMs += len;
|
|
384
|
+
stats.movedMarkers += 1;
|
|
385
|
+
}
|
|
386
|
+
else if (duration > 0 && marker.timeMs + duration > at + EPS) {
|
|
387
|
+
marker.durationMs = duration + len;
|
|
388
|
+
stats.movedMarkers += 1;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
const atTick = atTickOverride ?? chordTicks(scope, at);
|
|
393
|
+
const lenTick = lengthTicks(scope, len);
|
|
394
|
+
for (const track of scope.tracks) {
|
|
395
|
+
if (tracks !== null && !tracks.has(track.id))
|
|
396
|
+
continue;
|
|
397
|
+
if (track.chords) {
|
|
398
|
+
const used = new Set(track.chords.map((c) => c.id));
|
|
399
|
+
const next = [];
|
|
400
|
+
for (const chord of track.chords) {
|
|
401
|
+
if (chord.startTick >= atTick) {
|
|
402
|
+
next.push({ ...chord, startTick: chord.startTick + lenTick });
|
|
403
|
+
stats.changedChords += 1;
|
|
404
|
+
}
|
|
405
|
+
else if (chord.startTick + chord.durationTick > atTick) {
|
|
406
|
+
next.push({ ...chord, durationTick: atTick - chord.startTick });
|
|
407
|
+
next.push({
|
|
408
|
+
...chord,
|
|
409
|
+
id: newChordId(used),
|
|
410
|
+
startTick: atTick + lenTick,
|
|
411
|
+
durationTick: chord.startTick + chord.durationTick - atTick
|
|
412
|
+
});
|
|
413
|
+
stats.changedChords += 1;
|
|
414
|
+
}
|
|
415
|
+
else {
|
|
416
|
+
next.push(chord);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
track.chords = next;
|
|
420
|
+
}
|
|
421
|
+
if (skipAutomation)
|
|
422
|
+
continue;
|
|
423
|
+
for (const lane of track.automation ?? []) {
|
|
424
|
+
lane.points = laneAfterInsert(lane.points, at, len);
|
|
425
|
+
stats.movedAutomationPoints += lane.points.filter((p) => p.timeMs >= at - EPS).length;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
function removeRange(scope, from, to, tracks, stats) {
|
|
430
|
+
const len = to - from;
|
|
431
|
+
const lockedTracks = new Set(scope.tracks.filter((t) => t.locked).map((t) => t.id));
|
|
432
|
+
const locked = scope.clips.filter((c) => onTracks(c, tracks) &&
|
|
433
|
+
c.startMs < to - EPS &&
|
|
434
|
+
endOf(c) > from + EPS &&
|
|
435
|
+
(c.locked || lockedTracks.has(c.trackId)));
|
|
436
|
+
if (locked.length > 0) {
|
|
437
|
+
const names = locked.map((c) => `"${c.name}" (${c.id})`).join(", ");
|
|
438
|
+
throw new Error(`The range cuts or removes locked clips: ${names}. Unlock them first, or choose a range that avoids them.`);
|
|
439
|
+
}
|
|
440
|
+
const fromTick = chordTicks(scope, from);
|
|
441
|
+
const lenTick = lengthTicks(scope, len);
|
|
442
|
+
const toTick = fromTick + lenTick;
|
|
443
|
+
const lockedContent = scope.tracks.filter((t) => t.locked &&
|
|
444
|
+
(tracks === null || tracks.has(t.id)) &&
|
|
445
|
+
((t.chords ?? []).some((c) => c.startTick < toTick && c.startTick + c.durationTick > fromTick) ||
|
|
446
|
+
(t.automation ?? []).some((l) => l.points.some((p) => p.timeMs >= from - EPS && p.timeMs < to - EPS) ||
|
|
447
|
+
// A ramp that crosses the range has no point inside, and still changes.
|
|
448
|
+
(l.points.some((p) => p.timeMs < from - EPS) &&
|
|
449
|
+
l.points.some((p) => p.timeMs >= to - EPS)))));
|
|
450
|
+
if (lockedContent.length > 0) {
|
|
451
|
+
const names = lockedContent.map((t) => `"${t.name}" (${t.id})`).join(", ");
|
|
452
|
+
throw new Error(`The range holds chords or automation on locked tracks: ${names}. Unlock them first, or choose a range that avoids them.`);
|
|
453
|
+
}
|
|
454
|
+
// Without `trackIds` the beat-one origin moves with the content. With them it
|
|
455
|
+
// stays, so a chord cannot follow its clips to a time before it.
|
|
456
|
+
if (tracks !== null && resolveTempo(scope.state).offsetMs > from + EPS) {
|
|
457
|
+
const behind = scope.tracks.filter((t) => tracks.has(t.id) &&
|
|
458
|
+
(t.chords ?? []).some((c) => {
|
|
459
|
+
const end = c.startTick + c.durationTick;
|
|
460
|
+
if (end <= fromTick)
|
|
461
|
+
return false;
|
|
462
|
+
const start = c.startTick >= toTick ? c.startTick - lenTick : Math.min(c.startTick, fromTick);
|
|
463
|
+
const keeps = c.startTick >= toTick || (end > toTick ? end - lenTick : fromTick) > start;
|
|
464
|
+
return keeps && start < 0;
|
|
465
|
+
}));
|
|
466
|
+
if (behind.length > 0) {
|
|
467
|
+
const names = behind.map((t) => `"${t.name}" (${t.id})`).join(", ");
|
|
468
|
+
throw new Error(`The range starts before beat one (tempo.offsetMs), and chords on ${names} cannot move there. Delete across all tracks, or choose a range after beat one.`);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
cutAllCrossing(scope, from, tracks, stats);
|
|
472
|
+
cutAllCrossing(scope, to, tracks, stats);
|
|
473
|
+
const removed = new Set();
|
|
474
|
+
for (const clip of scope.clips) {
|
|
475
|
+
if (!onTracks(clip, tracks) || endOf(clip) <= from + EPS)
|
|
476
|
+
continue;
|
|
477
|
+
if (clip.startMs >= to - EPS) {
|
|
478
|
+
clip.startMs = Math.max(0, clip.startMs - len);
|
|
479
|
+
scope.touch(clip.id);
|
|
480
|
+
stats.movedClips += 1;
|
|
481
|
+
}
|
|
482
|
+
else if (clip.startMs >= from - EPS && endOf(clip) <= to + EPS) {
|
|
483
|
+
removed.add(clip.id);
|
|
484
|
+
}
|
|
485
|
+
else if (clip.mediaType === "group") {
|
|
486
|
+
// A group is never cut, so it shrinks by the part of the range it holds.
|
|
487
|
+
const newStart = Math.min(clip.startMs, from);
|
|
488
|
+
const newEnd = endOf(clip) > to ? endOf(clip) - len : from;
|
|
489
|
+
clip.startMs = newStart;
|
|
490
|
+
clip.durationMs = Math.max(0, newEnd - newStart);
|
|
491
|
+
scope.touch(clip.id);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
for (const c of scope.clips) {
|
|
495
|
+
// A removed group releases the children that stay, and they keep its look.
|
|
496
|
+
if (c.parentId === undefined || !removed.has(c.parentId) || removed.has(c.id))
|
|
497
|
+
continue;
|
|
498
|
+
let parentId = c.parentId;
|
|
499
|
+
while (parentId !== undefined && removed.has(parentId)) {
|
|
500
|
+
const group = scope.clips.find((g) => g.id === parentId);
|
|
501
|
+
const problem = groupBakeProblem(group, c);
|
|
502
|
+
if (problem !== undefined) {
|
|
503
|
+
throw new Error(`Clip "${c.name}" belongs to group "${group.name}" (${group.id}), which the range removes, and ${problem}. Add the clip's track to \`trackIds\`, or choose a range that keeps the group.`);
|
|
504
|
+
}
|
|
505
|
+
bakeGroupInto(c, group, scope.state);
|
|
506
|
+
parentId = group.parentId;
|
|
507
|
+
}
|
|
508
|
+
if (parentId === undefined)
|
|
509
|
+
delete c.parentId;
|
|
510
|
+
else
|
|
511
|
+
c.parentId = parentId;
|
|
512
|
+
scope.touch(c.id);
|
|
513
|
+
}
|
|
514
|
+
if (removed.size > 0) {
|
|
515
|
+
for (const c of scope.clips) {
|
|
516
|
+
if (removed.has(c.id) && c.linkId !== undefined)
|
|
517
|
+
stats.links.add(c.linkId);
|
|
518
|
+
}
|
|
519
|
+
scope.clips = scope.clips.filter((c) => !removed.has(c.id));
|
|
520
|
+
const droppedMediaTracks = new Set(scope.mediaTracks.filter((t) => removed.has(t.clipId)).map((t) => t.id));
|
|
521
|
+
scope.mediaTracks = scope.mediaTracks.filter((t) => !removed.has(t.clipId));
|
|
522
|
+
for (const c of scope.clips) {
|
|
523
|
+
if (c.trackBinding && droppedMediaTracks.has(c.trackBinding.trackId)) {
|
|
524
|
+
delete c.trackBinding;
|
|
525
|
+
scope.touch(c.id);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
scope.state.selectedClipIds = scope.state.selectedClipIds.filter((id) => !removed.has(id));
|
|
529
|
+
scope.touch(...removed);
|
|
530
|
+
stats.removedClips.push(...removed);
|
|
531
|
+
}
|
|
532
|
+
if (tracks === null) {
|
|
533
|
+
const keep = [];
|
|
534
|
+
for (const marker of scope.state.markers) {
|
|
535
|
+
const duration = marker.durationMs ?? 0;
|
|
536
|
+
const start = marker.timeMs;
|
|
537
|
+
const end = start + duration;
|
|
538
|
+
if (start >= to - EPS) {
|
|
539
|
+
marker.timeMs = Math.max(0, marker.timeMs - len);
|
|
540
|
+
stats.movedMarkers += 1;
|
|
541
|
+
}
|
|
542
|
+
else if (duration > 0 && end > from + EPS) {
|
|
543
|
+
const newStart = Math.min(start, from);
|
|
544
|
+
const newEnd = end > to ? end - len : from;
|
|
545
|
+
stats.movedMarkers += 1;
|
|
546
|
+
if (newEnd - newStart <= EPS)
|
|
547
|
+
continue;
|
|
548
|
+
marker.timeMs = newStart;
|
|
549
|
+
marker.durationMs = newEnd - newStart;
|
|
550
|
+
}
|
|
551
|
+
else if (duration === 0 && start >= from - EPS) {
|
|
552
|
+
stats.movedMarkers += 1;
|
|
553
|
+
continue;
|
|
554
|
+
}
|
|
555
|
+
keep.push(marker);
|
|
556
|
+
}
|
|
557
|
+
scope.state.markers = keep;
|
|
558
|
+
}
|
|
559
|
+
// Ticks count from `tempo.offsetMs`. A range that starts before it moves the
|
|
560
|
+
// beat-one origin with the content, so chords keep their place against clips.
|
|
561
|
+
const tempo = resolveTempo(scope.state);
|
|
562
|
+
let originShiftTicks = 0;
|
|
563
|
+
if (tracks === null && tempo.offsetMs > from + EPS) {
|
|
564
|
+
const newOffset = tempo.offsetMs >= to - EPS ? tempo.offsetMs - len : from;
|
|
565
|
+
originShiftTicks = Math.round(msToTicks(tempo.offsetMs - newOffset, tempo.bpm));
|
|
566
|
+
scope.state.tempo = { ...tempo, offsetMs: newOffset };
|
|
567
|
+
}
|
|
568
|
+
for (const track of scope.tracks) {
|
|
569
|
+
if (tracks !== null && !tracks.has(track.id))
|
|
570
|
+
continue;
|
|
571
|
+
if (track.chords) {
|
|
572
|
+
const next = [];
|
|
573
|
+
for (const chord of track.chords) {
|
|
574
|
+
const start = chord.startTick;
|
|
575
|
+
const end = start + chord.durationTick;
|
|
576
|
+
if (end <= fromTick) {
|
|
577
|
+
next.push(chord);
|
|
578
|
+
}
|
|
579
|
+
else if (start >= toTick) {
|
|
580
|
+
next.push({
|
|
581
|
+
...chord,
|
|
582
|
+
startTick: Math.max(0, start - lenTick + originShiftTicks)
|
|
583
|
+
});
|
|
584
|
+
stats.changedChords += 1;
|
|
585
|
+
}
|
|
586
|
+
else {
|
|
587
|
+
const newStart = Math.min(start, fromTick);
|
|
588
|
+
const newEnd = end > toTick ? end - lenTick : fromTick;
|
|
589
|
+
stats.changedChords += 1;
|
|
590
|
+
if (newEnd - newStart > 0) {
|
|
591
|
+
next.push({
|
|
592
|
+
...chord,
|
|
593
|
+
startTick: Math.max(0, newStart + originShiftTicks),
|
|
594
|
+
durationTick: newEnd - newStart
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
track.chords = next;
|
|
600
|
+
}
|
|
601
|
+
for (const lane of track.automation ?? []) {
|
|
602
|
+
stats.movedAutomationPoints += lane.points.filter((p) => p.timeMs >= from - EPS).length;
|
|
603
|
+
lane.points = laneAfterDelete(lane.points, from, to);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
export function summary(stats, extra) {
|
|
608
|
+
return {
|
|
609
|
+
ok: true,
|
|
610
|
+
...extra,
|
|
611
|
+
splitClips: stats.splitClips,
|
|
612
|
+
movedClips: stats.movedClips,
|
|
613
|
+
removedClipIds: stats.removedClips,
|
|
614
|
+
copiedClips: stats.copiedClips,
|
|
615
|
+
movedMarkers: stats.movedMarkers,
|
|
616
|
+
changedChords: stats.changedChords,
|
|
617
|
+
movedAutomationPoints: stats.movedAutomationPoints
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
export function runInsertTime(scope, op) {
|
|
621
|
+
const at = resolveBarTime(scope.state, op, op.atMs, "atMs");
|
|
622
|
+
if (at === undefined)
|
|
623
|
+
throw new Error("Send `atBar` or `atMs`.");
|
|
624
|
+
if (op.bars !== undefined && op.ms !== undefined) {
|
|
625
|
+
throw new Error("Send `bars` or `ms`, not both.");
|
|
626
|
+
}
|
|
627
|
+
const len = op.ms ?? (op.bars !== undefined ? op.bars * barLengthMs(scope) : undefined);
|
|
628
|
+
if (len === undefined)
|
|
629
|
+
throw new Error("Send `bars` or `ms` for the length.");
|
|
630
|
+
if (!Number.isFinite(len) || len <= 0) {
|
|
631
|
+
throw new Error("The inserted time must be longer than 0 ms.");
|
|
632
|
+
}
|
|
633
|
+
const tracks = resolveTargetTracks(scope, op.trackIds);
|
|
634
|
+
const stats = newStats();
|
|
635
|
+
assertNoLockedCrossing(scope, at, tracks);
|
|
636
|
+
const enclosing = enclosingGroups(scope);
|
|
637
|
+
insertGap(scope, at, len, tracks, stats);
|
|
638
|
+
reencloseGroups(scope, enclosing);
|
|
639
|
+
pruneSingletonLinks(scope, stats.links);
|
|
640
|
+
return summary(stats, { atMs: at, lengthMs: len });
|
|
641
|
+
}
|
|
642
|
+
export function runDeleteTime(scope, op) {
|
|
643
|
+
const { from, to } = resolveRange(scope, op);
|
|
644
|
+
const tracks = resolveTargetTracks(scope, op.trackIds);
|
|
645
|
+
const stats = newStats();
|
|
646
|
+
const enclosing = enclosingGroups(scope);
|
|
647
|
+
removeRange(scope, from, to, tracks, stats);
|
|
648
|
+
reencloseGroups(scope, enclosing);
|
|
649
|
+
pruneSingletonLinks(scope, stats.links);
|
|
650
|
+
return summary(stats, { fromMs: from, toMs: to, lengthMs: to - from });
|
|
651
|
+
}
|
|
652
|
+
/** The parts of `clip` that lie inside `[from, to)`, as detached copies. */
|
|
653
|
+
export function clipToRange(scope, clip, from, to) {
|
|
654
|
+
if (!(clip.startMs < to - EPS && endOf(clip) > from + EPS))
|
|
655
|
+
return [];
|
|
656
|
+
const { bpm, offsetMs: gridOffsetMs } = resolveTempo(scope.state);
|
|
657
|
+
const clone = structuredClone(clip);
|
|
658
|
+
const loopMs = activeLoopMs(clone);
|
|
659
|
+
const pieces = clone.mediaType !== "group" && loopMs !== undefined
|
|
660
|
+
? unrollLoopedClip(clone, bpm, loopMs, {
|
|
661
|
+
newId: () => scope.ctx.newId("clip"),
|
|
662
|
+
gridOffsetMs
|
|
663
|
+
})
|
|
664
|
+
: [clone];
|
|
665
|
+
const out = [];
|
|
666
|
+
if (clone.mediaType === "group") {
|
|
667
|
+
const start = Math.max(clone.startMs, from);
|
|
668
|
+
const end = Math.min(endOf(clone), to);
|
|
669
|
+
clone.startMs = start;
|
|
670
|
+
clone.durationMs = end - start;
|
|
671
|
+
if (clone.durationMs <= EPS)
|
|
672
|
+
return [];
|
|
673
|
+
// The window keeps only its own stretch of the group's curves and animations.
|
|
674
|
+
const offsetMs = start - clip.startMs;
|
|
675
|
+
if (clip.paramCurves && clip.durationMs > 0) {
|
|
676
|
+
clone.paramCurves = sliceParamCurves(clip.paramCurves, offsetMs / clip.durationMs, (offsetMs + clone.durationMs) / clip.durationMs, clip.durationMs);
|
|
677
|
+
}
|
|
678
|
+
if (clip.animations) {
|
|
679
|
+
clone.animations = animationsForWindow(clip.animations, {
|
|
680
|
+
offsetMs,
|
|
681
|
+
durationMs: clone.durationMs,
|
|
682
|
+
totalMs: clip.durationMs,
|
|
683
|
+
sourceFromMs: 0,
|
|
684
|
+
sourceToMs: clone.durationMs
|
|
685
|
+
}, true);
|
|
686
|
+
}
|
|
687
|
+
return [{ sourceId: clip.id, piece: clone }];
|
|
688
|
+
}
|
|
689
|
+
for (const start of pieces) {
|
|
690
|
+
let cur = start;
|
|
691
|
+
if (cur.mediaType !== "group") {
|
|
692
|
+
if (cur.startMs < from - EPS && endOf(cur) > from + EPS) {
|
|
693
|
+
cur = splitNamed(cur, from, bpm, gridOffsetMs)[1];
|
|
694
|
+
}
|
|
695
|
+
if (endOf(cur) > to + EPS && cur.startMs < to - EPS) {
|
|
696
|
+
cur = splitNamed(cur, to, bpm, gridOffsetMs)[0];
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
if (cur.startMs >= from - EPS && endOf(cur) <= to + EPS && cur.durationMs > EPS) {
|
|
700
|
+
out.push({ sourceId: clip.id, piece: cur });
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
return out;
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* Give detached range copies fresh ids, links, media tracks and parents.
|
|
707
|
+
* `shiftMs` moves them in time. A parent that is not copied is written into the
|
|
708
|
+
* copy, or the call refuses when that group cannot be written into a child.
|
|
709
|
+
*/
|
|
710
|
+
export function materializeCopies(scope, copies, opts) {
|
|
711
|
+
const freshIds = new Map();
|
|
712
|
+
for (const { sourceId } of copies) {
|
|
713
|
+
if (!freshIds.has(sourceId))
|
|
714
|
+
freshIds.set(sourceId, scope.ctx.newId("clip"));
|
|
715
|
+
}
|
|
716
|
+
const linkCounts = new Map();
|
|
717
|
+
for (const { piece } of copies) {
|
|
718
|
+
if (piece.linkId !== undefined) {
|
|
719
|
+
linkCounts.set(piece.linkId, (linkCounts.get(piece.linkId) ?? 0) + 1);
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
const freshLinks = new Map();
|
|
723
|
+
const made = [];
|
|
724
|
+
const newMediaTracks = [];
|
|
725
|
+
const firstCloneOf = new Map();
|
|
726
|
+
const clonesOf = new Map();
|
|
727
|
+
for (const { sourceId, piece } of copies) {
|
|
728
|
+
// One source can give several pieces (an unrolled loop): only the first keeps the mapped id.
|
|
729
|
+
const id = made.some((m) => m.id === freshIds.get(sourceId)) ? scope.ctx.newId("clip") : freshIds.get(sourceId);
|
|
730
|
+
piece.id = id;
|
|
731
|
+
piece.startMs += opts.shiftMs;
|
|
732
|
+
piece.locked = false;
|
|
733
|
+
if (piece.linkId !== undefined && (linkCounts.get(piece.linkId) ?? 0) >= 2) {
|
|
734
|
+
let fresh = freshLinks.get(piece.linkId);
|
|
735
|
+
if (fresh === undefined) {
|
|
736
|
+
fresh = scope.ctx.newId("link");
|
|
737
|
+
freshLinks.set(piece.linkId, fresh);
|
|
738
|
+
}
|
|
739
|
+
piece.linkId = fresh;
|
|
740
|
+
}
|
|
741
|
+
else {
|
|
742
|
+
delete piece.linkId;
|
|
743
|
+
}
|
|
744
|
+
const window = clipSourceWindowMs(piece);
|
|
745
|
+
const clones = new Map();
|
|
746
|
+
for (const t of opts.preMediaTracks) {
|
|
747
|
+
if (t.clipId !== sourceId)
|
|
748
|
+
continue;
|
|
749
|
+
const clone = {
|
|
750
|
+
...resliceMediaTrackSamples(t, window.fromMs, window.toMs),
|
|
751
|
+
id: scope.ctx.newId("track"),
|
|
752
|
+
clipId: piece.id
|
|
753
|
+
};
|
|
754
|
+
newMediaTracks.push(clone);
|
|
755
|
+
clones.set(t.id, clone.id);
|
|
756
|
+
if (!firstCloneOf.has(t.id))
|
|
757
|
+
firstCloneOf.set(t.id, clone.id);
|
|
758
|
+
}
|
|
759
|
+
clonesOf.set(piece, clones);
|
|
760
|
+
piece.animations =
|
|
761
|
+
piece.mediaType === "group"
|
|
762
|
+
? piece.animations
|
|
763
|
+
: piece.animations?.map((a) => ({ ...a, id: scope.ctx.newId("anim") }));
|
|
764
|
+
made.push(piece);
|
|
765
|
+
}
|
|
766
|
+
const liveTracks = new Set([...scope.mediaTracks, ...newMediaTracks].map((t) => t.id));
|
|
767
|
+
const copiedIds = new Set(made.map((m) => m.id));
|
|
768
|
+
for (const piece of made) {
|
|
769
|
+
// Parents: a copied group, or the presentation of one that stays behind.
|
|
770
|
+
let parentId = piece.parentId;
|
|
771
|
+
while (parentId !== undefined) {
|
|
772
|
+
const mapped = freshIds.get(parentId);
|
|
773
|
+
if (mapped !== undefined && copiedIds.has(mapped)) {
|
|
774
|
+
piece.parentId = mapped;
|
|
775
|
+
break;
|
|
776
|
+
}
|
|
777
|
+
const group = opts.originalById.get(parentId);
|
|
778
|
+
if (group === undefined) {
|
|
779
|
+
delete piece.parentId;
|
|
780
|
+
break;
|
|
781
|
+
}
|
|
782
|
+
const problem = groupBakeProblem(group, piece);
|
|
783
|
+
if (problem !== undefined) {
|
|
784
|
+
throw new Error(`Clip "${piece.name}" belongs to group "${group.name}" (${group.id}), which is not copied, and ${problem}. Add the group's track to \`trackIds\`.`);
|
|
785
|
+
}
|
|
786
|
+
bakeGroupInto(piece, group, scope.state);
|
|
787
|
+
parentId = group.parentId;
|
|
788
|
+
if (parentId === undefined)
|
|
789
|
+
delete piece.parentId;
|
|
790
|
+
else
|
|
791
|
+
piece.parentId = parentId;
|
|
792
|
+
}
|
|
793
|
+
const own = clonesOf.get(piece) ?? new Map();
|
|
794
|
+
const follow = (trackId) => own.get(trackId) ??
|
|
795
|
+
(liveTracks.has(trackId) ? trackId : firstCloneOf.get(trackId));
|
|
796
|
+
if (piece.trackBinding !== undefined) {
|
|
797
|
+
const target = follow(piece.trackBinding.trackId);
|
|
798
|
+
if (target === undefined)
|
|
799
|
+
delete piece.trackBinding;
|
|
800
|
+
else
|
|
801
|
+
piece.trackBinding = { ...piece.trackBinding, trackId: target };
|
|
802
|
+
}
|
|
803
|
+
if (piece.reframe?.trackId !== undefined) {
|
|
804
|
+
const target = follow(piece.reframe.trackId);
|
|
805
|
+
if (target === undefined) {
|
|
806
|
+
const { trackId: _dropped, ...rest } = piece.reframe;
|
|
807
|
+
piece.reframe = { ...rest, mode: "center" };
|
|
808
|
+
}
|
|
809
|
+
else {
|
|
810
|
+
piece.reframe = { ...piece.reframe, trackId: target };
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
return { made, newMediaTracks };
|
|
815
|
+
}
|
|
816
|
+
export function runDuplicateRange(scope, op) {
|
|
817
|
+
const { from, to } = resolveRange(scope, op);
|
|
818
|
+
const len = to - from;
|
|
819
|
+
const tracks = resolveTargetTracks(scope, op.trackIds);
|
|
820
|
+
const stats = newStats();
|
|
821
|
+
assertNoLockedCrossing(scope, to, tracks);
|
|
822
|
+
const copies = scope.clips
|
|
823
|
+
.filter((c) => onTracks(c, tracks))
|
|
824
|
+
.flatMap((c) => clipToRange(scope, c, from, to));
|
|
825
|
+
const markerCopies = tracks === null
|
|
826
|
+
? scope.state.markers.flatMap((m) => {
|
|
827
|
+
const duration = m.durationMs ?? 0;
|
|
828
|
+
if (duration > 0) {
|
|
829
|
+
const start = Math.max(m.timeMs, from);
|
|
830
|
+
const end = Math.min(m.timeMs + duration, to);
|
|
831
|
+
if (!(m.timeMs < to - EPS && m.timeMs + duration > from + EPS) || end - start <= EPS) {
|
|
832
|
+
return [];
|
|
833
|
+
}
|
|
834
|
+
return [{ ...m, timeMs: start, durationMs: end - start }];
|
|
835
|
+
}
|
|
836
|
+
return m.timeMs >= from - EPS && m.timeMs < to - EPS ? [{ ...m }] : [];
|
|
837
|
+
})
|
|
838
|
+
: [];
|
|
839
|
+
const fromTick = chordTicks(scope, from);
|
|
840
|
+
const lenTick = lengthTicks(scope, len);
|
|
841
|
+
const toTick = fromTick + lenTick;
|
|
842
|
+
const chordCopies = new Map();
|
|
843
|
+
const lanePoints = new Map();
|
|
844
|
+
for (const track of scope.tracks) {
|
|
845
|
+
if (tracks !== null && !tracks.has(track.id))
|
|
846
|
+
continue;
|
|
847
|
+
const chords = [];
|
|
848
|
+
for (const chord of track.chords ?? []) {
|
|
849
|
+
const start = Math.max(chord.startTick, fromTick);
|
|
850
|
+
const end = Math.min(chord.startTick + chord.durationTick, toTick);
|
|
851
|
+
if (end > start)
|
|
852
|
+
chords.push({ ...chord, startTick: start, durationTick: end - start });
|
|
853
|
+
}
|
|
854
|
+
if (chords.length > 0)
|
|
855
|
+
chordCopies.set(track.id, chords);
|
|
856
|
+
const lanes = new Map();
|
|
857
|
+
for (const lane of track.automation ?? []) {
|
|
858
|
+
lanes.set(lane.id, laneAfterDuplicate(lane.points, from, to));
|
|
859
|
+
}
|
|
860
|
+
if (lanes.size > 0)
|
|
861
|
+
lanePoints.set(track.id, lanes);
|
|
862
|
+
}
|
|
863
|
+
// A copy cannot go onto a locked track.
|
|
864
|
+
const lockedIds = new Set(scope.tracks.filter((t) => t.locked).map((t) => t.id));
|
|
865
|
+
const receiving = new Set([
|
|
866
|
+
...copies.map((c) => c.piece.trackId),
|
|
867
|
+
...chordCopies.keys()
|
|
868
|
+
]);
|
|
869
|
+
for (const track of scope.tracks) {
|
|
870
|
+
if ((tracks === null || tracks.has(track.id)) &&
|
|
871
|
+
(track.automation ?? []).some((l) => l.points.some((p) => p.timeMs >= from - EPS && p.timeMs < to - EPS))) {
|
|
872
|
+
receiving.add(track.id);
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
const lockedTargets = scope.tracks.filter((t) => lockedIds.has(t.id) && receiving.has(t.id));
|
|
876
|
+
if (lockedTargets.length > 0) {
|
|
877
|
+
const names = lockedTargets.map((t) => `"${t.name}" (${t.id})`).join(", ");
|
|
878
|
+
throw new Error(`The copy would write into locked tracks: ${names}. Unlock them first, or choose \`trackIds\` that avoid them.`);
|
|
879
|
+
}
|
|
880
|
+
// Each copy brings the media tracks of its source, cut to the copied window.
|
|
881
|
+
const preMediaTracks = scope.mediaTracks;
|
|
882
|
+
const originalById = new Map(scope.clips.map((c) => [c.id, c]));
|
|
883
|
+
const enclosing = enclosingGroups(scope);
|
|
884
|
+
// The copies end at `toTick`, so the tail splits and moves there too.
|
|
885
|
+
insertGap(scope, to, len, tracks, stats, toTick, true);
|
|
886
|
+
pruneSingletonLinks(scope, stats.links);
|
|
887
|
+
// Fresh ids, links and parents for the copies, then place them after the section.
|
|
888
|
+
const { made, newMediaTracks } = materializeCopies(scope, copies, {
|
|
889
|
+
shiftMs: len,
|
|
890
|
+
preMediaTracks,
|
|
891
|
+
originalById
|
|
892
|
+
});
|
|
893
|
+
scope.mediaTracks = [...scope.mediaTracks, ...newMediaTracks];
|
|
894
|
+
scope.clips.push(...made);
|
|
895
|
+
reencloseGroups(scope, enclosing);
|
|
896
|
+
scope.touch(...made.map((c) => c.id));
|
|
897
|
+
stats.copiedClips = made.length;
|
|
898
|
+
for (const marker of markerCopies) {
|
|
899
|
+
scope.state.markers.push({ ...marker, id: scope.ctx.newId("marker"), timeMs: marker.timeMs + len });
|
|
900
|
+
stats.movedMarkers += 1;
|
|
901
|
+
}
|
|
902
|
+
for (const track of scope.tracks) {
|
|
903
|
+
const chords = chordCopies.get(track.id);
|
|
904
|
+
if (chords) {
|
|
905
|
+
const used = new Set((track.chords ?? []).map((c) => c.id));
|
|
906
|
+
track.chords = [
|
|
907
|
+
...(track.chords ?? []),
|
|
908
|
+
...chords.map((c) => ({ ...c, id: newChordId(used), startTick: c.startTick + lenTick }))
|
|
909
|
+
].sort((a, b) => a.startTick - b.startTick);
|
|
910
|
+
stats.changedChords += chords.length;
|
|
911
|
+
}
|
|
912
|
+
const lanes = lanePoints.get(track.id);
|
|
913
|
+
if (lanes) {
|
|
914
|
+
for (const lane of track.automation ?? []) {
|
|
915
|
+
const pts = lanes.get(lane.id);
|
|
916
|
+
if (!pts)
|
|
917
|
+
continue;
|
|
918
|
+
stats.movedAutomationPoints += Math.max(0, pts.length - lane.points.length);
|
|
919
|
+
lane.points = pts;
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
return summary(stats, {
|
|
924
|
+
fromMs: from,
|
|
925
|
+
toMs: to,
|
|
926
|
+
lengthMs: len,
|
|
927
|
+
copiedClipIds: made.map((c) => c.id)
|
|
928
|
+
});
|
|
929
|
+
}
|
|
930
|
+
//# sourceMappingURL=sections.js.map
|