some macsound instrument play refinements

Also some better core placement of some of the Hero_playnotes calls.
This commit is contained in:
nhmall
2023-01-24 13:02:29 -05:00
parent 09fa9a865d
commit 5171fcdc1d
7 changed files with 81 additions and 70 deletions

View File

@@ -67,9 +67,6 @@
enum soundlib_ids {
soundlib_nosound,
#ifdef SND_LIB_QTSOUND
soundlib_qtsound,
#endif
#ifdef SND_LIB_PORTAUDIO
soundlib_portaudio,
#endif
@@ -95,8 +92,12 @@ enum soundlib_ids {
soundlib_windsound,
#endif
#ifdef SND_LIB_MACSOUND
soundlib_macsound
soundlib_macsound,
#endif
#ifdef SND_LIB_QTSOUND
soundlib_qtsound,
#endif
soundlib_notused
};
struct sound_procs {

View File

@@ -159,7 +159,7 @@ static void macsound_hero_playnotes(int32_t instrument,
const char *str, int32_t vol UNUSED)
{
#ifdef WAVEMUSIC_SOUNDS
uint32_t pseudo_seid;
uint32_t pseudo_seid, pseudo_seid_base;
boolean has_note_variations = FALSE;
char resourcename[120], *end_of_res = 0;
const char *c = 0;
@@ -170,91 +170,88 @@ static void macsound_hero_playnotes(int32_t instrument,
switch(instrument) {
case ins_tinkle_bell:
Strcpy(resourcename, "sound_Bell");
pseudo_seid = 0;
pseudo_seid_base = 0;
break;
case ins_taiko_drum: /* DRUM_OF_EARTHQUAKE */
Strcpy(resourcename, "sound_Drum_Of_Earthquake");
pseudo_seid = 1;
pseudo_seid_base = 1;
break;
case ins_baritone_sax: /* FIRE_HORN */
Strcpy(resourcename, "sound_Fire_Horn");
pseudo_seid = 2;
pseudo_seid_base = 2;
break;
case ins_french_horn: /* FROST_HORN */
Strcpy(resourcename, "sound_Frost_Horn");
pseudo_seid = 3;
pseudo_seid_base = 3;
break;
case ins_melodic_tom: /* LEATHER_DRUM */
Strcpy(resourcename, "sound_Leather_Drum");
pseudo_seid = 4;
pseudo_seid_base = 4;
break;
case ins_trumpet: /* BUGLE */
Strcpy(resourcename, "sound_Bugle");
has_note_variations = TRUE;
pseudo_seid = 5;
pseudo_seid_base = 5;
break;
case ins_cello: /* MAGIC_HARP */
Strcpy(resourcename, "sound_Magic_Harp");
has_note_variations = TRUE;
pseudo_seid = 12;
pseudo_seid_base = 12;
case ins_english_horn: /* TOOLED_HORN */
Strcpy(resourcename, "sound_Tooled_Horn");
has_note_variations = TRUE;
pseudo_seid = 19;
pseudo_seid_base = 19;
break;
case ins_flute: /* WOODEN_FLUTE */
Strcpy(resourcename, "sound_Wooden_Flute");
has_note_variations = TRUE;
pseudo_seid = 26;
pseudo_seid_base = 26;
break;
case ins_orchestral_harp: /* WOODEN_HARP */
Strcpy(resourcename, "sound_Wooden_Harp");
has_note_variations = TRUE;
pseudo_seid = 33;
pseudo_seid_base = 33;
break;
case ins_pan_flute: /* MAGIC_FLUTE */
/* wav files for sound_Magic_Flute not added yet */
Strcpy(resourcename, "sound_Wooden_Flute");
has_note_variations = TRUE;
pseudo_seid = 26;
pseudo_seid_base = 26;
break;
}
pseudo_seid += number_of_se_entries; /* get past se_ entries */
pseudo_seid_base += number_of_se_entries; /* get past se_ entries */
if (has_note_variations) {
int i, idx = 0, notecount = strlen(str);
static const char *const note_suffixes[]
= { "_A", "_B", "_C", "_D", "_E", "_F", "_G" };
int i, idx = 0, notecount = strlen(str);
static const char *const note_suffixes[]
= { "_A", "_B", "_C", "_D", "_E", "_F", "_G" };
end_of_res = eos(resourcename);
c = str;
for (i = 0; i < notecount; ++i) {
if (*c >= 'A' && *c <= 'G') {
end_of_res = eos(resourcename);
c = str;
for (i = 0; i < notecount; ++i) {
if (*c >= 'A' && *c <= 'G') {
pseudo_seid = pseudo_seid_base;
if (has_note_variations) {
idx = (*c) - 'A';
pseudo_seid += idx;
if (pseudo_seid >= SIZE(affiliation))
break;
break;
Strcpy(end_of_res, note_suffixes[idx]);
if (!affiliation[pseudo_seid]) {
affiliate(pseudo_seid, resourcename);
}
if (affiliation[pseudo_seid]) {
if ([seSound[pseudo_seid] isPlaying])
[seSound[pseudo_seid] stop];
[seSound[pseudo_seid] play];
}
if (!affiliation[pseudo_seid]) {
affiliate(pseudo_seid, resourcename);
}
if (affiliation[pseudo_seid]) {
if ([seSound[pseudo_seid] isPlaying])
[seSound[pseudo_seid] stop];
[seSound[pseudo_seid] play];
if (i < notecount - 1) {
/* more notes to follow */
msleep(150);
[seSound[pseudo_seid] stop];
}
}
c++;
}
} else {
if (!affiliation[pseudo_seid]) {
affiliate(pseudo_seid, resourcename);
}
if (affiliation[pseudo_seid]) {
if ([seSound[pseudo_seid] isPlaying])
[seSound[pseudo_seid] stop];
[seSound[pseudo_seid] play];
}
c++;
}
#endif
}

View File

@@ -574,19 +574,19 @@ do_improvisation(struct obj* instr)
case MAGIC_FLUTE: /* Make monster fall asleep */
consume_obj_charge(instr, TRUE);
Hero_playnotes(obj_to_instr(&itmp), "C", 50);
You("%sproduce %s music.", !Deaf ? "" : "seem to ",
Hallucination ? "piped" : "soft");
Hero_playnotes(obj_to_instr(&itmp), "C", 50);
put_monsters_to_sleep(u.ulevel * 5);
exercise(A_DEX, TRUE);
break;
case WOODEN_FLUTE: /* May charm snakes */
do_spec &= (rn2(ACURR(A_DEX)) + u.ulevel > 25);
Hero_playnotes(obj_to_instr(&itmp), "C", 50);
if (!Deaf)
pline("%s.", Tobjnam(instr, do_spec ? "trill" : "toot"));
else
You_feel("%s %s.", yname(instr), do_spec ? "trill" : "toot");
Hero_playnotes(obj_to_instr(&itmp), "C", 50);
if (do_spec)
charm_snakes(u.ulevel * 3);
exercise(A_DEX, TRUE);
@@ -602,57 +602,57 @@ do_improvisation(struct obj* instr)
if ((damage = zapyourself(instr, TRUE)) != 0) {
char buf[BUFSZ];
Hero_playnotes(obj_to_instr(&itmp), "C", 50);
Sprintf(buf, "using a magical horn on %sself", uhim());
Hero_playnotes(obj_to_instr(&itmp), "C", 50);
losehp(damage, buf, KILLED_BY); /* fire or frost damage */
}
} else {
int type = BZ_OFS_AD((instr->otyp == FROST_HORN) ? AD_COLD : AD_FIRE);
Hero_playnotes(obj_to_instr(&itmp), "C", 50);
if (!Blind)
pline("A %s blasts out of the horn!", flash_str(type, FALSE));
Hero_playnotes(obj_to_instr(&itmp), "C", 50);
ubuzz(BZ_U_WAND(type), rn1(6, 6));
}
makeknown(instr->otyp);
break;
case TOOLED_HORN: /* Awaken or scare monsters */
Hero_playnotes(obj_to_instr(&itmp), "C", 50);
if (!Deaf)
You("produce a frightful, grave sound.");
else
You("blow into the horn.");
Hero_playnotes(obj_to_instr(&itmp), "C", 50);
awaken_monsters(u.ulevel * 30);
exercise(A_WIS, FALSE);
break;
case BUGLE: /* Awaken & attract soldiers */
Hero_playnotes(obj_to_instr(&itmp), "C", 50);
if (!Deaf)
You("extract a loud noise from %s.", yname(instr));
else
You("blow into the bugle.");
Hero_playnotes(obj_to_instr(&itmp), "C", 50);
awaken_soldiers(&gy.youmonst);
exercise(A_WIS, FALSE);
break;
case MAGIC_HARP: /* Charm monsters */
consume_obj_charge(instr, TRUE);
Hero_playnotes(obj_to_instr(&itmp), "C", 50);
if (!Deaf)
pline("%s very attractive music.", Tobjnam(instr, "produce"));
else
You_feel("very soothing vibrations.");
Hero_playnotes(obj_to_instr(&itmp), "C", 50);
charm_monsters((u.ulevel - 1) / 3 + 1);
exercise(A_DEX, TRUE);
break;
case WOODEN_HARP: /* May calm Nymph */
do_spec &= (rn2(ACURR(A_DEX)) + u.ulevel > 25);
Hero_playnotes(obj_to_instr(&itmp), "C", 50);
if (!Deaf)
pline("%s %s.", Yname2(instr),
do_spec ? "produces a lilting melody" : "twangs");
else
You_feel("soothing vibrations.");
Hero_playnotes(obj_to_instr(&itmp), "C", 50);
if (do_spec)
calm_nymphs(u.ulevel * 3);
exercise(A_DEX, TRUE);
@@ -664,8 +664,8 @@ do_improvisation(struct obj* instr)
mundane is flagged */
consume_obj_charge(instr, TRUE);
Hero_playnotes(obj_to_instr(&itmp), "C", 50);
You("produce a heavy, thunderous rolling!");
Hero_playnotes(obj_to_instr(&itmp), "C", 50);
pline_The("entire %s is shaking around you!", generic_lvl_desc());
do_earthquake((u.ulevel - 1) / 3 + 1);
/* shake up monsters in a much larger radius... */
@@ -674,20 +674,21 @@ do_improvisation(struct obj* instr)
break;
case LEATHER_DRUM: /* Awaken monsters */
if (!mundane) {
Hero_playnotes(obj_to_instr(&itmp), "C", 50);
if (!Deaf) {
You("beat a deafening row!");
Hero_playnotes(obj_to_instr(&itmp), "CCC", 100);
incr_itimeout(&HDeaf, rn1(20, 30));
} else {
You("pound on the drum.");
}
exercise(A_WIS, FALSE);
} else
} else {
/* TODO maybe: sound effects for these riffs */
Hero_playnotes(obj_to_instr(&itmp), "C", 50);
You("%s %s.",
rn2(2) ? "butcher" : rn2(2) ? "manage" : "pull off",
an(beats[rn2(SIZE(beats))]));
Hero_playnotes(obj_to_instr(&itmp), "CCCCC", 50);
}
awaken_monsters(u.ulevel * (mundane ? 5 : 40));
gc.context.botl = TRUE;
break;

View File

@@ -1556,9 +1556,6 @@ release_sound_mappings(void)
struct sound_procs soundprocs;
#ifdef SND_LIB_QTSOUND
extern struct sound_procs qtsound_procs;
#endif
#ifdef SND_LIB_PORTAUDIO
extern struct sound_procs portaudio_procs;
#endif
@@ -1586,6 +1583,9 @@ extern struct sound_procs windsound_procs;
#ifdef SND_LIB_MACSOUND
extern struct sound_procs macsound_procs;
#endif
#ifdef SND_LIB_QTSOUND
extern struct sound_procs qtsound_procs;
#endif
struct sound_procs nosound_procs = {
SOUNDID(nosound),
@@ -1605,9 +1605,6 @@ static struct sound_choices {
struct sound_procs *sndprocs;
} soundlib_choices[] = {
{ &nosound_procs }, /* default, built-in */
#ifdef SND_LIB_QTSOUND
{ &qtsound_procs },
#endif
#ifdef SND_LIB_PORTAUDIO
{ &portaudio_procs },
#endif
@@ -1635,6 +1632,9 @@ static struct sound_choices {
#ifdef SND_LIB_MACSOUND
{ &macsound_procs },
#endif
#ifdef SND_LIB_QTSOUND
{ &qtsound_procs },
#endif
};
void

View File

@@ -170,12 +170,16 @@ ifeq "$(HAVE_SNDLIB)" "1"
SNDCFLAGS+= -DUSER_SOUNDS
endif
CFLAGS+= $(PKGCFLAGS) $(WINCFLAGS) #WINCFLAGS set from multiw-2.370
CFLAGS+= $(SNDCFLAGS) #SNDCFLAGS set from multiw-2.370
#WINCFLAGS set from multiw-2.370
#SNDCFLAGS set from multiw-2.370
CFLAGS+= $(PKGCFLAGS) $(WINCFLAGS)
CFLAGS+= $(SNDCFLAGS)
CFLAGS+= $(NHCFLAGS)
CCXXFLAGS+= $(WINCFLAGS) #WINCFLAGS set from multiw-2.370
CCXXFLAGS+= $(SNDCFLAGS) #SNDCFLAGS set from multiw-2.370
#WINCFLAGS set from multiw-2.370
#SNDCFLAGS set from multiw-2.370
CCXXFLAGS+= $(WINCFLAGS)
CCXXFLAGS+= $(SNDCFLAGS)
CCXXFLAGS+= $(NHCFLAGS)
VARDATND =

View File

@@ -39,6 +39,9 @@ ATTRNORETURN static void opt_terminate(void) NORETURN;
ATTRNORETURN static void opt_usage(const char *) NORETURN;
static void opt_showpaths(const char *);
ATTRNORETURN static void scores_only(int, char **, const char *) NORETURN;
#ifdef SND_LIB_INTEGRATED
uint32_t soundlibchoice = soundlib_nosound;
#endif
#ifdef _M_UNIX
extern void check_sco_console(void);
@@ -107,10 +110,12 @@ main(int argc, char *argv[])
* We can leave a hint here for activate_chosen_soundlib later.
* assign_soundlib() just sets an indicator, it doesn't initialize
* any soundlib, and the indicator could be overturned before
* activate_chosen_soundlib() gets called.
* activate_chosen_soundlib() gets called. Qt will place its own
* hint if qt_init_nhwindow() is invoked.
*/
#if defined(SND_LIB_MACSOUND) && !defined(SND_LIB_QTSOUND)
assign_soundlib(soundlib_macsound);
#if defined(SND_LIB_MACSOUND)
soundlibchoice = soundlib_macsound;
assign_soundlib(soundlibchoice);
#endif
#endif

View File

@@ -209,8 +209,11 @@ void NetHackQtBind::qt_init_nhwindows(int *argc, char **argv)
* should be loaded by activate_chosen_soundlib() shortly.
* gc.chosen_soundlib is initialized to soundlib_nosound.
*/
if (gc.chosen_soundlib == soundlib_nosound)
assign_soundlib(soundlib_qtsound);
if (gc.chosen_soundlib == (uint32_t) soundlib_nosound) {
uint32_t soundlibchoice = (uint32_t) soundlib_qtsound;
assign_soundlib(soundlibchoice);
}
#endif
}