seek fixes

This commit is contained in:
DylanSpeiser-BMD 2024-07-02 15:12:08 -07:00
parent 0294bdfed8
commit e70dddb99a

View file

@ -136,27 +136,29 @@ class BMDevice {
// Boolean parameter, true = forward, false = backwards // Boolean parameter, true = forward, false = backwards
seek(direction) { seek(direction) {
let clips = this.GETdata("/timelines/0")?.clips; let clips = this.GETdata("/timelines/0")?.clips;
let playbackData = this.GETdata("/transports/playback"); let playbackData = this.GETdata("/transports/0/playback");
let runningSum = 0; let runningSum = 0;
let currentClipFound = false;
let currentClipIndex = 0; let currentClipIndex = 0;
let clipStartingTimecodes = []; let clipStartingTimecodes = [];
let i = 0; let i = 0;
clips.forEach((clip) => { clips.forEach((clip) => {
if (runningSum+clip.frameCount > playbackData.position) { if ((runningSum+clip.frameCount > playbackData.position) && !currentClipFound) {
currentClipIndex = i; currentClipIndex = i;
currentClipFound = true;
} }
clipStartingTimecodes[i] = runningSum; clipStartingTimecodes[i] = runningSum;
runningSum += clip.frameCount; runningSum += clip.frameCount;
i++; i++;
}); });
let newClipIndex = min(max(0,(direction ? currentClipIndex+1 : currentClipIndex-1)), clips.length); let newClipIndex = Math.min(Math.max(0,(direction ? currentClipIndex+1 : currentClipIndex-1)), clips.length-1);
playbackData.position = clipStartingTimecodes[newClipIndex]; playbackData.position = clipStartingTimecodes[newClipIndex];
this.PUTdata("/transports/playback", playbackData); this.PUTdata("/transports/0/playback", playbackData);
} }
// Sets Timeline / Clip Looping // Sets Timeline / Clip Looping