Skip to content

Commit

Permalink
Manual formatting changes only
Browse files Browse the repository at this point in the history
No functional changes at all!
The changes in Enginge.cpp are also just refactoring.
  • Loading branch information
JohannesLorenz committed Nov 2, 2018
1 parent bdde4e3 commit 1e091ea
Show file tree
Hide file tree
Showing 10 changed files with 253 additions and 226 deletions.
3 changes: 3 additions & 0 deletions include/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ class LMMS_EXPORT LmmsCore : public QObject


private:
static class AutomatableModel*
getAutomatableOscModel(const QString& val, const QUrl& url);

// small helper function which sets the pointer to NULL before actually deleting
// the object it refers to
template<class T>
Expand Down
20 changes: 10 additions & 10 deletions include/SpaOscModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
template <class Base> class SpaOscModel : public Base
{
protected:
class SpaInstrument *inst_ref;
QByteArray dest;
class SpaInstrument *m_instRef;
QByteArray m_dest;

using Base::Base;
void init(class SpaInstrument *_inst_ref, const QString _dest)
void init(class SpaInstrument *instRef, const QString dest)
{
inst_ref = _inst_ref;
dest = _dest.toUtf8();
m_instRef = instRef;
m_dest = dest.toUtf8();
}
};

Expand All @@ -49,7 +49,7 @@ private slots:

public:
BoolOscModel(
class SpaInstrument *inst_ref, const QString dest, bool val);
class SpaInstrument *instRef, const QString dest, bool val);
};

class IntOscModel : public SpaOscModel<IntModel>
Expand All @@ -59,7 +59,7 @@ private slots:
void sendOsc();

public:
IntOscModel(class SpaInstrument *inst_ref, const QString dest, int min,
IntOscModel(class SpaInstrument *instRef, const QString dest, int min,
int max, int val);
};

Expand All @@ -70,14 +70,14 @@ private slots:
void sendOsc();

public:
FloatOscModel(class SpaInstrument *inst_ref, const QString dest,
FloatOscModel(class SpaInstrument *instRef, const QString dest,
float min, float max, float val);
};

struct SpaOscModelFactory
{
AutomatableModel *res;
SpaOscModelFactory(class SpaInstrument *inst_ref, const QString &dest);
AutomatableModel *m_res;
SpaOscModelFactory(class SpaInstrument *instRef, const QString &dest);
};

#endif // SPAOSCMODEL_H
4 changes: 2 additions & 2 deletions include/StringPairDrag.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ class LMMS_EXPORT StringPairDrag : public QDrag

static const char * mimeType()
{
return( "application/x-lmms-stringpair" );
return "application/x-lmms-stringpair";
}

static const char * mimeTypeOsc()
{
return( "application/x-osc-stringpair" );
return "application/x-osc-stringpair";
}

} ;
Expand Down
83 changes: 50 additions & 33 deletions src/core/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,52 +120,69 @@ void LmmsCore::updateFramesPerTick()



