Skip to content

Commit 1e091ea

Browse files
Manual formatting changes only
No functional changes at all! The changes in Enginge.cpp are also just refactoring.
1 parent bdde4e3 commit 1e091ea

File tree

10 files changed

+253
-226
lines changed

10 files changed

+253
-226
lines changed

include/Engine.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ class LMMS_EXPORT LmmsCore : public QObject
123123

124124

125125
private:
126+
static class AutomatableModel*
127+
getAutomatableOscModel(const QString& val, const QUrl& url);
128+
126129
// small helper function which sets the pointer to NULL before actually deleting
127130
// the object it refers to
128131
template<class T>

include/SpaOscModel.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@
3030
template <class Base> class SpaOscModel : public Base
3131
{
3232
protected:
33-
class SpaInstrument *inst_ref;
34-
QByteArray dest;
33+
class SpaInstrument *m_instRef;
34+
QByteArray m_dest;
3535

3636
using Base::Base;
37-
void init(class SpaInstrument *_inst_ref, const QString _dest)
37+
void init(class SpaInstrument *instRef, const QString dest)
3838
{
39-
inst_ref = _inst_ref;
40-
dest = _dest.toUtf8();
39+
m_instRef = instRef;
40+
m_dest = dest.toUtf8();
4141
}
4242
};
4343

@@ -49,7 +49,7 @@ private slots:
4949

5050
public:
5151
BoolOscModel(
52-
class SpaInstrument *inst_ref, const QString dest, bool val);
52+
class SpaInstrument *instRef, const QString dest, bool val);
5353
};
5454

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

6161
public:
62-
IntOscModel(class SpaInstrument *inst_ref, const QString dest, int min,
62+
IntOscModel(class SpaInstrument *instRef, const QString dest, int min,
6363
int max, int val);
6464
};
6565

@@ -70,14 +70,14 @@ private slots:
7070
void sendOsc();
7171

7272
public:
73-
FloatOscModel(class SpaInstrument *inst_ref, const QString dest,
73+
FloatOscModel(class SpaInstrument *instRef, const QString dest,
7474
float min, float max, float val);
7575
};
7676

7777
struct SpaOscModelFactory
7878
{
79-
AutomatableModel *res;
80-
SpaOscModelFactory(class SpaInstrument *inst_ref, const QString &dest);
79+
AutomatableModel *m_res;
80+
SpaOscModelFactory(class SpaInstrument *instRef, const QString &dest);
8181
};
8282

8383
#endif // SPAOSCMODEL_H

include/StringPairDrag.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ class LMMS_EXPORT StringPairDrag : public QDrag
5252

5353
static const char * mimeType()
5454
{
55-
return( "application/x-lmms-stringpair" );
55+
return "application/x-lmms-stringpair";
5656
}
5757

5858
static const char * mimeTypeOsc()
5959
{
60-
return( "application/x-osc-stringpair" );
60+
return "application/x-osc-stringpair";
6161
}
6262

6363
} ;

src/core/Engine.cpp

Lines changed: 50 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -120,52 +120,69 @@ void LmmsCore::updateFramesPerTick()
120120

121121

122122

