Use factory to create LADSPA control widgets

Replace the class `LadspaMatrixControlView` with the factory class
`LadspaWidgetFactory`. The former was a widget that wrapped the widget
representation of a LADSPA control in yet another widget with a layout.
The factory simply returns the configured widget so that it can be
incorporated directly in layouts or other widgets.

Adjust `LadspaMatrixControlDialog` so that it uses the
`LadspaWidgetFactory` instead of the `LadspaMatrixControlView`.
This commit is contained in:
Michael Gregorius
2023-07-08 13:15:16 +02:00
parent 610fb3442f
commit 816f3f5870
6 changed files with 145 additions and 157 deletions

View File

@@ -1,57 +0,0 @@
/*
* LadspaMatrixControlView.h - widget for controlling a LADSPA port
*
* Copyright (c) 2006-2008 Danny McRae <khjklujn/at/users.sourceforge.net>
* Copyright (c) 2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* Copyright (c) 2015 Michael Gregorius <michaelgregorius/at/web[dot]de>
*
* This file is part of LMMS - http://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 LADSPA_MATRIX_CONTROL_VIEW_H
#define LADSPA_MATRIX_CONTROL_VIEW_H
#include <QWidget>
#include "ModelView.h"
namespace lmms
{
class LadspaControl;
namespace gui
{
class LMMS_EXPORT LadspaMatrixControlView : public QWidget, public ModelView
{
Q_OBJECT
public:
LadspaMatrixControlView(QWidget* parent, LadspaControl* ladspaControl);
private:
LadspaControl* m_ladspaControl;
};
} // namespace gui
} // namespace lmms
#endif

View File

@@ -0,0 +1,49 @@
/*
* LadspaWidgetFactory.h - Factory that creates widgets for LADSPA ports
*
* Copyright (c) 2023 Michael Gregorius
*
* 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_LADSPA_WIDGET_FACTORY_H
#define LMMS_GUI_LADSPA_WIDGET_FACTORY_H
class QWidget;
namespace lmms
{
class LadspaControl;
namespace gui
{
class LadspaWidgetFactory
{
public:
static QWidget * createWidget(LadspaControl * ladspaControl, QWidget * parent);
};
} // namespace gui
} // namespace lmms
#endif // LMMS_GUI_LADSPA_WIDGET_FACTORY_H

View File

@@ -36,7 +36,7 @@
#include "LadspaControl.h"
#include "LadspaEffect.h"
#include "LadspaMatrixControlDialog.h"
#include "LadspaMatrixControlView.h"
#include "LadspaWidgetFactory.h"
#include "LadspaControlView.h"
#include "LedCheckBox.h"
@@ -152,8 +152,11 @@ void LadspaMatrixControlDialog::arrangeControls(QWidget * parent, QGridLayout* g
}
// TODO Use a factory to directly create the widgets? Currently they are wrapped in another layout in LadspaMatrixControlView...
LadspaMatrixControlView *ladspaMatrixControlView = new LadspaMatrixControlView(parent, ladspaControl);
gridLayout->addWidget(ladspaMatrixControlView, currentRow, currentChannelColumn);
QWidget * controlWidget = LadspaWidgetFactory::createWidget(ladspaControl, this);
if (controlWidget)
{
gridLayout->addWidget(controlWidget, currentRow, currentChannelColumn);
}
// Record the maximum row so that we add a vertical spacer after that row
maxRow = std::max(maxRow, currentRow);

View File

@@ -16,7 +16,7 @@ SET(LMMS_SRCS
gui/FileBrowser.cpp
gui/GuiApplication.cpp
gui/LadspaControlView.cpp
gui/LadspaMatrixControlView.cpp
gui/LadspaWidgetFactory.cpp
gui/LfoControllerDialog.cpp
gui/LinkedModelGroupViews.cpp
gui/LmmsPalette.cpp

View File

@@ -1,96 +0,0 @@
/*
* LadspaMatrixControlView.cpp - widget for controlling a LADSPA port
*
* Copyright (c) 2006-2008 Danny McRae <khjklujn/at/users.sourceforge.net>
* Copyright (c) 2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* Copyright (c) 2015 Michael Gregorius <michaelgregorius/at/web[dot]de>
*
* This file is part of LMMS - http://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.
*
*/
#include "LadspaMatrixControlView.h"
#include "LadspaControl.h"
#include "LadspaBase.h"
#include "BarModelEditor.h"
#include "LedCheckBox.h"
#include "TempoSyncKnob.h"
#include <QLayout>
#include <QLabel>
namespace lmms::gui
{
LadspaMatrixControlView::LadspaMatrixControlView(QWidget * parent,
LadspaControl * ladspaControl) :
QWidget(parent),
ModelView(ladspaControl, this),
m_ladspaControl(ladspaControl)
{
QHBoxLayout * layout = new QHBoxLayout(this);
layout->setMargin(0);
layout->setSpacing(0);
Knob * knob = nullptr;
buffer_data_t dataType = m_ladspaControl->port()->data_type;
QString const name = m_ladspaControl->port()->name;
switch (dataType)
{
case TOGGLED:
{
LedCheckBox * toggle = new LedCheckBox(
name, this, QString(), LedCheckBox::Green);
toggle->setModel(m_ladspaControl->toggledModel());
layout->addWidget(toggle);
setFixedSize(toggle->width(), toggle->height());
break;
}
case INTEGER:
case FLOATING:
/*knob = new Knob(knobBright_26, this, name);
knob->setModel(m_ladspaControl->knobModel());
knob->setLabel(name);*/
layout->addWidget(new BarModelEditor(name, m_ladspaControl->knobModel(), this));
break;
case TIME:
knob = new TempoSyncKnob(knobBright_26, this, name);
knob->setModel(m_ladspaControl->tempoSyncKnobModel());
knob->setLabel(name);
break;
default:
layout->addWidget(new QLabel(tr("%1 (unsupported)").arg(name), this));
break;
}
if (knob != nullptr)
{
knob->setHintText(tr("Value:"), "");
layout->addWidget(knob);
setFixedSize(knob->width(), knob->height());
}
}
} // namespace lmms::gui

