hydrogen 1.2.6
LadspaFXSelector.cpp
Go to the documentation of this file.
1/*
2 * Hydrogen
3 * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
4 * Copyright(c) 2008-2025 The hydrogen development team [hydrogen-devel@lists.sourceforge.net]
5 *
6 * http://www.hydrogen-music.org
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY, without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see https://www.gnu.org/licenses
20 *
21 */
22
23#include "LadspaFXSelector.h"
24#include "HydrogenApp.h"
25
26#include <core/Hydrogen.h>
27#include <core/Basics/Song.h>
29#include <core/FX/Effects.h>
30#include <core/FX/LadspaFX.h>
31
32using namespace H2Core;
33
35 : QDialog( nullptr )
36 , m_pCurrentItem( nullptr )
37{
38 //
39
40 setupUi( this );
41
42 setFixedSize( width(), height() );
43
44 setWindowTitle( tr( "Select LADSPA FX" ) );
45
47
48 m_nameLbl->setText( QString("") );
49 m_labelLbl->setText( QString("") );
50 m_typeLbl->setText( QString("") );
51 m_pIDLbl->setText( QString("") );
52 m_pMakerLbl->setText( QString("") );
53 m_pCopyrightLbl->setText( QString("") );
54 m_pPluginsListBox->clear();
55 m_pOkBtn->setEnabled(false);
56
57 m_pGroupsListView->setHeaderLabels( QStringList( tr( "Groups" ) ) );
58
59#ifdef H2CORE_HAVE_LADSPA
60 //std::shared_ptr<Song> pSong = Hydrogen::get_instance()->getSong();
61 LadspaFX *pFX = Effects::get_instance()->getLadspaFX(nLadspaFX);
62 if (pFX) {
64 }
66
67 m_pGroupsListView->headerItem()->setHidden( true );
68
69
70// LadspaFXGroup* pFXGroup = LadspaFX::getLadspaFXGroup();
71// vector<LadspaFXInfo*> list = findPluginsInGroup( m_sSelectedPluginName, pFXGroup );
72// for (uint i = 0; i < list.size(); i++) {
73// m_pPluginsListBox->addItem( list[i]->m_sName.c_str() );
74// }
75#endif
76
77 connect( m_pPluginsListBox, SIGNAL( itemSelectionChanged () ), this, SLOT( pluginSelected() ) );
79// on_m_pGroupsListView_currentItemChanged( m_pGroupsListView->currentItem(), NULL );
80}
81
82
83
85{
86 //INFOLOG( "DESTROY" );
87}
88
89
90
92{
93#ifdef H2CORE_HAVE_LADSPA
94 m_pGroupsListView->clear();
95
97
98 if(pFXGroup)
99 {
100 for (uint i = 0; i < pFXGroup->getChildList().size(); i++) {
101 H2Core::LadspaFXGroup *pNewGroup = ( pFXGroup->getChildList() )[ i ];
102 addGroup( m_pGroupsListView, pNewGroup );
103 }
104
105 m_pGroupsListView->setCurrentItem( m_pCurrentItem );
106 }
107
108
109#endif
110}
111
112
113
114#ifdef H2CORE_HAVE_LADSPA
115void LadspaFXSelector::addGroup( QTreeWidget *parent, H2Core::LadspaFXGroup *pGroup )
116{
117 QTreeWidgetItem* pNewItem = new QTreeWidgetItem( parent );
118 QFont f = pNewItem->font( 0 );
119 f.setBold( true );
120 pNewItem->setFont( 0, f );
121 buildGroup( pNewItem, pGroup );
122}
123
124void LadspaFXSelector::addGroup( QTreeWidgetItem * parent, H2Core::LadspaFXGroup *pGroup )
125{
126 QTreeWidgetItem* pNewItem = new QTreeWidgetItem( parent );
127 buildGroup( pNewItem, pGroup );
128}
129
130void LadspaFXSelector::buildGroup( QTreeWidgetItem *pNewItem, H2Core::LadspaFXGroup *pGroup )
131{
132 QString sGroupName = pGroup->getName();
133 if (sGroupName == QString("Uncategorized")) {
134 sGroupName = tr("Alphabetic List");
135 }
136 else if (sGroupName == QString("Categorized(LRDF)")) {
137 sGroupName = tr("Categorized");
138 }
139 else if (sGroupName == QString("Recently Used")) {
140 sGroupName = tr("Recently Used");
141 }
142 pNewItem->setText( 0, sGroupName );
143
144
145 for ( uint i = 0; i < pGroup->getChildList().size(); i++ ) {
146 H2Core::LadspaFXGroup *pNewGroup = ( pGroup->getChildList() )[ i ];
147
148 addGroup( pNewItem, pNewGroup );
149 }
150 for(uint i = 0; i < pGroup->getLadspaInfo().size(); i++) {
151 H2Core::LadspaFXInfo* pInfo = (pGroup->getLadspaInfo())[i];
152 if (pInfo->m_sName == m_sSelectedPluginName) {
153 m_pCurrentItem = pNewItem;
154 break;
155 }
156 }
157}
158#endif
159
160
161
166
167
169{
170#ifdef H2CORE_HAVE_LADSPA
171 //INFOLOG( "[pluginSelected]" );
172 //
173
174 if ( m_pPluginsListBox->selectedItems().isEmpty() ) return;
175
176 QString sSelected = m_pPluginsListBox->currentItem()->text();
177 m_sSelectedPluginName = sSelected;
178
179
180 std::vector<H2Core::LadspaFXInfo*> pluginList = Effects::get_instance()->getPluginList();
181 for (uint i = 0; i < pluginList.size(); i++) {
182 H2Core::LadspaFXInfo *pFXInfo = pluginList[i];
183 if (pFXInfo->m_sName == m_sSelectedPluginName ) {
184
185 m_nameLbl->setText( pFXInfo->m_sName );
186 m_labelLbl->setText( pFXInfo->m_sLabel );
187
188 if ( ( pFXInfo->m_nIAPorts == 2 ) && ( pFXInfo->m_nOAPorts == 2 ) ) { // Stereo plugin
189 m_typeLbl->setText( tr("Stereo") );
190 }
191 else if ( ( pFXInfo->m_nIAPorts == 1 ) && ( pFXInfo->m_nOAPorts == 1 ) ) { // Mono plugin
192 m_typeLbl->setText( tr("Mono") );
193 }
194 else {
195 // not supported
196 m_typeLbl->setText( tr("Not supported") );
197 }
198
199 m_pIDLbl->setText( pFXInfo->m_sID );
200 m_pMakerLbl->setText( pFXInfo->m_sMaker );
201 m_pCopyrightLbl->setText( pFXInfo->m_sCopyright );
202
203 break;
204 }
205 }
206 m_pOkBtn->setEnabled(true);
207#endif
208}
209
210
211
212void LadspaFXSelector::on_m_pGroupsListView_currentItemChanged( QTreeWidgetItem * currentItem, QTreeWidgetItem * previous )
213{
214 UNUSED( previous );
215#ifdef H2CORE_HAVE_LADSPA
216 //INFOLOG( "new selection: " + currentItem->text(0).toLocal8Bit().constData() );
217
218 m_pOkBtn->setEnabled(false);
219 m_nameLbl->setText( QString("") );
220 m_labelLbl->setText( QString("") );
221 m_typeLbl->setText( QString("") );
222 m_pIDLbl->setText( QString("") );
223 m_pMakerLbl->setText( QString("") );
224 m_pCopyrightLbl->setText( QString("") );
225
226 // nothing was selected
227 if ( currentItem == nullptr ) {
228 return;
229 }
230
231 if ( currentItem->childCount() ) {
232 currentItem->setExpanded( true );
233 }
234
235 QString itemText = currentItem->text( 0 );
236
237 m_pPluginsListBox->clear(); // ... Why not anyway ? Jakob Lund
238
240
241 std::vector<H2Core::LadspaFXInfo*> pluginList = findPluginsInGroup( itemText, pFXGroup );
242
243 int selectedIndex = -1;
244 for (int i = 0; i < (int)pluginList.size(); i++) {
245 //INFOLOG( "adding plugin: " + pluginList[ i ]->m_sName );
246 m_pPluginsListBox->addItem( pluginList[ i ]->m_sName );
247 if ( pluginList[ i ]->m_sName == m_sSelectedPluginName ) {
248 selectedIndex = i;
249 }
250 }
251 if ( selectedIndex >= 0 ) {
252 m_pPluginsListBox->setCurrentRow( selectedIndex );
253 }
254#endif
255}
256
257
258#ifdef H2CORE_HAVE_LADSPA
259std::vector<H2Core::LadspaFXInfo*> LadspaFXSelector::findPluginsInGroup( const QString& sSelectedGroup, H2Core::LadspaFXGroup *pGroup )
260{
261 //INFOLOG( "group: " + sSelectedGroup );
262 std::vector<H2Core::LadspaFXInfo*> list;
263
264 if ( pGroup->getName() == sSelectedGroup ) {
265 //INFOLOG( "found..." );
266 for ( uint i = 0; i < pGroup->getLadspaInfo().size(); ++i ) {
267 H2Core::LadspaFXInfo *pInfo = ( pGroup->getLadspaInfo() )[i];
268 list.push_back( pInfo );
269 }
270 return list;
271 }
272 else {
273 //INFOLOG( "not found...searching in the child groups" );
274 for ( uint i = 0; i < pGroup->getChildList().size(); ++i ) {
275 H2Core::LadspaFXGroup *pNewGroup = ( pGroup->getChildList() )[ i ];
276 list = findPluginsInGroup( sSelectedGroup, pNewGroup );
277 if (list.size() != 0) {
278 return list;
279 }
280 }
281 }
282
283 //WARNINGLOG( "[findPluginsInGroup] no group found ('" + sSelectedGroup + "')" );
284 return list;
285}
286#endif
LadspaFXGroup * getLadspaFXGroup()
Definition Effects.cpp:227
static Effects * get_instance()
Returns a pointer to the current Effects singleton stored in __instance.
Definition Effects.h:54
std::vector< LadspaFXInfo * > getPluginList()
Loads only usable plugins.
Definition Effects.cpp:131
LadspaFX * getLadspaFX(int nFX) const
Definition Effects.cpp:91
std::vector< LadspaFXInfo * > getLadspaInfo() const
Definition LadspaFX.h:74
const QString & getName() const
Definition LadspaFX.h:69
std::vector< LadspaFXGroup * > getChildList() const
Definition LadspaFX.h:79
unsigned m_nIAPorts
input audio port
Definition LadspaFX.h:54
unsigned m_nOAPorts
output audio port
Definition LadspaFX.h:55
const QString & getPluginName() const
Definition LadspaFX.h:146
void on_m_pGroupsListView_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous)
QTreeWidgetItem * m_pCurrentItem
QString m_sSelectedPluginName
LadspaFXSelector(int nLadspaFX)
#define UNUSED(v)
Definition Globals.h:42