aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/plugins/Input/wildmidi/decoder_wildmidi.cpp83
-rw-r--r--src/plugins/Input/wildmidi/decoder_wildmidi.h48
-rw-r--r--src/plugins/Input/wildmidi/decoderwildmidifactory.cpp100
-rw-r--r--src/plugins/Input/wildmidi/decoderwildmidifactory.h51
-rw-r--r--src/plugins/Input/wildmidi/wildmidi.pro31
-rw-r--r--src/plugins/Input/wildmidi/wildmidihelper.cpp41
-rw-r--r--src/plugins/Input/wildmidi/wildmidihelper.h21
7 files changed, 375 insertions, 0 deletions
diff --git a/src/plugins/Input/wildmidi/decoder_wildmidi.cpp b/src/plugins/Input/wildmidi/decoder_wildmidi.cpp
new file mode 100644
index 000000000..f29d60fef
--- /dev/null
+++ b/src/plugins/Input/wildmidi/decoder_wildmidi.cpp
@@ -0,0 +1,83 @@
+/***************************************************************************
+ * Copyright (C) 2008-2010 by Ilya Kotov *
+ * forkotov02@hotmail.ru *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#include "wildmidihelper.h"
+#include "decoder_wildmidi.h"
+
+// Decoder class
+DecoderWildMidi::DecoderWildMidi(const QString &path) : Decoder()
+{
+ m_path = path;
+ midi_ptr = 0;
+}
+
+DecoderWildMidi::~DecoderWildMidi()
+{
+ if(midi_ptr)
+ WildMidi_Close(midi_ptr);
+}
+
+bool DecoderWildMidi::initialize()
+{
+ m_totalTime = 0;
+
+ if(!WildMidiHelper::instance()->initialize())
+ {
+ qWarning("DecoderWildMidi: initialization failed");
+ return false;
+ }
+
+
+ midi_ptr = WildMidi_Open (m_path.toLocal8Bit());
+ if(!midi_ptr)
+ {
+ qWarning("DecoderWildMidi: unable to open file");
+ return false;
+ }
+ _WM_Info *wm_info = WildMidi_GetInfo(midi_ptr);
+
+ m_totalTime = (qint64)wm_info->approx_total_samples / 48;
+
+ configure(48000, 2, Qmmp::PCM_S16LE);
+
+ qDebug("DecoderWildMidi: initialize succes");
+ return true;
+}
+
+qint64 DecoderWildMidi::totalTime()
+{
+ return m_totalTime;
+}
+
+void DecoderWildMidi::seek(qint64 pos)
+{
+ ulong sample = ulong(pos*48);
+ WildMidi_FastSeek(midi_ptr, &sample);
+}
+
+int DecoderWildMidi::bitrate()
+{
+ return 8;
+}
+
+qint64 DecoderWildMidi::read(char *data, qint64 size)
+{
+ return WildMidi_GetOutput (midi_ptr, data, size);
+}
diff --git a/src/plugins/Input/wildmidi/decoder_wildmidi.h b/src/plugins/Input/wildmidi/decoder_wildmidi.h
new file mode 100644
index 000000000..222c1ef3c
--- /dev/null
+++ b/src/plugins/Input/wildmidi/decoder_wildmidi.h
@@ -0,0 +1,48 @@
+/***************************************************************************
+ * Copyright (C) 2008-2010 by Ilya Kotov *
+ * forkotov02@hotmail.ru *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#ifndef DECODER_WILDMIDI_H
+#define DECODER_WILDMIDI_H
+
+extern "C"{
+#include <wildmidi_lib.h>
+}
+#include <qmmp/decoder.h>
+
+class DecoderWildMidi : public Decoder
+{
+public:
+ DecoderWildMidi(const QString &path);
+ virtual ~DecoderWildMidi();
+
+ // Standard Decoder API
+ bool initialize();
+ qint64 totalTime();
+ int bitrate();
+ qint64 read(char *data, qint64 size);
+ void seek(qint64);
+
+private:
+ void *midi_ptr;
+ qint64 m_totalTime;
+ QString m_path;
+};
+
+#endif // DECODER_WILDMIDI_H
diff --git a/src/plugins/Input/wildmidi/decoderwildmidifactory.cpp b/src/plugins/Input/wildmidi/decoderwildmidifactory.cpp
new file mode 100644
index 000000000..13b3b2e06
--- /dev/null
+++ b/src/plugins/Input/wildmidi/decoderwildmidifactory.cpp
@@ -0,0 +1,100 @@
+/***************************************************************************
+ * Copyright (C) 2008-2010 by Ilya Kotov *
+ * forkotov02@hotmail.ru *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#include <QtGui>
+
+#include "wildmidihelper.h"
+#include "decoder_wildmidi.h"
+#include "decoderwildmidifactory.h"
+
+
+// DecoderWildMidiFactory
+
+bool DecoderWildMidiFactory::supports(const QString &source) const
+{
+
+ return (source.right(4).toLower() == ".mid");
+}
+
+bool DecoderWildMidiFactory::canDecode(QIODevice *) const
+{
+ return FALSE;
+}
+
+const DecoderProperties DecoderWildMidiFactory::properties() const
+{
+ DecoderProperties properties;
+ properties.name = tr("WildMidi Plugin");
+ properties.filter = "*.mid";
+ properties.description = tr("Midi Files");
+ //properties.contentType = ;
+ properties.hasAbout = FALSE;
+ properties.hasSettings = FALSE;
+ properties.noInput = TRUE;
+ properties.protocols = "file";
+ return properties;
+}
+
+Decoder *DecoderWildMidiFactory::create(const QString &path, QIODevice *input)
+{
+ Q_UNUSED(input);
+ return new DecoderWildMidi(path);
+}
+
+QList<FileInfo *> DecoderWildMidiFactory::createPlayList(const QString &fileName, bool useMetaData)
+{
+ QList <FileInfo*> list;
+ FileInfo *info = new FileInfo(fileName);
+
+ if(WildMidiHelper::instance()->initialize())
+ {
+ void *midi_ptr = WildMidi_Open (fileName.toLocal8Bit());
+ if(midi_ptr)
+ {
+ _WM_Info *wm_info = WildMidi_GetInfo(midi_ptr);
+ info->setLength((qint64)wm_info->approx_total_samples / 48000);
+ WildMidi_Close(midi_ptr);
+ }
+ }
+ list << info;
+ return list;
+}
+
+MetaDataModel* DecoderWildMidiFactory::createMetaDataModel(const QString &path, QObject *parent)
+{
+ /*DetailsDialog *d = new DetailsDialog(parent, path);
+ d -> show();*/
+ return 0;
+}
+
+void DecoderWildMidiFactory::showSettings(QWidget *)
+{}
+
+void DecoderWildMidiFactory::showAbout(QWidget *parent)
+{}
+
+QTranslator *DecoderWildMidiFactory::createTranslator(QObject *parent)
+{
+ QTranslator *translator = new QTranslator(parent);
+ QString locale = QLocale::system().name();
+ translator->load(QString(":/wildmidi_plugin_") + locale);
+ return translator;
+}
+Q_EXPORT_PLUGIN(DecoderWildMidiFactory)
diff --git a/src/plugins/Input/wildmidi/decoderwildmidifactory.h b/src/plugins/Input/wildmidi/decoderwildmidifactory.h
new file mode 100644
index 000000000..eeb11b544
--- /dev/null
+++ b/src/plugins/Input/wildmidi/decoderwildmidifactory.h
@@ -0,0 +1,51 @@
+/***************************************************************************
+ * Copyright (C) 2008 by Ilya Kotov *
+ * forkotov02@hotmail.ru *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+#ifndef DECODERWILDMIDIFACTORY_H
+#define DECODERWILDMIDIFACTORY_H
+
+#include <QObject>
+#include <QString>
+#include <QIODevice>
+#include <QWidget>
+
+#include <qmmp/decoder.h>
+#include <qmmp/output.h>
+#include <qmmp/decoderfactory.h>
+#include <qmmp/fileinfo.h>
+
+
+class DecoderWildMidiFactory : public QObject, DecoderFactory
+{
+ Q_OBJECT
+ Q_INTERFACES(DecoderFactory);
+
+public:
+ bool supports(const QString &source) const;
+ bool canDecode(QIODevice *input) const;
+ const DecoderProperties properties() const;
+ Decoder *create(const QString &path, QIODevice *input);
+ QList<FileInfo *> createPlayList(const QString &fileName, bool useMetaData);
+ MetaDataModel* createMetaDataModel(const QString &path, QObject *parent = 0);
+ void showSettings(QWidget *parent);
+ void showAbout(QWidget *parent);
+ QTranslator *createTranslator(QObject *parent);
+};
+
+#endif
diff --git a/src/plugins/Input/wildmidi/wildmidi.pro b/src/plugins/Input/wildmidi/wildmidi.pro
new file mode 100644
index 000000000..bd968223c
--- /dev/null
+++ b/src/plugins/Input/wildmidi/wildmidi.pro
@@ -0,0 +1,31 @@
+include(../../plugins.pri)
+FORMS +=
+HEADERS += decoderwildmidifactory.h \
+ decoder_wildmidi.h \
+ wildmidihelper.h
+SOURCES += decoder_wildmidi.cpp \
+ decoderwildmidifactory.cpp \
+ wildmidihelper.cpp
+TARGET = $$PLUGINS_PREFIX/Input/wildmidi
+QMAKE_CLEAN = $$PLUGINS_PREFIX/Input/libwildmidi.so
+INCLUDEPATH += ../../../
+CONFIG += release \
+ warn_on \
+ plugin
+TEMPLATE = lib
+QMAKE_LIBDIR += ../../../../lib
+LIBS += -lqmmp \
+ -L/usr/lib \
+ -I/usr/include \
+ -lWildMidi
+TRANSLATIONS = translations/wildmidi_plugin_cs.ts \
+ translations/wildmidi_plugin_de.ts \
+ translations/wildmidi_plugin_zh_CN.ts \
+ translations/wildmidi_plugin_zh_TW.ts \
+ translations/wildmidi_plugin_ru.ts \
+ translations/wildmidi_plugin_uk_UA.ts
+
+# RESOURCES = translations/translations.qrc
+isEmpty (LIB_DIR):LIB_DIR = /lib
+target.path = $$LIB_DIR/qmmp/Input
+INSTALLS += target
diff --git a/src/plugins/Input/wildmidi/wildmidihelper.cpp b/src/plugins/Input/wildmidi/wildmidihelper.cpp
new file mode 100644
index 000000000..7a9ec94b6
--- /dev/null
+++ b/src/plugins/Input/wildmidi/wildmidihelper.cpp
@@ -0,0 +1,41 @@
+#include <QApplication>
+extern "C"{
+#include <wildmidi_lib.h>
+}
+#include "wildmidihelper.h"
+
+WildMidiHelper *WildMidiHelper::m_instance = 0;
+
+WildMidiHelper::WildMidiHelper(QObject *parent) :
+ QObject(parent)
+{
+ m_inited = false;
+}
+
+WildMidiHelper::~WildMidiHelper()
+{
+ if(m_inited)
+ WildMidi_Shutdown();
+ m_instance = 0;
+}
+
+bool WildMidiHelper::initialize()
+{
+ if(m_inited)
+ return true;
+ if (WildMidi_Init ("/etc/timidity/timidity.cfg", 48000, 0) < 0)
+ {
+ qWarning("WildMidiHelper: unable to initialize WildMidi library");
+ return false;
+ }
+ m_inited = true;
+ return true;
+}
+
+
+WildMidiHelper *WildMidiHelper::instance()
+{
+ if(!m_instance)
+ m_instance = new WildMidiHelper(qApp);
+ return m_instance;
+}
diff --git a/src/plugins/Input/wildmidi/wildmidihelper.h b/src/plugins/Input/wildmidi/wildmidihelper.h
new file mode 100644
index 000000000..d428b4f09
--- /dev/null
+++ b/src/plugins/Input/wildmidi/wildmidihelper.h
@@ -0,0 +1,21 @@
+#ifndef WILDMIDIHELPER_H
+#define WILDMIDIHELPER_H
+
+#include <QObject>
+
+class WildMidiHelper : public QObject
+{
+Q_OBJECT
+public:
+ explicit WildMidiHelper(QObject *parent = 0);
+ ~WildMidiHelper();
+ bool initialize();
+ static WildMidiHelper *instance();
+
+private:
+ static WildMidiHelper *m_instance;
+ bool m_inited;
+
+};
+
+#endif // WILDMIDIHELPER_H