View File

@@ -0,0 +1,89 @@
/*
* LadspaWidgetFactory.cpp - Factory that creates widgets for LADSPA ports
*
* Copyright (c) 2006-2008 Danny McRae <khjklujn/at/users.sourceforge.net>
* Copyright (c) 2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* Copyright (c) 2015-2023 Michael Gregorius
*
* 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.
*
*/
#include "LadspaWidgetFactory.h"
#include "LadspaControl.h"
#include "LadspaBase.h"
#include "BarModelEditor.h"
#include "LedCheckBox.h"
#include "TempoSyncKnob.h"
#include <QLabel>
namespace lmms::gui
{
QWidget * LadspaWidgetFactory::createWidget(LadspaControl * ladspaControl, QWidget * parent)
{
Knob * knob = nullptr;
auto const * port = ladspaControl->port();
QString const name = port->name;
switch (port->data_type)
{
case TOGGLED:
{
LedCheckBox * toggle = new LedCheckBox(
name, parent, QString(), LedCheckBox::Green);
toggle->setModel(ladspaControl->toggledModel());
return toggle;
}
case INTEGER:
case FLOATING:
// TODO Remove when not needed anymore
/*knob = new Knob(knobBright_26, parent, name);
knob->setModel(ladspaControl->knobModel());
knob->setLabel(name);
break;*/
return new BarModelEditor(name, ladspaControl->knobModel(), parent);
case TIME:
knob = new TempoSyncKnob(knobBright_26, parent, name);
knob->setModel(ladspaControl->tempoSyncKnobModel());
knob->setLabel(name);
break;
default:
return new QLabel(QObject::tr("%1 (unsupported)").arg(name), parent);
}
if (knob != nullptr)
{
knob->setHintText(QObject::tr("Value:"), "");
return knob;
}
return nullptr;
}
} // namespace lmms::gui