Skip to content

Commit 463a6d1

Browse files
committed
feat(zscript): music seeking functions for ogg and mp3
1 parent 728d3ce commit 463a6d1

File tree

5 files changed

+30
-52
lines changed

5 files changed

+30
-52
lines changed

resources/docs/ZScript_Additions.txt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7768,18 +7768,17 @@ rgb ConvertRGBFrom(float[] buf, int color_space)
77687768
/// Audio-> ///
77697769
///////////////// // Audio
77707770

7771-
bool PlayOgg(int filename[], int track);
7772-
* Similar to PlayEnhancedMusic(), but only for OGG files.
7773-
* Supports seeking, and other special instructions.
7771+
int GetMusicPos();
7772+
* Returns the current seek position of the currently playing enhanced music in seconds.
7773+
* CURRENTLY ONLY SUPPORTS MP3
77747774

7775-
int GetOggPos();
7776-
* Returns the current seek position of an OGG started with PlayOgg, in ms.
7777-
7778-
void SetOggPos(int new_pos);
7779-
* Sets the play position for an OGG started with PlayOgg(), in ms.
7775+
void SetMusicPos(int new_pos);
7776+
* Sets the play position for the currently playing enhanced music in seconds.
7777+
* CURRENTLY ONLY SUPPORTS MP3
77807778

7781-
void SetOggSpeed(int newspeed);
7782-
* Sets the playback speed of an OGG started with PlayOgg();
7779+
void SetMusicSpeed(int newspeed);
7780+
* Sets the playback speed of the currently playing enhanced music.
7781+
* CURRENTLY ONLY SUPPORTS MP3
77837782

77847783

77857784
void PlaySound(int soundid); ZASM Instruction:

src/parser/symbols/AudioSymbols.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ static AccessorTable AudioTable[] =
2222
//Undocumented intentionally
2323
{ "AdjustSound", 0, ZTID_VOID, -1, FL_DEPR, { ZTID_AUDIO, ZTID_FLOAT, ZTID_FLOAT, ZTID_BOOL },{} },
2424
{ "PlayOgg", 0, ZTID_BOOL, -1, FL_DEPR, { ZTID_AUDIO, ZTID_FLOAT, ZTID_FLOAT },{} },
25-
{ "GetOggPos", 0, ZTID_FLOAT, -1, FL_DEPR, { ZTID_AUDIO },{} },
26-
{ "SetOggPos", 0, ZTID_VOID, -1, FL_DEPR, { ZTID_AUDIO, ZTID_FLOAT },{} },
27-
{ "SetOggSpeed", 0, ZTID_VOID, -1, FL_DEPR, { ZTID_AUDIO, ZTID_FLOAT },{} },
25+
{ "GetMusicPos", 0, ZTID_FLOAT, -1, FL_DEPR, { ZTID_AUDIO },{} },
26+
{ "SetMusicPos", 0, ZTID_VOID, -1, FL_DEPR, { ZTID_AUDIO, ZTID_FLOAT },{} },
27+
{ "SetMusicSpeed", 0, ZTID_VOID, -1, FL_DEPR, { ZTID_AUDIO, ZTID_FLOAT },{} },
2828
{ "getVolume[]", 0, ZTID_FLOAT, AUDIOVOLUME, FL_DEPR, { ZTID_AUDIO, ZTID_FLOAT },{} },
2929
{ "setVolume[]", 0, ZTID_VOID, AUDIOVOLUME, FL_DEPR, { ZTID_AUDIO, ZTID_FLOAT, ZTID_FLOAT },{} },
3030

@@ -230,7 +230,7 @@ void AudioSymbols::generateCode()
230230
}
231231
//int32_t GetEnhancedMusicPos(game)
232232
{
233-
Function* function = getFunction("GetOggPos");
233+
Function* function = getFunction("GetMusicPos");
234234
int32_t label = function->getLabel();
235235
vector<shared_ptr<Opcode>> code;
236236
//pop pointer, and ignore it
@@ -242,7 +242,7 @@ void AudioSymbols::generateCode()
242242
}
243243
//void SetEnhancedMusicPos(game, int32_t)
244244
{
245-
Function* function = getFunction("SetOggPos");
245+
Function* function = getFunction("SetMusicPos");
246246
int32_t label = function->getLabel();
247247
vector<shared_ptr<Opcode>> code;
248248
//pop off the params
@@ -256,7 +256,7 @@ void AudioSymbols::generateCode()
256256
}
257257
//void SetEnhancedMusicSpeed(game, int32_t)
258258
{
259-
Function* function = getFunction("SetOggSpeed");
259+
Function* function = getFunction("SetMusicSpeed");
260260
int32_t label = function->getLabel();
261261
vector<shared_ptr<Opcode>> code;
262262
//pop off the params

src/zc/ffscript.cpp

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29523,43 +29523,23 @@ void do_enh_music(bool v)
2952329523
}
2952429524
}
2952529525

