Files
lmms/include/MixerView.h
Michael Gregorius 629ba0362b Fix mixer channel updates on solo/mute (#7055)
* Fix mixer channel updates on solo/mute

Fix the update of the mixer channels whenever a channel is soloed or muted.

The solution is rather "brutal" as it updates all mixer channel views when one of the models changes.

Introduce private helper method `MixerView::updateAllMixerChannels`. It calls the `update` method on each `MixerChannelView` so that they can get repainted.

Call `updateAllMixerChannels` at the end of the existing method `toggledSolo`.

Introduce a new method `MixerView::toggledMute` which is called whenever the mute model of a channel changes. It also updates all mixer channels.

Fixes #7054.

* Improve mixer channel update for mute events

Improve the mixer channel update for mute events by not delegating to `MixerView` like for the solo case. Instead the `MixerChannelView` now has its own `toggledMute` slot which simply updates the widget on changes to the mute model.

Also fix `MixerChannelView::setChannelIndex` by disconnecting from the signals of the previous mixer channel and connecting to the signals for the new one.

Remove `toggledMute` from `MixerView`.

The solo implementation is kept as is because it also triggers changes to the core model. So the chain seems to be:
* Solo button clicked in mixer channel view
* Button changes solo model
* Solo model signals to mixer view which was connected via the mixer channel view
* Mixer view performs changes in the other core models
* All mixer channels are updated.

Are better chain would first update the core models and then update the GUI from the changes:
* Solo button clicked in mixer channel view
* Button changes solo model
* Solo model signals to core mixer, i.e. not a view!
* Mixer view performs changes in the other core models
* Changed models emit signal to GUI elements

* Revert "Improve mixer channel update for mute events"

This reverts commit ede65963ea.

* Add comment

After the revert done with commit the code is more consistent again but not in a good way. Hence a comment is added which indicates that an inprovement is needed.

* Abstract mixer retrieval

Abstract the retrieval of the mixer behind the new method `getMixer`. This is done in preparation for some dependency injection so that the `MixerView` does not have to ask the `Engine` for the mixer but gets it injected, a.k.a. the "Hollywood principle": "Don't call us, we'll call you."

It's called `getMixer` and not just mixer because it allows for locale variables to be called `mixer` without confusing it with the method.

* Let MixerView connect directly to models

Let the `MixerView` connect directly to the solo and mute models it is connected with.

Remove the connections that are made in `MixerChannelView` which acted as a proxy which only complicated things.

Add `connectToSoloAndMute` which connects the `MixerView` to the solo and mute models of a given channel. Call it whenever a new channel is created.

Add `disconnectFromSoloAndMute` which disconnects the `MixerView` from the solo and mute models of a given channel. Call it when a channel is deleted.

* Code cleanup

Cleanup code related to the creation of the master channel view.

* Inject the Mixer into the MixerView

Inject the `Mixer` into the `MixerView` via the constructor. This makes it more explicit that the `Mixer` is the model of the view. It also implements the "Dependency Inversion Principle" in that the `MIxerView` does not have to ask the `Engine` for the `Mixer` anymore.

The current changes should be safe in that the `Mixer` instance is static and does not change.

* Fix connections on song load

Disconnect and reconnect in `MixerView::refreshDisplay` which is called when a song is loaded.
2024-01-15 02:37:11 -05:00

138 lines
3.4 KiB
C++

/*
* MixerView.h - effect-mixer-view for LMMS
*
* Copyright (c) 2008-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of LMMS - https://lmms.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#ifndef LMMS_GUI_MIXER_VIEW_H
#define LMMS_GUI_MIXER_VIEW_H
#include <QWidget>
#include <QHBoxLayout>
#include <QStackedLayout>
#include <QScrollArea>
#include "MixerChannelView.h"
#include "ModelView.h"
#include "Engine.h"
#include "Fader.h"
#include "PixmapButton.h"
#include "embed.h"
#include "EffectRackView.h"
namespace lmms
{
class Mixer;
}
namespace lmms::gui
{
class LMMS_EXPORT MixerView : public QWidget, public ModelView,
public SerializingObjectHook
{
Q_OBJECT
public:
MixerView(Mixer* mixer);
void keyPressEvent(QKeyEvent* e) override;
void saveSettings(QDomDocument& doc, QDomElement& domElement) override;
void loadSettings(const QDomElement& domElement) override;
inline MixerChannelView* currentMixerChannel()
{
return m_currentMixerChannel;
}
inline MixerChannelView* channelView(int index)
{
return m_mixerChannelViews[index];
}
void setCurrentMixerChannel(MixerChannelView* channel);
void setCurrentMixerChannel(int channel);
void clear();
// display the send button and knob correctly
void updateMixerChannel(int index);
// notify the view that a mixer channel was deleted
void deleteChannel(int index);
bool confirmRemoval(int index);
// delete all unused channels
void deleteUnusedChannels();
// move the channel to the left or right
void moveChannelLeft(int index);
void moveChannelLeft(int index, int focusIndex);
void moveChannelRight(int index);
void renameChannel(int index);
// make sure the display syncs up with the mixer.
// useful for loading projects
void refreshDisplay();
public slots:
int addNewChannel();
protected:
void closeEvent(QCloseEvent* ce) override;
private slots:
void updateFaders();
// TODO This should be improved. Currently the solo and mute models are connected via
// the MixerChannelView's constructor with the MixerView. It would already be an improvement
// if the MixerView connected itself to each new MixerChannel that it creates/handles.
void toggledSolo();
void toggledMute();
private:
Mixer* getMixer() const;
void updateAllMixerChannels();
void connectToSoloAndMute(int channelIndex);
void disconnectFromSoloAndMute(int channelIndex);
private:
QVector<MixerChannelView*> m_mixerChannelViews;
MixerChannelView* m_currentMixerChannel;
QScrollArea* channelArea;
QHBoxLayout* chLayout;
QWidget* m_channelAreaWidget;
QStackedLayout* m_racksLayout;
QWidget* m_racksWidget;
Mixer* m_mixer;
void updateMaxChannelSelector();
friend class MixerChannelView;
} ;
} // namespace lmms::gui
#endif // LMMS_GUI_MIXER_VIEW_H