AutomatableModel *LmmsCore::getAutomatableModel(const QString& val, bool hasOsc)
AutomatableModel *LmmsCore::getAutomatableOscModel(const QString& val,
const QUrl& url)
{
AutomatableModel* mod = nullptr;

if(hasOsc)
// qDebug() << val;
const QMap<int, class SpaInstrument*>& insMap = getSpaInstruments();
auto itr = insMap.find(url.port());
if(itr == insMap.end())
{
QUrl url(val);
if(!url.isValid())
puts( "DnD from an instrument which is not "
"in LMMS... ignoring");
// TODO: MessageBox?
}
else
{
QMap<QString, AutomatableModel*>& connectedModels
= itr.value()->m_connectedModels;
auto itr2 = connectedModels.find(url.path());
if(itr2 != connectedModels.end())
{
printf("Could not find a port in %s => "
"can not make connection\n", val.toUtf8().data());
mod = *itr2;
}
else
{
// qDebug() << val;
const QMap<int, class SpaInstrument*>& insmap = Engine::getSpaInstruments();
auto itr = insmap.find(url.port());
if(itr == insmap.end())
AutomatableModel* spaMod = SpaOscModelFactory(itr.value(),
url.path()).m_res;
if(spaMod)
{
puts("DnD from an instrument which is not in LMMS... ignoring");
// TODO: MessageBox?
itr.value()->m_connectedModels.insert(
url.path(), spaMod);
mod = spaMod;
}
else
{
QMap<QString, AutomatableModel*>& connectedModels
= itr.value()->connectedModels;
auto itr2 = connectedModels.find(url.path());
if(itr2 != connectedModels.end())
{
return *itr2;
}
else
{
AutomatableModel* spamod = SpaOscModelFactory(itr.value(), url.path()).res;
if(spamod)
{
itr.value()->connectedModels.insert(url.path(), spamod);
mod = spamod;
}
else {
qDebug() << "LMMS: Could not create model from OSC port (received \"" << val << "\")";
}
}
else {
qDebug() << "LMMS: Could not create model from "
"OSC port (received \"" << val << "\")";
}
}
}

return mod;
}




AutomatableModel *LmmsCore::getAutomatableModel(const QString& val, bool hasOsc)
{
AutomatableModel* mod = nullptr;
if(hasOsc)
{
QUrl url(val);
if(!url.isValid())
{
printf( "Could not find a port in %s => "
"can not make connection\n",
val.toUtf8().data());
}
else
{
mod = getAutomatableOscModel(val, url);
}
}
else
{
mod = dynamic_cast<AutomatableModel *>(
Expand Down
14 changes: 7 additions & 7 deletions src/core/Plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,24 +111,24 @@ Plugin * Plugin::instantiate( const QString& pluginName, Model * parent,
}

Plugin* inst;
spa::descriptor_loader_t spa_loader;
spa::descriptor_loader_t spaLoader;
InstantiationHook instantiationHook;
if( (instantiationHook = ( InstantiationHook ) pi.library->resolve( "lmms_plugin_main" )) )
if ((instantiationHook = ( InstantiationHook ) pi.library->resolve( "lmms_plugin_main" )))
{
inst = instantiationHook( parent, data );
}
else if( (spa_loader = (spa::descriptor_loader_t) pi.library->resolve( spa::descriptor_name )) )
else if ((spaLoader = (spa::descriptor_loader_t) pi.library->resolve( spa::descriptor_name )))
{
// instantiate a SPA Instrument
// it will load and contain the SPA plugin
// and transfer LMMS events to SPA function calls
SpaInstrument* spa_inst = new SpaInstrument(
SpaInstrument* spaInst = new SpaInstrument(
static_cast<InstrumentTrack *>( data ),
pi.file.absoluteFilePath().toUtf8().data(),
pi.descriptor);
unsigned port = spa_inst->plugin->net_port();
Engine::getSpaInstruments().insert(port, spa_inst);
inst = spa_inst;
unsigned port = spaInst->m_plugin->net_port();
Engine::getSpaInstruments().insert(port, spaInst);
inst = spaInst;
}
else
{
Expand Down
8 changes: 4 additions & 4 deletions src/core/PluginFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,14 @@ void PluginFactory::discoverPlugins()
spa::descriptor* descriptor = (*spaDescriptorLoader)(0 /* = plugin number, TODO */);
if(descriptor)
{
std::string unique_name =
std::string uniqueName =
spa::unique_name(*descriptor);
m_garbage.push_back(unique_name);
m_garbage.push_back(uniqueName);

const char** xpm = descriptor->xpm_load();
assert(xpm);
QString xpmKey = "spa-plugin:" +
QString::fromStdString(unique_name);
QString::fromStdString(uniqueName);

// spa (simple plugin API) plugin
pluginDescriptor = new Plugin::Descriptor {
Expand All @@ -218,7 +218,7 @@ void PluginFactory::discoverPlugins()
info.descriptor = pluginDescriptor;
pluginInfos << info;

if(info.descriptor->supportedFileTypes)
if (info.descriptor->supportedFileTypes)
for (const QString& ext : QString(info.descriptor->supportedFileTypes).split(','))
{
m_pluginByExt.insert(ext, info);
Expand Down
55 changes: 30 additions & 25 deletions src/core/SpaOscModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,79 +31,84 @@

struct SpaOscModelFactoryVisitor : public spa::audio::visitor
{
class SpaInstrument *inst_ref;
const QString *dest;
AutomatableModel *res = nullptr;
class SpaInstrument *m_instRef;
const QString *m_dest;
AutomatableModel *m_res = nullptr;

template <class ModelType, class T> void make(T min, T max, T val)
{
res = new ModelType(inst_ref, *dest, min, max, val);
m_res = new ModelType(m_instRef, *m_dest, min, max, val);
}

template <class T> using c_in = spa::audio::control_in<T>;
virtual void visit(c_in<float> &in)
template <class T> using CtlIn = spa::audio::control_in<T>;
virtual void visit(CtlIn<float> &in)
{
make<FloatOscModel>(in.min, in.max, in.def);
}
virtual void visit(c_in<double> &in)
virtual void visit(CtlIn<double> &in)
{
make<FloatOscModel>(in.min, in.max, in.def);
}
virtual void visit(c_in<int> &in)
virtual void visit(CtlIn<int> &in)
{
make<IntOscModel>(in.min, in.max, in.def);
}
virtual void visit(c_in<bool> &in)
virtual void visit(CtlIn<bool> &in)
{
res = new BoolOscModel(inst_ref, *dest, in.def);
m_res = new BoolOscModel(m_instRef, *m_dest, in.def);
}
};

SpaOscModelFactory::SpaOscModelFactory(
SpaInstrument *inst_ref, const QString &dest)
SpaInstrument *instRef, const QString &dest)
{
SpaOscModelFactoryVisitor vis;
vis.inst_ref = inst_ref;
vis.dest = &dest;
spa::port_ref_base &base = inst_ref->plugin->port(dest.toUtf8().data());
vis.m_instRef = instRef;
vis.m_dest = &dest;
spa::port_ref_base &base = instRef->m_plugin->port(dest.toUtf8().data());
base.accept(vis);
res = vis.res;
m_res = vis.m_res;
}

void BoolOscModel::sendOsc()
{
inst_ref->writeOsc(dest.data(), value() ? "T" : "F");
m_instRef->writeOsc(m_dest.data(), value() ? "T" : "F");
}
void IntOscModel::sendOsc()
{
m_instRef->writeOsc(m_dest.data(), "i", value());
}
void FloatOscModel::sendOsc()
{
m_instRef->writeOsc(m_dest.data(), "f", value());
}
void IntOscModel::sendOsc() { inst_ref->writeOsc(dest.data(), "i", value()); }
void FloatOscModel::sendOsc() { inst_ref->writeOsc(dest.data(), "f", value()); }

BoolOscModel::BoolOscModel(
SpaInstrument *inst_ref, const QString dest, bool val) :
BoolOscModel::BoolOscModel(SpaInstrument *instRef, const QString dest, bool val) :
SpaOscModel<BoolModel>(val, nullptr, dest, false)
{
qDebug() << "LMMS: receiving bool model: val = " << val;
init(inst_ref, dest);
init(instRef, dest);
QObject::connect(this, SIGNAL(dataChanged()), this, SLOT(sendOsc()));
}

IntOscModel::IntOscModel(SpaInstrument *inst_ref, const QString dest, int min,
IntOscModel::IntOscModel(SpaInstrument *instRef, const QString dest, int min,
int max, int val) :
SpaOscModel<IntModel>(val, min, max, nullptr, dest, false)
{
qDebug() << "LMMS: receiving int model: (val, min, max) = (" << val
<< ", " << min << ", " << max << ")";
init(inst_ref, dest);
init(instRef, dest);
QObject::connect(this, SIGNAL(dataChanged()), this, SLOT(sendOsc()));
}

FloatOscModel::FloatOscModel(SpaInstrument *inst_ref, const QString dest,
FloatOscModel::FloatOscModel(SpaInstrument *instRef, const QString dest,
float min, float max, float val) :
SpaOscModel<FloatModel>(val, min, max, 0.1f, nullptr, dest, false)
/* TODO: get step from plugin (we currently need a plugin where this
can be tested) */
{
qDebug() << "LMMS: receiving float model: (val, min, max) = (" << val
<< ", " << min << ", " << max << ")";
init(inst_ref, dest);
init(instRef, dest);
QObject::connect(this, SIGNAL(dataChanged()), this, SLOT(sendOsc()));
}
Loading

0 comments on commit 1e091ea

Please sign in to comment.