Skip to content

Commit

Permalink
Make the send button and receive arrow occupy the same space in mixer…
Browse files Browse the repository at this point in the history
… channels (LMMS#7503)
  • Loading branch information
sakertooth committed Sep 19, 2024
1 parent c952d56 commit 1d7ed16
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 70 deletions.
18 changes: 7 additions & 11 deletions include/MixerChannelView.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <QLineEdit>
#include <QPixmap>
#include <QWidget>
#include <QStackedWidget>

namespace lmms
{
Expand All @@ -59,11 +60,6 @@ namespace lmms::gui
Q_PROPERTY(QColor strokeInnerActive READ strokeInnerActive WRITE setStrokeInnerActive)
Q_PROPERTY(QColor strokeInnerInactive READ strokeInnerInactive WRITE setStrokeInnerInactive)
public:
enum class SendReceiveState
{
None, SendToThis, ReceiveFromThis
};

MixerChannelView(QWidget* parent, MixerView* mixerView, int channelIndex);
void paintEvent(QPaintEvent* event) override;
void contextMenuEvent(QContextMenuEvent*) override;
Expand All @@ -74,9 +70,6 @@ namespace lmms::gui
int channelIndex() const;
void setChannelIndex(int index);

SendReceiveState sendReceiveState() const;
void setSendReceiveState(const SendReceiveState& state);

QBrush backgroundActive() const;
void setBackgroundActive(const QBrush& c);

Expand Down Expand Up @@ -115,19 +108,22 @@ namespace lmms::gui

private:
SendButtonIndicator* m_sendButton;
QLabel* m_receiveArrow;
QStackedWidget* m_receiveArrowOrSendButton;
int m_receiveArrowStackedIndex = -1;
int m_sendButtonStackedIndex = -1;

Knob* m_sendKnob;
LcdWidget* m_channelNumberLcd;
QLineEdit* m_renameLineEdit;
QGraphicsView* m_renameLineEditView;
QLabel* m_sendArrow;
QLabel* m_receiveArrow;
PixmapButton* m_muteButton;
PixmapButton* m_soloButton;
PeakIndicator* m_peakIndicator = nullptr;
Fader* m_fader;
EffectRackView* m_effectRackView;
MixerView* m_mixerView;
SendReceiveState m_sendReceiveState = SendReceiveState::None;
int m_channelIndex = 0;
bool m_inRename = false;

Expand All @@ -141,4 +137,4 @@ namespace lmms::gui
};
} // namespace lmms::gui

#endif
#endif // MIXER_CHANNEL_VIEW_H
72 changes: 24 additions & 48 deletions src/gui/MixerChannelView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,33 @@ namespace lmms::gui
widget->setSizePolicy(sizePolicy);
};

auto receiveArrowContainer = new QWidget{};
auto receiveArrowLayout = new QVBoxLayout{receiveArrowContainer};
m_receiveArrow = new QLabel{};
m_receiveArrow->setPixmap(embed::getIconPixmap("receive_bg_arrow"));
receiveArrowLayout->setContentsMargins(0, 0, 0, 0);
receiveArrowLayout->setSpacing(0);
receiveArrowLayout->addWidget(m_receiveArrow, 0, Qt::AlignHCenter);

auto sendButtonContainer = new QWidget{};
auto sendButtonLayout = new QVBoxLayout{sendButtonContainer};
m_sendButton = new SendButtonIndicator{this, this, mixerView};
retainSizeWhenHidden(m_sendButton);
sendButtonLayout->setContentsMargins(0, 0, 0, 0);
sendButtonLayout->setSpacing(0);
sendButtonLayout->addWidget(m_sendButton, 0, Qt::AlignHCenter);

m_receiveArrowOrSendButton = new QStackedWidget{this};
m_receiveArrowStackedIndex = m_receiveArrowOrSendButton->addWidget(receiveArrowContainer);
m_sendButtonStackedIndex = m_receiveArrowOrSendButton->addWidget(sendButtonContainer);
retainSizeWhenHidden(m_receiveArrowOrSendButton);

m_sendKnob = new Knob{KnobType::Bright26, this, tr("Channel send amount")};
retainSizeWhenHidden(m_sendKnob);

m_sendArrow = new QLabel{};
m_sendArrow->setPixmap(embed::getIconPixmap("send_bg_arrow"));
retainSizeWhenHidden(m_sendArrow);

m_channelNumberLcd = new LcdWidget{2, this};
m_channelNumberLcd->setValue(channelIndex);
retainSizeWhenHidden(m_channelNumberLcd);
Expand All @@ -89,16 +110,6 @@ namespace lmms::gui
renameLineEditProxy->setRotation(-90);
m_renameLineEditView->setFixedSize(m_renameLineEdit->height() + 5, m_renameLineEdit->width() + 5);

m_sendArrow = new QLabel{};
m_sendArrow->setPixmap(embed::getIconPixmap("send_bg_arrow"));
retainSizeWhenHidden(m_sendArrow);
m_sendArrow->setVisible(m_sendReceiveState == SendReceiveState::SendToThis);

m_receiveArrow = new QLabel{};
m_receiveArrow->setPixmap(embed::getIconPixmap("receive_bg_arrow"));
retainSizeWhenHidden(m_receiveArrow);
m_receiveArrow->setVisible(m_sendReceiveState == SendReceiveState::ReceiveFromThis);

