From 324b5afb50fabf31c37f7708e562134d713ce732 Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Thu, 30 Apr 2009 00:53:03 +0200 Subject: [PATCH] LV2: fixed serious violations of coding style conventions Unfortunately new LV2 code didn't respect coding style conventions so I fixed most of it and did various other cleanups. Still needs some work though. --- include/lv2_manager.h | 111 ++- plugins/lv2_browser/lv2_browser.cpp | 64 +- plugins/lv2_browser/lv2_browser.h | 9 +- plugins/lv2_browser/lv2_description.cpp | 25 +- plugins/lv2_browser/lv2_description.h | 2 +- plugins/lv2_browser/lv2_port_dialog.cpp | 42 +- plugins/lv2_browser/lv2_port_dialog.h | 4 +- src/core/lv2_2_lmms.cpp | 31 +- src/core/lv2_manager.cpp | 1053 ++++++----------------- 9 files changed, 384 insertions(+), 957 deletions(-) diff --git a/include/lv2_manager.h b/include/lv2_manager.h index ed89f10aa..45f0455e6 100644 --- a/include/lv2_manager.h +++ b/include/lv2_manager.h @@ -1,12 +1,10 @@ /* - * ladspa_manager.h - declaration of class lv2Manager - * a class to manage - * lv2 plugins + * lv2_manager.h - declaration of class lv2Manager a class to manage lv2 plugins * - * Copyright (c) 2005-2008 Danny McRae + * Copyright (c) 2009 Martin Andrews * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net - * + * * 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 @@ -28,11 +26,10 @@ #ifndef _LV2_MANAGER_H #define _LV2_MANAGER_H -//#include -#include "slv2/world.h" -#include "slv2/plugin.h" -#include "slv2/scalepoint.h" -#include "slv2/scalepoints.h" +#include +#include +#include +#include #include #include @@ -59,7 +56,7 @@ the filename the plug-in was loaded from and the label of the plug-in. The can be retrieved by using lv2_key_t (which is really just the LV2 URI) : // lv2_key_t key( "lalala" ) - + as the plug-in key. */ @@ -99,10 +96,9 @@ enum lv2PluginType typedef struct lv2ManagerStorage { - SLV2Plugin plugin; -// Uint32 index; - QString uri; - QString name; + SLV2Plugin plugin; + QString uri; + QString name; lv2PluginType type; Uint16 inputChannels; Uint16 outputChannels; @@ -112,16 +108,15 @@ typedef struct lv2ManagerStorage class EXPORT lv2Manager { public: - lv2Manager( void ); - virtual ~lv2Manager(); + virtual ~lv2Manager(); - void loadFromCacheFile(); - void saveToCacheFile(); + void loadFromCacheFile(); + void saveToCacheFile(); l_sortable_plugin_t getSortedPlugins(); lv2ManagerDescription * getDescription( const lv2_key_t & _plugin ); - + /* This identifier can be used as a unique, case-sensitive identifier for the plugin type within the plugin file. Plugin types should be identified by file and label rather than by index @@ -134,7 +129,7 @@ public: be cached or subject to significant latency. */ // bool hasRealTimeDependency( const lv2_key_t & _plugin ); - /* Indicates that the plugin may cease to work correctly if the + /* Indicates that the plugin may cease to work correctly if the host elects to use the same data location for both input and output (see connectPort). */ bool isInplaceBroken( const lv2_key_t & _plugin ); @@ -169,13 +164,13 @@ public: /* Indicates that the port is an control. */ bool isPortControl( const lv2_key_t & _plugin, Uint32 _port ); - /* Indicates that any bounds specified should be interpreted as - multiples of the sample rate. For instance, a frequency range from - 0Hz to the Nyquist frequency (half the sample rate) could be requested - by this hint in conjunction with LowerBound = 0 and UpperBound = 0.5. + /* Indicates that any bounds specified should be interpreted as + multiples of the sample rate. For instance, a frequency range from + 0Hz to the Nyquist frequency (half the sample rate) could be requested + by this hint in conjunction with LowerBound = 0 and UpperBound = 0.5. Hosts that support bounds at all must support this hint to retain meaning. */ -// bool areHintsSampleRateDependent( const ladspa_key_t & _plugin, +// bool areHintsSampleRateDependent( const ladspa_key_t & _plugin, // Uint32 _port ); /* Returns the lower boundary value for the given port. If @@ -194,30 +189,30 @@ public: the given port. */ float getDefaultSetting( const lv2_key_t & _plugin, Uint32 _port ); - /* Indicates that a user interface would probably wish to provide a - stepped control taking only integer values. Any bounds set should be + /* Indicates that a user interface would probably wish to provide a + stepped control taking only integer values. Any bounds set should be slightly wider than the actual integer range required to avoid floating - point rounding errors. For instance, the integer set {0,1,2,3} might + point rounding errors. For instance, the integer set {0,1,2,3} might be described as [-0.1, 3.1]. */ bool isInteger( const lv2_key_t & _plugin, Uint32 _port ); - + /* Indicates whether the given port should be considered 0 or 1 boolean switch. */ bool isPortToggled( const lv2_key_t & _plugin, Uint32 _port ); - + /* return the labels to be applied on the UI */ - QStringList listEnumeration( const lv2_key_t & _plugin, Uint32 _port ); + QStringList listEnumeration( const lv2_key_t & _plugin, Uint32 _port ); /* Indicates that it is likely that the user will find it more intuitive to view values using a logarithmic scale. This is particularly useful for frequencies and gains. */ // bool isLogarithmic( const ladspa_key_t & _plugin, Uint32 _port ); - + /* Returns the name of the port. */ QString getPortName( const lv2_key_t & _plugin, Uint32 _port ); - - + + /* This may be used by the plugin developer to pass any custom implementation data into an instantiate call. It must not be used or interpreted by the host. It is expected that most plugin @@ -225,24 +220,24 @@ public: used to hold instance data. */ // const void * getImplementationData( // const ladspa_key_t & _plugin ); - - + + /* Returns a pointer to the plug-in's descriptor from which control of the plug-in is accessible */ // const LADSPA_Descriptor * getDescriptor( // const ladspa_key_t & _plugin ); - - + + /* The following methods are convenience functions for use during development. A real instrument should use the getDescriptor() method and implement the plug-in manipulations internally to avoid the overhead associated with QMap lookups. */ - - + + /* Returns a handle to an instantiation of the given plug-in. */ - //LADSPA_Handle instantiate( const ladspa_key_t & _plugin, + //LADSPA_Handle instantiate( const ladspa_key_t & _plugin, // Uint32 _sample_rate ); - + /* This method calls a function pointer that connects a port on an instantiated plugin to a memory location at which a block of data for the port will be read/written. The data location is expected @@ -260,11 +255,11 @@ public: connectPort() must be called at least once for each port before run() or runAdding() is called. */ -// bool connectPort( const ladspa_key_t & _plugin, -// LADSPA_Handle _instance, +// bool connectPort( const ladspa_key_t & _plugin, +// LADSPA_Handle _instance, // Uint32 _port, // LADSPA_Data * _data_location ); - + /* This method calls a function pointer that initialises a plugin instance and activates it for use. This is separated from instantiate() to aid real-time support and so that hosts can @@ -297,7 +292,7 @@ public: before run() or run_adding(). If deactivate() is called for a plugin instance then the plugin instance may not be reused until activate() has been called again. */ -// bool run( const ladspa_key_t & _plugin, +// bool run( const ladspa_key_t & _plugin, // LADSPA_Handle _instance, // Uint32 _sample_count ); @@ -350,7 +345,7 @@ public: /* Once an instance of a plugin has been finished with it can be deleted using the following function. The instance handle passed ceases to be valid after this call. - + If activate() was called for a plugin instance then a corresponding call to deactivate() must be made before cleanup() is called. */ @@ -358,27 +353,29 @@ public: // LADSPA_Handle _instance ); private: - void addPlugins( SLV2Plugin _plugin ); - void ensureLV2DataExists( lv2ManagerDescription *desc ); + void addPlugins( SLV2Plugin _plugin ); + void ensureLV2DataExists( lv2ManagerDescription *desc ); - bool isPortClass( const lv2_key_t & _plugin, - Uint32 _port, SLV2Value _class ); + bool isPortClass( const lv2_key_t & _plugin, + Uint32 _port, SLV2Value _class ); - void getRanges( const lv2_key_t & _plugin, - Uint32 _port, float * _def, float * _min, float * _max ); + void getRanges( const lv2_key_t & _plugin, + Uint32 _port, float * _def, float * _min, float * _max ); - SLV2Plugins m_plugin_list; + SLV2Plugins m_pluginList; typedef QMap lv2ManagerMapType; lv2ManagerMapType m_lv2ManagerMap; l_sortable_plugin_t m_sortedPlugins; - LV2World m_lv2_bundle; + LV2World m_lv2_bundle; + + QString m_cacheFile; - QString m_cache_file; } ; // This is declared static in lv2_manager.cpp +// TODO: integrate into LMMS engine extern lv2Manager * static_lv2_manager; // There is only one of these... #endif diff --git a/plugins/lv2_browser/lv2_browser.cpp b/plugins/lv2_browser/lv2_browser.cpp index 6e71f1828..5fc3b440b 100644 --- a/plugins/lv2_browser/lv2_browser.cpp +++ b/plugins/lv2_browser/lv2_browser.cpp @@ -1,9 +1,8 @@ /* - * lv2_browser.cpp - dialog to display information about installed LV2 - * plugins + * lv2_browser.cpp - dialog to display information about installed LV2 plugins + * + * Copyright (c) 2009 Martin Andrews * - * Copyright (c) 2009-2009 Martin Andrews - * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * * This program is free software; you can redistribute it and/or @@ -66,7 +65,7 @@ plugin::descriptor PLUGIN_EXPORT lv2browser_plugin_descriptor = // neccessary for getting instance out of shared lib plugin * PLUGIN_EXPORT lmms_plugin_main( model * _parent, void * _data ) { - return( new lv2Browser ); + return new lv2Browser; } } @@ -77,10 +76,10 @@ plugin * PLUGIN_EXPORT lmms_plugin_main( model * _parent, void * _data ) lv2Browser::lv2Browser( void ) : tool( &lv2browser_plugin_descriptor, NULL ) { - if( static_lv2_manager == NULL ) - { - static_lv2_manager=new lv2Manager(); - } + if( static_lv2_manager == NULL ) + { + static_lv2_manager = new lv2Manager(); + } } @@ -88,10 +87,10 @@ lv2Browser::lv2Browser( void ) : lv2Browser::~lv2Browser() { - if( static_lv2_manager != NULL ) - { - delete static_lv2_manager; - } + if( static_lv2_manager != NULL ) + { + delete static_lv2_manager; + } } @@ -99,7 +98,7 @@ lv2Browser::~lv2Browser() QString lv2Browser::nodeName( void ) const { - return( lv2browser_plugin_descriptor.name ); + return lv2browser_plugin_descriptor.name; } @@ -115,34 +114,34 @@ lv2BrowserView::lv2BrowserView( tool * _tool ) : hlayout->setMargin( 0 ); m_tabBar = new tabBar( this, QBoxLayout::TopToBottom ); - m_tabBar->setExclusive( TRUE ); + m_tabBar->setExclusive( true ); m_tabBar->setFixedWidth( 72 ); QWidget * ws = new QWidget( this ); ws->setFixedSize( 500, 480 ); - QWidget * available = createTab( ws, tr( "Available Effects" ), VALID ); + QWidget * available = createTab( ws, tr( "Available Effects" ), VALID ); QWidget * unavailable = createTab( ws, tr( "Unavailable Effects" ), INVALID ); QWidget * instruments = createTab( ws, tr( "Instruments" ), SOURCE ); QWidget * analysis = createTab( ws, tr( "Analysis Tools" ), SINK ); QWidget * other = createTab( ws, tr( "Don't know" ), OTHER ); - m_tabBar->addTab( available, tr( "Available Effects" ), - 0, FALSE, TRUE + m_tabBar->addTab( available, tr( "Available Effects" ), + 0, false, true )->setIcon( embed::getIconPixmap( "setup_audio" ) ); - m_tabBar->addTab( unavailable, tr( "Unavailable Effects" ), - 1, FALSE, TRUE + m_tabBar->addTab( unavailable, tr( "Unavailable Effects" ), + 1, false, true )->setIcon( embed::getIconPixmap( "unavailable_sound" ) ); - m_tabBar->addTab( instruments, tr( "Instruments" ), - 2, FALSE, TRUE + m_tabBar->addTab( instruments, tr( "Instruments" ), + 2, false, true )->setIcon( embed::getIconPixmap( "setup_midi" ) ); - m_tabBar->addTab( analysis, tr( "Analysis Tools" ), - 3, FALSE, TRUE + m_tabBar->addTab( analysis, tr( "Analysis Tools" ), + 3, false, true )->setIcon( embed::getIconPixmap( "analysis" ) ); - m_tabBar->addTab( other, tr( "Don't know" ), - 4, TRUE, TRUE + m_tabBar->addTab( other, tr( "Don't know" ), + 4, true, true )->setIcon( embed::getIconPixmap( "uhoh" ) ); m_tabBar->setActiveTab( 0 ); @@ -186,7 +185,7 @@ lv2BrowserView::lv2BrowserView( tool * _tool ) : parentWidget()->hide(); parentWidget()->layout()->setSizeConstraint( QLayout::SetFixedSize ); - + Qt::WindowFlags flags = parentWidget()->windowFlags(); flags |= Qt::MSWindowsFixedSizeDialogHint; flags &= ~Qt::WindowMaximizeButtonHint; @@ -216,7 +215,7 @@ QWidget * lv2BrowserView::createTab( QWidget * _parent, const QString & _txt, const QString type = "" + tr( "Type:" ) + " "; QLabel * title = new QLabel( type + _txt, tab ); QFont f = title->font(); - f.setBold( TRUE ); + f.setBold( true ); title->setFont( pointSize<12>( f ) ); layout->addSpacing( 5 ); @@ -225,16 +224,18 @@ QWidget * lv2BrowserView::createTab( QWidget * _parent, const QString & _txt, lv2Description * description = new lv2Description( tab, _type ); - // Double-clicking on a row gives us a pop-up + // Double-clicking on a row gives us a pop-up connect( description, SIGNAL( doubleClicked( const lv2_key_t & ) ), SLOT( showPorts( const lv2_key_t & ) ) ); - layout->addWidget( description, 1 ); + layout->addWidget( description, 1 ); - return( tab ); + return tab; } + + void lv2BrowserView::showPorts( const lv2_key_t & _key ) { lv2PortDialog ports( _key ); @@ -243,3 +244,4 @@ void lv2BrowserView::showPorts( const lv2_key_t & _key ) #include "moc_lv2_browser.cxx" + diff --git a/plugins/lv2_browser/lv2_browser.h b/plugins/lv2_browser/lv2_browser.h index f7b6d16d9..06cca953d 100644 --- a/plugins/lv2_browser/lv2_browser.h +++ b/plugins/lv2_browser/lv2_browser.h @@ -1,9 +1,8 @@ /* - * ladspa_browser.h - dialog to display information about installed LADSPA - * plugins + * lv2_browser.h - dialog to display information about installed LV2 plugins + * + * Copyright (c) 2009 Martin Andrews * - * Copyright (c) 2009-2009 Martin Andrews - * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * * This program is free software; you can redistribute it and/or @@ -64,7 +63,7 @@ public: virtual pluginView * instantiateView( QWidget * ) { - return( new lv2BrowserView( this ) ); + return new lv2BrowserView( this ); } virtual QString nodeName( void ) const; diff --git a/plugins/lv2_browser/lv2_description.cpp b/plugins/lv2_browser/lv2_description.cpp index 2a02ef15a..f2a53c453 100644 --- a/plugins/lv2_browser/lv2_description.cpp +++ b/plugins/lv2_browser/lv2_description.cpp @@ -1,7 +1,7 @@ /* * lv2_description.cpp - LV2 plugin description * - * Copyright (c) 2007 Javier Serrano Polo + * Copyright (c) 2009 Martin Andrews * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * @@ -35,7 +35,6 @@ #include "audio_device.h" #include "engine.h" -// #include "ladspa_2_lmms.h" #include "mixer.h" @@ -45,9 +44,8 @@ lv2Description::lv2Description( QWidget * _parent, lv2PluginType _type ) : QWidget( _parent ) { -// ladspa2LMMS * manager = engine::getLADSPAManager(); - lv2Manager * manager = static_lv2_manager; -/* + lv2Manager * manager = static_lv2_manager; +/* switch( _type ) { case SOURCE: @@ -74,7 +72,7 @@ lv2Description::lv2Description( QWidget * _parent, */ // Simpler : Get all the plugins, and select based on the type... l_sortable_plugin_t plugins = manager->getSortedPlugins(); - + QList pluginNames; for( l_sortable_plugin_t::iterator it = plugins.begin(); it != plugins.end(); it++ ) @@ -82,11 +80,11 @@ lv2Description::lv2Description( QWidget * _parent, lv2ManagerDescription * description=manager->getDescription( ( *it ).second ); if( description->type == _type && ( - _type != VALID || - description->inputChannels <= engine::getMixer()->audioDev()->channels() + _type != VALID || + description->inputChannels <= engine::getMixer()->audioDev()->channels() ) ) - { + { pluginNames.push_back( ( *it ).first ); m_pluginKeys.push_back( ( *it ).second ); } @@ -139,8 +137,7 @@ void lv2Description::update( const lv2_key_t & _key ) QVBoxLayout * layout = new QVBoxLayout( description ); layout->setSizeConstraint( QLayout::SetFixedSize ); -// ladspa2LMMS * manager = engine::getLADSPAManager(); - lv2Manager * manager = static_lv2_manager; + lv2Manager * manager = static_lv2_manager; QLabel * name = new QLabel( description ); name->setText( QWidget::tr( "Name: " ) + manager->getName( _key ) ); @@ -157,7 +154,7 @@ void lv2Description::update( const lv2_key_t & _key ) maker_label->setAlignment( Qt::AlignTop ); QLabel * maker_content = new QLabel( maker ); maker_content->setText( manager->getMaker( _key ) ); - maker_content->setWordWrap( TRUE ); + maker_content->setWordWrap( true ); makerLayout->addWidget( maker_label ); makerLayout->addWidget( maker_content, 1 ); @@ -174,7 +171,7 @@ void lv2Description::update( const lv2_key_t & _key ) QLabel * copyright_content = new QLabel( copyright ); copyright_content->setText( manager->getCopyright( _key ) ); - copyright_content->setWordWrap( TRUE ); + copyright_content->setWordWrap( true ); copyrightLayout->addWidget( copyright_label ); copyrightLayout->addWidget( copyright_content, 1 ); @@ -225,7 +222,7 @@ void lv2Description::rowChanged( int _pluginIndex ) void lv2Description::onDoubleClicked( QListWidgetItem * _item ) { - emit( doubleClicked( m_currentSelection ) ); + emit doubleClicked( m_currentSelection ); } diff --git a/plugins/lv2_browser/lv2_description.h b/plugins/lv2_browser/lv2_description.h index bd14087e8..9878d88fd 100644 --- a/plugins/lv2_browser/lv2_description.h +++ b/plugins/lv2_browser/lv2_description.h @@ -1,7 +1,7 @@ /* * lv2_description.h - LV2 plugin description Pane of Information * - * Copyright (c) 2009-2009 Martin Andrews + * Copyright (c) 2009 Martin Andrews * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * diff --git a/plugins/lv2_browser/lv2_port_dialog.cpp b/plugins/lv2_browser/lv2_port_dialog.cpp index e2eb5573f..295a376a2 100644 --- a/plugins/lv2_browser/lv2_port_dialog.cpp +++ b/plugins/lv2_browser/lv2_port_dialog.cpp @@ -1,8 +1,8 @@ /* * lv2_port_dialog.cpp - dialog to test an LV2 plugin * - * Copyright (c) 2009-2009 Martin Andrews - * + * Copyright (c) 2009 Martin Andrews + * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * * This program is free software; you can redistribute it and/or @@ -30,18 +30,16 @@ #include "embed.h" #include "engine.h" -// #include "ladspa_2_lmms.h" #include "mixer.h" lv2PortDialog::lv2PortDialog( const lv2_key_t & _key ) { -// ladspa2LMMS * manager = engine::getLADSPAManager(); - lv2Manager * manager = static_lv2_manager; + lv2Manager * manager = static_lv2_manager; setWindowIcon( embed::getIconPixmap( "ports" ) ); setWindowTitle( tr( "Ports" ) ); - setModal( TRUE ); + setModal( true ); QVBoxLayout * vlayout = new QVBoxLayout( this ); vlayout->setSpacing( 0 ); @@ -59,7 +57,7 @@ lv2PortDialog::lv2PortDialog( const lv2_key_t & _key ) // ports.append( tr( "SR Dependent" ) ); QTableWidget * settings = new QTableWidget( pc, ports.size(), this ); - settings->setHorizontalHeaderLabels( ports ); + settings->setHorizontalHeaderLabels( ports ); for( Uint16 row = 0; row < pc; row++ ) { @@ -82,25 +80,25 @@ lv2PortDialog::lv2PortDialog( const lv2_key_t & _key ) manager->isPortInput( _key, row ) ? tr( "Input" ) : tr( "Output" ) ); - QStringList values; - if( manager->isInteger( _key, row ) ) - { - values = manager->listEnumeration( _key, row ); - settings->item( row, col )->setText( values.join("|") ); - } - else - { - settings->item( row, col )->setText( tr( "Float" ) ); - } - col++; - + QStringList values; + if( manager->isInteger( _key, row ) ) + { + values = manager->listEnumeration( _key, row ); + settings->item( row, col )->setText( values.join("|") ); + } + else + { + settings->item( row, col )->setText( tr( "Float" ) ); + } + col++; + /* settings->item( row, col++ )->setText( manager->isPortToggled( _key, row ) ? tr( "Toggled" ) : manager->isInteger( _key, row ) ? tr( "Integer" ) : tr( "Float" ) ); */ - + float min = manager->getLowerBound( _key, row ); float max = manager->getUpperBound( _key, row ); float def = manager->getDefaultSetting( _key, row ); @@ -126,7 +124,7 @@ lv2PortDialog::lv2PortDialog( const lv2_key_t & _key ) } else if( values.size() >0 ) { - // Don't have a minimum + // Don't have a minimum // range += QString::number( static_cast( min ) ) + " < "; } else @@ -163,7 +161,7 @@ lv2PortDialog::lv2PortDialog( const lv2_key_t & _key ) { range += QString::number( max ); } - + settings->item( row, col++ )->setText( range ); /* diff --git a/plugins/lv2_browser/lv2_port_dialog.h b/plugins/lv2_browser/lv2_port_dialog.h index 2ac0db3a1..5d14be193 100644 --- a/plugins/lv2_browser/lv2_port_dialog.h +++ b/plugins/lv2_browser/lv2_port_dialog.h @@ -1,8 +1,8 @@ /* * lv2_port_dialog.h - dialog to test an LV2 plugin * - * Copyright (c) 2009-2009 Martin Andrews - * + * Copyright (c) 2009 Martin Andrews + * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * * This program is free software; you can redistribute it and/or diff --git a/src/core/lv2_2_lmms.cpp b/src/core/lv2_2_lmms.cpp index 505aac5fd..359d8e307 100644 --- a/src/core/lv2_2_lmms.cpp +++ b/src/core/lv2_2_lmms.cpp @@ -1,11 +1,11 @@ /* * lv2_2_lmms.cpp - class that identifies and instantiates LV2 effects - * for use with LMMS + * for use with LMMS * - * Copyright (c) 2009-2009 Martin Andrews + * Copyright (c) 2009 Martin Andrews * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net - * + * * 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 @@ -30,16 +30,16 @@ lv22LMMS::lv22LMMS( void ) { l_sortable_plugin_t plugins = getSortedPlugins(); - + for( l_sortable_plugin_t::iterator it = plugins.begin(); it != plugins.end(); it++ ) { lv2_key_t key = (*it).second; lv2ManagerDescription * desc = getDescription( key ); - + if( desc->type == SOURCE ) { - m_instruments.append( qMakePair( getName( key ), + m_instruments.append( qMakePair( getName( key ), key ) ); } else if( desc->type == TRANSFER && @@ -57,7 +57,7 @@ lv22LMMS::lv22LMMS( void ) desc->inputChannels != 2 && desc->inputChannels != 4 ) ) ) { - m_invalidEffects.append( qMakePair( getName( key ), + m_invalidEffects.append( qMakePair( getName( key ), key ) ); } else if( desc->type == SINK ) @@ -67,25 +67,26 @@ lv22LMMS::lv22LMMS( void ) } else if( desc->type == OTHER ) { - m_otherPlugins.append( qMakePair( getName( key ), + m_otherPlugins.append( qMakePair( getName( key ), key ) ); } } } - - - - + + + + lv22LMMS::~lv22LMMS() { } + QString lv22LMMS::getShortName( const lv2_key_t & _key ) { QString name = getName( _key ); - + if( name.indexOf( "(" ) > 0 ) { name = name.left( name.indexOf( "(" ) ); @@ -120,7 +121,7 @@ QString lv22LMMS::getShortName( const lv2_key_t & _key ) { name = "LV2 Plugin"; } - - return( name ); + + return name; } diff --git a/src/core/lv2_manager.cpp b/src/core/lv2_manager.cpp index 1a1bb5451..4d5526e76 100644 --- a/src/core/lv2_manager.cpp +++ b/src/core/lv2_manager.cpp @@ -1,8 +1,7 @@ /* - * ladspa_manager.cpp - a class to manage loading and instantiation - * of lv2 plugins + * lv2_manager.cpp - a class to manage loading and instantiation of lv2 plugins * - * Copyright (c) 2005-2008 Danny McRae + * Copyright (c) 2009 Martin Andrews * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * @@ -28,7 +27,6 @@ #include #include #include -// #include #include #include @@ -38,38 +36,40 @@ lv2Manager * static_lv2_manager=(lv2Manager *)NULL; // There is only one of these... + + LV2World::LV2World() { - printf( "Creating static LV2World\n" ); - - world=slv2_world_new(); - slv2_world_load_all(world); - - input_class = slv2_value_new_uri(world, SLV2_PORT_CLASS_INPUT); - output_class = slv2_value_new_uri(world, SLV2_PORT_CLASS_OUTPUT); - control_class = slv2_value_new_uri(world, SLV2_PORT_CLASS_CONTROL); - audio_class = slv2_value_new_uri(world, SLV2_PORT_CLASS_AUDIO); - event_class = slv2_value_new_uri(world, SLV2_PORT_CLASS_EVENT); - midi_class = slv2_value_new_uri(world, SLV2_EVENT_CLASS_MIDI); - in_place_broken = slv2_value_new_uri(world, SLV2_NAMESPACE_LV2 "inPlaceBroken"); - integer = slv2_value_new_uri(world, SLV2_NAMESPACE_LV2 "integer"); - toggled = slv2_value_new_uri(world, SLV2_NAMESPACE_LV2 "toggled"); - srate = slv2_value_new_uri(world, SLV2_NAMESPACE_LV2 "sampleRate"); - gtk_gui = slv2_value_new_uri(world, "http://lv2plug.in/ns/extensions/ui#GtkUI"); + world=slv2_world_new(); + slv2_world_load_all( world ); + + input_class = slv2_value_new_uri( world, SLV2_PORT_CLASS_INPUT ); + output_class = slv2_value_new_uri(world, SLV2_PORT_CLASS_OUTPUT ); + control_class = slv2_value_new_uri( world, SLV2_PORT_CLASS_CONTROL ); + audio_class = slv2_value_new_uri( world, SLV2_PORT_CLASS_AUDIO ); + event_class = slv2_value_new_uri( world, SLV2_PORT_CLASS_EVENT ); + midi_class = slv2_value_new_uri( world, SLV2_EVENT_CLASS_MIDI ); + in_place_broken = slv2_value_new_uri( world, SLV2_NAMESPACE_LV2 "inPlaceBroken" ); + integer = slv2_value_new_uri( world, SLV2_NAMESPACE_LV2 "integer" ); + toggled = slv2_value_new_uri( world, SLV2_NAMESPACE_LV2 "toggled" ); + srate = slv2_value_new_uri( world, SLV2_NAMESPACE_LV2 "sampleRate" ); + gtk_gui = slv2_value_new_uri( world, "http://lv2plug.in/ns/extensions/ui#GtkUI" ); } + + + LV2World::~LV2World() { - slv2_value_free(input_class); - slv2_value_free(output_class); - slv2_value_free(control_class); - slv2_value_free(audio_class); - slv2_value_free(event_class); - slv2_value_free(midi_class); - slv2_value_free(in_place_broken); + slv2_value_free( input_class ); + slv2_value_free( output_class ); + slv2_value_free( control_class ); + slv2_value_free( audio_class ); + slv2_value_free( event_class ); + slv2_value_free( midi_class ); + slv2_value_free( in_place_broken ); - slv2_world_free( world ); - printf("Destroyed SLV2\n"); + slv2_world_free( world ); } @@ -77,96 +77,46 @@ LV2World::~LV2World() lv2Manager::lv2Manager( void ) { - if( m_lv2_bundle.world == NULL ) { - printf("Failed to Initialize slv2_world\n"); - return; - } - printf("Initialized slv2_world\n"); - - m_cache_file = configManager::inst()->workingDir() + "lv2_cache.txt"; - - loadFromCacheFile(); - - if( false ) { // This is to test the loading from the cache file - l_lv2_key_t keys = m_lv2ManagerMap.keys(); - for( l_lv2_key_t::iterator it = keys.begin(); - it != keys.end(); it++ ) - { - printf( "Read from file : '%s'\n", getName( *it ).toAscii().data() ); - } - } - -// slv2_world_load_all( m_world ); // No special path apart from LV2_PATH - m_plugin_list = slv2_world_get_all_plugins( m_lv2_bundle.world ); - - for(unsigned i=0; i < slv2_plugins_size( m_plugin_list ); i++) - { - SLV2Plugin p = slv2_plugins_get_at( m_plugin_list, i ); - addPlugins( p ); // This will just return if the plugin information is cached (after being loaded) - } - -/* - QStringList lv2Directories = QString( getenv( "LV2_PATH" ) ). - split( ',' ); -// lv2Directories += configManager::inst()->ladspaDir().split( ',' ); - - lv2Directories.push_back( configManager::inst()->pluginDir() + "lv2" ); -#ifndef LMMS_BUILD_WIN32 - lv2Directories.push_back( QString( LIB_DIR ) + "lv2" ); - lv2Directories.push_back( "/usr/lib/lmms/lv2" ); - lv2Directories.push_back( "/usr/local/lib/lmms/lv2" ); - lv2Directories.push_back( "/usr/lib/lv2" ); - lv2Directories.push_back( "/usr/local/lib/lv2" ); -#endif - - for( QStringList::iterator it = lv2Directories.begin(); - it != lv2Directories.end(); ++it ) + if( m_lv2_bundle.world == NULL ) { - QDir directory( ( *it ) ); - QFileInfoList list = directory.entryInfoList(); - for( QFileInfoList::iterator file = list.begin(); - file != list.end(); ++file ) + printf( "Failed to Initialize slv2_world\n" ); + return; + } + printf( "Initialized slv2_world\n" ); + + m_cacheFile = configManager::inst()->workingDir() + ".lv2_cache.txt"; + + loadFromCacheFile(); + + if( false ) + { + // This is to test the loading from the cache file + l_lv2_key_t keys = m_lv2ManagerMap.keys(); + for( l_lv2_key_t::iterator it = keys.begin(); + it != keys.end(); it++ ) { - const QFileInfo & f = *file; - if( !f.isFile() || -#ifdef LMMS_BUILD_WIN32 - f.fileName().right( 3 ).toLower() != "dll" -#else - f.fileName().right( 2 ).toLower() != "so" -#endif - ) - { - continue; - } - - QLibrary plugin_lib( f.absoluteFilePath() ); - - if( plugin_lib.load() == TRUE ) - { - LADSPA_Descriptor_Function descriptorFunction = - ( LADSPA_Descriptor_Function ) plugin_lib.resolve( - "ladspa_descriptor" ); - if( descriptorFunction != NULL ) - { - addPlugins( descriptorFunction, - f.fileName() ); - } - } + printf( "Read from file : '%s'\n", getName( *it ).toAscii().data() ); } } - */ - saveToCacheFile(); + // slv2_world_load_all( m_world ); // No special path apart from LV2_PATH + m_pluginList = slv2_world_get_all_plugins( m_lv2_bundle.world ); + + for( unsigned i=0; i < slv2_plugins_size( m_pluginList ); ++i ) + { + SLV2Plugin p = slv2_plugins_get_at( m_pluginList, i ); + addPlugins( p ); // This will just return if the plugin information is cached (after being loaded) + } + + saveToCacheFile(); l_lv2_key_t keys = m_lv2ManagerMap.keys(); - for( l_lv2_key_t::iterator it = keys.begin(); - it != keys.end(); it++ ) + for( l_lv2_key_t::iterator it = keys.begin(); it != keys.end(); ++it ) { m_sortedPlugins.append( qMakePair( getName( *it ), *it ) ); } qSort( m_sortedPlugins ); - printf("Sorted plugins\n"); } @@ -179,26 +129,20 @@ lv2Manager::~lv2Manager() { delete it.value(); } - - slv2_plugins_free( m_lv2_bundle.world, m_plugin_list ); - printf("Freed list of plugins\n"); - -// if( m_world != NULL ) { -// slv2_world_free( m_world ); -// } + + slv2_plugins_free( m_lv2_bundle.world, m_pluginList ); } -lv2ManagerDescription * lv2Manager::getDescription( - const lv2_key_t & _plugin ) +lv2ManagerDescription * lv2Manager::getDescription( const lv2_key_t & _plugin ) { if( m_lv2ManagerMap.contains( _plugin ) ) { - return( m_lv2ManagerMap[_plugin] ); + return m_lv2ManagerMap[_plugin]; } - return( NULL ); // If it doesn't exist + return NULL; // If it doesn't exist } @@ -206,25 +150,20 @@ lv2ManagerDescription * lv2Manager::getDescription( void lv2Manager::ensureLV2DataExists( lv2ManagerDescription *desc ) { -// printf( "Ensuring LV2 Data for '%s'\n", (desc->uri).toAscii().data() ); - if( desc->plugin == NULL ) - { - printf( " Need to load actual plugin data for '%s'\n", (desc->uri).toAscii().constData() ); - - // use uri to get data - SLV2Value uri = slv2_value_new_uri( m_lv2_bundle.world, (desc->uri).toAscii().constData() ); - desc->plugin = slv2_plugins_get_by_uri( m_plugin_list, uri ); - slv2_value_free( uri ); - - if( desc->plugin == NULL ) // Still empty?? - { - printf( " Failed to load actual plugin data for '%s'\n", (desc->uri).toAscii().constData() ); - } - } - else { -// printf( " LV2 Data already existed for '%s'\n", (desc->uri).toAscii().data() ); - } - return; // There really should be data there now (or a suitable comment) + if( desc->plugin == NULL ) + { + printf( " Need to load actual plugin data for '%s'\n", (desc->uri).toAscii().constData() ); + + // use uri to get data + SLV2Value uri = slv2_value_new_uri( m_lv2_bundle.world, (desc->uri).toAscii().constData() ); + desc->plugin = slv2_plugins_get_by_uri( m_pluginList, uri ); + slv2_value_free( uri ); + + if( desc->plugin == NULL ) // Still empty?? + { + printf( " Failed to load actual plugin data for '%s'\n", (desc->uri).toAscii().constData() ); + } + } } @@ -232,43 +171,44 @@ void lv2Manager::ensureLV2DataExists( lv2ManagerDescription *desc ) void lv2Manager::addPlugins( SLV2Plugin _plugin ) { - QString uri= QString( slv2_value_as_uri( slv2_plugin_get_uri( _plugin ) ) ); - lv2_key_t key = lv2_key_t( uri ); - - if( m_lv2ManagerMap.contains( key ) ) { - printf( "Already in Cache LV2 plugin URI : '%s'\n", uri.toAscii().constData() ); - return; - } + QString uri= QString( slv2_value_as_uri( slv2_plugin_get_uri( _plugin ) ) ); + lv2_key_t key = lv2_key_t( uri ); -/* + if( m_lv2ManagerMap.contains( key ) ) + { + printf( "Already in Cache LV2 plugin URI : '%s'\n", uri.toAscii().constData() ); + return; + } + +/* // Speed things up (before caching of data implemented) - if( ! uri.contains( "Organ" ) ) + if( ! uri.contains( "Organ" ) ) { printf( "Skipping LV2 plugin URI : '%s'\n", uri.toAscii().constData() ); - return; + return; } */ printf( "Examining LV2 plugin URI : '%s'\n", uri.toAscii().constData() ); - + lv2ManagerDescription * description = new lv2ManagerDescription; description->plugin = _plugin; // Investigate this plugin description->uri = uri; - + // Any data accessed within the plugin itself causes the whole thing to be 'unwrapped' SLV2Value data = slv2_plugin_get_name( _plugin ); description->name = QString( slv2_value_as_string( data ) ); // printf( " LV2 plugin Name : '%s'\n", slv2_value_as_string( data ) ); slv2_value_free( data ); - + description->inputChannels = slv2_plugin_get_num_ports_of_class( _plugin, m_lv2_bundle.input_class, m_lv2_bundle.audio_class, NULL); description->outputChannels = slv2_plugin_get_num_ports_of_class( _plugin, m_lv2_bundle.output_class, m_lv2_bundle.audio_class, NULL); - -// This always seems to return 'Plugin', which isn't so useful to us + +// This always seems to return 'Plugin', which isn't so useful to us // SLV2PluginClass pclass = slv2_plugin_get_class( _plugin ); // SLV2Value label = slv2_plugin_class_get_label( pclass ); // printf( "Plugin Class is : '%s'\n", slv2_value_as_string( label ) ); @@ -295,9 +235,9 @@ void lv2Manager::addPlugins( SLV2Plugin _plugin ) } m_lv2ManagerMap[key] = description; - + printf( " Finished that plugin : type=%d\n", (int)description->type ); - + /* const LADSPA_Descriptor * descriptor; @@ -310,7 +250,7 @@ void lv2Manager::addPlugins( SLV2Plugin _plugin ) { continue; } - + plugIn->index = pluginIndex; m_ladspaManagerMap[key] = plugIn; @@ -320,91 +260,37 @@ void lv2Manager::addPlugins( SLV2Plugin _plugin ) } -/* -// This is an (Approximate) counting function - -Uint16 ladspaManager::getPluginInputs( - const LADSPA_Descriptor * _descriptor ) -{ - Uint16 inputs = 0; - - for( Uint16 port = 0; port < _descriptor->PortCount; port++ ) - { - if( LADSPA_IS_PORT_INPUT( - _descriptor->PortDescriptors[port] ) && - LADSPA_IS_PORT_AUDIO( - _descriptor->PortDescriptors[port] ) ) - { - QString name = QString( - _descriptor->PortNames[port] ); - if( name.toUpper().contains( "IN" ) ) - { - inputs++; - } - } - } - return inputs; -} - - -// This is an (Approximate) counting function - -Uint16 ladspaManager::getPluginOutputs( - const LADSPA_Descriptor * _descriptor ) -{ - Uint16 outputs = 0; - - for( Uint16 port = 0; port < _descriptor->PortCount; port++ ) - { - if( LADSPA_IS_PORT_OUTPUT( - _descriptor->PortDescriptors[port] ) && - LADSPA_IS_PORT_AUDIO( - _descriptor->PortDescriptors[port] ) ) - { - QString name = QString( - _descriptor->PortNames[port] ); - if( name.toUpper().contains( "OUT" ) ) - { - outputs++; - } - } - } - return outputs; -} - -*/ - l_sortable_plugin_t lv2Manager::getSortedPlugins() { - return( m_sortedPlugins ); + return m_sortedPlugins; } -void lv2Manager::saveToCacheFile() +void lv2Manager::saveToCacheFile() { - QFile file( m_cache_file ); + QFile file( m_cacheFile ); QString line; - if ( file.open( QIODevice::WriteOnly ) ) { + if ( file.open( QIODevice::WriteOnly ) ) { QTextStream stream( &file ); stream << "; This file is auto-regenerated by lmms\n\n"; - + l_lv2_key_t keys = m_lv2ManagerMap.keys(); for( l_lv2_key_t::iterator it = keys.begin(); it != keys.end(); it++ ) { stream << "[" << (*it) << "]\n"; // Plugin URI - + lv2ManagerDescription * description=getDescription( (*it) ); - stream << "name=" << description->name << "\n"; // Plugin name + stream << "name=" << description->name << "\n"; // Plugin name stream << "type=" << (int)description->type << "\n"; stream << "channels.audio.input=" << description->inputChannels << "\n"; stream << "channels.audio.output=" << description->outputChannels << "\n"; - + stream << "\n"; } - + file.close(); } return; @@ -413,39 +299,39 @@ void lv2Manager::saveToCacheFile() -void lv2Manager::loadFromCacheFile() +void lv2Manager::loadFromCacheFile() { - QFile file( m_cache_file ); + QFile file( m_cacheFile ); QString line; if ( file.open( QIODevice::ReadOnly ) ) { // file opened successfully QTextStream stream( &file ); while ( !stream.atEnd() ) { // until end of file... - line = stream.readLine().trimmed(); + line = stream.readLine().trimmed(); if( line.startsWith( "[" ) && line.endsWith( "]" ) ) // Skip over everything else { lv2ManagerDescription * desc=new lv2ManagerDescription; desc->plugin = NULL; // To ensure that we don't attempt to use it desc->uri = line.mid( 1, line.length()-2 ); // Extract the URI printf( "Reading Data for '%s' from the Cache\n", desc->uri.toAscii().data() ); - + // Read in data for this uri - until we get to a blank line bool finished = false; - while ( !stream.atEnd() && !finished ) - { + while ( !stream.atEnd() && !finished ) + { line = stream.readLine().trimmed(); - if( line.length() == 0 ) + if( line.length() == 0 ) { finished = true; continue; } int equals = line.indexOf( "=" ); - if( equals > 0 ) + if( equals > 0 ) { QString name = line.left(equals); QString value = line.mid(equals+1); printf( " Found '%s' = '%s'\n", name.toAscii().data(), value.toAscii().data() ); - - if( name == "name" ) + + if( name == "name" ) { desc->name = value; } @@ -461,7 +347,7 @@ void lv2Manager::loadFromCacheFile() { desc->outputChannels = value.toInt(); } - else + else { printf( "Could not parse line : '%s' in lv2.cache\n", line.toAscii().data() ); } @@ -481,99 +367,30 @@ void lv2Manager::loadFromCacheFile() -/* - -QString ladspaManager::getLabel( const ladspa_key_t & _plugin ) -{ - if( m_ladspaManagerMap.contains( _plugin ) ) - { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - return( QString( descriptor->Label ) ); - } - else - { - return( QString( "" ) ); - } -} - - - - -bool ladspaManager::hasRealTimeDependency( - const ladspa_key_t & _plugin ) -{ - if( m_ladspaManagerMap.contains( _plugin ) ) - { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - return( LADSPA_IS_REALTIME( descriptor->Properties ) ); - } - else - { - return( FALSE ); - } -} - -*/ - bool lv2Manager::isInplaceBroken( const lv2_key_t & _plugin ) { if( m_lv2ManagerMap.contains( _plugin ) ) { - lv2ManagerDescription * d = m_lv2ManagerMap[_plugin]; - ensureLV2DataExists( d ); - return ( slv2_plugin_has_feature( d->plugin, m_lv2_bundle.in_place_broken ) ); - } - else - { - return( FALSE ); + lv2ManagerDescription * d = m_lv2ManagerMap[_plugin]; + ensureLV2DataExists( d ); + return slv2_plugin_has_feature( d->plugin, m_lv2_bundle.in_place_broken ); } + return false; } -/* - -bool ladspaManager::isRealTimeCapable( - const ladspa_key_t & _plugin ) -{ - if( m_ladspaManagerMap.contains( _plugin ) ) - { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - return( LADSPA_IS_HARD_RT_CAPABLE( descriptor->Properties ) ); - } - else - { - return( FALSE ); - } -} - -*/ QString lv2Manager::getName( const lv2_key_t & _plugin ) { if( m_lv2ManagerMap.contains( _plugin ) ) { - // This is a cached entry - so it will be here - // whether the plugin rdf is fully loaded or not - return m_lv2ManagerMap[_plugin]->name; - } - else - { - return( QString( "" ) ); + // This is a cached entry - so it will be here + // whether the plugin rdf is fully loaded or not + return m_lv2ManagerMap[_plugin]->name; } + return QString(); } @@ -583,18 +400,14 @@ QString lv2Manager::getMaker( const lv2_key_t & _plugin ) { if( m_lv2ManagerMap.contains( _plugin ) ) { - lv2ManagerDescription * d = m_lv2ManagerMap[_plugin]; - ensureLV2DataExists( d ); + lv2ManagerDescription * d = m_lv2ManagerMap[_plugin]; + ensureLV2DataExists( d ); SLV2Value data = slv2_plugin_get_author_name( d->plugin ); - QString ret = QString( data ? - slv2_value_as_string( data ) : "Unknown" ); + QString ret = QString( data ? slv2_value_as_string( data ) : "Unknown" ); slv2_value_free( data ); - return( ret ); - } - else - { - return( QString( "" ) ); + return ret; } + return QString(); } @@ -604,18 +417,14 @@ QString lv2Manager::getCopyright( const lv2_key_t & _plugin ) { if( m_lv2ManagerMap.contains( _plugin ) ) { - lv2ManagerDescription * d = m_lv2ManagerMap[_plugin]; - ensureLV2DataExists( d ); + lv2ManagerDescription * d = m_lv2ManagerMap[_plugin]; + ensureLV2DataExists( d ); SLV2Value data = slv2_plugin_get_author_homepage( d->plugin ); - QString ret = QString( data ? - slv2_value_as_string( data ) : "Unknown" ); + QString ret = QString( data ? slv2_value_as_string( data ) : "Unknown" ); slv2_value_free( data ); - return( ret ); - } - else - { - return( QString( "" ) ); + return ret; } + return QString(); } @@ -625,48 +434,41 @@ Uint32 lv2Manager::getPortCount( const lv2_key_t & _plugin ) { if( m_lv2ManagerMap.contains( _plugin ) ) { - lv2ManagerDescription * d = m_lv2ManagerMap[_plugin]; - ensureLV2DataExists( d ); - return( (Uint32) - slv2_plugin_get_num_ports( d->plugin ) - ); - } - else - { - return( 0 ); + lv2ManagerDescription * d = m_lv2ManagerMap[_plugin]; + ensureLV2DataExists( d ); + return (Uint32) slv2_plugin_get_num_ports( d->plugin ); } + return 0; } -bool lv2Manager::isPortClass( const lv2_key_t & _plugin, - Uint32 _port, SLV2Value _class ) + + +bool lv2Manager::isPortClass( const lv2_key_t & _plugin, + Uint32 _port, SLV2Value _class ) { - if( m_lv2ManagerMap.contains( _plugin ) ) - { - lv2ManagerDescription * d = m_lv2ManagerMap[_plugin]; - ensureLV2DataExists( d ); - if( _port < slv2_plugin_get_num_ports( d->plugin ) ) - { - SLV2Port port = slv2_plugin_get_port_by_index( d->plugin, _port ); - return( - slv2_port_is_a( d->plugin, port, _class ) - ); - } + if( m_lv2ManagerMap.contains( _plugin ) ) + { + lv2ManagerDescription * d = m_lv2ManagerMap[_plugin]; + ensureLV2DataExists( d ); + if( _port < slv2_plugin_get_num_ports( d->plugin ) ) + { + SLV2Port port = slv2_plugin_get_port_by_index( d->plugin, _port ); + return slv2_port_is_a( d->plugin, port, _class ); + } } - return( FALSE ); // Not found + return false; // Not found } -bool lv2Manager::isPortInput( const lv2_key_t & _plugin, - Uint32 _port ) +bool lv2Manager::isPortInput( const lv2_key_t & _plugin, Uint32 _port ) { return isPortClass( _plugin, _port, m_lv2_bundle.input_class ); } -bool lv2Manager::isPortOutput( const lv2_key_t & _plugin, - Uint32 _port ) +bool lv2Manager::isPortOutput( const lv2_key_t & _plugin, Uint32 _port ) { return isPortClass( _plugin, _port, m_lv2_bundle.output_class ); } @@ -674,8 +476,7 @@ bool lv2Manager::isPortOutput( const lv2_key_t & _plugin, -bool lv2Manager::isPortAudio( const lv2_key_t & _plugin, - Uint32 _port ) +bool lv2Manager::isPortAudio( const lv2_key_t & _plugin, Uint32 _port ) { return isPortClass( _plugin, _port, m_lv2_bundle.audio_class ); } @@ -683,241 +484,105 @@ bool lv2Manager::isPortAudio( const lv2_key_t & _plugin, -bool lv2Manager::isPortControl( const lv2_key_t & _plugin, - Uint32 _port ) +bool lv2Manager::isPortControl( const lv2_key_t & _plugin, Uint32 _port ) { return isPortClass( _plugin, _port, m_lv2_bundle.control_class ); } -/* - -bool ladspaManager::areHintsSampleRateDependent( - const ladspa_key_t & _plugin, - Uint32 _port ) -{ - if( m_ladspaManagerMap.contains( _plugin ) - && _port < getPortCount( _plugin ) ) - { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - LADSPA_PortRangeHintDescriptor hintDescriptor = - descriptor->PortRangeHints[_port].HintDescriptor; - return( LADSPA_IS_HINT_SAMPLE_RATE ( hintDescriptor ) ); - } - else - { - return( FALSE ); - } -} - -*/ void lv2Manager::getRanges( const lv2_key_t & _plugin, - Uint32 _port, float * _def, float * _min, float * _max ) + Uint32 _port, float * _def, float * _min, float * _max ) { - if( m_lv2ManagerMap.contains( _plugin ) ) - { - lv2ManagerDescription * d = m_lv2ManagerMap[_plugin]; - ensureLV2DataExists( d ); - if( _port < slv2_plugin_get_num_ports( d->plugin ) ) - { - SLV2Port port = slv2_plugin_get_port_by_index( d->plugin, _port ); - SLV2Value def, min, max; - slv2_port_get_range( d->plugin, port, &def, &min, &max ); - *_def = NOHINT; - if( def != NULL ) - { - *_def = slv2_value_as_float(def); - slv2_value_free(def); - } - *_min = NOHINT; - if( min != NULL ) - { - *_min = slv2_value_as_float(min); - slv2_value_free(min); - } - *_max = NOHINT; - if( max != NULL ) - { - *_max = slv2_value_as_float(max); - slv2_value_free(max); - } - } + if( m_lv2ManagerMap.contains( _plugin ) ) + { + lv2ManagerDescription * d = m_lv2ManagerMap[_plugin]; + ensureLV2DataExists( d ); + if( _port < slv2_plugin_get_num_ports( d->plugin ) ) + { + SLV2Port port = slv2_plugin_get_port_by_index( d->plugin, _port ); + SLV2Value def, min, max; + slv2_port_get_range( d->plugin, port, &def, &min, &max ); + *_def = NOHINT; + if( def != NULL ) + { + *_def = slv2_value_as_float(def); + slv2_value_free(def); + } + *_min = NOHINT; + if( min != NULL ) + { + *_min = slv2_value_as_float(min); + slv2_value_free(min); + } + *_max = NOHINT; + if( max != NULL ) + { + *_max = slv2_value_as_float(max); + slv2_value_free(max); + } + } } } + float lv2Manager::getLowerBound( const lv2_key_t & _plugin, Uint32 _port ) { - float def, min, max; - getRanges( _plugin, _port, &def, &min, &max ); - return( min ); + float def, min, max; + getRanges( _plugin, _port, &def, &min, &max ); + return min; } + + float lv2Manager::getUpperBound( const lv2_key_t & _plugin, Uint32 _port ) { - float def, min, max; - getRanges( _plugin, _port, &def, &min, &max ); - return( max ); + float def, min, max; + getRanges( _plugin, _port, &def, &min, &max ); + return max; } + + float lv2Manager::getDefaultSetting( const lv2_key_t & _plugin, Uint32 _port ) { - float def, min, max; - getRanges( _plugin, _port, &def, &min, &max ); - return( def ); + float def, min, max; + getRanges( _plugin, _port, &def, &min, &max ); + return def; } - -/* -float ladspaManager::getDefaultSetting( const ladspa_key_t & _plugin, - Uint32 _port ) -{ - if( m_ladspaManagerMap.contains( _plugin ) - && _port < getPortCount( _plugin ) ) - { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - LADSPA_PortRangeHintDescriptor hintDescriptor = - descriptor->PortRangeHints[_port].HintDescriptor; - switch( hintDescriptor & LADSPA_HINT_DEFAULT_MASK ) - { - case LADSPA_HINT_DEFAULT_NONE: - return( NOHINT ); - case LADSPA_HINT_DEFAULT_MINIMUM: - return( descriptor->PortRangeHints[_port]. - LowerBound ); - case LADSPA_HINT_DEFAULT_LOW: - if( LADSPA_IS_HINT_LOGARITHMIC - ( hintDescriptor ) ) - { - return( exp( log( descriptor->PortRangeHints[_port].LowerBound ) - * 0.75 - + log( descriptor->PortRangeHints[_port].UpperBound ) - * 0.25 ) ); - } - else - { - return( descriptor->PortRangeHints[_port].LowerBound - * 0.75 - + descriptor->PortRangeHints[_port].UpperBound - * 0.25 ); - } - case LADSPA_HINT_DEFAULT_MIDDLE: - if( LADSPA_IS_HINT_LOGARITHMIC - ( hintDescriptor ) ) - { - return( sqrt( descriptor->PortRangeHints[_port].LowerBound - * descriptor->PortRangeHints[_port].UpperBound ) ); - } - else - { - return( 0.5 * ( descriptor->PortRangeHints[_port].LowerBound - + descriptor->PortRangeHints[_port].UpperBound ) ); - } - case LADSPA_HINT_DEFAULT_HIGH: - if( LADSPA_IS_HINT_LOGARITHMIC - ( hintDescriptor ) ) - { - return( exp( log( descriptor->PortRangeHints[_port].LowerBound ) - * 0.25 - + log( descriptor->PortRangeHints[_port].UpperBound ) - * 0.75 ) ); - } - else - { - return( descriptor->PortRangeHints[_port].LowerBound - * 0.25 - + descriptor->PortRangeHints[_port].UpperBound - * 0.75 ); - } - case LADSPA_HINT_DEFAULT_MAXIMUM: - return( descriptor->PortRangeHints[_port].UpperBound ); - case LADSPA_HINT_DEFAULT_0: - return( 0.0 ); - case LADSPA_HINT_DEFAULT_1: - return( 1.0 ); - case LADSPA_HINT_DEFAULT_100: - return( 100.0 ); - case LADSPA_HINT_DEFAULT_440: - return( 440.0 ); - default: - return( NOHINT ); - } - } - else - { - return( NOHINT ); - } -} -*/ - - -/* -bool ladspaManager::isLogarithmic( const ladspa_key_t & _plugin, - Uint32 _port ) -{ - if( m_ladspaManagerMap.contains( _plugin ) - && _port < getPortCount( _plugin ) ) - { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - LADSPA_PortRangeHintDescriptor hintDescriptor = - descriptor->PortRangeHints[_port].HintDescriptor; - return( LADSPA_IS_HINT_LOGARITHMIC( hintDescriptor ) ); - } - else - { - return( FALSE ); - } -} - - -*/ - - - QStringList lv2Manager::listEnumeration( const lv2_key_t & _plugin, Uint32 _port ) { - QStringList list; - if( m_lv2ManagerMap.contains( _plugin ) ) - { - lv2ManagerDescription * d = m_lv2ManagerMap[_plugin]; - ensureLV2DataExists( d ); - if( _port < slv2_plugin_get_num_ports( d->plugin ) ) - { - SLV2Port port = slv2_plugin_get_port_by_index( d->plugin, _port ); - SLV2ScalePoints sp_list = slv2_port_get_scale_points( d->plugin, port ); - if( sp_list != NULL ) - { - printf( "Got %d ScalePoints for port=%d\n", - slv2_scale_points_size( sp_list ), _port ); - - for( unsigned i = 0; i < slv2_scale_points_size( sp_list ); i++ ) - { - SLV2ScalePoint sp = slv2_scale_points_get_at( sp_list, i ); - SLV2Value label = slv2_scale_point_get_label( sp ); - list.append( QString( slv2_value_as_string( label ) ) ); - // slv2_value_free( label ); - // slv2_scale_point_free( sp ); - } - slv2_scale_points_free( sp_list ); - } - } + QStringList list; + if( m_lv2ManagerMap.contains( _plugin ) ) + { + lv2ManagerDescription * d = m_lv2ManagerMap[_plugin]; + ensureLV2DataExists( d ); + if( _port < slv2_plugin_get_num_ports( d->plugin ) ) + { + SLV2Port port = slv2_plugin_get_port_by_index( d->plugin, _port ); + SLV2ScalePoints sp_list = slv2_port_get_scale_points( d->plugin, port ); + if( sp_list != NULL ) + { + printf( "Got %d ScalePoints for port=%d\n", + slv2_scale_points_size( sp_list ), _port ); + + for( unsigned i = 0; i < slv2_scale_points_size( sp_list ); i++ ) + { + SLV2ScalePoint sp = slv2_scale_points_get_at( sp_list, i ); + SLV2Value label = slv2_scale_point_get_label( sp ); + list.append( QString( slv2_value_as_string( label ) ) ); + // slv2_value_free( label ); + // slv2_scale_point_free( sp ); + } + slv2_scale_points_free( sp_list ); + } + } } - return( list ); + return list; } @@ -925,24 +590,24 @@ QStringList lv2Manager::listEnumeration( const lv2_key_t & _plugin, Uint32 _port -bool lv2Manager::isInteger( const lv2_key_t & _plugin, - Uint32 _port ) +bool lv2Manager::isInteger( const lv2_key_t & _plugin, Uint32 _port ) { - if( listEnumeration( _plugin, _port).size() >= 2 ) { - return( TRUE ); - } - return( FALSE ); + if( listEnumeration( _plugin, _port ).size() >= 2 ) + { + return true; + } + return false; } -bool lv2Manager::isPortToggled( const lv2_key_t & _plugin, - Uint32 _port ) +bool lv2Manager::isPortToggled( const lv2_key_t & _plugin, Uint32 _port ) { - if( listEnumeration( _plugin, _port).size() == 2 ) { - return( TRUE ); - } - return( FALSE ); + if( listEnumeration( _plugin, _port ).size() == 2 ) + { + return true; + } + return false; } @@ -953,249 +618,17 @@ bool lv2Manager::isPortToggled( const lv2_key_t & _plugin, QString lv2Manager::getPortName( const lv2_key_t & _plugin, Uint32 _port ) { - if( m_lv2ManagerMap.contains( _plugin ) ) - { - lv2ManagerDescription * d = m_lv2ManagerMap[_plugin]; - ensureLV2DataExists( d ); - if( _port < slv2_plugin_get_num_ports( d->plugin ) ) - { - SLV2Port port = slv2_plugin_get_port_by_index( d->plugin, _port ); - return( QString( - slv2_value_as_string( slv2_port_get_name( d->plugin, port ) ) - ) ); - } - } - return( QString( "" ) ); -} - - - -/* -const void * ladspaManager::getImplementationData( - const ladspa_key_t & _plugin ) -{ - if( m_ladspaManagerMap.contains( _plugin ) ) + if( m_lv2ManagerMap.contains( _plugin ) ) { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - return( descriptor->ImplementationData ); - } - else - { - return( NULL ); - } -} - - - - -const LADSPA_Descriptor * ladspaManager::getDescriptor( - const ladspa_key_t & _plugin ) -{ - if( m_ladspaManagerMap.contains( _plugin ) ) - { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - return( descriptor ); - } - else - { - return( NULL ); - } -} - -*/ - - -/* -LADSPA_Handle ladspaManager::instantiate( - const ladspa_key_t & _plugin, - Uint32 _sample_rate ) -{ - if( m_ladspaManagerMap.contains( _plugin ) ) - { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - return( ( descriptor->instantiate ) - ( descriptor, _sample_rate ) ); - } - else - { - return( NULL ); - } -} - - - - -bool ladspaManager::connectPort( const ladspa_key_t & _plugin, - LADSPA_Handle _instance, - Uint32 _port, - LADSPA_Data * _data_location ) -{ - if( m_ladspaManagerMap.contains( _plugin ) - && _port < getPortCount( _plugin ) ) - { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - if( descriptor->connect_port != NULL ) + lv2ManagerDescription * d = m_lv2ManagerMap[_plugin]; + ensureLV2DataExists( d ); + if( _port < slv2_plugin_get_num_ports( d->plugin ) ) { - ( descriptor->connect_port ) - ( _instance, _port, _data_location ); - return( TRUE ); + SLV2Port port = slv2_plugin_get_port_by_index( d->plugin, _port ); + return QString( slv2_value_as_string( slv2_port_get_name( d->plugin, port ) ) ); } } - return( FALSE ); + return QString(); } - - -bool ladspaManager::activate( const ladspa_key_t & _plugin, - LADSPA_Handle _instance ) -{ - if( m_ladspaManagerMap.contains( _plugin ) ) - { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - if( descriptor->activate != NULL ) - { - ( descriptor->activate ) ( _instance ); - return( TRUE ); - } - } - return( FALSE ); -} - - - - -bool ladspaManager::run( const ladspa_key_t & _plugin, - LADSPA_Handle _instance, - Uint32 _sample_count ) -{ - if( m_ladspaManagerMap.contains( _plugin ) ) - { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - if( descriptor->run != NULL ) - { - ( descriptor->run ) ( _instance, _sample_count ); - return( TRUE ); - } - } - return( FALSE ); -} - - - - -bool ladspaManager::runAdding( const ladspa_key_t & _plugin, - LADSPA_Handle _instance, - Uint32 _sample_count ) -{ - if( m_ladspaManagerMap.contains( _plugin ) ) - { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - if( descriptor->run_adding != NULL && - descriptor->set_run_adding_gain != NULL ) - { - ( descriptor->run_adding ) ( _instance, _sample_count ); - return( TRUE ); - } - } - return( FALSE ); -} - - - - -bool ladspaManager::setRunAddingGain( const ladspa_key_t & _plugin, - LADSPA_Handle _instance, - LADSPA_Data _gain ) -{ - if( m_ladspaManagerMap.contains( _plugin ) ) - { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - if( descriptor->run_adding != NULL && - descriptor->set_run_adding_gain != NULL ) - { - ( descriptor->set_run_adding_gain ) - ( _instance, _gain ); - return( TRUE ); - } - } - return( FALSE ); -} - - - - -bool ladspaManager::deactivate( const ladspa_key_t & _plugin, - LADSPA_Handle _instance ) -{ - if( m_ladspaManagerMap.contains( _plugin ) ) - { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - if( descriptor->deactivate != NULL ) - { - ( descriptor->deactivate ) ( _instance ); - return( TRUE ); - } - } - return( FALSE ); -} - - - - -bool ladspaManager::cleanup( const ladspa_key_t & _plugin, - LADSPA_Handle _instance ) -{ - if( m_ladspaManagerMap.contains( _plugin ) ) - { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - if( descriptor->cleanup != NULL ) - { - ( descriptor->cleanup ) ( _instance ); - return( TRUE ); - } - } - return( FALSE ); -} -*/ -