Skip to content

Commit

Permalink
sound: Allow title music to be replaced
Browse files Browse the repository at this point in the history
As a demo, this includes an initial demonstration file that changes the
title music.
  • Loading branch information
fragglet committed Oct 16, 2024
1 parent d55dbf4 commit f7410f4
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ EXTRA_DIST = $(AUX_DIST_GEN) $(DOC_FILES) \
embuild.sh \
icon.png \
maps/README.md maps/original.sop maps/empty.sop \
maps/tank_strike.sop maps/triplane.sop
maps/tank_strike.sop maps/triplane.sop maps/bogey.sop

MAINTAINERCLEANFILES = $(AUX_DIST_GEN)

Expand Down
14 changes: 14 additions & 0 deletions maps/bogey.sop
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Example file that changes the title music to "Colonel Bogey":

sounds {
title_tune:
"<e4/c+4/r4/r4/r4/c+4/d4/e4/>c+4/r4/c+4/r4/a4/r4/r4/r4/"&
"<e4/c+4/r4/r4/r4/c+4/d4/c+4/e4/r4/e4/r4/d4/r4/r4/r4/"&
"d4/b4/r4/r4/r4/b4/c+4/d4/e4/c+4/r4/r4/r4/"&
"c+4/d+4/c+4/b4/e4/r4/c+4/d+4/b4/r4/f+4/e4/"&
"r8/f+8/e4/r8/f+8/e4/d4/c+4/b4/"&
"e4/c+4/r4/r4/r4/c+4/d4/e4/>c+4/r4/c+4/r4/a4/r4/r4/r4/"&
"<e4/c+4/r4/r4/r4/c+4/d4/c+4/e4/r4/e4/r4/d4/r4/r4/r4/"&
"d4/b4/r4/r4/r4/f+4/g+4/f+4/>a4/<e4/r4/r4/r4/"&
"e4/d4/c+4/b4/f+4/r4/a4/<g+4/>e4/r4/e4/a4/r2/"
}
18 changes: 18 additions & 0 deletions src/swgames.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "sw.h"
#include "swgames.h"
#include "swsound.h"
#include "video.h"
#include "yocton.h"

Expand Down Expand Up @@ -362,6 +363,20 @@ static void process_symbol(const char *name, struct yocton_object *obj)
}
}

static void process_sounds(struct yocton_object *obj)
{
struct yocton_prop *p;
char *title_tune = NULL;

while ((p = yocton_next_prop(obj)) != NULL) {
YOCTON_VAR_STRING(p, "title_tune", title_tune);
}

if (title_tune != NULL) {
expltune = title_tune;
}
}

static void process_symbols(struct yocton_object *obj)
{
struct yocton_prop *p;
Expand Down Expand Up @@ -405,6 +420,9 @@ void load_custom_level(const char *filename)
if (!strcmp(name, "symbols")) {
process_symbols(yocton_prop_inner(p));
}
if (!strcmp(name, "sounds")) {
process_sounds(yocton_prop_inner(p));
}
}

if (yocton_have_error(obj, &lineno, &error_msg)) {
Expand Down
2 changes: 1 addition & 1 deletion src/swsound.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static int exploctv; /* Octave */

//#define SOPWITH1_TUNE

static char *expltune =
char *expltune =
#ifdef SOPWITH1_TUNE
">e4./d8/c4/d4/e4/d+4/e4/c4/d4/d4/d4/d1/"
"d4./c8/b4/c4/d4/c+4/d4/b4/c4/c4/c4/c1/<g4./g+8/"
Expand Down
5 changes: 4 additions & 1 deletion src/swsound.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ extern void sound(int type, int parm, OBJECTS *ob);
extern void swsound(void);
extern void initsound(OBJECTS *obp, int type);
extern void stopsound(OBJECTS *ob);
extern void swsndupdate(void);

extern OBJECTS *ob;
extern unsigned freq;
extern unsigned modulo;
extern void swsndupdate(void);
extern char *expltune;


#endif

0 comments on commit f7410f4

Please sign in to comment.