LCOV - code coverage report
Current view: top level - src/playback/qml/MuseScore/Playback - mixerchannelitem.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 0.0 % 466 0
Test Date: 2026-11-19 04:14:36

            Line data    Source code
       1              : /*
       2              :  * SPDX-License-Identifier: GPL-3.0-only
       3              :  * MuseScore-Studio-CLA-applies
       4              :  *
       5              :  * MuseScore Studio
       6              :  * Music Composition & Notation
       7              :  *
       8              :  * Copyright (C) 2026 MuseScore Limited 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              : 
      23              : #include "mixerchannelitem.h"
      24              : 
      25              : #include <QPointer>
      26              : 
      27              : #include "defer.h"
      28              : #include "translation.h"
      29              : #include "log.h"
      30              : 
      31              : #include "notation/imasternotation.h" // IWYU pragma: keep
      32              : #include "notation/inotationplayback.h"
      33              : 
      34              : #include "project/inotationproject.h"
      35              : 
      36              : #include "vst/vstcommands.h"
      37              : 
      38              : using namespace mu::playback;
      39              : using namespace muse;
      40              : using namespace muse::audio;
      41              : using namespace muse::vst;
      42              : using namespace mu::project;
      43              : 
      44              : static constexpr volume_dbfs_t MAX_DISPLAYED_DBFS = volume_dbfs_t::make(0.f);   // 100%
      45              : static constexpr volume_dbfs_t MIN_DISPLAYED_DBFS = volume_dbfs_t::make(-60.f); // 0%
      46              : 
      47              : static constexpr float BALANCE_SCALING_FACTOR = 100.f;
      48              : 
      49              : static constexpr int OUTPUT_RESOURCE_COUNT_LIMIT = 4;
      50              : 
      51              : static const std::string TRACK_ID_KEY("trackId");
      52              : static const std::string RESOURCE_ID_KEY("resourceId");
      53              : static const std::string CHAIN_ORDER_KEY("chainOrder");
      54              : 
      55            0 : MixerChannelItem::MixerChannelItem(QObject* parent, Type type, bool outputOnly, audio::TrackId trackId)
      56            0 :     : QObject(parent), muse::Contextable(muse::iocCtxForQmlObject(this)),
      57            0 :     m_type(type),
      58            0 :     m_trackId(trackId),
      59            0 :     m_outputOnly(outputOnly),
      60            0 :     m_leftChannelPressure(MIN_DISPLAYED_DBFS),
      61            0 :     m_rightChannelPressure(MIN_DISPLAYED_DBFS)
      62              : {
      63            0 :     if (!m_outputOnly) {
      64            0 :         m_inputResourceItem = buildInputResourceItem();
      65              :     }
      66              : 
      67            0 :     m_panel = new ui::NavigationPanel(this);
      68            0 :     m_panel->setDirection(ui::NavigationPanel::Vertical);
      69            0 :     m_panel->setName("MixerChannelPanel " + QString::number(m_trackId));
      70            0 :     m_panel->accessible()->setName(muse::qtrc("playback", "Mixer channel panel %1").arg(m_trackId));
      71            0 :     m_panel->componentComplete();
      72              : 
      73            0 :     connect(this, &MixerChannelItem::mutedChanged, this, [this]() {
      74            0 :         if (muted()) {
      75            0 :             resetAudioChannelsVolumePressure();
      76              :         }
      77            0 :     });
      78            0 : }
      79              : 
      80            0 : MixerChannelItem::~MixerChannelItem()
      81              : {
      82            0 :     m_audioSignalChanges.disconnect(this);
      83            0 : }
      84              : 
      85            0 : MixerChannelItem::Type MixerChannelItem::type() const
      86              : {
      87            0 :     return m_type;
      88              : }
      89              : 
      90            0 : TrackId MixerChannelItem::trackId() const
      91              : {
      92            0 :     return m_trackId;
      93              : }
      94              : 
      95            0 : const mu::engraving::InstrumentTrackId& MixerChannelItem::instrumentTrackId() const
      96              : {
      97            0 :     return m_instrumentTrackId;
      98              : }
      99              : 
     100            0 : void MixerChannelItem::setInstrumentTrackId(const mu::engraving::InstrumentTrackId& instrumentTrackId)
     101              : {
     102            0 :     m_instrumentTrackId = instrumentTrackId;
     103              : 
     104            0 :     updateHasAutomationFlags();
     105            0 : }
     106              : 
     107            0 : QString MixerChannelItem::title() const
     108              : {
     109            0 :     return m_title;
     110              : }
     111              : 
     112            0 : float MixerChannelItem::leftChannelPressure() const
     113              : {
     114            0 :     return m_leftChannelPressure;
     115              : }
     116              : 
     117            0 : float MixerChannelItem::rightChannelPressure() const
     118              : {
     119            0 :     return m_rightChannelPressure;
     120              : }
     121              : 
     122            0 : float MixerChannelItem::volumeLevel() const
     123              : {
     124            0 :     return m_volumeLevel;
     125              : }
     126              : 
     127            0 : float MixerChannelItem::volumeLevelMin() const
     128              : {
     129            0 :     return audio::VOLUME_DB_MIN.raw();
     130              : }
     131              : 
     132            0 : float MixerChannelItem::volumeLevelMax() const
     133              : {
     134            0 :     return audio::VOLUME_DB_MAX.raw();
     135              : }
     136              : 
     137            0 : int MixerChannelItem::balance() const
     138              : {
     139            0 :     return m_balance;
     140              : }
     141              : 
     142            0 : int MixerChannelItem::balanceMin() const
     143              : {
     144            0 :     return audio::BALANCE_MIN.raw() * BALANCE_SCALING_FACTOR;
     145              : }
     146              : 
     147            0 : int MixerChannelItem::balanceMax() const
     148              : {
     149            0 :     return audio::BALANCE_MAX.raw() * BALANCE_SCALING_FACTOR;
     150              : }
     151              : 
     152            0 : bool MixerChannelItem::hasVolumeAutomation() const
     153              : {
     154            0 :     return m_hasVolumeAutomation;
     155              : }
     156              : 
     157            0 : bool MixerChannelItem::hasBalanceAutomation() const
     158              : {
     159            0 :     return m_hasBalanceAutomation;
     160              : }
     161              : 
     162            0 : bool MixerChannelItem::solo() const
     163              : {
     164            0 :     return m_outParams.solo;
     165              : }
     166              : 
     167            0 : bool MixerChannelItem::muted() const
     168              : {
     169            0 :     return m_outParams.muted;
     170              : }
     171              : 
     172            0 : bool MixerChannelItem::forceMute() const
     173              : {
     174            0 :     return m_outParams.forceMute;
     175              : }
     176              : 
     177            0 : muse::ui::NavigationPanel* MixerChannelItem::panel() const
     178              : {
     179            0 :     return m_panel;
     180              : }
     181              : 
     182            0 : void MixerChannelItem::setPanelOrder(int panelOrder)
     183              : {
     184            0 :     m_panel->setOrder(panelOrder);
     185            0 : }
     186              : 
     187            0 : void MixerChannelItem::setPanelSection(muse::ui::INavigationSection* section)
     188              : {
     189            0 :     m_panel->setSection(section);
     190            0 : }
     191              : 
     192            0 : void MixerChannelItem::setOutputResourceItemCount(size_t count)
     193              : {
     194            0 :     IF_ASSERT_FAILED(count >= m_outParams.fxChain.size()) {
     195            0 :         return;
     196              :     }
     197              : 
     198            0 :     count = std::min(count, static_cast<size_t>(OUTPUT_RESOURCE_COUNT_LIMIT));
     199            0 :     size_t itemsSize = static_cast<size_t>(m_outputResourceItems.size());
     200              : 
     201            0 :     if (itemsSize == count) {
     202            0 :         return;
     203              :     }
     204              : 
     205            0 :     if (itemsSize < count) {
     206            0 :         addBlankSlots(count - itemsSize);
     207            0 :     } else if (itemsSize > count) {
     208            0 :         removeBlankSlotsFromEnd(itemsSize - count);
     209              :     }
     210              : }
     211              : 
     212            0 : void MixerChannelItem::addBlankSlots(size_t count)
     213              : {
     214            0 :     TRACEFUNC;
     215              : 
     216            0 :     if (count == 0) {
     217            0 :         return;
     218              :     }
     219              : 
     220            0 :     for (size_t i = 0; i < count; ++i) {
     221            0 :         AudioFxParams params;
     222            0 :         params.chainOrder = resolveNewBlankOutputResourceItemOrder();
     223            0 :         m_outputResourceItems.insert(params.chainOrder, buildOutputResourceItem(params));
     224            0 :     }
     225              : 
     226            0 :     emit outputResourceItemListChanged();
     227            0 : }
     228              : 
     229            0 : void MixerChannelItem::removeBlankSlotsFromEnd(size_t count)
     230              : {
     231            0 :     TRACEFUNC;
     232              : 
     233            0 :     bool itemsRemoved = false;
     234            0 :     DEFER {
     235            0 :         if (itemsRemoved) {
     236            0 :             emit outputResourceItemListChanged();
     237              :         }
     238            0 :     };
     239              : 
     240            0 :     for (size_t i = 0; i < count; ++i) {
     241            0 :         if (m_outputResourceItems.empty()) {
     242            0 :             return;
     243              :         }
     244              : 
     245            0 :         auto lastItemIt = std::prev(m_outputResourceItems.end());
     246            0 :         OutputResourceItem* item = lastItemIt.value();
     247              : 
     248            0 :         if (!item->isBlank()) {
     249            0 :             return;
     250              :         }
     251              : 
     252            0 :         m_outputResourceItems.erase(lastItemIt);
     253            0 :         closeEditor(item);
     254            0 :         item->disconnect();
     255            0 :         item->deleteLater();
     256            0 :         itemsRemoved = true;
     257              :     }
     258            0 : }
     259              : 
     260            0 : void MixerChannelItem::loadInputParams(const AudioInputParams& newParams)
     261              : {
     262            0 :     if (m_outputOnly) {
     263            0 :         return;
     264              :     }
     265              : 
     266            0 :     if (m_inputParams == newParams) {
     267            0 :         return;
     268              :     }
     269              : 
     270            0 :     m_inputParams = newParams;
     271            0 :     m_inputResourceItem->setParams(newParams);
     272              : }
     273              : 
     274            0 : void MixerChannelItem::loadOutputParams(const AudioOutputParams& newParams)
     275              : {
     276            0 :     if (!muse::RealIsEqual(m_outParams.volume, newParams.volume)) {
     277            0 :         m_outParams.volume = newParams.volume;
     278            0 :         if (!m_hasVolumeAutomation) {
     279            0 :             setDisplayedVolumeLevel(m_outParams.volume);
     280              :         }
     281              :     }
     282              : 
     283            0 :     if (!muse::RealIsEqual(m_outParams.balance, newParams.balance)) {
     284            0 :         m_outParams.balance = newParams.balance;
     285            0 :         if (!m_hasBalanceAutomation) {
     286            0 :             setDisplayedBalance(m_outParams.balance.raw() * BALANCE_SCALING_FACTOR);
     287              :         }
     288              :     }
     289              : 
     290            0 :     if (m_outParams.solo != newParams.solo) {
     291            0 :         m_outParams.solo = newParams.solo;
     292            0 :         emit soloChanged();
     293              :     }
     294              : 
     295            0 :     if (m_outParams.muted != newParams.muted) {
     296            0 :         m_outParams.muted = newParams.muted;
     297            0 :         emit mutedChanged();
     298              :     }
     299              : 
     300            0 :     if (m_outParams.forceMute != newParams.forceMute) {
     301            0 :         m_outParams.forceMute = newParams.forceMute;
     302            0 :         emit forceMuteChanged();
     303              :     }
     304              : 
     305            0 :     loadOutputResourceItems(newParams.fxChain);
     306            0 :     loadAuxSendItems(newParams.auxSends);
     307            0 : }
     308              : 
     309            0 : void MixerChannelItem::loadOutputResourceItems(const AudioFxChain& fxChain)
     310              : {
     311            0 :     m_outParams.fxChain = fxChain;
     312              : 
     313            0 :     m_outputResourceItemsLoading = true;
     314            0 :     DEFER {
     315            0 :         m_outputResourceItemsLoading = false;
     316            0 :     };
     317              : 
     318            0 :     QMap<AudioFxChainOrder, OutputResourceItem*> newItems = m_outputResourceItems;
     319              : 
     320            0 :     for (AudioFxChainOrder chainOrder : m_outputResourceItems.keys()) {
     321            0 :         OutputResourceItem* item = m_outputResourceItems.value(chainOrder);
     322              : 
     323            0 :         if (item->isBlank()) {
     324            0 :             continue;
     325              :         }
     326              : 
     327            0 :         if (fxChain.find(chainOrder) == fxChain.cend()) {
     328            0 :             item->disconnect();
     329            0 :             item->deleteLater();
     330            0 :             newItems.remove(chainOrder);
     331              :         }
     332            0 :     }
     333              : 
     334            0 :     for (const auto& pair : fxChain) {
     335            0 :         OutputResourceItem* item = newItems.value(pair.first, nullptr);
     336              : 
     337            0 :         if (item) {
     338            0 :             item->setParams(pair.second);
     339              :         } else {
     340            0 :             newItems.insert(pair.first, buildOutputResourceItem(pair.second));
     341              :         }
     342              :     }
     343              : 
     344            0 :     if (m_outputResourceItems != newItems) {
     345            0 :         m_outputResourceItems = std::move(newItems);
     346            0 :         emit outputResourceItemListChanged();
     347              :     }
     348            0 : }
     349              : 
     350            0 : void MixerChannelItem::loadAuxSendItems(const AuxSendsParams& auxSends)
     351              : {
     352            0 :     if (m_outParams.auxSends == auxSends) {
     353            0 :         return;
     354              :     }
     355              : 
     356            0 :     m_outParams.auxSends = auxSends;
     357              : 
     358            0 :     configuration()->isAuxSendVisibleChanged().onReceive(this, [this](aux_channel_idx_t index, bool visible) {
     359            0 :         if (visible) {
     360            0 :             IF_ASSERT_FAILED(index < m_outParams.auxSends.size()) {
     361            0 :                 return;
     362              :             };
     363              : 
     364            0 :             m_auxSendItems.insert(index, buildAuxSendItem(index, m_outParams.auxSends[index]));
     365              :         } else {
     366            0 :             m_auxSendItems.remove(index);
     367              :         }
     368              : 
     369            0 :         emit auxSendItemListChanged();
     370              :     }, async::Asyncable::Mode::SetReplace);
     371              : 
     372            0 :     if (m_auxSendItems.size() == static_cast<int>(auxSends.size())) {
     373            0 :         return;
     374              :     }
     375              : 
     376            0 :     QMap<aux_channel_idx_t, AuxSendItem*> newItems;
     377              : 
     378            0 :     for (aux_channel_idx_t i = 0; i < auxSends.size(); ++i) {
     379            0 :         if (!configuration()->isAuxSendVisible(i)) {
     380            0 :             continue;
     381              :         }
     382              : 
     383            0 :         auto it = m_auxSendItems.find(i);
     384              : 
     385            0 :         if (it != m_auxSendItems.end()) {
     386            0 :             newItems.insert(it.key(), it.value());
     387              :         } else {
     388            0 :             newItems.insert(i, buildAuxSendItem(i, auxSends[i]));
     389              :         }
     390              :     }
     391              : 
     392            0 :     if (m_auxSendItems != newItems) {
     393            0 :         m_auxSendItems = std::move(newItems);
     394            0 :         emit auxSendItemListChanged();
     395              :     }
     396            0 : }
     397              : 
     398            0 : void MixerChannelItem::loadSoloMuteState(const notation::INotationSoloMuteState::SoloMuteState& newState)
     399              : {
     400            0 :     if (m_outParams.muted != newState.mute) {
     401            0 :         m_outParams.muted = newState.mute;
     402            0 :         emit mutedChanged();
     403              :     }
     404              : 
     405            0 :     if (m_outParams.solo != newState.solo) {
     406            0 :         m_outParams.solo = newState.solo;
     407            0 :         emit soloChanged();
     408              :     }
     409            0 : }
     410              : 
     411            0 : void MixerChannelItem::subscribeOnAudioSignalChanges(AudioSignalChanges& audioSignalChanges)
     412              : {
     413            0 :     m_audioSignalChanges = audioSignalChanges;
     414              : 
     415            0 :     m_audioSignalChanges.onReceive(this, [this](const AudioSignalValuesMap& signalValues) {
     416              :         //!Note There should be no signal changes when the mixer channel is muted.
     417              :         //!     But some audio signal changes still might be "on the way" from the times when the mixer channel wasn't muted
     418              :         //!     So that we have to just ignore them
     419            0 :         if (muted()) {
     420            0 :             return;
     421              :         }
     422              : 
     423            0 :         for (const auto& pair : signalValues) {
     424            0 :             audioch_t audioChNum = pair.first;
     425            0 :             volume_dbfs_t newPressure = pair.second.pressure;
     426              : 
     427            0 :             if (newPressure < MIN_DISPLAYED_DBFS) {
     428            0 :                 setAudioChannelVolumePressure(audioChNum, MIN_DISPLAYED_DBFS);
     429            0 :             } else if (newPressure > MAX_DISPLAYED_DBFS) {
     430            0 :                 setAudioChannelVolumePressure(audioChNum, MAX_DISPLAYED_DBFS);
     431              :             } else {
     432            0 :                 setAudioChannelVolumePressure(audioChNum, newPressure);
     433              :             }
     434              :         }
     435              :     });
     436            0 : }
     437              : 
     438            0 : void MixerChannelItem::subscribeOnAutomatedControlParamsChanges(AutomatedControlParamsChanges& changes)
     439              : {
     440            0 :     m_automatedControlParamsChanges = changes;
     441              : 
     442            0 :     m_automatedControlParamsChanges.onReceive(this, [this](const AutomatedControlParams& params) {
     443            0 :         if (m_hasVolumeAutomation) {
     444            0 :             setDisplayedVolumeLevel(params.volume.raw());
     445              :         }
     446              : 
     447            0 :         if (m_hasBalanceAutomation) {
     448            0 :             setDisplayedBalance(params.balance.raw() * BALANCE_SCALING_FACTOR);
     449              :         }
     450            0 :     });
     451            0 : }
     452              : 
     453            0 : void MixerChannelItem::setTitle(QString title)
     454              : {
     455            0 :     if (m_title == title) {
     456            0 :         return;
     457              :     }
     458              : 
     459            0 :     m_title = title;
     460            0 :     emit titleChanged(m_title);
     461              : }
     462              : 
     463            0 : void MixerChannelItem::setLeftChannelPressure(float leftChannelPressure)
     464              : {
     465            0 :     if (qFuzzyCompare(m_leftChannelPressure, leftChannelPressure)) {
     466            0 :         return;
     467              :     }
     468              : 
     469            0 :     m_leftChannelPressure = leftChannelPressure;
     470            0 :     emit leftChannelPressureChanged(m_leftChannelPressure);
     471              : }
     472              : 
     473            0 : void MixerChannelItem::setRightChannelPressure(float rightChannelPressure)
     474              : {
     475            0 :     if (qFuzzyCompare(m_rightChannelPressure, rightChannelPressure)) {
     476            0 :         return;
     477              :     }
     478              : 
     479            0 :     m_rightChannelPressure = rightChannelPressure;
     480            0 :     emit rightChannelPressureChanged(m_rightChannelPressure);
     481              : }
     482              : 
     483            0 : void MixerChannelItem::setVolumeLevel(float volumeLevel)
     484              : {
     485            0 :     if (qFuzzyCompare(m_outParams.volume, volumeLevel)) {
     486            0 :         return;
     487              :     }
     488              : 
     489            0 :     m_outParams.volume = volumeLevel;
     490            0 :     setDisplayedVolumeLevel(volumeLevel);
     491            0 :     emit controlParamsChanged(m_outParams);
     492              : }
     493              : 
     494            0 : void MixerChannelItem::setBalance(int balance)
     495              : {
     496            0 :     if (m_outParams.balance.raw() * BALANCE_SCALING_FACTOR == balance) {
     497            0 :         return;
     498              :     }
     499              : 
     500            0 :     m_outParams.balance = balance / BALANCE_SCALING_FACTOR;
     501            0 :     setDisplayedBalance(balance);
     502            0 :     emit controlParamsChanged(m_outParams);
     503              : }
     504              : 
     505            0 : void MixerChannelItem::setSolo(bool solo)
     506              : {
     507            0 :     if (m_outParams.solo == solo) {
     508            0 :         return;
     509              :     }
     510              : 
     511            0 :     m_outParams.solo = solo;
     512              : 
     513            0 :     notation::INotationSoloMuteState::SoloMuteState soloMuteState;
     514            0 :     soloMuteState.mute = m_outParams.muted;
     515            0 :     soloMuteState.solo = m_outParams.solo;
     516              : 
     517            0 :     emit soloMuteStateChanged(soloMuteState);
     518            0 :     emit soloChanged();
     519              : 
     520            0 :     if (solo && m_outParams.muted) {
     521            0 :         setMuted(false);
     522              :     }
     523              : }
     524              : 
     525            0 : void MixerChannelItem::setMuted(bool mute)
     526              : {
     527            0 :     if (m_outParams.muted == mute) {
     528            0 :         return;
     529              :     }
     530              : 
     531            0 :     m_outParams.muted = mute;
     532              : 
     533            0 :     notation::INotationSoloMuteState::SoloMuteState soloMuteState;
     534            0 :     soloMuteState.mute = m_outParams.muted;
     535            0 :     soloMuteState.solo = m_outParams.solo;
     536              : 
     537            0 :     emit soloMuteStateChanged(soloMuteState);
     538            0 :     emit mutedChanged();
     539              : 
     540            0 :     if (mute && m_outParams.solo) {
     541            0 :         setSolo(false);
     542              :     }
     543              : }
     544              : 
     545            0 : mu::notation::INotationPlaybackPtr MixerChannelItem::notationPlayback() const
     546              : {
     547            0 :     project::INotationProjectPtr project = context()->project();
     548            0 :     return project ? project->masterNotation()->playback() : nullptr;
     549            0 : }
     550              : 
     551            0 : std::optional<mu::notation::AutomationCurveKey> MixerChannelItem::automationCurveKey(notation::AutomationType type) const
     552              : {
     553            0 :     if (m_type == Type::Master) {
     554            0 :         return notation::AutomationCurveKey::global(type);
     555              :     }
     556              : 
     557            0 :     if (m_instrumentTrackId.isValid()) {
     558            0 :         return notation::AutomationCurveKey::instrument(type, m_instrumentTrackId);
     559              :     }
     560              : 
     561            0 :     return std::nullopt;
     562              : }
     563              : 
     564            0 : bool MixerChannelItem::hasAutomationCurve(notation::AutomationType type) const
     565              : {
     566            0 :     const std::optional<notation::AutomationCurveKey> key = automationCurveKey(type);
     567            0 :     if (!key) {
     568            0 :         return false;
     569              :     }
     570              : 
     571            0 :     const INotationProjectPtr project = context()->project();
     572            0 :     if (!project) {
     573            0 :         return false;
     574              :     }
     575              : 
     576            0 :     const notation::AutomationDataConstPtr automationData = project->masterNotation()->automation()->automationData();
     577            0 :     return automationData && !automationData->curve(*key).empty();
     578            0 : }
     579              : 
     580            0 : void MixerChannelItem::updateHasAutomationFlags()
     581              : {
     582            0 :     const bool hasVolumeAutomation = hasAutomationCurve(notation::AutomationType::Volume);
     583            0 :     const bool hasBalanceAutomation = hasAutomationCurve(notation::AutomationType::Pan);
     584              : 
     585            0 :     if (m_hasVolumeAutomation != hasVolumeAutomation) {
     586            0 :         m_hasVolumeAutomation = hasVolumeAutomation;
     587            0 :         emit hasVolumeAutomationChanged();
     588            0 :         if (!m_hasVolumeAutomation) {
     589            0 :             setDisplayedVolumeLevel(m_outParams.volume);
     590              :         }
     591              :     }
     592              : 
     593            0 :     if (m_hasBalanceAutomation != hasBalanceAutomation) {
     594            0 :         m_hasBalanceAutomation = hasBalanceAutomation;
     595            0 :         emit hasBalanceAutomationChanged();
     596            0 :         if (!m_hasBalanceAutomation) {
     597            0 :             setDisplayedBalance(m_outParams.balance.raw() * BALANCE_SCALING_FACTOR);
     598              :         }
     599              :     }
     600            0 : }
     601              : 
     602            0 : void MixerChannelItem::setDisplayedVolumeLevel(float volumeLevel)
     603              : {
     604            0 :     if (muse::RealIsEqual(m_volumeLevel, volumeLevel)) {
     605            0 :         return;
     606              :     }
     607              : 
     608            0 :     m_volumeLevel = volumeLevel;
     609            0 :     emit volumeLevelChanged(m_volumeLevel);
     610              : }
     611              : 
     612            0 : void MixerChannelItem::setDisplayedBalance(int balance)
     613              : {
     614            0 :     if (m_balance == balance) {
     615            0 :         return;
     616              :     }
     617              : 
     618            0 :     m_balance = balance;
     619            0 :     emit balanceChanged(m_balance);
     620              : }
     621              : 
     622            0 : void MixerChannelItem::setAudioChannelVolumePressure(const audio::audioch_t chNum, const float newValue)
     623              : {
     624            0 :     if (chNum == 0) {
     625            0 :         setLeftChannelPressure(newValue);
     626              :     } else {
     627            0 :         setRightChannelPressure(newValue);
     628              :     }
     629            0 : }
     630              : 
     631            0 : void MixerChannelItem::resetAudioChannelsVolumePressure()
     632              : {
     633            0 :     setLeftChannelPressure(MIN_DISPLAYED_DBFS);
     634            0 :     setRightChannelPressure(MIN_DISPLAYED_DBFS);
     635            0 : }
     636              : 
     637            0 : InputResourceItem* MixerChannelItem::buildInputResourceItem()
     638              : {
     639            0 :     InputResourceItem* newItem = new InputResourceItem(this);
     640              : 
     641            0 :     connect(newItem, &InputResourceItem::inputParamsChangeRequested, this, [this, newItem](const AudioResourceMeta& newMeta) {
     642            0 :         askAboutChangingSound().onResolve(this, [item = QPointer<InputResourceItem>(newItem), newMeta](bool change) {
     643            0 :             if (change && item) {
     644            0 :                 item->setParamsRecourceMeta(newMeta);
     645              :             }
     646            0 :         });
     647            0 :     });
     648              : 
     649            0 :     connect(newItem, &InputResourceItem::inputParamsChanged, this, [this, newItem]() {
     650            0 :         bool audioSourceChanged = m_inputParams.type() != newItem->params().type();
     651              : 
     652            0 :         m_inputParams = newItem->params();
     653            0 :         emit inputParamsChanged(m_inputParams);
     654              : 
     655            0 :         if (!audioSourceChanged) {
     656            0 :             return;
     657              :         }
     658              : 
     659            0 :         bool auxParamsChanged = false;
     660            0 :         for (aux_channel_idx_t idx = 0; idx < static_cast<size_t>(m_outParams.auxSends.size()); ++idx) {
     661            0 :             const muse::String& soundId = m_inputParams.resourceMeta.attributeVal(PLAYBACK_SETUP_DATA_ATTRIBUTE);
     662            0 :             gain_t newAudioSignalAmount = configuration()->defaultAuxSendValue(idx, m_inputParams.type(), soundId);
     663              : 
     664            0 :             auto it = m_auxSendItems.find(idx);
     665            0 :             if (it == m_auxSendItems.end()) {
     666            0 :                 if (!muse::RealIsEqual(m_outParams.auxSends.at(idx).signalAmount, newAudioSignalAmount)) {
     667            0 :                     m_outParams.auxSends.at(idx).signalAmount = newAudioSignalAmount;
     668            0 :                     auxParamsChanged = true;
     669              :                 }
     670              :             } else {
     671            0 :                 it.value()->setAudioSignalPercentage(newAudioSignalAmount * 100.f);
     672              :             }
     673              :         }
     674              : 
     675            0 :         if (auxParamsChanged) {
     676            0 :             emit auxSendsParamsChanged(m_outParams);
     677              :         }
     678              :     });
     679              : 
     680            0 :     connect(newItem, &InputResourceItem::isBlankChanged, this, &MixerChannelItem::inputResourceItemChanged);
     681              : 
     682            0 :     connect(newItem, &InputResourceItem::nativeEditorViewLaunchRequested, this, [this, newItem]() {
     683            0 :         if (newItem->params().type() != AudioSourceType::Vsti) {
     684            0 :             return;
     685              :         }
     686              : 
     687            0 :         rcommand::CommandQuery aq(VST_OPEN_INSTRUMENT_EDITOR_COMMAND);
     688            0 :         aq.addParam(TRACK_ID_KEY, Val(m_trackId));
     689            0 :         aq.addParam(RESOURCE_ID_KEY, Val(newItem->params().resourceMeta.id));
     690              : 
     691            0 :         openEditor(newItem, aq);
     692            0 :     });
     693              : 
     694            0 :     connect(newItem, &InputResourceItem::nativeEditorViewCloseRequested, this, [this, newItem]() {
     695            0 :         closeEditor(newItem);
     696            0 :     });
     697              : 
     698            0 :     return newItem;
     699              : }
     700              : 
     701            0 : OutputResourceItem* MixerChannelItem::buildOutputResourceItem(const audio::AudioFxParams& fxParams)
     702              : {
     703            0 :     OutputResourceItem* newItem = new OutputResourceItem(this, fxParams);
     704              : 
     705            0 :     connect(newItem, &OutputResourceItem::fxParamsChanged, this, [this]() {
     706            0 :         if (m_outputResourceItemsLoading) {
     707            0 :             return;
     708              :         }
     709              : 
     710            0 :         m_outParams.fxChain.clear();
     711              : 
     712            0 :         for (const OutputResourceItem* item : std::as_const(m_outputResourceItems)) {
     713            0 :             m_outParams.fxChain.insert({ item->params().chainOrder, item->params() });
     714              :         }
     715              : 
     716            0 :         emit fxChainParamsChanged(m_outParams);
     717              :     });
     718              : 
     719            0 :     connect(newItem, &OutputResourceItem::nativeEditorViewLaunchRequested, this, [this, newItem]() {
     720            0 :         if (newItem->params().type() != AudioFxType::VstFx) {
     721            0 :             return;
     722              :         }
     723              : 
     724            0 :         rcommand::CommandQuery aq(VST_OPEN_FX_EDITOR_COMMAND);
     725              : 
     726            0 :         aq.addParam(TRACK_ID_KEY, Val(m_trackId));
     727            0 :         aq.addParam(RESOURCE_ID_KEY, Val(newItem->params().resourceMeta.id));
     728            0 :         aq.addParam(CHAIN_ORDER_KEY, Val(newItem->params().chainOrder));
     729              : 
     730            0 :         openEditor(newItem, aq);
     731            0 :     });
     732              : 
     733            0 :     connect(newItem, &OutputResourceItem::nativeEditorViewCloseRequested, this, [this, newItem]() {
     734            0 :         closeEditor(newItem);
     735            0 :     });
     736              : 
     737            0 :     return newItem;
     738              : }
     739              : 
     740            0 : AuxSendItem* MixerChannelItem::buildAuxSendItem(aux_channel_idx_t index, const AuxSendParams& params)
     741              : {
     742            0 :     AuxSendItem* newItem = new AuxSendItem(this);
     743            0 :     newItem->blockSignals(true);
     744            0 :     newItem->setIsActive(params.active);
     745            0 :     newItem->setAudioSignalPercentage(params.signalAmount * 100.f);
     746            0 :     newItem->setTitle(muse::qtrc("playback", "Aux %1").arg(index + 1));
     747            0 :     newItem->blockSignals(false);
     748              : 
     749            0 :     connect(newItem, &AuxSendItem::isActiveChanged, this, [this, index](bool active) {
     750            0 :         IF_ASSERT_FAILED(index < m_outParams.auxSends.size()) {
     751            0 :             return;
     752              :         }
     753              : 
     754            0 :         m_outParams.auxSends[index].active = active;
     755            0 :         emit auxSendsParamsChanged(m_outParams);
     756              :     });
     757              : 
     758            0 :     connect(newItem, &AuxSendItem::audioSignalPercentageChanged, this, [this, index](int percentage) {
     759            0 :         IF_ASSERT_FAILED(index < m_outParams.auxSends.size()) {
     760            0 :             return;
     761              :         }
     762              : 
     763            0 :         m_outParams.auxSends[index].signalAmount = static_cast<float>(percentage) / 100.f;
     764            0 :         emit auxSendsParamsChanged(m_outParams);
     765              :     });
     766              : 
     767            0 :     return newItem;
     768              : }
     769              : 
     770            0 : void MixerChannelItem::openEditor(AbstractAudioResourceItem* item, const rcommand::CommandQuery& command)
     771              : {
     772            0 :     if (item->editorCommand() != command) {
     773            0 :         if (item->editorCommand().isValid()) {
     774              :             // make and send close
     775            0 :             rcommand::CommandQuery closeCommand = item->editorCommand();
     776            0 :             closeCommand.addParam("operation", Val("close"));
     777            0 :             closeCommand.addParam("sync", Val(true));
     778            0 :             commandDispatcher()->dispatch(closeCommand);
     779            0 :         }
     780              :         // set new action
     781            0 :         item->setEditorCommand(command);
     782              :     }
     783              : 
     784            0 :     commandDispatcher()->dispatch(command);
     785            0 : }
     786              : 
     787            0 : void MixerChannelItem::closeEditor(AbstractAudioResourceItem* item)
     788              : {
     789              :     // make and send close
     790            0 :     rcommand::CommandQuery closeCommand = item->editorCommand();
     791            0 :     closeCommand.addParam("operation", Val("close"));
     792            0 :     closeCommand.addParam("sync", Val(true));
     793            0 :     commandDispatcher()->dispatch(closeCommand);
     794              : 
     795            0 :     item->setEditorCommand({});
     796            0 : }
     797              : 
     798            0 : async::Promise<bool> MixerChannelItem::askAboutChangingSound()
     799              : {
     800            0 :     if (!configuration()->needToShowResetSoundFlagsWhenChangeSoundWarning()
     801            0 :         || !notationPlayback()->hasSoundFlags({ m_instrumentTrackId })) {
     802            0 :         return async::make_promise<bool>([](auto resolve) {
     803            0 :             return resolve(true);
     804            0 :         });
     805              :     }
     806              : 
     807            0 :     return async::make_promise<bool>([this](auto resolve) {
     808            0 :         int changeBtn = int(IInteractive::Button::Apply);
     809            0 :         IInteractive::Options options = IInteractive::Option::WithIcon | IInteractive::Option::WithDontShowAgainCheckBox;
     810            0 :         IInteractive::ButtonDatas buttons = {
     811            0 :             interactive()->buttonData(IInteractive::Button::Cancel),
     812            0 :             IInteractive::ButtonData(changeBtn, muse::trc("playback", "Change sound"), true /*accent*/)
     813              :         };
     814              : 
     815            0 :         interactive()->warning(muse::trc("playback", "Are you sure you want to change this sound?"),
     816            0 :                                IInteractive::Text(muse::trc("playback",
     817              :                                                             "Sound flags on this instrument may be reset, but staff text will remain. This action can’t be undone.")),
     818              :                                buttons, changeBtn, options)
     819            0 :         .onResolve(this, [this, changeBtn, resolve](const IInteractive::Result& result) {
     820            0 :             if (result.button() != changeBtn) {
     821            0 :                 (void)resolve(false);
     822            0 :                 return;
     823              :             }
     824              : 
     825            0 :             if (!result.showAgain()) {
     826            0 :                 configuration()->setNeedToShowResetSoundFlagsWhenChangeSoundWarning(false);
     827              :             }
     828              : 
     829            0 :             (void)resolve(true);
     830              :         });
     831              : 
     832            0 :         return async::Promise<bool>::dummy_result();
     833            0 :     }, async::PromiseType::AsyncByBody);
     834            0 : }
     835              : 
     836            0 : AudioFxChainOrder MixerChannelItem::resolveNewBlankOutputResourceItemOrder() const
     837              : {
     838            0 :     if (m_outputResourceItems.empty()) {
     839            0 :         return 0;
     840              :     }
     841              : 
     842            0 :     AudioFxChainOrder lastChainOrder = m_outputResourceItems.lastKey();
     843            0 :     if (lastChainOrder < OUTPUT_RESOURCE_COUNT_LIMIT - 1) {
     844            0 :         return lastChainOrder + 1;
     845              :     }
     846              : 
     847            0 :     for (AudioFxChainOrder order = 0; order < OUTPUT_RESOURCE_COUNT_LIMIT; ++order) {
     848            0 :         if (!m_outputResourceItems.contains(order)) {
     849            0 :             return order;
     850              :         }
     851              :     }
     852              : 
     853            0 :     return OUTPUT_RESOURCE_COUNT_LIMIT - 1;
     854              : }
     855              : 
     856            0 : bool MixerChannelItem::outputOnly() const
     857              : {
     858            0 :     return m_outputOnly;
     859              : }
     860              : 
     861            0 : const AudioInputParams& MixerChannelItem::inputParams() const
     862              : {
     863            0 :     return m_inputParams;
     864              : }
     865              : 
     866            0 : const AudioOutputParams& MixerChannelItem::outputParams() const
     867              : {
     868            0 :     return m_outParams;
     869              : }
     870              : 
     871            0 : InputResourceItem* MixerChannelItem::inputResourceItem() const
     872              : {
     873            0 :     return m_inputResourceItem;
     874              : }
     875              : 
     876            0 : QList<OutputResourceItem*> MixerChannelItem::outputResourceItemList() const
     877              : {
     878            0 :     return m_outputResourceItems.values();
     879              : }
     880              : 
     881            0 : QList<AuxSendItem*> MixerChannelItem::auxSendItemList() const
     882              : {
     883            0 :     return m_auxSendItems.values();
     884              : }
     885              : 
     886            0 : const QMap<aux_channel_idx_t, AuxSendItem*>& MixerChannelItem::auxSendItems() const
     887              : {
     888            0 :     return m_auxSendItems;
     889              : }
        

Generated by: LCOV version 2.0-1