ClipAudioThumbs.qml 2.77 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
import QtQuick 2.6
import QtQuick.Controls 2.2
import Kdenlive.Controls 1.0
import QtQml.Models 2.2
import com.enums 1.0

Row {
    id: waveform
    visible: clipStatus != ClipState.VideoOnly && parentTrack.isAudio && timeline.showAudioThumbnails  && !parentTrack.isMute
    opacity: clipStatus == ClipState.Disabled ? 0.2 : 1
11
    property int maxWidth: 2000
12 13
    property int innerWidth: clipRoot.width - clipRoot.border.width * 2
    anchors.fill: parent
14 15
    property int scrollStart: scrollView.flickableItem.contentX - clipRoot.modelStart * timeline.scaleFactor
    property int scrollEnd: scrollStart + scrollView.viewport.width
16 17
    property int scrollMin: scrollView.flickableItem.contentX / timeline.scaleFactor
    property int scrollMax: scrollMin + scrollView.viewport.width / timeline.scaleFactor
18

19 20
    Timer {
        id: waveTimer
21
        interval: 5; running: false; repeat: false
22 23 24
        onTriggered: processReload()
    }

25
    onScrollStartChanged: {
26
        waveTimer.start()
27
    }
28

29
    function reload() {
30 31 32 33
        waveTimer.start()
    }

    function processReload() {
34 35
        // This is needed to make the model have the correct count.
        // Model as a property expression is not working in all cases.
36 37 38
        if (!waveform.visible || !timeline.showAudioThumbnails || (waveform.scrollMin > clipRoot.modelStart + clipRoot.clipDuration) || (clipRoot.modelStart > waveform.scrollMax) || clipRoot.audioLevels == '') {
            return;
        }
39
            //var t0 = new Date();
40
            waveformRepeater.model = Math.ceil(waveform.innerWidth / waveform.maxWidth)
41 42 43
            var firstWaveRepeater = Math.max(0, Math.floor((waveform.scrollMin - clipRoot.modelStart) / (waveform.maxWidth / timeline.scaleFactor)))
            var lastWaveRepeater = Math.min(waveformRepeater.count - 1, firstWaveRepeater + Math.ceil((waveform.scrollMax - waveform.scrollMin) / (waveform.maxWidth / timeline.scaleFactor)))
            for (var i = firstWaveRepeater; i <= lastWaveRepeater; i++) {
44
                waveformRepeater.itemAt(i).update()
45 46 47 48 49 50 51 52
            }
    }

    Repeater {
        id: waveformRepeater
        TimelineWaveform {
            width: Math.min(waveform.innerWidth, waveform.maxWidth)
            height: waveform.height
53
            channels: clipRoot.audioChannels
54
            isFirstChunk: index == 0
55
            showItem: waveform.visible && (index * width) < waveform.scrollEnd && (index * width + width) > waveform.scrollStart
56
            format: timeline.audioThumbFormat
57 58
            inPoint: Math.round((clipRoot.inPoint + (index * waveform.maxWidth / clipRoot.timeScale)) * clipRoot.speed) * channels
            outPoint: inPoint + Math.round(width / clipRoot.timeScale * clipRoot.speed) * channels
59
            levels: clipRoot.audioLevels
60
            fillColor: activePalette.text
61 62 63
        }
    }
}