Compile suitable demo files from doc/ (#611)

This commit is contained in:
Tom M 2020-01-24 08:57:20 +01:00 committed by GitHub
parent 5070fe8419
commit 872c6bc678
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 6 deletions

View file

@ -1,9 +1,9 @@
macro ( ADD_FLUID_TEST _test )
ADD_EXECUTABLE(${_test} ${_test}.c $<TARGET_OBJECTS:libfluidsynth-OBJ> )
# only build this unit test when explicitly requested by "make check"
set_target_properties(${_test} PROPERTIES EXCLUDE_FROM_ALL TRUE)
# import necessary compile flags and dependency libraries
if ( FLUID_CPPFLAGS )
set_target_properties ( ${_test} PROPERTIES COMPILE_FLAGS ${FLUID_CPPFLAGS} )
@ -21,8 +21,33 @@ macro ( ADD_FLUID_TEST _test )
# add the test to ctest
ADD_TEST(NAME ${_test} COMMAND ${_test})
# append the current unit test to check-target as dependency
add_dependencies(check ${_test})
endmacro ( ADD_FLUID_TEST )
macro ( ADD_FLUID_DEMO _demo )
ADD_EXECUTABLE(${_demo} ${_demo}.c )
# only build this unit test when explicitly requested by "make check"
set_target_properties(${_demo} PROPERTIES EXCLUDE_FROM_ALL TRUE)
# import necessary compile flags and dependency libraries
if ( FLUID_CPPFLAGS )
set_target_properties ( ${_demo} PROPERTIES COMPILE_FLAGS ${FLUID_CPPFLAGS} )
endif ( FLUID_CPPFLAGS )
TARGET_LINK_LIBRARIES(${_demo} libfluidsynth)
# use the local include path to look for fluidsynth.h, as we cannot be sure fluidsynth is already installed
target_include_directories(${_demo}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include> # include auto generated headers
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include> # include "normal" public (sub-)headers
$<TARGET_PROPERTY:libfluidsynth,INCLUDE_DIRECTORIES> # include all other header search paths needed by libfluidsynth (esp. glib)
)
# append the current unit test to check-target as dependency
add_dependencies(demo ${_demo})
endmacro ( ADD_FLUID_TEST )

View file

@ -33,3 +33,12 @@ if ( UNIX )
install ( FILES fluidsynth.1
DESTINATION ${MAN_INSTALL_DIR} )
endif ( UNIX )
include ( FluidUnitTest )
add_custom_target ( demo )
ADD_FLUID_DEMO ( example )
ADD_FLUID_DEMO ( fluidsynth_arpeggio )
ADD_FLUID_DEMO ( fluidsynth_fx )
ADD_FLUID_DEMO ( fluidsynth_metronome )
ADD_FLUID_DEMO ( fluidsynth_simple )

View file

@ -21,6 +21,7 @@
#define sleep(_t) Sleep(_t * 1000)
#else
#include <stdlib.h>
#include <unistd.h>
#endif
int main(int argc, char **argv)
@ -47,6 +48,12 @@ int main(int argc, char **argv)
* get used from the SoundFont) */
sfont_id = fluid_synth_sfload(synth, "example.sf2", 1);
if(sfont_id == FLUID_FAILED)
{
puts("Loading the SoundFont failed!");
goto err;
}
/* Initialize the random number generator */
srand(getpid());
@ -66,6 +73,7 @@ int main(int argc, char **argv)
fluid_synth_noteoff(synth, 0, key);
}
err:
/* Clean up */
delete_fluid_audio_driver(adriver);
delete_fluid_synth(synth);

View file

@ -18,6 +18,10 @@ int main()
const char *DRV[] = { "alsa", "jack", "portaudio" };
const char *adrivers[2];
/* three iterations, first register only alsa, then only jack, and last portaudio
* ...just to demonstrate how and under which conditions fluid_audio_driver_register()
* can be called
*/
for(int i = 0; i < sizeof(DRV) / sizeof(DRV[0]); i++)
{
adrivers[0] = DRV[i];
@ -39,11 +43,10 @@ int main()
fluid_settings_t *settings = new_fluid_settings();
res = fluid_settings_setstr(settings, "audio.driver", DRV[i]);
/* settings API will be refactored to return FLUID_OK|FAILED next major release
* returning TRUE or FALSE is deprecated
/* As of fluidsynth 2, settings API has been refactored to return FLUID_OK|FAILED
* rather than returning TRUE or FALSE
*/
#if FLUIDSYNTH_VERSION_MAJOR >= 2
if(res != FLUID_OK)
#else
if(res == 0)