1
/***************************************************************************
2
* Project TUPI: Magia 2D *
3
* Project Contact: info@maefloresta.com *
4
* Project Website: http://www.maefloresta.com *
5
* Project Leader: Gustav Gonzalez <info@maefloresta.com> *
9
* Gustavo Gonzalez / xtingray *
20
* Copyright (C) 2010 Gustav Gonzalez - http://www.maefloresta.com *
22
* This program is free software; you can redistribute it and/or modify *
23
* it under the terms of the GNU General Public License as published by *
24
* the Free Software Foundation; either version 3 of the License, or *
25
* (at your option) any later version. *
27
* This program is distributed in the hope that it will be useful, *
28
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
29
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30
* GNU General Public License for more details. *
32
* You should have received a copy of the GNU General Public License *
33
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
34
***************************************************************************/
36
#include "tupsoundlayer.h"
37
#include "taudioplayer.h"
38
#include "tuplibrary.h"
39
#include "tupproject.h"
40
#include "tuplibraryobject.h"
44
struct TupSoundLayer::Private
46
QString filePath, symbolName;
50
TupSoundLayer::TupSoundLayer(TupScene *parent)
51
: TupLayer(parent), k(new Private)
55
TupSoundLayer::~TupSoundLayer()
60
void TupSoundLayer::fromSymbol(const QString &symbolName)
62
TupLibrary *library = project()->library();
64
if (TupLibraryObject *object = library->findObject(symbolName)) {
65
if (object->type() == TupLibraryObject::Sound) {
66
k->symbolName = symbolName;
67
k->filePath = object->dataPath();
68
k->playerId = TAudioPlayer::instance()->load(k->filePath);
73
QString TupSoundLayer::filePath() const
78
void TupSoundLayer::play()
80
TAudioPlayer::instance()->setCurrentPlayer(k->playerId);
81
TAudioPlayer::instance()->play();
84
void TupSoundLayer::stop()
86
TAudioPlayer::instance()->setCurrentPlayer(k->playerId);
87
TAudioPlayer::instance()->stop();
90
void TupSoundLayer::fromXml(const QString &xml)
92
QDomDocument document;
94
if (! document.setContent(xml))
97
QDomElement root = document.documentElement();
98
setLayerName(root.attribute("name", layerName()));
100
fromSymbol(root.attribute("symbol"));
103
QDomElement TupSoundLayer::toXml(QDomDocument &doc) const
105
QDomElement root = doc.createElement("soundlayer");
106
root.setAttribute("name", layerName());
107
root.setAttribute("symbol", k->symbolName);