~ubuntu-branches/ubuntu/vivid/rlvm/vivid-proposed

« back to all changes in this revision

Viewing changes to src/Systems/SDL/SDLMusic.hpp

  • Committer: Package Import Robot
  • Author(s): Ying-Chun Liu (PaulLiu)
  • Date: 2014-10-22 03:24:19 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20141022032419-yqxls9ky4n1w811n
Tags: 0.14-1
* New upstream release
* Bump Standards-Version to 3.9.6: nothing needs to be changed

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// -*- Mode: C++; tab-width:2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2
 
// vi:tw=80:et:ts=2:sts=2
3
 
//
4
 
// -----------------------------------------------------------------------
5
 
//
6
 
// This file is part of RLVM, a RealLive virtual machine clone.
7
 
//
8
 
// -----------------------------------------------------------------------
9
 
//
10
 
// Copyright (C) 2008 Elliot Glaysher
11
 
//
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.
16
 
//
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.
21
 
//
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.
25
 
//
26
 
// -----------------------------------------------------------------------
27
 
 
28
 
#ifndef SRC_SYSTEMS_SDL_SDLMUSIC_HPP_
29
 
#define SRC_SYSTEMS_SDL_SDLMUSIC_HPP_
30
 
 
31
 
#include <string>
32
 
 
33
 
#include "Systems/Base/SoundSystem.hpp"
34
 
 
35
 
#include <boost/enable_shared_from_this.hpp>
36
 
#include <boost/noncopyable.hpp>
37
 
#include <boost/shared_ptr.hpp>
38
 
 
39
 
#include <SDL/SDL_mixer.h>
40
 
 
41
 
#include "xclannad/wavfile.h"
42
 
 
43
 
// Encapsulates access to SDLMussic.
44
 
//
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.
49
 
//
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.
56
 
//
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> {
61
 
 public:
62
 
  ~SDLMusic();
63
 
 
64
 
  // Whether we were told to loop when we were play()ed.
65
 
  bool isLooping() const;
66
 
 
67
 
  // Whether we are currently fading out.
68
 
  bool isFading() const;
69
 
 
70
 
  // TODO: Now that I understand wtf is going on, redo this part here.
71
 
  void play(bool loop);
72
 
  void stop();
73
 
  void fadeIn(bool loop, int fade_in_ms);
74
 
  void fadeOut(int fade_out_ms);
75
 
  void pause();
76
 
  void unpause();
77
 
  std::string name() const;
78
 
 
79
 
  // Returns the current playing status of the current track. Uses the
80
 
  // same return codes as SoundSystem::bgmStatus().
81
 
  int bgmStatus() const;
82
 
 
83
 
  // Creates a MusicImpl object from the incoming description of the
84
 
  // music.
85
 
  static boost::shared_ptr<SDLMusic> CreateMusic(
86
 
    System& system, const SoundSystem::DSTrack& track);
87
 
 
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;
92
 
  }
93
 
 
94
 
  // Whether music is currently playing.
95
 
  static bool IsCurrentlyPlaying() { return s_currently_playing; }
96
 
 
97
 
  // Whether we should output music.
98
 
  static void SetBgmEnabled(const int in) { s_bgm_enabled = in; }
99
 
 
100
 
  // What volume we should play this at normally.
101
 
  static void SetComputedBgmVolume(const int in) {
102
 
    s_computed_bgm_vol = in / 2;
103
 
  }
104
 
 
105
 
 private:
106
 
  // Builds an SDLMusic object.
107
 
  SDLMusic(const SoundSystem::DSTrack& track, WAVFILE* wav);
108
 
 
109
 
  // Callback function to Mix_HookMusic.
110
 
  //
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);
114
 
 
115
 
  // Strongly coupled because of access to SDLMusic::MixMusic.
116
 
  friend class SDLSoundSystem;
117
 
 
118
 
  // Underlying data stream. (These classes stolen from xclannad.)
119
 
  WAVFILE* file_;
120
 
 
121
 
  // The underlying track information
122
 
  const SoundSystem::DSTrack& track_;
123
 
 
124
 
  // No idea.
125
 
  int fade_count_;
126
 
 
127
 
  // Number of milliseconds left to fade out the
128
 
  int fadetime_total_;
129
 
 
130
 
  // Number of milliseconds to fade in.
131
 
  int fade_in_ms_;
132
 
 
133
 
  // The starting loop point.
134
 
  int loop_point_;
135
 
 
136
 
  // Whether the music is currently paused.
137
 
  bool music_paused_;
138
 
 
139
 
  // The currently playing track.
140
 
  static boost::shared_ptr<SDLMusic> s_currently_playing;
141
 
 
142
 
  // Whether we should even be playing music.
143
 
  static bool s_bgm_enabled;
144
 
 
145
 
  // The volume we should play music at as a [0,128] range.
146
 
  static int s_computed_bgm_vol;
147
 
};
148
 
 
149
 
// -----------------------------------------------------------------------
150
 
 
151
 
#endif  // SRC_SYSTEMS_SDL_SDLMUSIC_HPP_