29526-
void FFScript::do_playogg_ex(const bool v)
29526+
void FFScript::do_set_music_position(const bool v)
2952729527
{
29528-
int32_t arrayptr = SH::get_arg(sarg1, v) / 10000;
29529-
int32_t track = (SH::get_arg(sarg2, v) / 10000)-1;
29530-
29531-
if(arrayptr == 0)
29532-
music_stop();
29533-
else // Pointer to a string..
29534-
{
29535-
string filename_str;
29536-
char filename_char[256];
29537-
bool ret;
29538-
ArrayH::getString(arrayptr, filename_str, 256);
29539-
strncpy(filename_char, filename_str.c_str(), 255);
29540-
filename_char[255]='\0';
29541-
ret=try_zcmusic_ex(filename_char, track, -1000);
29542-
set_register(sarg2, ret ? 10000 : 0);
29543-
}
29544-
}
29545-
29546-
void FFScript::do_set_oggex_position(const bool v)
29547-
{
29548-
int32_t newposition = SH::get_arg(sarg1, v) / 10;
29528+
int32_t newposition = SH::get_arg(sarg1, v);
2954929529

2955029530
set_zcmusicpos(newposition);
2955129531
}
2955229532

29553-
void FFScript::go_get_oggex_position()
29533+
void FFScript::do_get_music_position()
2955429534
{
29555-
int32_t pos = get_zcmusicpos()*10;
29535+
int32_t pos = get_zcmusicpos();
2955629536
// zprint("ZC OGG Position is %d\n", pos);
2955729537
set_register(sarg1, pos);
2955829538
}
2955929539

29560-
void FFScript::do_set_oggex_speed(const bool v)
29540+
void FFScript::do_set_music_speed(const bool v)
2956129541
{
29562-
int32_t newspeed = SH::get_arg(sarg1, v) / 10;
29542+
int32_t newspeed = SH::get_arg(sarg1, v);
2956329543

2956429544
set_zcmusicspeed(newspeed);
2956529545
}
@@ -34258,19 +34238,20 @@ int32_t run_script_int(bool is_jitted)
3425834238
}
3425934239

3426034240
case PLAYENHMUSICEX:
34261-
FFCore.do_playogg_ex(false);
34241+
// DEPRECATED
34242+
do_enh_music(false);
3426234243
break;
3426334244

3426434245
case GETENHMUSICPOS:
34265-
FFCore.go_get_oggex_position();
34246+
FFCore.do_get_music_position();
3426634247
break;
3426734248

3426834249
case SETENHMUSICPOS:
34269-
FFCore.do_set_oggex_position(false);
34250+
FFCore.do_set_music_position(false);
3427034251
break;
3427134252

3427234253
case SETENHMUSICSPEED:
34273-
FFCore.do_set_oggex_speed(false);
34254+
FFCore.do_set_music_speed(false);
3427434255
break;
3427534256

3427634257
case DIREXISTS:

src/zc/ffscript.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,10 +1209,9 @@ void do_isvalidbitmap();
12091209
void do_isallocatedbitmap();
12101210

12111211
//OGG Ex --dimi
1212-
void do_playogg_ex(const bool v);
1213-
void do_set_oggex_position(const bool v);
1214-
void go_get_oggex_position();
1215-
void do_set_oggex_speed(const bool v);
1212+
void do_set_music_position(const bool v);
1213+
void do_get_music_position();
1214+
void do_set_music_speed(const bool v);
12161215

12171216
BITMAP* GetScriptBitmap(int32_t id, bool skipError = false);
12181217

src/zc/zc_sys.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8157,8 +8157,7 @@ void set_zcmusicpos(int32_t position)
81578157

81588158
void set_zcmusicspeed(int32_t speed)
81598159
{
8160-
int32_t newspeed = vbound(speed, 0, 10000);
8161-
zcmusic_set_speed(zcmusic, newspeed);
8160+
zcmusic_set_speed(zcmusic, speed);
81628161
}
81638162

81648163
void jukebox(int32_t index,int32_t loop)

0 commit comments

Comments
 (0)