123-
AutomatableModel *LmmsCore::getAutomatableModel(const QString& val, bool hasOsc)
123+
AutomatableModel *LmmsCore::getAutomatableOscModel(const QString& val,
124+
const QUrl& url)
124125
{
125126
AutomatableModel* mod = nullptr;
126127

127-
if(hasOsc)
128+
// qDebug() << val;
129+
const QMap<int, class SpaInstrument*>& insMap = getSpaInstruments();
130+
auto itr = insMap.find(url.port());
131+
if(itr == insMap.end())
128132
{
129-
QUrl url(val);
130-
if(!url.isValid())
133+
puts( "DnD from an instrument which is not "
134+
"in LMMS... ignoring");
135+
// TODO: MessageBox?
136+
}
137+
else
138+
{
139+
QMap<QString, AutomatableModel*>& connectedModels
140+
= itr.value()->m_connectedModels;
141+
auto itr2 = connectedModels.find(url.path());
142+
if(itr2 != connectedModels.end())
131143
{
132-
printf("Could not find a port in %s => "
133-
"can not make connection\n", val.toUtf8().data());
144+
mod = *itr2;
134145
}
135146
else
136147
{
137-
// qDebug() << val;
138-
const QMap<int, class SpaInstrument*>& insmap = Engine::getSpaInstruments();
139-
auto itr = insmap.find(url.port());
140-
if(itr == insmap.end())
148+
AutomatableModel* spaMod = SpaOscModelFactory(itr.value(),
149+
url.path()).m_res;
150+
if(spaMod)
141151
{
142-
puts("DnD from an instrument which is not in LMMS... ignoring");
143-
// TODO: MessageBox?
152+
itr.value()->m_connectedModels.insert(
153+
url.path(), spaMod);
154+
mod = spaMod;
144155
}
145-
else
146-
{
147-
QMap<QString, AutomatableModel*>& connectedModels
148-
= itr.value()->connectedModels;
149-
auto itr2 = connectedModels.find(url.path());
150-
if(itr2 != connectedModels.end())
151-
{
152-
return *itr2;
153-
}
154-
else
155-
{
156-
AutomatableModel* spamod = SpaOscModelFactory(itr.value(), url.path()).res;
157-
if(spamod)
158-
{
159-
itr.value()->connectedModels.insert(url.path(), spamod);
160-
mod = spamod;
161-
}
162-
else {
163-
qDebug() << "LMMS: Could not create model from OSC port (received \"" << val << "\")";
164-
}
165-
}
156+
else {
157+
qDebug() << "LMMS: Could not create model from "
158+
"OSC port (received \"" << val << "\")";
166159
}
167160
}
168161
}
162+
163+
return mod;
164+
}
165+
166+
167+
168+
169+
AutomatableModel *LmmsCore::getAutomatableModel(const QString& val, bool hasOsc)
170+
{
171+
AutomatableModel* mod = nullptr;
172+
if(hasOsc)
173+
{
174+
QUrl url(val);
175+
if(!url.isValid())
176+
{
177+
printf( "Could not find a port in %s => "
178+
"can not make connection\n",
179+
val.toUtf8().data());
180+
}
181+
else
182+
{
183+
mod = getAutomatableOscModel(val, url);
184+
}
185+
}
169186
else
170187
{
171188
mod = dynamic_cast<AutomatableModel *>(

src/core/Plugin.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,24 +111,24 @@ Plugin * Plugin::instantiate( const QString& pluginName, Model * parent,
111111
}
112112

113113
Plugin* inst;
114-
spa::descriptor_loader_t spa_loader;
114+
spa::descriptor_loader_t spaLoader;
115115
InstantiationHook instantiationHook;
116-
if( (instantiationHook = ( InstantiationHook ) pi.library->resolve( "lmms_plugin_main" )) )
116+
if ((instantiationHook = ( InstantiationHook ) pi.library->resolve( "lmms_plugin_main" )))
117117
{
118118
inst = instantiationHook( parent, data );
119119
}
120-
else if( (spa_loader = (spa::descriptor_loader_t) pi.library->resolve( spa::descriptor_name )) )
120+
else if ((spaLoader = (spa::descriptor_loader_t) pi.library->resolve( spa::descriptor_name )))
121121
{
122122
// instantiate a SPA Instrument
123123
// it will load and contain the SPA plugin
124124
// and transfer LMMS events to SPA function calls
125-
SpaInstrument* spa_inst = new SpaInstrument(
125+
SpaInstrument* spaInst = new SpaInstrument(
126126
static_cast<InstrumentTrack *>( data ),
127127
pi.file.absoluteFilePath().toUtf8().data(),
128128
pi.descriptor);
129-
unsigned port = spa_inst->plugin->net_port();
130-
Engine::getSpaInstruments().insert(port, spa_inst);
131-
inst = spa_inst;
129+
unsigned port = spaInst->m_plugin->net_port();
130+
Engine::getSpaInstruments().insert(port, spaInst);
131+
inst = spaInst;
132132
}
133133
else
134134
{

src/core/PluginFactory.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,14 @@ void PluginFactory::discoverPlugins()
184184
spa::descriptor* descriptor = (*spaDescriptorLoader)(0 /* = plugin number, TODO */);
185185
if(descriptor)
186186
{
187-
std::string unique_name =
187+
std::string uniqueName =
188188
spa::unique_name(*descriptor);
189-
m_garbage.push_back(unique_name);
189+
m_garbage.push_back(uniqueName);
190190

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

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

221-
if(info.descriptor->supportedFileTypes)
221+
if (info.descriptor->supportedFileTypes)
222222
for (const QString& ext : QString(info.descriptor->supportedFileTypes).split(','))
223223
{
224224
m_pluginByExt.insert(ext, info);

src/core/SpaOscModel.cpp

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,79 +31,84 @@
3131

3232
struct SpaOscModelFactoryVisitor : public spa::audio::visitor
3333
{
34-
class SpaInstrument *inst_ref;
35-
const QString *dest;
36-
AutomatableModel *res = nullptr;
34+
class SpaInstrument *m_instRef;
35+
const QString *m_dest;
36+
AutomatableModel *m_res = nullptr;
3737

3838
template <class ModelType, class T> void make(T min, T max, T val)
3939
{
40-
res = new ModelType(inst_ref, *dest, min, max, val);
40+
m_res = new ModelType(m_instRef, *m_dest, min, max, val);
4141
}
4242

43-
template <class T> using c_in = spa::audio::control_in<T>;
44-
virtual void visit(c_in<float> &in)
43+
template <class T> using CtlIn = spa::audio::control_in<T>;
44+
virtual void visit(CtlIn<float> &in)
4545
{
4646
make<FloatOscModel>(in.min, in.max, in.def);
4747
}
48-
virtual void visit(c_in<double> &in)
48+
virtual void visit(CtlIn<double> &in)
4949
{
5050
make<FloatOscModel>(in.min, in.max, in.def);
5151
}
52-
virtual void visit(c_in<int> &in)
52+
virtual void visit(CtlIn<int> &in)
5353
{
5454
make<IntOscModel>(in.min, in.max, in.def);
5555
}
56-
virtual void visit(c_in<bool> &in)
56+
virtual void visit(CtlIn<bool> &in)
5757
{
58-
res = new BoolOscModel(inst_ref, *dest, in.def);
58+
m_res = new BoolOscModel(m_instRef, *m_dest, in.def);
5959
}
6060
};
6161

6262
SpaOscModelFactory::SpaOscModelFactory(
63-
SpaInstrument *inst_ref, const QString &dest)
63+
SpaInstrument *instRef, const QString &dest)
6464
{
6565
SpaOscModelFactoryVisitor vis;
66-
vis.inst_ref = inst_ref;
67-
vis.dest = &dest;
68-
spa::port_ref_base &base = inst_ref->plugin->port(dest.toUtf8().data());
66+
vis.m_instRef = instRef;
67+
vis.m_dest = &dest;
68+
spa::port_ref_base &base = instRef->m_plugin->port(dest.toUtf8().data());
6969
base.accept(vis);
70-
res = vis.res;
70+
m_res = vis.m_res;
7171
}
7272

7373
void BoolOscModel::sendOsc()
7474
{
75-
inst_ref->writeOsc(dest.data(), value() ? "T" : "F");
75+
m_instRef->writeOsc(m_dest.data(), value() ? "T" : "F");
76+
}
77+
void IntOscModel::sendOsc()
78+
{
79+
m_instRef->writeOsc(m_dest.data(), "i", value());
80+
}
81+
void FloatOscModel::sendOsc()
82+
{
83+
m_instRef->writeOsc(m_dest.data(), "f", value());
7684
}
77-
void IntOscModel::sendOsc() { inst_ref->writeOsc(dest.data(), "i", value()); }
78-
void FloatOscModel::sendOsc() { inst_ref->writeOsc(dest.data(), "f", value()); }
7985

80-
BoolOscModel::BoolOscModel(
81-
SpaInstrument *inst_ref, const QString dest, bool val) :
86+
BoolOscModel::BoolOscModel(SpaInstrument *instRef, const QString dest, bool val) :
8287
SpaOscModel<BoolModel>(val, nullptr, dest, false)
8388
{
8489
qDebug() << "LMMS: receiving bool model: val = " << val;
85-
init(inst_ref, dest);
90+
init(instRef, dest);
8691
QObject::connect(this, SIGNAL(dataChanged()), this, SLOT(sendOsc()));
8792
}
8893

89-
IntOscModel::IntOscModel(SpaInstrument *inst_ref, const QString dest, int min,
94+
IntOscModel::IntOscModel(SpaInstrument *instRef, const QString dest, int min,
9095
int max, int val) :
9196
SpaOscModel<IntModel>(val, min, max, nullptr, dest, false)
9297
{
9398
qDebug() << "LMMS: receiving int model: (val, min, max) = (" << val
9499
<< ", " << min << ", " << max << ")";
95-
init(inst_ref, dest);
100+
init(instRef, dest);
96101
QObject::connect(this, SIGNAL(dataChanged()), this, SLOT(sendOsc()));
97102
}
98103

99-
FloatOscModel::FloatOscModel(SpaInstrument *inst_ref, const QString dest,
104+
FloatOscModel::FloatOscModel(SpaInstrument *instRef, const QString dest,
100105
float min, float max, float val) :
101106
SpaOscModel<FloatModel>(val, min, max, 0.1f, nullptr, dest, false)
102107
/* TODO: get step from plugin (we currently need a plugin where this
103108
can be tested) */
104109
{
105110
qDebug() << "LMMS: receiving float model: (val, min, max) = (" << val
106111
<< ", " << min << ", " << max << ")";
107-
init(inst_ref, dest);
112+
init(instRef, dest);
108113
QObject::connect(this, SIGNAL(dataChanged()), this, SLOT(sendOsc()));
109114
}

0 commit comments

Comments
 (0)