Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
bgm_control.c
Go to the documentation of this file.
1#include "common.h"
2#include "npc.h"
3#include "audio.h"
4
5void bgm_update_volume(void);
6void bgm_set_target_volume(s32 volume);
7
12
14
16 .flags = 0,
17 .state = MUSIC_STATE_IDLE,
18 .fadeOutTime = -1,
19 .fadeInTime = 0,
20 .fadeStartVolume = 0,
21 .fadeEndVolume = 0,
22 .requestedSongID = AU_SONG_NONE,
23 .variation = -1,
24 .songName = -1,
25 .battleSongID = 0,
26 .battleVariation = 0,
27 .savedSongID = 0,
28 .savedVariation = 0,
29 .savedSongName = 0
30};
31
42
44
51 u32 i;
52
53 for (i = 0; i < ARRAY_COUNT(SongsUsingVariationFlag); i++) {
54 if (SongsUsingVariationFlag[i] == songID) {
56
57 return map->songVariation & 1;
58 }
59 }
60
61 return -1;
62}
63
76
81
82//TODO refactor out constants
85 s32 i = 0;
88 s32 flags;
89
90 for (i; i < ARRAY_COUNT(gMusicControlData); i++, music++) {
91 switch (music->state) {
93 break;
95 if (music->flags & MUSIC_FLAG_PLAYING) {
96 if (music->fadeOutTime < 250) {
97 if (!(music->flags & MUSIC_FLAG_PUSHING)) {
98 if (snd_song_stop(music->songName) == AU_RESULT_OK) {
100 }
101 } else {
102 if (snd_song_push_stop(music->songName) == AU_RESULT_OK) {
103 music->state = stateFadeOut;
104 }
105 }
106 } else if (!(music->flags & MUSIC_FLAG_PUSHING)) {
107 if (snd_song_request_fade_out(music->songName, music->fadeOutTime, NULL) == AU_RESULT_OK) {
108 music->state = stateFadeOut;
109 }
110 } else {
111 if (snd_song_request_push_fade_out(music->songName, 250) == AU_RESULT_OK) {
112 music->state = stateFadeOut;
113 }
114 }
115 } else {
116 if (music->flags & MUSIC_FLAG_PUSHING) {
117 // nothing was playing in this case, so remember to skip the next pop
119 }
120 music->flags &= ~pushedFlag;
122 }
123 break;
125 flags = music->flags;
126 music->flags &= ~pushedFlag;
128 if (snd_song_is_playing(music->songName) == AU_RESULT_OK) {
129 music->flags &= ~MUSIC_FLAG_PLAYING;
130 music->state = MUSIC_STATE_DELAY_2;
131 }
132 } else {
134 }
135 break;
137 music->state = MUSIC_STATE_DELAY_1;
138 break;
141 break;
143 if (!(music->flags & MUSIC_FLAG_POPPING)) {
144 if (music->requestedSongID <= AU_SONG_NONE) {
145 // new song is AU_SONG_NONE, play nothing
146 music->state = MUSIC_STATE_IDLE;
147 } else {
148 music->songName = snd_song_load(music->requestedSongID, i);
149 // snd_song_lond may return either songName or an AuResult error code.
150 // since song names are 4-character big-endian identifiers packed into an s32, we require
151 // the upper half of the return value to be nonzero for songs which loaded without error.
152 // this reserves return values from 0 to 0xFFFF for AuResult codes.
153 if (music->songName > 0xFFFFU) {
154 if ((music->flags & MUSIC_FLAG_FADE_IN_NEXT)) {
155 snd_song_request_fade_in(music->songName, music->variation,
156 music->fadeInTime, music->fadeStartVolume, music->fadeEndVolume);
158 } else {
159 // if we aren't fading in, just start at the default volume level
161 }
163 if (snd_song_request_play(music->songName, music->variation) == AU_RESULT_OK) {
164 music->flags |= MUSIC_FLAG_PLAYING;
165 music->state = MUSIC_STATE_IDLE;
166 }
167 }
168 }
169 } else {
170 if (music->flags & MUSIC_FLAG_IGNORE_POP) {
171 music->state = MUSIC_STATE_IDLE;
173 } else if (snd_song_request_pop(music->savedSongName) == AU_RESULT_OK) {
174 music->requestedSongID = music->savedSongID;
175 music->variation = music->savedVariation;
176 music->songName = music->savedSongName;
177 music->state = MUSIC_STATE_IDLE;
178 music->flags |= MUSIC_FLAG_PLAYING;
179 music->flags &= ~MUSIC_FLAG_POPPING;
180 }
181 }
182 break;
183 }
184 }
186}
187
188s32 _bgm_set_song(s32 playerIndex, s32 songID, s32 variation, s32 fadeOutTime, s16 volume) {
191
193 return 1;
194 }
195
196 music = &gMusicControlData[playerIndex];
197
199 snd_song_stop(music->songName);
200 music->flags &= ~MUSIC_FLAG_PLAYING;
201 return 1;
202 }
203
205 if (mapSongVariation >= 0) {
206 variation = mapSongVariation;
207 }
208
209 if (music->requestedSongID == songID && music->variation == variation) {
210 bgm_set_target_volume(volume);
211
212 if (music->flags & MUSIC_FLAG_PUSHING) {
214 music->flags &= ~MUSIC_FLAG_PUSHING;
215 }
216
217 return 2;
218 }
219
220 MusicDefaultVolume = volume;
221 music->requestedSongID = songID;
222 music->variation = variation;
223 music->fadeOutTime = fadeOutTime;
226
227 return 1;
228}
229
230s32 bgm_set_song(s32 playerIndex, s32 songID, s32 variation, s32 fadeOutTime, s16 volume) {
232
233 return _bgm_set_song(playerIndex, songID, variation, fadeOutTime, volume);
234}
235
236b32 bgm_fade_in_song(s32 playerIndex, s32 songID, s32 variation, s32 fadeInTime, s16 fadeStartVolume, s16 fadeEndVolume) {
239
241 return TRUE;
242 }
243
244 music = &gMusicControlData[playerIndex];
245
247 snd_song_stop(music->songName);
248 music->flags &= ~MUSIC_FLAG_PLAYING;
249 return TRUE;
250 }
251
253 if (mapSongVariation >= 0) {
254 variation = mapSongVariation;
255 }
256
257 music->fadeInTime = fadeInTime;
258 music->fadeStartVolume = fadeStartVolume;
259 music->fadeEndVolume = fadeEndVolume;
260 music->requestedSongID = songID;
261 music->variation = variation;
265
266 return TRUE;
267}
268
269s32 bgm_adjust_proximity(s32 playerIndex, s32 mix, s16 state) {
271
272 if (!(music->flags & MUSIC_FLAG_PLAYING)) {
273 return FALSE;
274 }
275
276 if (!(music->flags & MUSIC_FLAG_ENABLE_PROX_MIX)) {
277 return FALSE;
278 }
279
280 switch (state) {
283 break;
286 break;
289 break;
290 }
291 return TRUE;
292}
293
296
297 if (!(music->flags & MUSIC_FLAG_PLAYING)) {
298 return AU_RESULT_OK;
299 }
300
302}
303
306
307 if (!(music->flags & MUSIC_FLAG_PLAYING)) {
308 return AU_RESULT_OK;
309 }
310
312}
313
316
317 if (!(music->flags & MUSIC_FLAG_PLAYING)) {
318 return AU_RESULT_OK;
319 }
320
321 return snd_song_set_linked_mode(music->songName, mode);
322}
323
327
328 return 1;
329}
330
334
338
340 MusicTargetVolume = volume;
341}
342
345
346 if (NextVolumeUpdateTimer != 0) {
348 return;
349 }
350
352 if (toVolume > MusicMaxVolume) {
354 }
355
359 } else {
361 }
364 }
365}
366
369 s32 i;
370
371 for (i = 0; i < ARRAY_COUNT(gMusicControlData); i++, music++) {
372 if (music->flags & MUSIC_FLAG_PLAYING) {
373 if (snd_song_is_playing(music->songName)) {
374 return TRUE;
375 }
376 }
377 }
378 return FALSE;
379}
380
381void bgm_pop_song(void) {
383
386 _bgm_set_song(0, music->savedSongID, music->savedVariation, 0, VOL_LEVEL_FULL);
387 }
388}
389
390void bgm_push_song(s32 songID, s32 variation) {
392
394 music->savedSongID = music->requestedSongID;
395 music->savedVariation = music->variation;
396 music->savedSongName = music->songName;
397 music->flags |= MUSIC_FLAG_PUSHING;
398 bgm_set_song(0, songID, variation, 500, VOL_LEVEL_FULL);
399 }
400}
401
415
418
421 snd_ambient_pause(0, 250);
422 music->savedSongID = music->requestedSongID;
423 music->savedVariation = music->variation;
424 music->savedSongName = music->songName;
425 music->flags |= MUSIC_FLAG_PUSHING;
426 bgm_set_song(0, music->battleSongID, music->battleVariation, 500, VOL_LEVEL_FULL);
427 }
428 }
429}
430
431void bgm_set_battle_song(s32 songID, s32 variation) {
433
434 music->battleSongID = songID;
435 music->battleVariation = variation;
436}
437
438void bgm_NOOP(void) {
439}
BSS s32 PopupMenu_SelectedIndex
@ MUSIC_STATE_PLAY_NEXT
Definition audio.h:179
@ MUSIC_STATE_IDLE
Definition audio.h:174
@ MUSIC_STATE_STOP_CURRENT
Definition audio.h:175
@ MUSIC_STATE_AWAIT_FADEOUT
Definition audio.h:176
@ MUSIC_STATE_DELAY_2
Definition audio.h:177
@ MUSIC_STATE_DELAY_1
Definition audio.h:178
#define AU_SONG_NONE
Definition audio.h:105
@ MUSIC_FLAG_PUSHING
Definition audio.h:185
@ MUSIC_FLAG_PLAYING
Definition audio.h:183
@ MUSIC_FLAG_POPPING
Definition audio.h:186
@ MUSIC_FLAG_FADE_IN_NEXT
Definition audio.h:188
@ MUSIC_FLAG_IGNORE_POP
Definition audio.h:187
@ MUSIC_FLAG_ENABLE_PROX_MIX
Definition audio.h:184
s32 _bgm_set_song(s32 playerIndex, s32 songID, s32 variation, s32 fadeOutTime, s16 volume)
void bgm_pop_song(void)
void bgm_quiet_max_volume(void)
s32 bgm_set_song(s32 playerIndex, s32 songID, s32 variation, s32 fadeOutTime, s16 volume)
s32 SongsUsingVariationFlag[]
Lists the songs that are forced to use the variation determined by map.songVariation & 1.
Definition bgm_control.c:34
void bgm_reset_max_volume(void)
s16 NextVolumeUpdateTimer
Definition bgm_control.c:43
MusicControlData gMusicControlData[2]
Definition bgm_control.c:13
void bgm_update_volume(void)
BSS s16 MusicMaxVolume
Definition bgm_control.c:10
MusicControlData BlankMusicControlData
Definition bgm_control.c:15
void bgm_update_music_control(void)
Definition bgm_control.c:83
AuResult bgm_set_linked_mode(s32 playerIndex, b16 mode)
void bgm_reset_volume(void)
Definition bgm_control.c:77
void bgm_pop_battle_song(void)
b32 bgm_is_any_song_playing(void)
s32 bgm_init_music_players(void)
BSS s16 MusicCurrentVolume
Definition bgm_control.c:11
AuResult bgm_clear_track_volumes(s32 playerIndex, s16 trackVolSet)
s32 bgm_adjust_proximity(s32 playerIndex, s32 mix, s16 state)
void bgm_set_battle_song(s32 songID, s32 variation)
AuResult bgm_set_track_volumes(s32 playerIndex, s16 trackVolSet)
b32 bgm_fade_in_song(s32 playerIndex, s32 songID, s32 variation, s32 fadeInTime, s16 fadeStartVolume, s16 fadeEndVolume)
void bgm_reset_sequence_players(void)
Definition bgm_control.c:64
void bgm_set_target_volume(s32 volume)
BSS s16 MusicDefaultVolume
Definition bgm_control.c:8
void bgm_NOOP(void)
void bgm_push_song(s32 songID, s32 variation)
void bgm_push_battle_song(void)
BSS s16 MusicTargetVolume
Definition bgm_control.c:9
s32 bgm_get_map_default_variation(s32 songID)
If the given song ID is present in SongsUsingVariationFlag, returns the current map's songVariation &...
Definition bgm_control.c:50
s32 battleSongID
name or handle of currently playing song
s32 b32
s16 b16
s8 flags
Definition demo_api.c:15
@ SONG_NEW_PARTNER
Definition enums.h:412
@ SONG_TUBBA_BLUBBA_BATTLE
Definition enums.h:293
@ SONG_YOSHI_KIDS_FOUND
Definition enums.h:360
@ SONG_SPECIAL_BATTLE
Definition enums.h:285
@ SONG_JR_TROOPA_BATTLE
Definition enums.h:286
@ SONG_ITEM_UPGRADE
Definition enums.h:348
@ VOL_LEVEL_FULL
Definition enums.h:1822
@ VOL_LEVEL_4
Definition enums.h:1818
AuResult
Definition enums.h:1758
@ AU_RESULT_OK
Definition enums.h:1759
@ DEMO_STATE_NONE
Definition enums.h:3568
@ GLOBAL_OVERRIDES_DONT_RESUME_SONG_AFTER_BATTLE
Definition enums.h:3921
@ MUSIC_PROXIMITY_NEAR
Definition enums.h:1789
@ MUSIC_PROXIMITY_FULL
Definition enums.h:1790
@ MUSIC_PROXIMITY_FAR
Definition enums.h:1788
AuResult snd_song_set_track_volumes(s32 songName, MusicTrackVols arg1)
void snd_song_set_proximity_mix_far(s32 songName, s32 mix)
AuResult snd_song_clear_track_volumes(s32 songName, MusicTrackVols arg1)
void snd_song_set_proximity_mix_near(s32 songName, s32 mix)
void snd_song_set_proximity_mix_full(s32 songName, s32 mix)
AuResult snd_song_push_stop(s32 songName)
AuResult snd_song_request_fade_out(s32 songName, s32 fadeTime, AuCallback callback)
AuResult snd_ambient_pause(s32 arg0, s32 arg1)
AuResult snd_song_request_play(s32 songName, s32 variation)
Called from bgm_control to start playing a particular song + variation.
AuResult snd_song_request_push_fade_out(s32 songName, s32 fadeTime)
void snd_set_bgm_volume(VolumeLevels volume)
AuResult snd_song_load(s32 songID, s32 playerIndex)
return value may be either an AuResult error code OR a valid songName
AuResult snd_song_request_pop(s32 songName)
AuResult snd_song_request_fade_in(s32 songName, s32 variation, s32 fadeInTime, s32 startVolume, s32 endVolume)
Called from bgm_control to fade in a particular song + variation.
AuResult snd_song_request_snapshot(s32 songName)
AuResult snd_ambient_resume(s32 arg0, s32 arg1)
AuResult snd_song_is_playing(s32 songName)
AuResult snd_song_stop(s32 songName)
AuResult snd_song_set_linked_mode(s32 songName, b32 mode)
#define BSS
Definition macros.h:7
#define ARRAY_COUNT(arr)
Definition macros.h:40
s8 songVariation
0 or 1.
Definition map.h:50
AreaConfig gAreas[29]
Zero-terminated.
Definition world.c:868
MapConfig * maps
Definition map.h:56
s32 gOverrideFlags
Definition main_loop.c:10
GameStatus * gGameStatusPtr
Definition main_loop.c:31