1
// -*- Mode: C++; tab-width:2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2
// vi:tw=80:et:ts=2:sts=2
4
// -----------------------------------------------------------------------
6
// This file is part of RLVM, a RealLive virtual machine clone.
8
// -----------------------------------------------------------------------
10
// Copyright (C) 2008 Elliot Glaysher
12
// This program is free software; you can redistribute it and/or modify
13
// it under the terms of the GNU General Public License as published by
14
// the Free Software Foundation; either version 3 of the License, or
15
// (at your option) any later version.
17
// This program is distributed in the hope that it will be useful,
18
// but WITHOUT ANY WARRANTY; without even the implied warranty of
19
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
// GNU General Public License for more details.
22
// You should have received a copy of the GNU General Public License
23
// along with this program; if not, write to the Free Software
24
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
26
// -----------------------------------------------------------------------
28
#ifndef SRC_SYSTEMS_SDL_SDLMUSIC_HPP_
29
#define SRC_SYSTEMS_SDL_SDLMUSIC_HPP_
33
#include "Systems/Base/SoundSystem.hpp"
35
#include <boost/enable_shared_from_this.hpp>
36
#include <boost/noncopyable.hpp>
37
#include <boost/shared_ptr.hpp>
39
#include <SDL/SDL_mixer.h>
41
#include "xclannad/wavfile.h"
43
// Encapsulates access to SDLMussic.
45
// This system is the way it is for a good reason. The first shot of
46
// this had two subclasses of SDLMusic, one which implemented formats
47
// (ogg, mp3, wav, etc.), the other which mucks about with SDL_Mixer's
48
// Mix_HookMusic() method for just nwa files.
50
// Jagarl used Mix_HookMusic along with his own loaders for all file
51
// formats. He did this because in the \#DSTRACK definition, there is
52
// a point in the file where you loop back to when the track
53
// ends. This is why ripped NWA files end so abruptly if you play them
54
// in a music player: they're designed to be looped forever and you
55
// can't get that effect with built ins.
57
// So instead of taking just jagarl's nwatowav.cc, I'm also stealing
58
// wavfile.{cc,h}, and some binding code.
59
class SDLMusic : public boost::noncopyable,
60
public boost::enable_shared_from_this<SDLMusic> {
64
// Whether we were told to loop when we were play()ed.
65
bool isLooping() const;
67
// Whether we are currently fading out.
68
bool isFading() const;
70
// TODO: Now that I understand wtf is going on, redo this part here.
73
void fadeIn(bool loop, int fade_in_ms);
74
void fadeOut(int fade_out_ms);
77
std::string name() const;
79
// Returns the current playing status of the current track. Uses the
80
// same return codes as SoundSystem::bgmStatus().
81
int bgmStatus() const;
83
// Creates a MusicImpl object from the incoming description of the
85
static boost::shared_ptr<SDLMusic> CreateMusic(
86
System& system, const SoundSystem::DSTrack& track);
88
// Returns the currently playing SDLMusic object. Returns NULL if no
89
// music is currently playing.
90
static boost::shared_ptr<SDLMusic> CurrnetlyPlaying() {
91
return s_currently_playing;
94
// Whether music is currently playing.
95
static bool IsCurrentlyPlaying() { return s_currently_playing; }
97
// Whether we should output music.
98
static void SetBgmEnabled(const int in) { s_bgm_enabled = in; }
100
// What volume we should play this at normally.
101
static void SetComputedBgmVolume(const int in) {
102
s_computed_bgm_vol = in / 2;
106
// Builds an SDLMusic object.
107
SDLMusic(const SoundSystem::DSTrack& track, WAVFILE* wav);
109
// Callback function to Mix_HookMusic.
111
// This function was ripped off almost verbatim from xclannad! Specifically
112
// the static method WavChunk::callback in music2/music.cc.
113
static void MixMusic(void *udata, Uint8 *stream, int len);
115
// Strongly coupled because of access to SDLMusic::MixMusic.
116
friend class SDLSoundSystem;
118
// Underlying data stream. (These classes stolen from xclannad.)
121
// The underlying track information
122
const SoundSystem::DSTrack& track_;
127
// Number of milliseconds left to fade out the
130
// Number of milliseconds to fade in.
133
// The starting loop point.
136
// Whether the music is currently paused.
139
// The currently playing track.
140
static boost::shared_ptr<SDLMusic> s_currently_playing;
142
// Whether we should even be playing music.
143
static bool s_bgm_enabled;
145
// The volume we should play music at as a [0,128] range.
146
static int s_computed_bgm_vol;
149
// -----------------------------------------------------------------------
151
#endif // SRC_SYSTEMS_SDL_SDLMUSIC_HPP_