-
Notifications
You must be signed in to change notification settings - Fork 5
/
mugensound.cpp
166 lines (140 loc) · 3.83 KB
/
mugensound.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include "mugensound.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <prism/sound.h>
#include <prism/file.h>
#include <prism/stlutil.h>
#include "osuhandler.h"
#include "gamelogic.h"
#include "config.h"
using namespace std;
static struct {
int mIsPlayingMusic;
int mIsPausedFlag;
} gDolmexicaMugenSoundData;
static void loadDolmexicaSoundHandler(void*) {
setProfilingSectionMarkerCurrentFunction();
gDolmexicaMugenSoundData.mIsPlayingMusic = 0;
gDolmexicaMugenSoundData.mIsPausedFlag = 0;
}
static void updatePauseFlag() {
if (!gDolmexicaMugenSoundData.mIsPausedFlag) return;
if (gDolmexicaMugenSoundData.mIsPausedFlag == 2) {
resumeMusic();
gDolmexicaMugenSoundData.mIsPausedFlag = 0;
}
else {
gDolmexicaMugenSoundData.mIsPausedFlag++;
}
}
static void updateDolmexicaSoundHandler(void*) {
setProfilingSectionMarkerCurrentFunction();
if (!gDolmexicaMugenSoundData.mIsPlayingMusic) return;
updatePauseFlag();
}
ActorBlueprint getDolmexicaSoundHandler()
{
return makeActorBlueprint(loadDolmexicaSoundHandler, NULL, updateDolmexicaSoundHandler);
}
DreamMugenSound makeDreamMugenSound(int tGroup, int tItem)
{
DreamMugenSound ret;
ret.mGroup = tGroup;
ret.mItem = tItem;
return ret;
}
void setNoMusicFlag()
{
pauseMusic();
gDolmexicaMugenSoundData.mIsPausedFlag = 1;
}
int isMugenBGMMusicPath(const char * tPath)
{
return isMugenBGMMusicPath(tPath, "");
}
int isMugenBGMMusicPath(const char* tPath, const char* tRootFilePath) {
if (!strchr(tPath, '.')) return 0;
const char* fileExtension = getFileExtension(tPath);
if (!strcmp("da", fileExtension)) return 1;
if (getGameMode() == GAME_MODE_OSU && !strcmp("osu", fileExtension)) return 1;
char inFolderPath[1024];
sprintf(inFolderPath, "%smusic/%s", getDolmexicaAssetFolder().c_str(), tPath);
if (isFile(inFolderPath)) return 1;
if (*tRootFilePath) {
string s;
const char* folderEnd = strrchr(tRootFilePath, '/');
if (folderEnd) {
s = string(tRootFilePath, size_t(folderEnd - tRootFilePath + 1));
}
sprintf(inFolderPath, "%s%s", s.data(), tPath);
if (isFile(inFolderPath)) return 1;
}
return isFile(tPath);
}
void playMugenBGMMusicPath(const char * tPath, int tIsLooping)
{
playMugenBGMMusicPath(tPath, "", tIsLooping);
}
static void playMugenBGMTrack(const char* tPath, int tIsLooping) {
char modPath[1024];
strcpy(modPath, tPath);
*strrchr(modPath, '.') = '\0';
int trackNumber = atoi(modPath);
if (tIsLooping) {
playTrack(trackNumber);
}
else {
playTrackOnce(trackNumber);
}
gDolmexicaMugenSoundData.mIsPlayingMusic = 1;
}
static void playMugenBGMMusicCompletePath(const char* tPath, int tIsLooping) {
if (tIsLooping) {
streamMusicFile(tPath);
}
else {
streamMusicFileOnce(tPath);
}
gDolmexicaMugenSoundData.mIsPlayingMusic = 1;
}
void playMugenBGMMusicPath(const char* tPath, const char* tRootFilePath, int tIsLooping) {
const char* fileExtension = getFileExtension(tPath);
if (!strcmp("osu", fileExtension)) {
if (*tRootFilePath)
{
std::string folder;
getPathToFile(folder, tRootFilePath);
const auto totalPath = folder + tPath;
if (isFile(totalPath)) {
setOsuFile(totalPath.c_str());
return;
}
}
setOsuFile(tPath);
return;
}
if (!strcmp("da", fileExtension)) {
playMugenBGMTrack(tPath, tIsLooping);
return;
}
char inFolderPath[1024];
sprintf(inFolderPath, "%smusic/%s", getDolmexicaAssetFolder().c_str(), tPath);
if (isFile(inFolderPath)) {
playMugenBGMMusicCompletePath(inFolderPath, tIsLooping);
return;
}
if (*tRootFilePath) {
string s;
const char* folderEnd = strrchr(tRootFilePath, '/');
if (folderEnd) {
s = string(tRootFilePath, size_t(folderEnd - tRootFilePath + 1));
}
sprintf(inFolderPath, "%s%s", s.data(), tPath);
if (isFile(inFolderPath)) {
playMugenBGMMusicCompletePath(inFolderPath, tIsLooping);
return;
}
}
playMugenBGMMusicCompletePath(tPath, tIsLooping);
}