Skip to content

Commit

Permalink
reimplement effect gui without qml
Browse files Browse the repository at this point in the history
  • Loading branch information
wschweer committed Jan 7, 2015
1 parent c6d6c4b commit f22515c
Show file tree
Hide file tree
Showing 24 changed files with 258 additions and 286 deletions.
7 changes: 2 additions & 5 deletions effects/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ endif (APPLE)

QT4_ADD_RESOURCES (qrc_effects_files
zita1/zita.qrc
# freeverb/freeverb.qrc
noeffect/noeffect.qrc
)

QT4_WRAP_CPP(effectMocs
effectgui.h
# freeverb/freeverb.h
zita1/zita.h
zita1/zitagui.h
noeffect/noeffect.h
noeffect/noeffectgui.h
effect.h
)

Expand All @@ -40,8 +39,6 @@ add_library (effects STATIC
effect.cpp
effectgui.cpp
noeffect/noeffect.cpp
# freeverb/freeverb.cpp
# freeverb/freeverbgui.cpp
zita1/zita.cpp
zita1/zitagui.cpp
${INCS}
Expand Down
4 changes: 2 additions & 2 deletions effects/effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ class Effect : public QObject {
Q_OBJECT

protected:
EffectGui* _gui;
EffectGui* _gui { nullptr };

public slots:
virtual void setValue(const QString& name, double value);
virtual void setValue(int idx, double value);
virtual void setNValue(int idx, double value) = 0;

public:
Effect() : QObject() { _gui = 0; }
Effect() : QObject() { }
virtual ~Effect() {}
virtual void process(int frames, float*, float*) = 0;
virtual const char* name() const = 0;
Expand Down
53 changes: 3 additions & 50 deletions effects/effectgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,57 +12,22 @@

#include "effectgui.h"
#include "effect.h"
#include <QQmlContext>

namespace Ms {

//---------------------------------------------------------
// EffectGui
//---------------------------------------------------------

EffectGui::EffectGui(Effect* e)
: QQuickWidget()
EffectGui::EffectGui(Effect* e, QWidget* parent)
: QWidget(parent)
{
_effect = e;
setResizeMode(QQuickWidget::SizeViewToRootObject);
// setFocusPolicy(Qt::StrongFocus);
connect(this, SIGNAL(statusChanged(QQuickWidget::Status)), SLOT(reportErrors(QQuickWidget::Status)));
}

//---------------------------------------------------------
// reportErrors
//---------------------------------------------------------

void EffectGui::reportErrors(QQuickWidget::Status status)
{
// printf("EffectGui::statusChange: %d\n", int(status));
if (status == QQuickWidget::Error) {
for (auto e : errors())
qDebug("EffectGui: Error: %s", qPrintable(e.toString()));
}
}

//---------------------------------------------------------
// init
//---------------------------------------------------------

void EffectGui::init(QUrl& url)
{
if (_effect) {
rootContext()->setContextProperty("myEffect", _effect);
setSource(url);

if (rootObject()) {
connect(rootObject(), SIGNAL(valueChanged(QString, qreal)),
SLOT(valueChanged(QString, qreal)));
}
else
qDebug("no root object for %s", qPrintable(_effect->name()));
}
}

//---------------------------------------------------------
// valueChanged
// a value in the gui was changed
//---------------------------------------------------------

void EffectGui::valueChanged(const QString& msg, qreal val)
Expand All @@ -73,17 +38,5 @@ void EffectGui::valueChanged(const QString& msg, qreal val)
}
}

//---------------------------------------------------------
// updateValues
//---------------------------------------------------------

void EffectGui::updateValues()
{
if (rootObject()) {
if (!QMetaObject::invokeMethod(rootObject(), "updateValues")) {
qDebug("EffectGui::updateValues: failed");
}
}
}
}

10 changes: 3 additions & 7 deletions effects/effectgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,20 @@ class Effect;
// EffectGui
//---------------------------------------------------------

