Debian Codegraph @

au4/src/playback/view/toolbars/playbacktoolbarlevelitem.cpp

raw
1 /*
2 * SPDX-License-Identifier: GPL-3.0-only
3 * MuseScore-CLA-applies
4 *
5 * MuseScore
6 * Music Composition & Notation
7 *
8 * Copyright (C) 2021 MuseScore BVBA and others
9 *
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 3 as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22 #include "playbacktoolbarlevelitem.h"
23
24 #include <QVariantMap>
25
26 #include "iaudiooutput.h"
27
28 using namespace au::playback;
29 using namespace au::audio;
30
31 PlaybackToolBarLevelItem::PlaybackToolBarLevelItem(const muse::ui::UiAction& action, muse::uicomponents::ToolBarItemType::Type type,
32 QObject* parent)
33 : muse::uicomponents::ToolBarItem(action, type, parent)
34 {
35 playback()->audioOutput()->playbackVolumeChanged().onReceive(this, [this](audio::volume_dbfs_t volume){
36 m_level = volume;
37 emit levelChanged();
38 });
39
40 playback()->audioOutput()->playbackSignalChanges()
41 .onResolve(this, [this](muse::async::Channel<audio::audioch_t, audio::AudioSignalVal> signalVal) {
42 signalVal.onReceive(this, [this](const audioch_t audioChNum, const audio::AudioSignalVal& newValue) {
43 if (newValue.pressure < MIN_DISPLAYED_DBFS) {
44 setAudioChannelVolumePressure(audioChNum, MIN_DISPLAYED_DBFS);
45 } else if (newValue.pressure > MAX_DISPLAYED_DBFS) {
46 setAudioChannelVolumePressure(audioChNum, MAX_DISPLAYED_DBFS);
47 } else {
48 setAudioChannelVolumePressure(audioChNum, newValue.pressure);
49 }
50 });
51 });
52
53 resetAudioChannelsVolumePressure();
54 }
55
56 int PlaybackToolBarLevelItem::level() const
57 {
58 return m_level;
59 }
60
61 void PlaybackToolBarLevelItem::setLevel(int newLevel)
62 {
63 if (m_level == newLevel) {
64 return;
65 }
66
67 playback()->audioOutput()->setPlaybackVolume(newLevel);
68 }
69
70 float PlaybackToolBarLevelItem::leftChannelPressure() const
71 {
72 return m_leftChannelPressure;
73 }
74
75 float PlaybackToolBarLevelItem::rightChannelPressure() const
76 {
77 return m_rightChannelPressure;
78 }
79
80 void PlaybackToolBarLevelItem::setLeftChannelPressure(float leftChannelPressure)
81 {
82 if (qFuzzyCompare(m_leftChannelPressure, leftChannelPressure)) {
83 return;
84 }
85
86 m_leftChannelPressure = leftChannelPressure;
87 emit leftChannelPressureChanged(m_leftChannelPressure);
88 }
89
90 void PlaybackToolBarLevelItem::setRightChannelPressure(float rightChannelPressure)
91 {
92 if (qFuzzyCompare(m_rightChannelPressure, rightChannelPressure)) {
93 return;
94 }
95
96 m_rightChannelPressure = rightChannelPressure;
97 emit rightChannelPressureChanged(m_rightChannelPressure);
98 }
99
100 void PlaybackToolBarLevelItem::setAudioChannelVolumePressure(const audio::audioch_t chNum, const float newValue)
101 {
102 if (chNum == 0) {
103 setLeftChannelPressure(newValue);
104 } else {
105 setRightChannelPressure(newValue);
106 }
107 }
108
109 void PlaybackToolBarLevelItem::resetAudioChannelsVolumePressure()
110 {
111 setLeftChannelPressure(MIN_DISPLAYED_DBFS);
112 setRightChannelPressure(MIN_DISPLAYED_DBFS);
113 }
114
115 float PlaybackToolBarLevelItem::leftRecentPeak() const
116 {
117 return m_leftRecentPeak;
118 }
119
120 void PlaybackToolBarLevelItem::setLeftRecentPeak(float newLeftRecentPeak)
121 {
122 if (qFuzzyCompare(m_leftRecentPeak, newLeftRecentPeak)) {
123 return;
124 }
125
126 m_leftRecentPeak = newLeftRecentPeak;
127 emit leftRecentPeakChanged();
128 }
129
130 float PlaybackToolBarLevelItem::leftMaxPeak() const
131 {
132 return m_leftMaxPeak;
133 }
134
135 void PlaybackToolBarLevelItem::setLeftMaxPeak(float newLeftMaxPeak)
136 {
137 if (qFuzzyCompare(m_leftMaxPeak, newLeftMaxPeak)) {
138 return;
139 }
140
141 m_leftMaxPeak = newLeftMaxPeak;
142 emit leftMaxPeakChanged();
143 }
144
145 float PlaybackToolBarLevelItem::rightRecentPeak() const
146 {
147 return m_rightRecentPeak;
148 }
149
150 void PlaybackToolBarLevelItem::setRightRecentPeak(float newRightRecentPeak)
151 {
152 if (qFuzzyCompare(m_rightRecentPeak, newRightRecentPeak)) {
153 return;
154 }
155
156 m_rightRecentPeak = newRightRecentPeak;
157 emit rightRecentPeakChanged();
158 }
159
160 float PlaybackToolBarLevelItem::rightMaxPeak() const
161 {
162 return m_rightMaxPeak;
163 }
164
165 void PlaybackToolBarLevelItem::setRightMaxPeak(float newRightMaxPeak)
166 {
167 if (qFuzzyCompare(m_rightMaxPeak, newRightMaxPeak)) {
168 return;
169 }
170
171 m_rightMaxPeak = newRightMaxPeak;
172 emit rightMaxPeakChanged();
173 }