forked from philstopford/CCX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
music.cpp
executable file
·151 lines (139 loc) · 2.8 KB
/
music.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include <string.h>
#include "main.h"
#include "music.h"
#include "gworld.h"
#include "gameticks.h"
#include "soundfx.h"
#include "graphics.h"
#include "resources.h"
const int kNoMusic = -1;
MBoolean musicOn = true, musicFast = false;
int musicLevel = 0, musicSelection = kNoMusic;
// UseSDLMixer now defined in configurations for XCode
// #define UseSDLMixer
#ifdef UseSDLMixer
// SDL Mixer
#include "SDL.h"
#include "SDL_mixer.h"
Mix_Music *musicModule;
#else
#include "fmod.h"
#include "fmod_errors.h"
FMUSIC_MODULE *musicModule = NULL;
#endif
void EnableMusic( MBoolean on )
{
musicOn = on;
#ifdef UseSDLMixer
Mix_VolumeMusic(musicOn? 128: 0);
#else
FMUSIC_SetMasterVolume( musicModule, musicOn? 192: 0 );
#endif
}
void FastMusic( void )
{
if( musicModule && !musicFast )
{
#ifdef UseSDLMixer
// SDL has no implementation for this, it seems
musicFast = true;
#else
// FMod
if( musicModule && !musicFast )
{
FMUSIC_SetMasterSpeed( musicModule, 1.3f );
musicFast = true;
}
#endif
}
}
void SlowMusic( void )
{
if( musicModule && musicFast )
{
#ifdef UseSDLMixer
// SDL has no implementation for this.
musicFast = false;
#else
// FMod
if( musicModule && musicFast )
{
FMUSIC_SetMasterSpeed( musicModule, 1.0f );
musicFast = false;
}
#endif
}
}
void PauseMusic( void )
{
if( musicSelection >= 0 && musicSelection <= kSongs )
{
#ifdef UseSDLMixer
Mix_PauseMusic();
musicLevel++;
#else
if( musicSelection >= 0 && musicSelection <= kSongs )
{
FMUSIC_SetPaused( musicModule, true );
musicLevel++;
}
#endif
}
}
void ResumeMusic( void )
{
if( musicSelection >= 0 && musicSelection <= kSongs )
{
#ifdef UseSDLMixer
musicLevel--;
Mix_ResumeMusic();
#else
if( musicSelection >= 0 && musicSelection <= kSongs )
{
musicLevel--;
FMUSIC_SetPaused( musicModule, false );
}
#endif
}
}
void ChooseMusic( short which )
{
if( musicSelection >= 0 && musicSelection <= kSongs )
{
#ifdef UseSDLMixer
Mix_HaltMusic();
Mix_FreeMusic(musicModule);
#else
// FMod
FMUSIC_StopSong( musicModule );
FMUSIC_FreeSong( musicModule );
#endif
musicModule = NULL;
}
if( which >= 0 && which <= kSongs )
{
#ifdef UseSDLMixer
musicModule = Mix_LoadMUS( QuickResourceName( "mod", which+128, "" ) );
if (musicModule != NULL)
{
Mix_VolumeMusic(musicOn? 128: 0);
if(Mix_PlayMusic(musicModule, -1)==-1) {
printf("Mix_PlayMusic: %s\n", Mix_GetError());
}
musicSelection = which;
musicLevel = 0;
}
#else
// FMod
musicModule = FMUSIC_LoadSong( QuickResourceName( "mod", which+128, "" ) );
if( musicModule != NULL )
{
FMUSIC_SetMasterVolume( musicModule, musicOn? 192: 0 );
FMUSIC_SetLooping( musicModule, true );
FMUSIC_PlaySong( musicModule );
musicSelection = which;
musicLevel = 0;
}
#endif
}
}