|
| 1 | +// This file is part of Noteahead. |
| 2 | +// Copyright (C) 2026 Jussi Lind <jussi.lind@iki.fi> |
| 3 | +// |
| 4 | +// Noteahead 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 | +// Noteahead is distributed in the hope that it will be useful, |
| 9 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | +// GNU General Public License for more details. |
| 12 | +// |
| 13 | +// You should have received a copy of the GNU General Public License |
| 14 | +// along with Noteahead. If not, see <http://www.gnu.org/licenses/>. |
| 15 | + |
| 16 | +import QtQuick 2.15 |
| 17 | +import QtQuick.Controls 2.15 |
| 18 | +import QtQuick.Controls.Universal 2.15 |
| 19 | +import QtQuick.Layouts 1.15 |
| 20 | +import Noteahead 1.0 |
| 21 | + |
| 22 | +ColumnLayout { |
| 23 | + id: knobRoot |
| 24 | + property string label: "" |
| 25 | + property real value: 0 |
| 26 | + property real from: 0 |
| 27 | + property real to: 100 |
| 28 | + property string suffix: "%" |
| 29 | + property real sampleRate: 44100 |
| 30 | + property bool isHpf: false |
| 31 | + signal moved(real val) |
| 32 | + |
| 33 | + Universal.theme: Universal.Dark |
| 34 | + Universal.accent: themeService.accentColor |
| 35 | + |
| 36 | + readonly property real cutoffHz: { |
| 37 | + const normalizedCutoff = value / 100.0; |
| 38 | + if (isHpf && normalizedCutoff <= 0.001) { |
| 39 | + return 0.0; |
| 40 | + } |
| 41 | + const freq = 20.0 * Math.pow(Math.min(20000.0, sampleRate * 0.49) / 20.0, normalizedCutoff); |
| 42 | + return freq; |
| 43 | + } |
| 44 | + |
| 45 | + readonly property string freqString: { |
| 46 | + if (isHpf && value <= 0) { |
| 47 | + return "0 Hz"; |
| 48 | + } |
| 49 | + if (!isHpf && value >= 100) { |
| 50 | + return qsTr("Bypass"); |
| 51 | + } |
| 52 | + if (cutoffHz >= 1000) { |
| 53 | + return (cutoffHz / 1000.0).toFixed(1) + " kHz"; |
| 54 | + } |
| 55 | + return Math.round(cutoffHz) + " Hz"; |
| 56 | + } |
| 57 | + |
| 58 | + spacing: 2 |
| 59 | + Label { |
| 60 | + text: knobRoot.label + " (" + Math.round(knobRoot.value) + knobRoot.suffix + " / " + knobRoot.freqString + ")" |
| 61 | + font.pixelSize: 11 |
| 62 | + color: themeService.accentColor |
| 63 | + Layout.alignment: Qt.AlignHCenter |
| 64 | + } |
| 65 | + Slider { |
| 66 | + from: knobRoot.from |
| 67 | + to: knobRoot.to |
| 68 | + value: knobRoot.value |
| 69 | + stepSize: 1 |
| 70 | + Layout.fillWidth: true |
| 71 | + onMoved: () => knobRoot.moved(value) |
| 72 | + } |
| 73 | +} |
0 commit comments