m_muteButton = new PixmapButton(this, tr("Mute"));
m_muteButton->setModel(&mixerChannel->m_muteModel);
m_muteButton->setActiveGraphic(embed::getIconPixmap("led_off"));
Expand Down Expand Up @@ -131,8 +142,7 @@ namespace lmms::gui
mainLayout->setContentsMargins(4, 4, 4, 4);
mainLayout->setSpacing(2);

mainLayout->addWidget(m_receiveArrow, 0, Qt::AlignHCenter);
mainLayout->addWidget(m_sendButton, 0, Qt::AlignHCenter);
mainLayout->addWidget(m_receiveArrowOrSendButton, 0, Qt::AlignHCenter);
mainLayout->addWidget(m_sendKnob, 0, Qt::AlignHCenter);
mainLayout->addWidget(m_sendArrow, 0, Qt::AlignHCenter);
mainLayout->addWidget(m_channelNumberLcd, 0, Qt::AlignHCenter);
Expand Down Expand Up @@ -179,13 +189,11 @@ namespace lmms::gui

void MixerChannelView::paintEvent(QPaintEvent* event)
{
auto * mixer = Engine::mixer();
const auto channel = mixerChannel();
const bool muted = channel->m_muteModel.value();
const auto name = channel->m_name;
const auto elidedName = elideName(name);
const auto * mixerChannelView = m_mixerView->currentMixerChannel();
const auto isActive = mixerChannelView == this;
const auto isActive = m_mixerView->currentMixerChannel() == this;

if (!m_inRename && m_renameLineEdit->text() != elidedName)
{
Expand Down Expand Up @@ -213,26 +221,6 @@ namespace lmms::gui
painter.setPen(isActive ? strokeOuterActive() : strokeOuterInactive());
painter.drawRect(0, 0, width - MIXER_CHANNEL_OUTER_BORDER_SIZE, height - MIXER_CHANNEL_OUTER_BORDER_SIZE);

const auto & currentMixerChannelIndex = mixerChannelView->m_channelIndex;
const auto sendToThis = mixer->channelSendModel(currentMixerChannelIndex, m_channelIndex) != nullptr;
const auto receiveFromThis = mixer->channelSendModel(m_channelIndex, currentMixerChannelIndex) != nullptr;
const auto sendReceiveStateNone = !sendToThis && !receiveFromThis;

// Only one or none of them can be on
assert(sendToThis ^ receiveFromThis || sendReceiveStateNone);

m_sendArrow->setVisible(sendToThis);
m_receiveArrow->setVisible(receiveFromThis);

if (sendReceiveStateNone)
{
setSendReceiveState(SendReceiveState::None);
}
else
{
setSendReceiveState(sendToThis ? SendReceiveState::SendToThis : SendReceiveState::ReceiveFromThis);
}

QWidget::paintEvent(event);
}

Expand Down Expand Up @@ -284,18 +272,6 @@ namespace lmms::gui
m_channelIndex = index;
}

MixerChannelView::SendReceiveState MixerChannelView::sendReceiveState() const
{
return m_sendReceiveState;
}

void MixerChannelView::setSendReceiveState(const SendReceiveState& state)
{
m_sendReceiveState = state;
m_sendArrow->setVisible(state == SendReceiveState::SendToThis);
m_receiveArrow->setVisible(state == SendReceiveState::ReceiveFromThis);
}

QBrush MixerChannelView::backgroundActive() const
{
return m_backgroundActive;
Expand Down
31 changes: 20 additions & 11 deletions src/gui/MixerView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,28 +343,37 @@ void MixerView::setCurrentMixerChannel(MixerChannelView* channel)

void MixerView::updateMixerChannel(int index)
{
Mixer * mix = getMixer();
const auto mixer = getMixer();

// does current channel send to this channel?
int selIndex = m_currentMixerChannel->channelIndex();
auto thisLine = m_mixerChannelViews[index];
const auto currentIndex = m_currentMixerChannel->channelIndex();
const auto thisLine = m_mixerChannelViews[index];
thisLine->setToolTip(getMixer()->mixerChannel(index)->m_name);

FloatModel * sendModel = mix->channelSendModel(selIndex, index);
if (sendModel == nullptr)
const auto sendModelCurrentToThis = mixer->channelSendModel(currentIndex, index);
if (sendModelCurrentToThis == nullptr)
{
// does not send, hide send knob
thisLine->m_sendKnob->setVisible(false);
thisLine->m_sendArrow->setVisible(false);
}
else
{
// it does send, show knob and connect
thisLine->m_sendKnob->setVisible(true);
thisLine->m_sendKnob->setModel(sendModel);
thisLine->m_sendKnob->setModel(sendModelCurrentToThis);
thisLine->m_sendArrow->setVisible(true);
}

const auto sendModelThisToCurrent = mixer->channelSendModel(index, currentIndex);
if (sendModelThisToCurrent)
{
thisLine->m_receiveArrowOrSendButton->setVisible(true);
thisLine->m_receiveArrowOrSendButton->setCurrentIndex(thisLine->m_receiveArrowStackedIndex);
}
else
{
thisLine->m_receiveArrowOrSendButton->setVisible(!mixer->isInfiniteLoop(currentIndex, index));
thisLine->m_receiveArrowOrSendButton->setCurrentIndex(thisLine->m_sendButtonStackedIndex);
}

// disable the send button if it would cause an infinite loop
thisLine->m_sendButton->setVisible(!mix->isInfiniteLoop(selIndex, index));
thisLine->m_sendButton->updateLightStatus();
thisLine->update();
}
Expand Down

0 comments on commit 1d7ed16

Please sign in to comment.