Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions include/Effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ class LMMS_EXPORT Effect : public Plugin
{
Q_OBJECT
public:
Effect( const Plugin::Descriptor * _desc,
Model * _parent,
const Descriptor::SubPluginFeatures::Key * _key );
Effect(const Plugin::Descriptor* _desc,
Model* _parent,
const Descriptor::SubPluginFeatures::Key* _key);

void saveSettings( QDomDocument & _doc, QDomElement & _parent ) override;
void loadSettings( const QDomElement & _this ) override;
void saveSettings(QDomDocument& _doc, QDomElement& _parent) override;
void loadSettings(const QDomElement& _this) override;

inline QString nodeName() const override
{
Expand Down Expand Up @@ -130,16 +130,18 @@ class LMMS_EXPORT Effect : public Plugin
return m_autoQuitEnabled;
}

EffectChain * effectChain() const
EffectChain* effectChain() const
{
return m_parent;
}

virtual EffectControls * controls() = 0;
virtual EffectControls* controls() = 0;

static Effect * instantiate( const QString & _plugin_name,
Model * _parent,
Descriptor::SubPluginFeatures::Key * _key );
static Effect* instantiate(const QString & _plugin_name,
Model* _parent,
Descriptor::SubPluginFeatures::Key* _key);

static Effect* createFromPreset(const QString& filePath, Model* parent);


protected:
Expand Down Expand Up @@ -167,7 +169,7 @@ class LMMS_EXPORT Effect : public Plugin
virtual void processBypassedImpl() {}


gui::PluginView* instantiateView( QWidget * ) override;
gui::PluginView* instantiateView(QWidget*) override;

void goToSleep()
{
Expand All @@ -192,7 +194,7 @@ class LMMS_EXPORT Effect : public Plugin
void handleAutoQuit(bool silentOutput);


EffectChain * m_parent;
EffectChain* m_parent;

bool m_okay;
bool m_noRun;
Expand Down
4 changes: 4 additions & 0 deletions include/EffectRackView.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ private slots:
virtual void update();
void addEffect();

protected:
void dragEnterEvent(QDragEnterEvent* event) override;
void dropEvent(QDropEvent* event) override;

private:
void addFromPreset(const QString& filePath);
void modelChanged() override;
QSize sizeHint() const override;
QSize minimumSizeHint() const override { return sizeHint(); }
Expand Down
2 changes: 2 additions & 0 deletions include/EffectView.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public slots:
void editControls();
void moveUp();
void moveDown();
void savePreset();
void loadPreset();
void deletePlugin();

signals:
Expand Down
8 changes: 5 additions & 3 deletions include/FileBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ class FileItem : public FileBrowserWidgetItem
enum class FileType
{
Project,
Preset,
InstrumentPreset,
EffectPreset,
Sample,
SoundFont,
Patch,
Expand All @@ -258,7 +259,8 @@ class FileItem : public FileBrowserWidgetItem
{
NotSupported,
LoadAsProject,
LoadAsPreset,
LoadAsInstrumentPreset,
LoadAsEffectPreset,
LoadByPlugin,
ImportAsProject
} ;
Expand All @@ -285,7 +287,7 @@ class FileItem : public FileBrowserWidgetItem

inline bool isTrack() const
{
return m_handling == FileHandling::LoadAsPreset || m_handling == FileHandling::LoadByPlugin;
return m_handling == FileHandling::LoadAsInstrumentPreset || m_handling == FileHandling::LoadByPlugin;
}

QString extension();
Expand Down
28 changes: 17 additions & 11 deletions src/core/DataFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,22 +199,28 @@ DataFile::DataFile( const QByteArray & _data ) :

bool DataFile::validate( QString extension )
{
switch( m_type )
switch (m_type)
{
case Type::SongProject:
if( extension == "mmp" || extension == "mmpz" )
if (extension == "mmp" || extension == "mmpz")
{
return true;
}
break;
case Type::SongProjectTemplate:
if( extension == "mpt" )
if (extension == "mpt")
{
return true;
}
break;
case Type::InstrumentTrackSettings:
if ( extension == "xpf" || extension == "xml" )
if (extension == "xpf" || extension == "xml")
{
return true;
}
break;
case Type::EffectSettings:
if (extension == "fxp")
{
return true;
}
Expand Down Expand Up @@ -263,29 +269,29 @@ QString DataFile::nameWithExtension( const QString & _fn ) const
{
const QString extension = _fn.section( '.', -1 );

switch( type() )
switch (type())
{
case Type::SongProject:
if( extension != "mmp" &&
if (extension != "mmp" &&
extension != "mpt" &&
extension != "mmpz" )
extension != "mmpz")
{
if( ConfigManager::inst()->value( "app",
"nommpz" ).toInt() == 0 )
if (ConfigManager::inst()->value("app",
"nommpz" ).toInt() == 0)
{
return _fn + ".mmpz";
}
return _fn + ".mmp";
}
break;
case Type::SongProjectTemplate:
if( extension != "mpt" )
if (extension != "mpt")
{
return _fn + ".mpt";
}
break;
case Type::InstrumentTrackSettings:
if( extension != "xpf" )
if (extension != "xpf")
{
return _fn + ".xpf";
}
Expand Down
41 changes: 34 additions & 7 deletions src/core/Effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "EffectControls.h"
#include "EffectView.h"
#include "SampleFrame.h"
#include "DataFile.h"

namespace lmms
{
Expand All @@ -58,7 +59,7 @@ Effect::Effect( const Plugin::Descriptor * _desc,
connect(&m_enabledModel, &BoolModel::dataChanged, [this] { onEnabledChanged(); });
}

void Effect::saveSettings( QDomDocument & _doc, QDomElement & _this )
void Effect::saveSettings(QDomDocument& _doc, QDomElement& _this)
{
m_enabledModel.saveSettings( _doc, _this, "on" );
m_wetDryModel.saveSettings( _doc, _this, "wet" );
Expand All @@ -69,7 +70,7 @@ void Effect::saveSettings( QDomDocument & _doc, QDomElement & _this )



void Effect::loadSettings( const QDomElement & _this )
void Effect::loadSettings(const QDomElement& _this)
{
m_enabledModel.loadSettings( _this, "on" );
m_wetDryModel.loadSettings( _this, "wet" );
Expand Down Expand Up @@ -147,13 +148,13 @@ bool Effect::processAudioBuffer(AudioBuffer& inOut)



Effect * Effect::instantiate( const QString& pluginName,
Model * _parent,
Descriptor::SubPluginFeatures::Key * _key )
Effect* Effect::instantiate(const QString& pluginName,
Model* _parent,
Descriptor::SubPluginFeatures::Key* _key)
{
Plugin * p = Plugin::instantiateWithKey( pluginName, _parent, _key );
Plugin* p = Plugin::instantiateWithKey(pluginName, _parent, _key);
// check whether instantiated plugin is an effect
if( dynamic_cast<Effect *>( p ) != nullptr )
if (dynamic_cast<Effect*>(p) != nullptr)
{
// everything ok, so return pointer
auto effect = dynamic_cast<Effect*>(p);
Expand All @@ -169,6 +170,32 @@ Effect * Effect::instantiate( const QString& pluginName,



Effect* Effect::createFromPreset(const QString& filePath, Model* parent)
{
DataFile dataFile(filePath);

const QDomElement content = dataFile.content();
if (content.isNull()) { return nullptr; }

const QString displayName = content.attribute("displayname");
const QString pluginName = content.attribute("pluginname");
if (displayName.isEmpty() || pluginName.isEmpty()) { return nullptr; }

QDomElement keyElement = content.firstChildElement("key");
if (keyElement.isNull()) { return nullptr; }

EffectKey key(keyElement);

Effect* fx = Effect::instantiate(pluginName, parent, &key);
if (!fx) { return nullptr; }

fx->loadSettings(content);

return fx;
}




void Effect::handleAutoQuit(bool silentOutput)
{
Expand Down
66 changes: 61 additions & 5 deletions src/gui/EffectRackView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@
#include <QScrollArea>
#include <QVBoxLayout>

#include "Effect.h"
#include "DeprecationHelper.h"
#include "EffectSelectDialog.h"
#include "EffectView.h"
#include "StringPairDrag.h"
#include "GroupBox.h"
#include "TextFloat.h"
#include "embed.h"


namespace lmms::gui
Expand Down Expand Up @@ -71,6 +75,7 @@ EffectRackView::EffectRackView( EffectChain* model, QWidget* parent ) :

connect( addButton, SIGNAL(clicked()), this, SLOT(addEffect()));

setAcceptDrops(true);

m_lastY = 0;

Expand All @@ -87,6 +92,57 @@ EffectRackView::~EffectRackView()



void EffectRackView::dragEnterEvent(QDragEnterEvent* event)
{
const QString type = StringPairDrag::decodeKey(event);
if (type == "effectpresetfile")
{
event->acceptProposedAction();
}
else
{
event->ignore();
}
}


void EffectRackView::dropEvent(QDropEvent* event)
{
const QString type = StringPairDrag::decodeKey(event);
const QString filePath = StringPairDrag::decodeValue(event);

if (type == "effectpresetfile")
{
addFromPreset(filePath);
event->accept();
}
else
{
event->ignore();
}
}



void EffectRackView::addFromPreset(const QString& filePath)
{
Effect* fx = Effect::createFromPreset(filePath, fxChain());
if (!fx)
{
TextFloat::displayMessage(
"Preset loading error",
tr("Couldn't load preset file."),
embed::getIconPixmap("error")
);
return;
}
fxChain()->appendEffect(fx);
update();
}





void EffectRackView::clearViews()
{
Expand All @@ -103,14 +159,14 @@ void EffectRackView::clearViews()

void EffectRackView::moveUp( EffectView* view )
{
fxChain()->moveUp( view->effect() );
if( view != m_effectViews.first() )
fxChain()->moveUp(view->effect());
if (view != m_effectViews.first())
{
int i = 0;
for( QVector<EffectView *>::Iterator it = m_effectViews.begin();
it != m_effectViews.end(); it++, i++ )
for (auto it = m_effectViews.begin();
it != m_effectViews.end(); it++, i++)
{
if( *it == view )
if (*it == view)
{
break;
}
Expand Down
Loading
Loading