Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom file playback to playef() #902

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions desktop_version/src/Music.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class SoundTrack
format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign;
format.cbSize = 0;
valid = true;
name = std::string(SDL_strrchr(fileName, '/') + 1);
end:
VVV_free(mem);
}
Expand Down Expand Up @@ -170,6 +171,7 @@ class SoundTrack

ogg_file = mem;
valid = true;
name = std::string(SDL_strrchr(fileName, '/') + 1);
}

void Dispose(void)
Expand Down Expand Up @@ -364,6 +366,8 @@ class SoundTrack
static FAudioSourceVoice** voices;
static FAudioWaveFormatEx voice_formats[VVV_MAX_CHANNELS];
static float volume;

std::string name;
};
FAudioSourceVoice** SoundTrack::voices = NULL;
FAudioWaveFormatEx SoundTrack::voice_formats[VVV_MAX_CHANNELS];
Expand Down Expand Up @@ -744,6 +748,8 @@ musicclass::musicclass(void)
quick_fade = true;

usingmmmmmm = false;

stockSoundTracks = 0;
}

void musicclass::init(void)
Expand Down Expand Up @@ -789,6 +795,31 @@ void musicclass::init(void)
soundTracks.push_back(SoundTrack( "sounds/newrecord.wav" ));
soundTracks.push_back(SoundTrack( "sounds/trophy.wav" ));
soundTracks.push_back(SoundTrack( "sounds/rescue.wav" ));

stockSoundTracks = soundTracks.size();

//Here's where we find all the custom sounds in a level's assets folder
EnumHandle handle = {};
const char* item;
while ((item = FILESYSTEM_enumerateAssets("sounds/", &handle)) != NULL)
{
const std::string str_item = item;
bool match;
for (int j = 0; j < soundTracks.size(); j++)
{
match = (str_item == soundTracks[j].name);
if (match)
{
break;
}
}
if (!match)
{
soundTracks.push_back(SoundTrack( ("sounds/" + str_item).c_str() ));
}
}
FILESYSTEM_freeEnumerate(&handle);


#ifdef VVV_COMPILEMUSIC
binaryBlob musicWriteBlob;
Expand Down Expand Up @@ -1297,6 +1328,20 @@ void musicclass::playef(int t)
soundTracks[t].Play();
}

void musicclass::playef_name(std::string& t)
{
for (int i = 0; i < soundTracks.size(); i++)
{
size_t lastindex = soundTracks[i].name.find_last_of('.');
std::string rawname = soundTracks[i].name.substr(0, lastindex);
if (t == rawname)
{
soundTracks[i].Play();
return;
}
}
}

void musicclass::pauseef(void)
{
SoundTrack::Pause();
Expand Down
4 changes: 4 additions & 0 deletions desktop_version/src/Music.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define MUSIC_H

#include "BinaryBlob.h"
#include <string>

#define musicroom(rx, ry) ((rx) + ((ry) * 20))

Expand Down Expand Up @@ -92,6 +93,7 @@ class musicclass
int haltedsong;

void playef(int t);
void playef_name(std::string& t);
void pauseef(void);
void resumeef(void);

Expand All @@ -117,6 +119,8 @@ class musicclass
bool mmmmmm;
bool usingmmmmmm;

int stockSoundTracks;

binaryBlob pppppp_blob;
binaryBlob mmmmmm_blob;
int num_pppppp_tracks;
Expand Down
9 changes: 8 additions & 1 deletion desktop_version/src/Script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,14 @@ void scriptclass::run(void)
}
if (words[0] == "playef")
{
music.playef(ss_toi(words[1]));
if (is_number(words[1].c_str()) && ss_toi(words[1]) >= 0 && ss_toi(words[1]) < music.stockSoundTracks)
{
music.playef(ss_toi(words[1]));
}
else
{
music.playef_name(raw_words[1]);
}
}
if (words[0] == "play")
{
Expand Down