diff --git a/include/LadspaMatrixControlView.h b/include/LadspaMatrixControlView.h deleted file mode 100644 index c6cffe99e..000000000 --- a/include/LadspaMatrixControlView.h +++ /dev/null @@ -1,57 +0,0 @@ -/* -* LadspaMatrixControlView.h - widget for controlling a LADSPA port -* -* Copyright (c) 2006-2008 Danny McRae -* Copyright (c) 2009 Tobias Doerffel -* Copyright (c) 2015 Michael Gregorius -* -* 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 - -#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 diff --git a/include/LadspaWidgetFactory.h b/include/LadspaWidgetFactory.h new file mode 100644 index 000000000..807334d32 --- /dev/null +++ b/include/LadspaWidgetFactory.h @@ -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 diff --git a/plugins/LadspaEffect/LadspaMatrixControlDialog.cpp b/plugins/LadspaEffect/LadspaMatrixControlDialog.cpp index 3d2a14556..e492638ba 100644 --- a/plugins/LadspaEffect/LadspaMatrixControlDialog.cpp +++ b/plugins/LadspaEffect/LadspaMatrixControlDialog.cpp @@ -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); diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 3db69aec8..8446d3fce 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -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 diff --git a/src/gui/LadspaMatrixControlView.cpp b/src/gui/LadspaMatrixControlView.cpp deleted file mode 100644 index 96ae96db9..000000000 --- a/src/gui/LadspaMatrixControlView.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/* - * LadspaMatrixControlView.cpp - widget for controlling a LADSPA port - * - * Copyright (c) 2006-2008 Danny McRae - * Copyright (c) 2009 Tobias Doerffel - * Copyright (c) 2015 Michael Gregorius - * - * 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 -#include - - -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 diff --git a/src/gui/LadspaWidgetFactory.cpp b/src/gui/LadspaWidgetFactory.cpp new file mode 100644 index 000000000..c900095fa --- /dev/null +++ b/src/gui/LadspaWidgetFactory.cpp @@ -0,0 +1,89 @@ +/* + * LadspaWidgetFactory.cpp - Factory that creates widgets for LADSPA ports + * + * Copyright (c) 2006-2008 Danny McRae + * Copyright (c) 2009 Tobias Doerffel + * 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 + + +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