take initial stab at macsound interface

Use macOS AppKit framework routines for a first cut at a
macsound soundlib interface.

Requires WANT_MACSOUND=1 on build.

Nothing has been done to move the stock sounds into the resources
of a bundle, so after building, if you want to try the stock sounds
out:
	cp sound/wav/*.wav ~/Library/Sounds

Because the NSSound macOS routines always do the search, supposedly
the following locations are searched in this order:
   1. the application’s main bundle
   2. ~/Library/Sounds
   3. /Library/Sounds
   4. /Network/Library/Sounds
   5. /System/Library/Sounds

Although not specifically implemented as of yet, it may be pretty
close to being able to put soundeffects wav files (by se_ name)
into ~/Library/Sounds working for the SND_SOUNDEFFECTS_AUTOMAP feature.

Feedback is welcome. Contributions for improving it are even more
welcome.

The new soundlib supporting file is named
sound/macsound/macsound.m since it's got objective C in it.

Known bugs and glitches:

The Hero_playnotes on a set of 5 notes goes too fast, so there
needs to be a slight delay added between the note of a multi-note
play.
This commit is contained in:
nhmall
2023-01-23 23:50:43 -05:00
parent ae6bb2420b
commit 3d908c49ef
14 changed files with 524 additions and 50 deletions

View File

@@ -155,6 +155,21 @@ endif #CURSES_UNICODE=0
endif #CURSES_UNIODE=sys
endif #MAKEFILE_SRC
ifdef WANT_MACSOUND
HAVE_SNDLIB = 1
SNDCFLAGS+= -DSND_LIB_MACSOUND -DSND_SOUNDEFFECTS_AUTOMAP
SNDLIBSRC = ../sound/macsound/macsound.m
SNDLIBOBJ = macsound.o
LFLAGS += -framework AppKit
endif
# HAVE_SNDLIB could have been set just above, or it could
# have been set in multiw-2 for Qt. Either way, if it is
# set, add USER_SOUNDS
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
CFLAGS+= $(NHCFLAGS)
@@ -373,12 +388,48 @@ VARDIR=$(HACKDIR)
#
#-INCLUDE gbdates-pre.370
#
ifdef WANT_MACSOUND
WAVDIR = ../sound/wav
SNDWAVS = se_squeak_A se_squeak_B se_squeak_B_flat se_squeak_C se_squeak_D \
se_squeak_D_flat se_squeak_E se_squeak_E_flat se_squeak_F \
se_squeak_F_sharp se_squeak_G se_squeak_G_sharp sound_Bell \
sound_Bugle_A sound_Bugle_B sound_Bugle_C sound_Bugle_D \
sound_Bugle_E sound_Bugle_F sound_Bugle_G \
sound_Drum_Of_Earthquake sound_Fire_Horn sound_Frost_Horn \
sound_Leather_Drum sound_Magic_Harp_A sound_Magic_Harp_B \
sound_Magic_Harp_C sound_Magic_Harp_D sound_Magic_Harp_E \
sound_Magic_Harp_F sound_Magic_Harp_G sound_Tooled_Horn_A \
sound_Tooled_Horn_B sound_Tooled_Horn_C sound_Tooled_Horn_D \
sound_Tooled_Horn_E sound_Tooled_Horn_F sound_Tooled_Horn_G \
sound_Wooden_Flute_A sound_Wooden_Flute_B sound_Wooden_Flute_C \
sound_Wooden_Flute_D sound_Wooden_Flute_E sound_Wooden_Flute_F \
sound_Wooden_Flute_G sound_Wooden_Harp_A sound_Wooden_Harp_B \
sound_Wooden_Harp_C sound_Wooden_Harp_D sound_Wooden_Harp_E \
sound_Wooden_Harp_F sound_Wooden_Harp_G
WAVS = $(addprefix $(WAVDIR)/, $(addsuffix .wav, $(SNDWAVS)))
endif
#-POST
#
#-INCLUDE gbdates-post.370
#
ifdef WANT_MACSOUND
$(TARGETPFX)$(SNDLIBOBJ): $(SNDLIBSRC) $(HACK_H)
$(CC) $(CFLAGS) -c -o$@ $(SNDLIBSRC)
$(WAVDIR)/%.wav: ../util/uudecode $(WAVDIR)/%.uu
$^
mv $(notdir $@) $@
../util/uudecode: uudecode.o
$(CC) $(LFLAGS) uudecode.o -o $@
uudecode.o: ../sys/share/uudecode.c
$(CC) $(CFLAGS) -c -o $@ ../sys/share/uudecode.c
endif # WANT_MACSOUND
ifdef WANT_LIBNH
$(TARGETPFX)libnh.a: $(HOBJ) $(LIBNHSYSOBJ) ../lib/lua/liblua.a
$(AR) rcs $@ $(HOBJ) $(LIBNHSYSOBJ) ../lib/lua/liblua.a