make duration proportional to length of segment

This commit is contained in:
j 2023-05-16 09:42:16 +01:00
parent fa21a06856
commit 07034fe8dc
2 changed files with 24 additions and 8 deletions

View file

@ -328,23 +328,24 @@ async function loadAnnotations(config) {
annotation.clipId = annotation.id.split('/')[0] + '/' + annotation.in.toFixed(3) + '-'+ annotation.out.toFixed(3) 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.user && annotation.user != config.user) && isInside(config, annotation)) {
if (config.split && config.split.indexOf(layer) > -1) { if (config.split && config.split.indexOf(layer) > -1) {
var parts = annotation.value.replace(/<br\ \/>/g, '<br>').replace(/<br\/>/g, '<br>').split('<br>') var parts = splitText(annotation.value, annotation.out - annotation['in'])
var duration = (annotation.out - annotation['in']) / parts.length var duration = (annotation.out - annotation['in']) / parts.length
if (parts.length > 1 && duration > 2) { if (parts.length > 1 && duration > 2) {
var position = annotation['in'] var position = annotation['in']
var part var part
while (parts.length) { while (parts.length) {
part = { ...annotation } part = { ...annotation }
var segment = parts.shift()
part.value = segment.value
part['in'] = position 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.clipId = part.id.split('/')[0] + '/' + part.in.toFixed(3) + '-'+ part.out.toFixed(3)
part.colorId = annotation.clipId part.colorId = annotation.clipId
part.value = parts.shift()
if (parts.length) {
position = part['out'] position = part['out']
} else {
position = annotation.out
}
annotations.push(part) annotations.push(part)
} }
} }

View file

@ -137,3 +137,18 @@ function onVisibilityChange(el, callback) {
function parseTime(value) { function parseTime(value) {
return value.split(":").map(p => parseFloat(p)).reduce((c, p) => { return c*60 + p}, 0) return value.split(":").map(p => parseFloat(p)).reduce((c, p) => { return c*60 + p}, 0)
} }
function splitText(text, duration) {
var parts = []
text = text.replace(/<br\ \/>/g, '<br>').replace(/<br\/>/g, '<br>')
var length = text.replace(/<br>/g, '').length
var texts = text.split('<br>')
texts.forEach(part => {
parts.push({
value: part.trim(),
duration: duration / length * part.length
})
})
return parts
}