class EffectGui : public QQuickWidget {
class EffectGui : public QWidget {
Q_OBJECT
Effect* _effect;

signals:
void valueChanged();

private slots:
void reportErrors(QQuickWidget::Status);

public slots:
void valueChanged(const QString& name, qreal);

public:
EffectGui(Effect*);
void init(QUrl& url);
EffectGui(Effect*, QWidget* parent = 0);
Effect* effect() const { return _effect; }
virtual void updateValues();
virtual void updateValues() = 0;
};

}
Expand Down
32 changes: 26 additions & 6 deletions effects/noeffect/noeffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,36 @@
#include "effects/effect.h"
#include "effects/effectgui.h"
#include "noeffect.h"
#include "noeffectgui.h"

namespace Ms {

static const std::vector<ParDescr> noeffectPd;

//---------------------------------------------------------
// gui
//---------------------------------------------------------

EffectGui* NoEffect::gui()
{
EffectGui* eg = new EffectGui(this);
QUrl url("qrc:/noeffect/noeffect.qml");
eg->init(url);
return eg;
if (!_gui) {
_gui = new NoEffectGui(this);
_gui->setGeometry(0, 0, 644, 79);
_gui->show();
}
return _gui;
}

//---------------------------------------------------------
// NoEffectGui
//---------------------------------------------------------

NoEffectGui::NoEffectGui(Effect* e, QWidget* parent)
: EffectGui(e, parent)
{
QLabel* l = new QLabel;
l->setText(tr("no plugin"));
QLayout* la = new QVBoxLayout;
la->addWidget(l);
setLayout(la);
}

//---------------------------------------------------------
Expand All @@ -36,9 +51,14 @@ EffectGui* NoEffect::gui()

const std::vector<ParDescr>& NoEffect::parDescr() const
{
static const std::vector<ParDescr> noeffectPd;
return noeffectPd;
}

//---------------------------------------------------------
// process
//---------------------------------------------------------

void NoEffect::process(int n, float* src, float* dst)
{
memcpy(dst, src, n * 2 * sizeof(float));
Expand Down
18 changes: 9 additions & 9 deletions effects/noeffect/noeffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ class NoEffect : public Effect
public:
NoEffect() {}

virtual void init(float) {}
virtual void process(int, float*, float*);
virtual void init(float) override {}
virtual void process(int, float*, float*) override;

virtual void setValue(int, double) {}
virtual void setNValue(int, double) {}
virtual double value(int) const { return 0.0; }
virtual double nvalue(int) const { return 0.0; }
virtual void setValue(int, double) override {}
virtual void setNValue(int, double) override {}
virtual double value(int) const override { return 0.0; }
virtual double nvalue(int) const override { return 0.0; }

virtual const char* name() const { return "NoEffect"; }
virtual EffectGui* gui();
virtual const std::vector<ParDescr>& parDescr() const;
virtual const char* name() const override { return "NoEffect"; }
virtual EffectGui* gui() override;
virtual const std::vector<ParDescr>& parDescr() const override;
};
}

Expand Down
24 changes: 0 additions & 24 deletions effects/noeffect/noeffect.qml

This file was deleted.

7 changes: 0 additions & 7 deletions effects/noeffect/noeffect.qrc

This file was deleted.

48 changes: 0 additions & 48 deletions effects/noeffect/noeffectgui.cpp

This file was deleted.

15 changes: 5 additions & 10 deletions effects/noeffect/noeffectgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,22 @@
// the file LICENCE.GPL
//=============================================================================

#ifndef __NOEFFECTGUI_H__
#define __NOEFFECTGUI_H__

#include "effects/effectgui.h"

namespace Ms {

class NoEffect;

//---------------------------------------------------------
// gui
// NoEffectGui
//---------------------------------------------------------

class NoEffectGui : public EffectGui {
Q_OBJECT

virtual void updateValues() {}

public:
NoEffectGui(NoEffect*, QWidget* parent = 0);
NoEffectGui(Effect* e, QWidget* parent = 0);
};
}

#endif

}

Loading

0 comments on commit f22515c

Please sign in to comment.