ScummVM API documentation
u8_music_process.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 #ifndef ULTIMA8_AUDIO_U8MUSICPROCESS_H
23 #define ULTIMA8_AUDIO_U8MUSICPROCESS_H
24 
25 #include "ultima/ultima8/audio/music_process.h"
26 #include "ultima/ultima8/misc/classtype.h"
27 #include "audio/mididrv.h"
28 
29 namespace Ultima {
30 namespace Ultima8 {
31 
32 class Debugger;
33 class MidiPlayer;
34 
35 class U8MusicProcess : public MusicProcess {
36  friend class Debugger;
37 
38  enum PlaybackStates {
39  PLAYBACK_NORMAL = 1,
40  PLAYBACK_TRANSITION = 2,
41  PLAYBACK_PLAY_WANTED = 3
42  };
43 
44 public:
46  struct TrackState {
48  int _wanted;
52  int _queued;
53 
54  TrackState() : _wanted(0), _lastRequest(0), _queued(0) { }
55  TrackState(int wanted, int lastRequest, int queued) :
56  _wanted(wanted), _lastRequest(lastRequest), _queued(queued) { }
57  };
58 
59 private:
62  void playMusic_internal(int track) override;
63 
64  MidiPlayer *_midiPlayer;
65  PlaybackStates _state;
67  int _songBranches[128];
68 
69  int _currentTrack;
70 
71  TrackState _trackState;
72 
74  TrackState *_savedTrackState;
75 
77  bool _combatMusicActive;
78 
79 public:
81  U8MusicProcess(MidiPlayer *player); // Note that this does NOT delete the driver
82  ~U8MusicProcess() override;
83 
84  ENABLE_RUNTIME_CLASSTYPE()
85 
86 
88  return _theMusicProcess;
89  }
90 
92  void playMusic(int track) override;
94  void playCombatMusic(int track) override;
96  void queueMusic(int track) override;
98  void unqueueMusic() override;
100  void restoreMusic() override;
101 
103  void fadeMusic(uint16 length) override;
105  bool isFading() override;
106 
108  void saveTrackState() override;
110  void restoreTrackState() override;
111 
113  void getTrackState(TrackState &trackState) const;
114 
115  void setTrackState(const TrackState &state);
116 
118  bool isPlaying() override;
119 
121  void pauseMusic() override;
123  void unpauseMusic() override;
124 
125  void run() override;
126 
127  bool loadData(Common::ReadStream *rs, uint32 version);
128  void saveData(Common::WriteStream *ws) override;
129 };
130 
131 } // End of namespace Ultima8
132 } // End of namespace Ultima
133 
134 #endif
void playCombatMusic(int track) override
Play some combat music - the last played track will be remembered.
void fadeMusic(uint16 length) override
Fades out the music over the specified time (in milliseconds)
int _queued
Track queued to start after current.
Definition: u8_music_process.h:52
static MusicProcess * get_instance()
Get the current instance of the Music Processes.
Definition: u8_music_process.h:87
Definition: stream.h:77
The saveable part of track state.
Definition: u8_music_process.h:46
void restoreTrackState() override
Bring back the track state from before it was put on hold.
void restoreMusic() override
Restore the last requested non-combat track (eg, at the end of combat)
void pauseMusic() override
Pause the currently playing track.
Definition: detection.h:27
void playMusic(int track) override
Play some background music. Does not change the current track if combat music is active. If another track is currently queued, just queues this track for play.
void getTrackState(TrackState &trackState) const
Get the state of tracks (wanted, requested, queued)
void queueMusic(int track) override
Queue a track to start once the current one finishes.
Definition: midi_player.h:32
Definition: u8_music_process.h:35
int _wanted
Track we want to play.
Definition: u8_music_process.h:48
int _lastRequest
Last requested track that was not a temporary (ie, combat) track.
Definition: u8_music_process.h:50
void unpauseMusic() override
Resume the current track after pausing.
void saveTrackState() override
Save the current track state - used when the menu is opened.
void unqueueMusic() override
Clear any queued track (does not affect currently playing track)
Definition: stream.h:385
Definition: music_process.h:36
bool isFading() override
Returns true if the music is currently fading.
bool isPlaying() override
Is a track currently playing?
Definition: debugger.h:37
void saveData(Common::WriteStream *ws) override
save Process data