Warning, /multimedia/kdenlive/src/timeline2/view/qml/ClipAudioThumbs.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 SPDX-FileCopyrightText: 2018 Jean-Baptiste Mardelle <jb@kdenlive.org>
0003 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004 */
0005
0006 import QtQuick 2.15
0007 import QtQuick.Controls 2.15
0008 import Kdenlive.Controls 1.0
0009 import QtQml.Models 2.15
0010 import com.enums 1.0
0011
0012 Row {
0013 id: waveform
0014 opacity: clipState === ClipState.Disabled ? 0.2 : 1
0015 property int maxWidth: 2048
0016 property int totalChunks: 0
0017 property bool usesOffset: false
0018 property int offset: -1
0019 property real timeScale: root.timeScale
0020 anchors.fill: parent
0021
0022 Timer {
0023 id: waveTimer
0024 interval: 50; running: false; repeat: false
0025 onTriggered: processReload()
0026 }
0027
0028 onHeightChanged: {
0029 waveTimer.start()
0030 }
0031
0032 function reload(reset) {
0033 if (reset === 0) {
0034 waveform.offset = 0
0035 waveform.totalChunks = 0
0036 waveformRepeater.model = 0
0037 }
0038 waveTimer.start()
0039 }
0040
0041 onTimeScaleChanged: {
0042 waveTimer.start()
0043 }
0044
0045 function processReload() {
0046 // This is needed to make the model have the correct count.
0047 // Model as a property expression is not working in all cases.
0048 if (!waveform.visible || !timeline.showAudioThumbnails) {
0049 return;
0050 }
0051 var total = Math.ceil(waveform.width / waveform.maxWidth)
0052 var chunks = total
0053 var updatedOffset = 0
0054 if (chunks > 10) {
0055 // Having too many chunks causes major slowdowns. In this case, we use an offset and only allow up to 20 chunks
0056 waveform.usesOffset = true
0057 updatedOffset = Math.max(0, Math.floor(clipRoot.scrollStart / waveform.maxWidth - 2))
0058 if (updatedOffset < waveform.offset || updatedOffset > (waveform.offset + 5) || total != waveform.totalChunks) {
0059 // Enforce repaint
0060 //waveformRepeater.model = 0
0061 } else {
0062 // All required audio thumbs chunks are already painted
0063 return
0064 }
0065 chunks = Math.min(10, total - updatedOffset)
0066 } else {
0067 waveform.usesOffset = false
0068 updatedOffset = 0
0069 }
0070 waveform.offset = updatedOffset
0071 waveform.totalChunks = total
0072 if (waveformRepeater.model === undefined || chunks !== waveformRepeater.model) {
0073 waveformRepeater.model = chunks
0074 } else {
0075 // Enforce repaint
0076 waveformRepeater.repaintNodes = !waveformRepeater.repaintNodes
0077 }
0078 }
0079 Item {
0080 width: waveform.offset * waveform.maxWidth
0081 height: parent.height
0082 }
0083
0084 Repeater {
0085 id: waveformRepeater
0086 property bool repaintNodes: false
0087 TimelineWaveform {
0088 width: waveform.maxWidth < waveform.width ? (index + waveform.offset == waveform.totalChunks - 1 ? waveform.width % waveform.maxWidth : waveform.maxWidth) : Math.round(waveform.width)
0089 height: waveform.height
0090 ix: index
0091 channels: clipRoot.audioChannels
0092 binId: clipRoot.binId
0093 audioStream: clipRoot.audioStream
0094 isFirstChunk: index + waveform.offset == 0
0095 isOpaque: true
0096 scaleFactor: waveform.timeScale
0097 format: timeline.audioThumbFormat
0098 normalize: timeline.audioThumbNormalize
0099 speed: clipRoot.speed
0100 waveInPoint: clipRoot.speed < 0 ? (Math.ceil((clipRoot.maxDuration - 1 - clipRoot.inPoint) * Math.abs(clipRoot.speed) - ((index + waveform.offset) * waveform.maxWidth / waveform.timeScale) * Math.abs(clipRoot.speed)) * clipRoot.audioChannels) : (Math.round((clipRoot.inPoint + ((index + waveform.offset) * waveform.maxWidth / waveform.timeScale)) * clipRoot.speed) * clipRoot.audioChannels)
0101 waveOutPoint: clipRoot.speed < 0 ? Math.max(0, (waveInPoint - Math.round(width / waveform.timeScale * Math.abs(clipRoot.speed)) * clipRoot.audioChannels)) : (waveInPoint + Math.round(width / waveform.timeScale * clipRoot.speed) * clipRoot.audioChannels)
0102 fillColor0: clipRoot.color
0103 fillColor1: root.thumbColor1
0104 fillColor2: root.thumbColor2
0105 enforceRepaint: waveformRepeater.repaintNodes
0106 }
0107 }
0108 }