ScummVM API documentation
musicparam.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22/*
23 * This code is based on the CRAB engine
24 *
25 * Copyright (c) Arvind Raja Yadav
26 *
27 * Licensed under MIT
28 *
29 */
30
31#ifndef CRAB_MUSICPARAM_H
32#define CRAB_MUSICPARAM_H
33#include "audio/audiostream.h"
35#include "common/file.h"
36#include "crab/loaders.h"
37#include "crab/filesystem.h"
38
39namespace Crab {
40
41namespace pyrodactyl {
42namespace music {
43// We use this object as key for music tracks
44// Empty sounds are represented by -1
45typedef int MusicKey;
46
47// We use this object as key for sound effects
48// Empty sounds are represented by -1
49typedef int ChunkKey;
50
51struct MusicData {
52 // The id of this track
53 MusicKey _id;
54 Audio::AudioStream *_track;
55 Common::File _file;
56
57 // Sound parameters
58 uint32 _fadeInDuration;
59
60 MusicData() {
61 reset();
62 }
63
64 void reset() {
65 _id = -1;
66 _track = nullptr;
67 _fadeInDuration = 100;
68
69 if (_file.isOpen()) {
70 _file.close();
71 }
72 }
73
74 void load(rapidxml::xml_node<char> *node) {
75 loadNum(_id, "id", node);
76 loadNum(_fadeInDuration, "fade_in", node);
77
78 Common::Path cleansedPath = cleansePath(Common::Path(node->first_attribute("path")->value(), '/'));
79 if (_file.open(cleansedPath)) {
80 Audio::SeekableAudioStream *stream = Audio::makeVorbisStream(&_file, DisposeAfterUse::NO);
81 // loops=0 means infinite here.
82 _track = Audio::makeLoopingAudioStream(stream, 0, 0, 0);
83 } else {
84 warning("Could not open file %s", cleansedPath.toString().c_str());
85 }
86 }
87};
88} // End of namespace music
89} // End of namespace pyrodactyl
90
91} // End of namespace Crab
92
93#endif // CRAB_MUSICPARAM_H
Definition: audiostream.h:50
Definition: audiostream.h:212
Definition: file.h:47
bool isOpen() const
virtual void close()
virtual bool open(const Path &filename)
Definition: path.h:52
String toString(char separator='/') const
AudioStream * makeLoopingAudioStream(RewindableAudioStream *stream, uint loops)
void warning(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Definition: musicparam.h:51