From eb4ea872e95fb11b9eb60d07aeaa85d42069f345 Mon Sep 17 00:00:00 2001 From: Kim Woelders Date: Wed, 30 Dec 2020 20:20:23 +0100 Subject: [PATCH] Sound: Treat player engine like others --- configure.ac | 1 + src/Makefile.am | 10 +++++-- src/actions.c | 4 +-- src/file.c | 4 +-- src/sound.c | 47 ++++-------------------------- src/sound_player.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 90 insertions(+), 47 deletions(-) create mode 100644 src/sound_player.c diff --git a/configure.ac b/configure.ac index 28e8ad16..e33e98f0 100644 --- a/configure.ac +++ b/configure.ac @@ -176,6 +176,7 @@ if test "x$enable_sound" = "xplayer"; then with_sndplayer="/usr/bin/aplay -q %s") AC_DEFINE_UNQUOTED(SOUND_PLAYER_FMT, "$with_sndplayer", [Audio player]), fi +AM_CONDITIONAL(USE_SOUND_PLAYER, test "x$enable_sound" = "xplayer") case x$enable_sound in xpulseaudio|xesound|xsndio|xalsa) diff --git a/src/Makefile.am b/src/Makefile.am index 991da605..a94ce330 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -176,7 +176,7 @@ MODULE_LIBS = $(DLOPEN_LIBS) libe16dir = $(pkglibdir) -libe16_LTLIBRARIES = $(LIBSND_ESD) $(LIBSND_PULSE) $(LIBSND_SNDIO) $(LIBSND_ALSA) $(LIBFNT_IFT) $(LIBFNT_XFT) $(LIBFNT_PANGO) +libe16_LTLIBRARIES = $(LIBSND_ESD) $(LIBSND_PULSE) $(LIBSND_SNDIO) $(LIBSND_ALSA) $(LIBSND_PLAYER) $(LIBFNT_IFT) $(LIBFNT_XFT) $(LIBFNT_PANGO) if USE_SOUND_ESD LIBSND_ESD = libsound_esd.la @@ -210,6 +210,12 @@ libsound_alsa_la_LIBADD = $(ALSA_LIBS) $(SNDLDR_LIBS) libsound_alsa_la_LDFLAGS = -module -avoid-version endif +if USE_SOUND_PLAYER +LIBSND_PLAYER = libsound_player.la +libsound_player_la_SOURCES = sound_player.c +libsound_player_la_LDFLAGS = -module -avoid-version +endif + LIBFNT_IFT = libfont_ift.la libfont_ift_la_SOURCES = ttfont.c libfont_ift_la_CFLAGS = $(IMLIB2_CFLAGS) @@ -234,7 +240,7 @@ endif else -MODULE_SRCS = sound_esd.c sound_pulse.c sound_sndio.c sound_alsa.c sound_load.c \ +MODULE_SRCS = sound_esd.c sound_pulse.c sound_sndio.c sound_alsa.c sound_player.c sound_load.c \ ttfont.c text_xft.c text_pango.c MODULE_LIBS = $(ESD_LIBS) $(PA_LIBS) $(SNDIO_LIBS) $(ALSA_LIBS) $(SNDLDR_LIBS) $(PANGO_LIBS) $(XFT_LIBS) MODULE_CFLAGS = $(ESD_CFLAGS) $(PA_CFLAGS) $(SNDIO_CFLAGS) $(SNDLDR_CFLAGS) $(PANGO_CFLAGS) $(XFT_CFLAGS) diff --git a/src/actions.c b/src/actions.c index 2ebd3d65..d18b044a 100644 --- a/src/actions.c +++ b/src/actions.c @@ -1,6 +1,6 @@ /* * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors - * Copyright (C) 2004-2020 Kim Woelders + * Copyright (C) 2004-2021 Kim Woelders * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -212,7 +212,7 @@ _Espawn(int argc __UNUSED__, char **argv) exit(100); } -void +__EXPORT__ void Espawn(const char *fmt, ...) { va_list args; diff --git a/src/file.c b/src/file.c index c1153732..0f1fad2f 100644 --- a/src/file.c +++ b/src/file.c @@ -1,6 +1,6 @@ /* * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors - * Copyright (C) 2007-2020 Kim Woelders + * Copyright (C) 2007-2021 Kim Woelders * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -322,7 +322,7 @@ path_canexec(const char *file) return 1; } -int +__EXPORT__ int path_canexec0(const char *cmd) { char exe[4096]; diff --git a/src/sound.c b/src/sound.c index 2dd5053c..49c30f02 100644 --- a/src/sound.c +++ b/src/sound.c @@ -31,8 +31,6 @@ #include "sound.h" #include "sounds.h" -#define HAVE_SOUND_OPS 1 - #if USE_SOUND_ESD #define SOUND_SERVER_NAME "esd" #define SOUND_MODULE_NAME "esd" @@ -46,7 +44,8 @@ #define SOUND_SERVER_NAME "ALSA" #define SOUND_MODULE_NAME "alsa" #elif USE_SOUND_PLAYER -#undef HAVE_SOUND_OPS +#define SOUND_SERVER_NAME SOUND_PLAYER_FMT +#define SOUND_MODULE_NAME "player" #else #error Invalid sound configuration #endif @@ -92,6 +91,9 @@ static const SoundOps *ops = &SoundOps_sndio; #elif USE_SOUND_ALSA extern const SoundOps SoundOps_alsa; static const SoundOps *ops = &SoundOps_alsa; +#elif USE_SOUND_PLAYER +extern const SoundOps SoundOps_player; +static const SoundOps *ops = &SoundOps_player; #endif #endif @@ -167,10 +169,9 @@ _SclassSampleDestroy(void *data, void *user_data __UNUSED__) if (!sclass || !sclass->sample) return; -#if HAVE_SOUND_OPS if (ops) ops->SampleDestroy(sclass->sample); -#endif + sclass->sample = NULL; } @@ -206,29 +207,12 @@ _SclassDestroy(SoundClass * sclass) Efree(sclass); } -#if USE_SOUND_PLAYER -static void -_SclassPlayAplay(SoundClass * sclass) -{ - char *file; - - file = FindFile(sclass->file, SOUND_THEME_PATH, FILE_TYPE_SOUND); - if (!file) - return; - Espawn(SOUND_PLAYER_FMT, file); - Efree(file); -} -#endif - static void _SclassApply(SoundClass * sclass) { if (!sclass || !Conf_sound.enable) return; -#if USE_SOUND_PLAYER - _SclassPlayAplay(sclass); -#else if (!sclass->sample) { char *file; @@ -253,7 +237,6 @@ _SclassApply(SoundClass * sclass) } ops->SamplePlay(sclass->sample); -#endif } static int @@ -322,8 +305,6 @@ _SoundInit(void) if (!Conf_sound.enable) return; -#if HAVE_SOUND_OPS - #if USE_MODULES if (!ops) ops = ModLoadSym("sound", "SoundOps", SOUND_MODULE_NAME); @@ -340,20 +321,6 @@ _SoundInit(void) return; } -#elif USE_SOUND_PLAYER - - if (!path_canexec0(SOUND_PLAYER_FMT)) - { - Conf_sound.enable = 0; - DialogOK(_("Error initialising sound"), - _ - ("The sound player is not executable (%s).\n" - "Audio will now be disabled.\n"), SOUND_PLAYER_FMT); - return; - } - -#endif /* HAVE_SOUND_OPS */ - _SoundConfigLoad(); } @@ -364,10 +331,8 @@ _SoundExit(void) LIST_FOR_EACH(SoundClass, &sound_list, sc) _SclassSampleDestroy(sc, NULL); -#if HAVE_SOUND_OPS if (ops) ops->Exit(); -#endif Conf_sound.enable = 0; } diff --git a/src/sound_player.c b/src/sound_player.c new file mode 100644 index 00000000..bc10638c --- /dev/null +++ b/src/sound_player.c @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2021 Kim Woelders + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies of the Software, its documentation and marketing & publicity + * materials, and acknowledgment shall be given in the documentation, materials + * and software packages that this Software was used. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "E.h" +#if defined(ENABLE_SOUND) && defined(USE_SOUND_PLAYER) +#include "file.h" +#include "sound.h" + +#ifdef USE_MODULES +#define Estrdup strdup +#endif + +static Sample * +_sound_player_Load(const char *file) +{ + return (Sample *) Estrdup(file); +} + +static void +_sound_player_Destroy(Sample * s) +{ + Efree(s); +} + +static void +_sound_player_Play(Sample * s) +{ + Espawn(SOUND_PLAYER_FMT, s); +} + +static int +_sound_player_Init(void) +{ + if (!path_canexec0(SOUND_PLAYER_FMT)) + return -1; + return 0; +} + +static void +_sound_player_Exit(void) +{ +} + +__EXPORT__ extern const SoundOps SoundOps_player; + +const SoundOps SoundOps_player = { + _sound_player_Init, _sound_player_Exit, + _sound_player_Load, _sound_player_Destroy, _sound_player_Play, +}; + +#endif /* ENABLE_SOUND && USE_SOUND_PLAYER */