Commit 1035b7dd authored by Sandro Andrade's avatar Sandro Andrade
Browse files

Fix issue of not registration of ISoundController when audio plugin is missing

parent 08603cfa
......@@ -22,6 +22,8 @@
#include "core.h"
#include <qqml.h>
#include "uicontroller.h"
#include "plugincontroller.h"
#include "exercisecontroller.h"
......@@ -40,6 +42,10 @@ bool Core::initialize()
if (m_self)
return true;
qRegisterMetaType<Minuet::ISoundController::State>("State");
qmlRegisterInterface<Minuet::ISoundController>("ISoundController");
qmlRegisterUncreatableType<Minuet::ISoundController>("org.kde.minuet.isoundcontroller", 1, 0, "ISoundController", "ISoundController cannot be instantiated");
m_self = new Core;
return true;
......@@ -78,13 +84,22 @@ Core::Core(QObject *parent)
m_soundController(0)
{
m_pluginController = new PluginController(this);
((PluginController *)m_pluginController)->initialize(this);
if (!((PluginController *)m_pluginController)->initialize(this)) {
qCritical() << m_pluginController->errorString();
exit(-1);
}
m_exerciseController = new ExerciseController(this);
((ExerciseController *)m_exerciseController)->initialize(this);
if (!((ExerciseController *)m_exerciseController)->initialize(this)) {
qCritical() << m_exerciseController->errorString();
exit(-2);
}
m_uiController = new UiController(this);
((UiController *)m_uiController)->initialize(this);
if (!((UiController *)m_uiController)->initialize(this)) {
qCritical() << m_uiController->errorString();
exit(-3);
}
}
}
......
......@@ -51,6 +51,7 @@ bool ExerciseController::initialize(Core *core)
{
Q_UNUSED(core)
m_errorString.clear();
bool definitionsMerge = mergeJsonFiles("definitions", m_definitions);
bool exercisesMerge = mergeJsonFiles("exercises", m_exercises, true, "name", "children");
......@@ -62,6 +63,11 @@ bool ExerciseController::initialize(Core *core)
return definitionsMerge & exercisesMerge;
}
QString ExerciseController::errorString() const
{
return m_errorString;
}
void ExerciseController::randomlySelectExerciseOptions()
{
while (!m_selectedExerciseOptions.isEmpty())
......@@ -104,11 +110,6 @@ unsigned int ExerciseController::chosenRootNote()
return m_chosenRootNote;
}
QString ExerciseController::errorString() const
{
return m_errorString;
}
QJsonArray ExerciseController::exercises() const
{
return m_exercises[QStringLiteral("exercises")].toArray();
......@@ -116,7 +117,6 @@ QJsonArray ExerciseController::exercises() const
bool ExerciseController::mergeJsonFiles(const QString directoryName, QJsonObject &targetObject, bool applyDefinitionsFlag, QString commonKey, QString mergeKey)
{
m_errorString.clear();
#if defined(Q_OS_ANDROID)
QStringList jsonDirs;
jsonDirs += "/data/data/org.kde.minuet/qt-reserved-files/share/minuet/" + directoryName;
......@@ -141,7 +141,7 @@ bool ExerciseController::mergeJsonFiles(const QString directoryName, QJsonObject
QJsonDocument jsonDocument = QJsonDocument::fromJson(jsonFile.readAll(), &error);
if (error.error != QJsonParseError::NoError) {
m_errorString = error.errorString();
m_errorString += QStringLiteral("Error when parsing JSON file '%1'. ").arg(jsonDir.absoluteFilePath(json));
jsonFile.close();
return false;
}
......
......@@ -42,10 +42,10 @@ public:
virtual ~ExerciseController();
bool initialize(Core *core);
virtual QString errorString() const;
Q_INVOKABLE unsigned int chosenRootNote();
QString errorString() const;
virtual QJsonArray exercises() const override;
public Q_SLOTS:
......
......@@ -46,7 +46,7 @@ PluginController::PluginController(QObject *parent)
#if !defined(Q_OS_ANDROID)
m_plugins = KPluginLoader::findPlugins(QStringLiteral("minuet"), [&](const KPluginMetaData &meta) {
if (!meta.serviceTypes().contains(QStringLiteral("Minuet/Plugin"))) {
qDebug() << "Plugin" << meta.fileName() << "is installed into the minuet plugin directory, but does not have"
qWarning() << "Plugin" << meta.fileName() << "is installed into the minuet plugin directory, but does not have"
" \"Minuet/Plugin\" set as the service type. This plugin will not be loaded.";
return false;
}
......@@ -65,7 +65,9 @@ PluginController::~PluginController()
bool PluginController::initialize(Core *core)
{
m_errorString.clear();
#if !defined(Q_OS_ANDROID)
ISoundController *soundController = 0;
foreach (const KPluginMetaData &pluginMetaData, m_plugins)
{
if (m_loadedPlugins.value(pluginMetaData))
......@@ -75,22 +77,30 @@ bool PluginController::initialize(Core *core)
IPlugin *plugin = qobject_cast<IPlugin *>(loader.instance());
if (plugin) {
m_loadedPlugins.insert(pluginMetaData, plugin);
ISoundController *soundController = 0;
if (!core->soundController() && (soundController = qobject_cast<ISoundController *>(plugin))) {
qDebug() << "Setting soundcontroller to" << soundController->metaObject()->className();
qInfo() << "Setting soundcontroller to" << soundController->metaObject()->className();
core->setSoundController(soundController);
}
}
}
if (!soundController) {
m_errorString = QStringLiteral("Could not find a suitable SoundController plugin!");
return false;
}
#else
ISoundController *soundController = 0;
if (!core->soundController() && (soundController = new CsoundSoundController)) {
qDebug() << "Setting soundcontroller to" << soundController->metaObject()->className();
qInfo() << "Setting soundcontroller to" << soundController->metaObject()->className();
core->setSoundController(soundController);
}
#endif
return true;
}
QString PluginController::errorString() const
{
return m_errorString;
}
}
......@@ -42,8 +42,9 @@ class PluginController : public IPluginController
public:
PluginController(QObject *parent = 0);
~PluginController() override;
bool initialize(Core *core);
virtual QString errorString() const;
private:
#ifndef Q_OS_ANDROID
......@@ -52,6 +53,7 @@ private:
typedef QHash<KPluginMetaData, IPlugin *> InfoToPluginMap;
InfoToPluginMap m_loadedPlugins;
#endif
QString m_errorString;
};
}
......
......@@ -47,6 +47,7 @@ UiController::~UiController()
bool UiController::initialize(Core *core)
{
m_errorString.clear();
QQmlApplicationEngine *engine = new QQmlApplicationEngine(this);
QQmlContext *rootContext = engine->rootContext();
rootContext->setContextProperty(QStringLiteral("core"), core);
......@@ -60,5 +61,10 @@ bool UiController::initialize(Core *core)
return true;
}
QString UiController::errorString() const
{
return m_errorString;
}
}
......@@ -61,6 +61,10 @@ public:
~UiController() override;
bool initialize(Core *core);
virtual QString errorString() const;
private:
QString m_errorString;
};
}
......
......@@ -42,6 +42,8 @@ class MINUETINTERFACES_EXPORT IExerciseController : public QObject
public:
virtual ~IExerciseController() override;
virtual QString errorString() const = 0;
virtual QJsonArray exercises() const = 0;
void setCurrentExercise(QVariantMap currentExercise);
......
......@@ -36,6 +36,8 @@ class MINUETINTERFACES_EXPORT IPluginController : public QObject
public:
virtual ~IPluginController() override;
virtual QString errorString() const = 0;
protected:
explicit IPluginController(QObject *parent = 0);
......
......@@ -22,18 +22,12 @@
#include "isoundcontroller.h"
#include <qqml.h>
namespace Minuet
{
ISoundController::ISoundController(QObject *parent)
: IPlugin(parent)
{
qRegisterMetaType<State>("State");
qmlRegisterInterface<ISoundController>("ISoundController");
qmlRegisterUncreatableType<ISoundController>("org.kde.minuet.isoundcontroller", 1, 0, "ISoundController", "ISoundController cannot be instantiated");
setPlaybackLabel(QStringLiteral("00:00.00"));
setState(StoppedState);
}
......
......@@ -36,6 +36,8 @@ class MINUETINTERFACES_EXPORT IUiController : public QObject
public:
virtual ~IUiController() override;
virtual QString errorString() const = 0;
protected:
explicit IUiController(QObject *parent = 0);
......
......@@ -53,7 +53,7 @@ FluidSynthSoundController::FluidSynthSoundController(QObject *parent)
int fluid_res = fluid_synth_sfload(m_synth, QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("minuet/soundfonts/GeneralUser-v1.47.sf2")).toLatin1(), 1);
#endif
if (fluid_res == FLUID_FAILED)
qDebug() << "Error when loading soundfont!";
qCritical() << "Error when loading soundfont!";
resetEngine();
}
......@@ -226,7 +226,7 @@ void FluidSynthSoundController::resetEngine()
m_audioDriver = new_fluid_audio_driver(m_settings, m_synth);
}
if (!m_audioDriver) {
qDebug() << "Couldn't start audio driver!";
qCritical() << "Couldn't start audio driver!";
}
m_sequencer = new_fluid_sequencer2(0);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment