diff options
Diffstat (limited to 'pokescripting/SoundWrapper.h')
| -rw-r--r-- | pokescripting/SoundWrapper.h | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/pokescripting/SoundWrapper.h b/pokescripting/SoundWrapper.h index 683cca13..9f7f7eec 100644 --- a/pokescripting/SoundWrapper.h +++ b/pokescripting/SoundWrapper.h @@ -24,6 +24,13 @@ // Pokemod includes #include "../pokemod/Sound.h" +// Qt includes +#include <QtCore/QBuffer> + +// Phonon includes +#include <Phonon/MediaObject> +#include <Phonon/MediaSource> + namespace Pokescripting { class POKESCRIPTING_EXPORT SoundWrapper : public ObjectWrapper @@ -31,11 +38,17 @@ class POKESCRIPTING_EXPORT SoundWrapper : public ObjectWrapper Q_OBJECT public: - SoundWrapper(const Pokemod::Sound* sound, QObject* parent); + static SoundWrapper* create(const Pokemod::Sound* sound, QObject* parent) + { + if (!m_instances.contains(sound->id())) + m_instances[sound->id()] = new SoundWrapper(sound, parent); + return qobject_cast<SoundWrapper*>(m_instances[sound->id()]); + } public slots: QString name() const; - // TODO: Get audio data from it + Phonon::MediaObject* data(); private: + SoundWrapper(const Pokemod::Sound* sound, QObject* parent); SoundWrapper& operator=(const SoundWrapper& rhs); const Pokemod::Sound* m_sound; @@ -52,6 +65,15 @@ inline QString SoundWrapper::name() const return m_sound->name(); } +inline Phonon::MediaObject* SoundWrapper::data() +{ + Phonon::MediaObject* media = new Phonon::MediaObject(this); + QBuffer* buffer = new QBuffer(media); + buffer->setData(m_sound->data()); + media->setCurrentSource(buffer); + return media; +} + } #endif |
