From 07034fe8dcf12e66533d019fd20cfa5b40693a42 Mon Sep 17 00:00:00 2001 From: j Date: Tue, 16 May 2023 09:42:16 +0100 Subject: [PATCH] make duration proportional to length of segment --- app/static/js/ascroll.js | 17 +++++++++-------- app/static/js/utils.js | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/app/static/js/ascroll.js b/app/static/js/ascroll.js index 71fe43e..c18ab4e 100644 --- a/app/static/js/ascroll.js +++ b/app/static/js/ascroll.js @@ -328,23 +328,24 @@ async function loadAnnotations(config) { annotation.clipId = annotation.id.split('/')[0] + '/' + annotation.in.toFixed(3) + '-'+ annotation.out.toFixed(3) if (!(config.user && annotation.user != config.user) && isInside(config, annotation)) { if (config.split && config.split.indexOf(layer) > -1) { - var parts = annotation.value.replace(//g, '
').replace(//g, '
').split('
') + var parts = splitText(annotation.value, annotation.out - annotation['in']) var duration = (annotation.out - annotation['in']) / parts.length if (parts.length > 1 && duration > 2) { var position = annotation['in'] var part while (parts.length) { part = { ...annotation } + var segment = parts.shift() + part.value = segment.value part['in'] = position - part['out'] = position + duration + if (parts.length) { + part['out'] = position + segment.duration + } else { + part['out'] = annotation.out + } part.clipId = part.id.split('/')[0] + '/' + part.in.toFixed(3) + '-'+ part.out.toFixed(3) part.colorId = annotation.clipId - part.value = parts.shift() - if (parts.length) { - position = part['out'] - } else { - position = annotation.out - } + position = part['out'] annotations.push(part) } } diff --git a/app/static/js/utils.js b/app/static/js/utils.js index dcec429..fcb9bd7 100644 --- a/app/static/js/utils.js +++ b/app/static/js/utils.js @@ -137,3 +137,18 @@ function onVisibilityChange(el, callback) { function parseTime(value) { return value.split(":").map(p => parseFloat(p)).reduce((c, p) => { return c*60 + p}, 0) } + + +function splitText(text, duration) { + var parts = [] + text = text.replace(//g, '
').replace(//g, '
') + var length = text.replace(/
/g, '').length + var texts = text.split('
') + texts.forEach(part => { + parts.push({ + value: part.trim(), + duration: duration / length * part.length + }) + }) + return parts +}