1/*
2 * Copyright (c) 2016-2021 Meltytech, LLC
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18import QtQuick 2.12
19import QtQuick.Controls 2.12
20import QtQuick.Layouts 1.12
21import QtQml 2.12
22import Shotcut.Controls 1.0 as Shotcut
23
24Rectangle {
25    id: root
26
27    property bool enableIntegrated: false
28    property bool enableShortterm: false
29    property bool enableMomentary: false
30    property bool enableRange: false
31    property bool enablePeak: false
32    property bool enableTruePeak: false
33    property double integrated: -100
34    property double shortterm: -100
35    property double momentary: -100
36    property double range: -1
37    property double peak: -100
38    property double maxPeak: -100
39    property double truePeak: -100
40    property double maxTruePeak: -100
41    property int orientation: Qt.Vertical
42
43    color: activePalette.window
44    state: orientation == Qt.Horizontal ? "landscape" : "portrait"
45    SystemPalette { id: activePalette }
46
47    TextMetrics {
48        id: textMetrics
49        font: momentaryLabel.font
50        text: "-00.0"
51    }
52
53    GridLayout {
54        id: grid
55        anchors.fill: parent
56
57        Label {
58            Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
59            id: momentaryTitle
60            text: 'M'
61            color: activePalette.text
62            Shotcut.HoverTip {text: qsTr('Momentary Loudness.')}
63            visible: enableMomentary
64        }
65        Label {
66            Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
67            Layout.minimumWidth: textMetrics.width + 5
68            Layout.preferredWidth: Layout.minimumWidth
69            id: momentaryLabel
70            text: momentary < -99 ? '--' : momentary.toFixed(1)
71            color: activePalette.text
72            horizontalAlignment: Qt.AlignHCenter
73            visible: enableMomentary
74        }
75        Label {
76            Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
77            id: momentaryUnits
78            text: 'LUFS'
79            color: activePalette.text
80            visible: enableMomentary
81        }
82        Shotcut.Gauge {
83            Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
84            id: momentaryGauge
85            from: -50
86            value: momentary
87            to: 0
88            decimals: 0
89            visible: enableMomentary
90        }
91
92        Label {
93            Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
94            text: 'S'
95            color: activePalette.text
96            Shotcut.HoverTip {text: qsTr('Short-term Loudness.')}
97            visible: enableShortterm
98        }
99        Label {
100            Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
101            Layout.minimumWidth: textMetrics.width + 5
102            Layout.preferredWidth: Layout.minimumWidth
103            id: shorttermLabel
104            text: shortterm < -99 ? '--' : shortterm.toFixed(1)
105            color: activePalette.text
106            horizontalAlignment: Qt.AlignHCenter
107            visible: enableShortterm
108        }
109        Label {
110            Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
111            id: shorttermUnits
112            text: 'LUFS'
113            color: activePalette.text
114            visible: enableShortterm
115        }
116        Shotcut.Gauge {
117            Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
118            id: shorttermGauge
119            from: -50
120            value: shortterm
121            to: 0
122            decimals: 0
123            visible: enableShortterm
124        }
125
126        Label {
127            Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
128            text: 'I'
129            color: activePalette.text
130            Shotcut.HoverTip {text: qsTr('Integrated Loudness.')}
131            visible: enableIntegrated
132        }
133        Label {
134            Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
135            Layout.minimumWidth: textMetrics.width + 5
136            Layout.preferredWidth: Layout.minimumWidth
137            id: integratedLabel
138            text: integrated < -99 ? '--' : integrated.toFixed(1)
139            color: activePalette.text
140            horizontalAlignment: Qt.AlignHCenter
141            visible: enableIntegrated
142        }
143        Label {
144            Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
145            id: integratedUnits
146            text: 'LUFS'
147            color: activePalette.text
148            visible: enableIntegrated
149        }
150        Shotcut.Gauge {
151            Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
152            id: integratedGauge
153            from: -50
154            value: integrated
155            to: 0
156            decimals: 0
157            visible: enableIntegrated
158        }
159
160        Label {
161            Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
162            text: 'LRA'
163            color: activePalette.text
164            Shotcut.HoverTip {text: qsTr('Loudness Range.')}
165            visible: enableRange
166        }
167        Label {
168            Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
169            Layout.minimumWidth: textMetrics.width + 5
170            Layout.preferredWidth: Layout.minimumWidth
171            id: rangeLabel
172            text: range < 0 ? '--' : range.toFixed(1)
173            color: activePalette.text
174            horizontalAlignment: Qt.AlignHCenter
175            visible: enableRange
176        }
177        Label {
178            Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
179            id: rangeUnits
180            text: 'LU'
181            color: activePalette.text
182            visible: enableRange
183        }
184        Shotcut.Gauge {
185            Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
186            id: rangeGauge
187            from: 0
188            value: range
189            to: 30
190            decimals: 0
191            visible: enableRange
192        }
193
194        Label {
195            Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
196            text: 'P'
197            color: activePalette.text
198            Shotcut.HoverTip {text: qsTr('Peak.')}
199            visible: enablePeak
200        }
201        Label {
202            Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
203            Layout.minimumWidth: textMetrics.width + 5
204            Layout.preferredWidth: Layout.minimumWidth
205            id: peakLabel
206            text: peak < -99 ? '--' : peak.toFixed(1)
207            color: activePalette.text
208            horizontalAlignment: Qt.AlignHCenter
209            visible: enablePeak
210        }
211        Label {
212            Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
213            id: peakUnits
214            text: 'dBFS'
215            color: activePalette.text
216            visible: enablePeak
217        }
218        Shotcut.Gauge {
219            Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
220            id: peakGauge
221            from: -50
222            value: peak
223            to: 3
224            decimals: 0
225            visible: enablePeak
226        }
227
228        Label {
229            Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
230            text: 'TP'
231            color: activePalette.text
232            Shotcut.HoverTip {text: qsTr('True Peak.')}
233            visible: enableTruePeak
234        }
235        Label {
236            Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
237            Layout.minimumWidth: textMetrics.width + 5
238            Layout.preferredWidth: Layout.minimumWidth
239            id: truePeakLabel
240            text: truePeak < -99 ? '--' : truePeak.toFixed(1)
241            color: activePalette.text
242            horizontalAlignment: Qt.AlignHCenter
243            visible: enableTruePeak
244        }
245        Label {
246            Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
247            id: truePeakUnits
248            text: 'dBTP'
249            color: activePalette.text
250            visible: enableTruePeak
251        }
252        Shotcut.Gauge {
253            Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
254            id: truePeakGauge
255            from: -50
256            value: truePeak
257            to: 3
258            decimals: 0
259            visible: enableTruePeak
260        }
261
262        Item {
263            id: filler
264        }
265    }
266
267    states: [
268        State {
269            name: "landscape"
270            PropertyChanges { target: grid; flow: GridLayout.LeftToRight; columns: 4 }
271            PropertyChanges { target: momentaryGauge; orientation: Qt.Horizontal; Layout.fillWidth: true; Layout.fillHeight: false }
272            PropertyChanges { target: shorttermGauge; orientation: Qt.Horizontal; Layout.fillWidth: true; Layout.fillHeight: false }
273            PropertyChanges { target: integratedGauge; orientation: Qt.Horizontal; Layout.fillWidth: true; Layout.fillHeight: false }
274            PropertyChanges { target: rangeGauge; orientation: Qt.Horizontal; Layout.fillWidth: true; Layout.fillHeight: false }
275            PropertyChanges { target: peakGauge; orientation: Qt.Horizontal; Layout.fillWidth: true; Layout.fillHeight: false }
276            PropertyChanges { target: truePeakGauge; orientation: Qt.Horizontal; Layout.fillWidth: true; Layout.fillHeight: false }
277            PropertyChanges { target: filler; Layout.fillHeight: true; Layout.fillWidth: false }
278        },
279        State {
280            name: "portrait"
281            PropertyChanges { target: grid; flow: GridLayout.TopToBottom; rows: 4 }
282            PropertyChanges { target: momentaryGauge; orientation: Qt.Vertical; Layout.fillWidth: false; Layout.fillHeight: true }
283            PropertyChanges { target: shorttermGauge; orientation: Qt.Vertical; Layout.fillWidth: false; Layout.fillHeight: true }
284            PropertyChanges { target: integratedGauge; orientation: Qt.Vertical; Layout.fillWidth: false; Layout.fillHeight: true }
285            PropertyChanges { target: rangeGauge; orientation: Qt.Vertical; Layout.fillWidth: false; Layout.fillHeight: true }
286            PropertyChanges { target: peakGauge; orientation: Qt.Vertical; Layout.fillWidth: false; Layout.fillHeight: true }
287            PropertyChanges { target: truePeakGauge; orientation: Qt.Vertical; Layout.fillWidth: false; Layout.fillHeight: true }
288            PropertyChanges { target: filler; Layout.fillHeight: false; Layout.fillWidth: true }
289        }
290    ]
291}