2010-10-31 16:15:32 +00:00
# FluidSynth - A Software Synthesizer
2010-03-17 20:14:13 +00:00
#
2021-03-13 17:24:28 +00:00
# Copyright (C) 2003-2021 Peter Hanappe and others.
2010-03-17 20:14:13 +00:00
#
# This library is free software; you can redistribute it and/or
2017-07-12 15:45:23 +00:00
# modify it under the terms of the GNU Lesser General Public License
2017-07-12 15:53:03 +00:00
# as published by the Free Software Foundation; either version 2.1 of
2010-03-17 20:14:13 +00:00
# the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2017-07-12 15:45:23 +00:00
# Lesser General Public License for more details.
2010-03-17 20:14:13 +00:00
#
2017-07-12 15:54:54 +00:00
# You should have received a copy of the GNU Lesser General Public
2010-03-17 20:14:13 +00:00
# License along with this library; if not, write to the Free
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307, USA
# CMake based build system. Pedro Lopez-Cabanillas <plcl@users.sf.net>
2018-03-22 19:42:03 +00:00
cmake_minimum_required ( VERSION 3.1.0 ) # because of CMAKE_C_STANDARD
2021-04-13 19:12:25 +00:00
2021-04-25 12:49:03 +00:00
if(POLICY CMP0075)
cmake_policy(SET CMP0075 NEW)
endif()
2021-04-13 19:12:25 +00:00
if(POLICY CMP0091)
cmake_policy(SET CMP0091 NEW)
endif()
Revise the sequencer's event queue (#604)
Proposing a new event queue for the sequencer, based on prior discussion:
https://lists.nongnu.org/archive/html/fluid-dev/2019-12/msg00001.html
With this change fluidsynth will require a C++98 compliant compiler.
Consider this as RFC, feedback is welcome.
The "pain-points" from the discussion:
#### 1. It is slow.
Done (thanks to heap sort), see runtime of `test_seq_event_queue_sort`.
#### 2. A meaningful ordering for events with the same tick has not been considered.
Done, see comments in `fluid_seq_queue.cpp`.
#### 3. Complicated implementation
Now uses one single event queue, which requires C++98. Implemented similarly to std::priority_queue by using heap sort.
The "queue" I use currently is of type `std::deque`. `deque` does not provide preallocation. `std::vector` does provide it. However, `std::deque` has the huge advantage that appending additional elements is cheap. For `std::vector` appending new elements would require to reallocate all the memory and copy it to the new array. So,
* either use `std::deque` with the risk that memory allocation may occur during `fluid_sequencer_send_at()`, or
* use `std::vector` with a preallocated pool of events and make `fluid_sequencer_send_at()` when the `vector` runs out of capacity.
Comments?
#### 4. Events that have been processed are deleted and gone.
After having thought about this more, this is the correct behavior. After events have been dispatched, they must be released to free underlying memory, see point 3. For the very rare case that a client (e.g. fluid_player) may require those events in the future, the client should be responsible for storing the events somewhere.
#### 5. The sequencer supports the system timer as alternative time source.
The conclusion from the mailing list was that the system timer can be removed. This has been done.
#### 6. Time Scaling
Time scaling can now be used for arbitrary tempo changes. The previous implementation was capable of that as well, however, the time-scale was limited to 1000. The only limitation for the scale is now >0, see `test_seq_scale`.
### Other Points
* `fluid_sequencer_remove_events()` turned out to be broken before, as it did not remove all events from the queue. This has been fixed, see `test_seq_event_queue_remove`.
* Consider the following code executed by `threadA`:
```c
fluid_sequencer_send_at(event0);
fluid_sequencer_set_time_scale(); // new scale
fluid_sequencer_send_at(event1);
```
The new scale will be definitely applied to `event1`. However, if another concurrently running `threadB` executes `fluid_sequencer_process()`, it was previously not clear, whether the new scale was also applied to event0. This depends on whether `event0` was still in the `preQueue`, and this depends on `event0.time` and the tick count that `fluid_sequencer_process()` is being called with. This has been changed. As of now, events are queued with their timestamp AS-IS. And only the latest call to `fluid_sequencer_set_time_scale()` is being considered during `fluid_sequencer_process()`. This makes the implementation very simple, i.e. no events need to be changed and the sequencer doesn't have to be locked down. On the other hand, it means that `fluid_sequencer_set_time_scale()` can only be used for tempo changes when called from the sequencer callback. In other words, if `threadA` executes the code above followed by `fluid_sequencer_process()`, `event0` and `event1` will be executed with the same tempo, which is the latest scale provided to the seq. Is this acceptable? The old implementation had the same limitation. And when looking through the internet, I only find users who call `fluid_sequencer_set_time_scale()` from the sequencer callback. Still, this is a point I'm raising for discussion.
2020-05-26 15:16:22 +00:00
project ( FluidSynth C CXX )
2010-03-17 20:14:13 +00:00
set ( CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake_admin )
# FluidSynth package name
set ( PACKAGE "fluidsynth" )
# FluidSynth package version
2017-11-30 12:25:40 +00:00
set ( FLUIDSYNTH_VERSION_MAJOR 2 )
2021-03-27 16:46:01 +00:00
set ( FLUIDSYNTH_VERSION_MINOR 2 )
2021-05-08 16:30:07 +00:00
set ( FLUIDSYNTH_VERSION_MICRO 1 )
2010-10-31 16:15:32 +00:00
set ( VERSION "${FLUIDSYNTH_VERSION_MAJOR}.${FLUIDSYNTH_VERSION_MINOR}.${FLUIDSYNTH_VERSION_MICRO}" )
2010-03-17 20:14:13 +00:00
set ( FLUIDSYNTH_VERSION "\"${VERSION}\"" )
2010-08-08 12:04:58 +00:00
# libfluidsynth - Library version
# *** NOTICE ***
# Update library version upon each release (follow these steps in order)
# if any source code changes: REVISION++
# if any interfaces added/removed/changed: REVISION=0
# if any interfaces removed/changed (compatibility broken): CURRENT++
# if any interfaces have been added: AGE++
# if any interfaces have been removed/changed (compatibility broken): AGE=0
# This is not exactly the same algorithm as the libtool one, but the results are the same.
2020-05-26 14:53:59 +00:00
set ( LIB_VERSION_CURRENT 3 )
set ( LIB_VERSION_AGE 0 )
2021-05-08 16:30:07 +00:00
set ( LIB_VERSION_REVISION 1 )
2010-10-31 16:15:32 +00:00
set ( LIB_VERSION_INFO
2010-10-16 18:27:29 +00:00
"${LIB_VERSION_CURRENT}.${LIB_VERSION_AGE}.${LIB_VERSION_REVISION}" )
2010-03-17 20:14:13 +00:00
# Options disabled by default
2021-04-03 15:34:48 +00:00
option ( enable-coverage "enable gcov code coverage" off )
2018-03-17 11:48:14 +00:00
option ( enable-debug "enable debugging (default=no)" off )
2010-03-17 20:14:13 +00:00
option ( enable-floats "enable type float instead of double for DSP samples" off )
2018-03-17 11:48:14 +00:00
option ( enable-fpe-check "enable Floating Point Exception checks and debug messages" off )
2010-10-19 21:30:29 +00:00
option ( enable-portaudio "compile PortAudio support" off )
2018-03-17 11:48:14 +00:00
option ( enable-profiling "profile the dsp code" off )
2010-03-17 20:14:13 +00:00
option ( enable-trap-on-fpe "enable SIGFPE trap on Floating Point Exceptions" off )
2019-03-27 17:02:23 +00:00
option ( enable-ubsan "compile and link against UBSan (for debugging fluidsynth internals)" off )
2010-03-17 20:14:13 +00:00
# Options enabled by default
option ( enable-aufile "compile support for sound file output" on )
2010-08-11 11:18:53 +00:00
option ( BUILD_SHARED_LIBS "Build a shared object or DLL" on )
2018-03-17 11:48:14 +00:00
option ( enable-dbus "compile DBUS support (if it is available)" on )
2018-03-17 12:08:19 +00:00
option ( enable-ipv6 "enable ipv6 support" on )
2018-03-17 11:48:14 +00:00
option ( enable-jack "compile JACK support (if it is available)" on )
option ( enable-ladspa "enable LADSPA effect units" on )
2019-05-11 03:31:56 +00:00
option ( enable-libinstpatch "use libinstpatch (if available) to load DLS and GIG files" on )
2018-03-17 11:48:14 +00:00
option ( enable-libsndfile "compile libsndfile support (if it is available)" on )
option ( enable-midishare "compile MidiShare support (if it is available)" on )
2019-03-27 17:02:23 +00:00
option ( enable-opensles "compile OpenSLES support (if it is available)" off )
option ( enable-oboe "compile Oboe support (requires OpenSLES and/or AAudio)" off )
2018-03-17 12:08:19 +00:00
option ( enable-network "enable network support (requires BSD sockets)" on )
2018-03-17 11:48:14 +00:00
option ( enable-oss "compile OSS support (if it is available)" on )
2018-10-26 17:48:01 +00:00
option ( enable-dsound "compile DirectSound support (if it is available)" on )
2021-01-29 17:11:17 +00:00
option ( enable-wasapi "compile Windows WASAPI support (if it is available)" on )
2018-12-01 14:04:26 +00:00
option ( enable-waveout "compile Windows WaveOut support (if it is available)" on )
2018-10-26 17:48:01 +00:00
option ( enable-winmidi "compile Windows MIDI support (if it is available)" on )
2018-12-14 15:43:35 +00:00
option ( enable-sdl2 "compile SDL2 audio support (if it is available)" on )
2018-03-17 11:48:14 +00:00
option ( enable-pkgconfig "use pkg-config to locate fluidsynth's (mostly optional) dependencies" on )
option ( enable-pulseaudio "compile PulseAudio support (if it is available)" on )
option ( enable-readline "compile readline lib line editing (if it is available)" on )
2018-11-18 08:45:28 +00:00
option ( enable-threads "enable multi-threading support (such as parallel voice synthesis)" on )
2010-03-17 20:14:13 +00:00
2010-10-13 21:57:19 +00:00
# Platform specific options
2018-11-24 19:08:09 +00:00
if ( CMAKE_SYSTEM MATCHES "Linux|FreeBSD|DragonFly" )
2010-10-13 21:57:19 +00:00
option ( enable-lash "compile LASH support (if it is available)" on )
option ( enable-alsa "compile ALSA support (if it is available)" on )
2018-11-24 19:08:09 +00:00
endif ( CMAKE_SYSTEM MATCHES "Linux|FreeBSD|DragonFly" )
2010-10-13 21:57:19 +00:00
2019-02-26 08:05:49 +00:00
if ( CMAKE_SYSTEM MATCHES "Linux" )
option ( enable-systemd "compile systemd support (if it is available)" on )
endif ( CMAKE_SYSTEM MATCHES "Linux" )
2016-01-21 12:25:21 +00:00
if ( CMAKE_SYSTEM MATCHES "Darwin" )
2010-10-13 21:57:19 +00:00
option ( enable-coreaudio "compile CoreAudio support (if it is available)" on )
option ( enable-coremidi "compile CoreMIDI support (if it is available)" on )
2010-10-31 16:15:32 +00:00
option ( enable-framework "create a Mac OSX style FluidSynth.framework" on )
2016-01-21 12:25:21 +00:00
endif ( CMAKE_SYSTEM MATCHES "Darwin" )
2010-10-13 21:57:19 +00:00
2016-01-21 12:25:21 +00:00
if ( CMAKE_SYSTEM MATCHES "OS2" )
2010-10-13 21:57:19 +00:00
option ( enable-dart "compile DART support (if it is available)" on )
2016-01-18 09:16:37 +00:00
set ( enable-ipv6 off )
2016-01-21 12:25:21 +00:00
endif ( CMAKE_SYSTEM MATCHES "OS2" )
2010-10-13 21:57:19 +00:00
2010-03-17 20:14:13 +00:00
# Initialize the library directory name suffix.
2019-02-03 06:35:30 +00:00
if (NOT MINGW AND NOT MSVC AND NOT CMAKE_SYSTEM_NAME MATCHES "FreeBSD|DragonFly")
2010-03-17 20:14:13 +00:00
if ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
set ( _init_lib_suffix "64" )
else ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
set ( _init_lib_suffix "" )
endif ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
2017-11-17 21:15:46 +00:00
else ()
set ( _init_lib_suffix "" )
endif()
2010-10-31 16:15:32 +00:00
set ( LIB_SUFFIX ${_init_lib_suffix} CACHE STRING
2010-03-17 20:14:13 +00:00
"library directory name suffix (32/64/nothing)" )
mark_as_advanced ( LIB_SUFFIX )
2018-03-22 19:42:03 +00:00
# the default C standard to use for all targets
set(CMAKE_C_STANDARD 90)
Revise the sequencer's event queue (#604)
Proposing a new event queue for the sequencer, based on prior discussion:
https://lists.nongnu.org/archive/html/fluid-dev/2019-12/msg00001.html
With this change fluidsynth will require a C++98 compliant compiler.
Consider this as RFC, feedback is welcome.
The "pain-points" from the discussion:
#### 1. It is slow.
Done (thanks to heap sort), see runtime of `test_seq_event_queue_sort`.
#### 2. A meaningful ordering for events with the same tick has not been considered.
Done, see comments in `fluid_seq_queue.cpp`.
#### 3. Complicated implementation
Now uses one single event queue, which requires C++98. Implemented similarly to std::priority_queue by using heap sort.
The "queue" I use currently is of type `std::deque`. `deque` does not provide preallocation. `std::vector` does provide it. However, `std::deque` has the huge advantage that appending additional elements is cheap. For `std::vector` appending new elements would require to reallocate all the memory and copy it to the new array. So,
* either use `std::deque` with the risk that memory allocation may occur during `fluid_sequencer_send_at()`, or
* use `std::vector` with a preallocated pool of events and make `fluid_sequencer_send_at()` when the `vector` runs out of capacity.
Comments?
#### 4. Events that have been processed are deleted and gone.
After having thought about this more, this is the correct behavior. After events have been dispatched, they must be released to free underlying memory, see point 3. For the very rare case that a client (e.g. fluid_player) may require those events in the future, the client should be responsible for storing the events somewhere.
#### 5. The sequencer supports the system timer as alternative time source.
The conclusion from the mailing list was that the system timer can be removed. This has been done.
#### 6. Time Scaling
Time scaling can now be used for arbitrary tempo changes. The previous implementation was capable of that as well, however, the time-scale was limited to 1000. The only limitation for the scale is now >0, see `test_seq_scale`.
### Other Points
* `fluid_sequencer_remove_events()` turned out to be broken before, as it did not remove all events from the queue. This has been fixed, see `test_seq_event_queue_remove`.
* Consider the following code executed by `threadA`:
```c
fluid_sequencer_send_at(event0);
fluid_sequencer_set_time_scale(); // new scale
fluid_sequencer_send_at(event1);
```
The new scale will be definitely applied to `event1`. However, if another concurrently running `threadB` executes `fluid_sequencer_process()`, it was previously not clear, whether the new scale was also applied to event0. This depends on whether `event0` was still in the `preQueue`, and this depends on `event0.time` and the tick count that `fluid_sequencer_process()` is being called with. This has been changed. As of now, events are queued with their timestamp AS-IS. And only the latest call to `fluid_sequencer_set_time_scale()` is being considered during `fluid_sequencer_process()`. This makes the implementation very simple, i.e. no events need to be changed and the sequencer doesn't have to be locked down. On the other hand, it means that `fluid_sequencer_set_time_scale()` can only be used for tempo changes when called from the sequencer callback. In other words, if `threadA` executes the code above followed by `fluid_sequencer_process()`, `event0` and `event1` will be executed with the same tempo, which is the latest scale provided to the seq. Is this acceptable? The old implementation had the same limitation. And when looking through the internet, I only find users who call `fluid_sequencer_set_time_scale()` from the sequencer callback. Still, this is a point I'm raising for discussion.
2020-05-26 15:16:22 +00:00
# the default C++ standard to use for all targets
set(CMAKE_CXX_STANDARD 98)
# whether to use gnu extensions
set(CMAKE_CXX_EXTENSIONS OFF)
2018-08-05 15:55:07 +00:00
# Compile with position independent code if the user requested a shared lib, i.e. no PIC if static requested.
# This is cmakes default behavior, but here it's explicitly required due to the use of libfluidsynth-OBJ as object library,
# which would otherwise always be compiled without PIC.
2020-01-31 14:45:18 +00:00
if ( NOT CMAKE_POSITION_INDEPENDENT_CODE )
set ( CMAKE_POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS} )
2020-02-02 14:25:39 +00:00
endif ( NOT CMAKE_POSITION_INDEPENDENT_CODE )
2018-08-05 15:55:07 +00:00
2018-06-02 10:50:57 +00:00
# the default global visibility level for all target
# no visibility support on OS2
if ( NOT OS2 )
set ( CMAKE_C_VISIBILITY_PRESET hidden )
endif ( NOT OS2 )
2018-09-18 15:34:10 +00:00
# enforce visibility control for all types of cmake targets
if ( POLICY CMP0063 )
cmake_policy ( SET CMP0063 NEW )
endif ( POLICY CMP0063 )
2018-06-02 10:50:57 +00:00
2010-10-16 17:27:47 +00:00
# Default install directory names
include ( DefaultDirs )
2010-03-17 20:14:13 +00:00
# Basic C library checks
2020-08-16 18:17:26 +00:00
include ( CheckCCompilerFlag )
2010-03-17 20:14:13 +00:00
include ( CheckSTDC )
include ( CheckIncludeFile )
2021-04-25 12:49:03 +00:00
include ( CheckSymbolExists )
2020-05-26 14:53:59 +00:00
include ( CheckTypeSize )
2010-03-17 20:14:13 +00:00
check_include_file ( string.h HAVE_STRING_H )
2010-10-31 16:15:32 +00:00
check_include_file ( stdlib.h HAVE_STDLIB_H )
check_include_file ( stdio.h HAVE_STDIO_H )
check_include_file ( math.h HAVE_MATH_H )
check_include_file ( errno.h HAVE_ERRNO_H )
check_include_file ( stdarg.h HAVE_STDARG_H )
check_include_file ( unistd.h HAVE_UNISTD_H )
check_include_file ( sys/mman.h HAVE_SYS_MMAN_H )
check_include_file ( sys/types.h HAVE_SYS_TYPES_H )
check_include_file ( sys/time.h HAVE_SYS_TIME_H )
check_include_file ( sys/stat.h HAVE_SYS_STAT_H )
check_include_file ( fcntl.h HAVE_FCNTL_H )
check_include_file ( sys/socket.h HAVE_SYS_SOCKET_H )
check_include_file ( netinet/in.h HAVE_NETINET_IN_H )
check_include_file ( netinet/tcp.h HAVE_NETINET_TCP_H )
check_include_file ( arpa/inet.h HAVE_ARPA_INET_H )
2010-03-17 20:14:13 +00:00
check_include_file ( limits.h HAVE_LIMITS_H )
2010-10-31 16:15:32 +00:00
check_include_file ( pthread.h HAVE_PTHREAD_H )
check_include_file ( signal.h HAVE_SIGNAL_H )
2012-03-11 11:49:49 +00:00
check_include_file ( getopt.h HAVE_GETOPT_H )
2017-11-04 11:53:44 +00:00
check_include_file ( stdint.h HAVE_STDINT_H )
2020-05-26 14:53:59 +00:00
check_type_size ( "long long" LONG_LONG )
if ( NOT HAVE_LONG_LONG AND NOT MSVC)
message ( FATAL_ERROR "Your compiler does not support intrinsic type 'long long'. Unable to compile fluidsynth." )
endif ()
2010-03-17 20:14:13 +00:00
include ( TestInline )
2010-07-15 21:02:00 +00:00
include ( TestVLA )
2010-03-17 20:14:13 +00:00
include ( TestBigEndian )
test_big_endian ( WORDS_BIGENDIAN )
2010-10-16 15:36:06 +00:00
unset ( LIBFLUID_CPPFLAGS CACHE )
unset ( LIBFLUID_LIBS CACHE )
unset ( FLUID_CPPFLAGS CACHE )
unset ( FLUID_LIBS CACHE )
2019-03-27 17:02:23 +00:00
unset ( ENABLE_UBSAN CACHE )
2010-03-17 20:14:13 +00:00
2019-11-13 19:27:48 +00:00
if ( CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID STREQUAL "Intel" )
2010-11-21 15:12:37 +00:00
if ( NOT APPLE AND NOT OS2 )
2010-10-31 16:15:32 +00:00
set ( CMAKE_EXE_LINKER_FLAGS
2010-03-17 20:14:13 +00:00
"${CMAKE_EXE_LINKER_FLAGS} -Wl,--as-needed" )
2010-10-31 16:15:32 +00:00
set ( CMAKE_SHARED_LINKER_FLAGS
2010-03-17 20:14:13 +00:00
"${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined" )
2010-11-21 15:12:37 +00:00
endif ( NOT APPLE AND NOT OS2 )
2020-01-11 08:45:05 +00:00
2018-05-04 18:05:45 +00:00
# define some warning flags
2020-08-16 18:17:26 +00:00
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -W -Wpointer-arith -Wcast-qual -Wstrict-prototypes -Wno-unused-parameter -Wdeclaration-after-statement -Werror=implicit-function-declaration" )
check_c_compiler_flag ( "-Werror=incompatible-pointer-types" HAVE_INCOMPATIBLE_POINTER_TYPES )
if ( HAVE_INCOMPATIBLE_POINTER_TYPES )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=incompatible-pointer-types" )
endif ( HAVE_INCOMPATIBLE_POINTER_TYPES )
Revise the sequencer's event queue (#604)
Proposing a new event queue for the sequencer, based on prior discussion:
https://lists.nongnu.org/archive/html/fluid-dev/2019-12/msg00001.html
With this change fluidsynth will require a C++98 compliant compiler.
Consider this as RFC, feedback is welcome.
The "pain-points" from the discussion:
#### 1. It is slow.
Done (thanks to heap sort), see runtime of `test_seq_event_queue_sort`.
#### 2. A meaningful ordering for events with the same tick has not been considered.
Done, see comments in `fluid_seq_queue.cpp`.
#### 3. Complicated implementation
Now uses one single event queue, which requires C++98. Implemented similarly to std::priority_queue by using heap sort.
The "queue" I use currently is of type `std::deque`. `deque` does not provide preallocation. `std::vector` does provide it. However, `std::deque` has the huge advantage that appending additional elements is cheap. For `std::vector` appending new elements would require to reallocate all the memory and copy it to the new array. So,
* either use `std::deque` with the risk that memory allocation may occur during `fluid_sequencer_send_at()`, or
* use `std::vector` with a preallocated pool of events and make `fluid_sequencer_send_at()` when the `vector` runs out of capacity.
Comments?
#### 4. Events that have been processed are deleted and gone.
After having thought about this more, this is the correct behavior. After events have been dispatched, they must be released to free underlying memory, see point 3. For the very rare case that a client (e.g. fluid_player) may require those events in the future, the client should be responsible for storing the events somewhere.
#### 5. The sequencer supports the system timer as alternative time source.
The conclusion from the mailing list was that the system timer can be removed. This has been done.
#### 6. Time Scaling
Time scaling can now be used for arbitrary tempo changes. The previous implementation was capable of that as well, however, the time-scale was limited to 1000. The only limitation for the scale is now >0, see `test_seq_scale`.
### Other Points
* `fluid_sequencer_remove_events()` turned out to be broken before, as it did not remove all events from the queue. This has been fixed, see `test_seq_event_queue_remove`.
* Consider the following code executed by `threadA`:
```c
fluid_sequencer_send_at(event0);
fluid_sequencer_set_time_scale(); // new scale
fluid_sequencer_send_at(event1);
```
The new scale will be definitely applied to `event1`. However, if another concurrently running `threadB` executes `fluid_sequencer_process()`, it was previously not clear, whether the new scale was also applied to event0. This depends on whether `event0` was still in the `preQueue`, and this depends on `event0.time` and the tick count that `fluid_sequencer_process()` is being called with. This has been changed. As of now, events are queued with their timestamp AS-IS. And only the latest call to `fluid_sequencer_set_time_scale()` is being considered during `fluid_sequencer_process()`. This makes the implementation very simple, i.e. no events need to be changed and the sequencer doesn't have to be locked down. On the other hand, it means that `fluid_sequencer_set_time_scale()` can only be used for tempo changes when called from the sequencer callback. In other words, if `threadA` executes the code above followed by `fluid_sequencer_process()`, `event0` and `event1` will be executed with the same tempo, which is the latest scale provided to the seq. Is this acceptable? The old implementation had the same limitation. And when looking through the internet, I only find users who call `fluid_sequencer_set_time_scale()` from the sequencer callback. Still, this is a point I'm raising for discussion.
2020-05-26 15:16:22 +00:00
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -W -Wpointer-arith -Wcast-qual -Wno-unused-parameter" )
2020-01-11 08:45:05 +00:00
2019-03-27 17:02:23 +00:00
# prepend to build type specific flags, to allow users to override
2019-08-02 11:21:21 +00:00
set ( CMAKE_C_FLAGS_DEBUG "-g ${CMAKE_C_FLAGS_DEBUG}" )
2020-01-11 08:45:05 +00:00
2018-05-04 18:05:45 +00:00
if ( CMAKE_C_COMPILER_ID STREQUAL "Intel" )
# icc needs the restrict flag to recognize C99 restrict pointers
2018-06-02 10:50:57 +00:00
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -restrict" )
2018-05-04 18:05:45 +00:00
else () # not intel
# gcc and clang support bad function cast and alignment warnings; add them as well.
2018-06-02 10:50:57 +00:00
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wbad-function-cast -Wcast-align" )
Revise the sequencer's event queue (#604)
Proposing a new event queue for the sequencer, based on prior discussion:
https://lists.nongnu.org/archive/html/fluid-dev/2019-12/msg00001.html
With this change fluidsynth will require a C++98 compliant compiler.
Consider this as RFC, feedback is welcome.
The "pain-points" from the discussion:
#### 1. It is slow.
Done (thanks to heap sort), see runtime of `test_seq_event_queue_sort`.
#### 2. A meaningful ordering for events with the same tick has not been considered.
Done, see comments in `fluid_seq_queue.cpp`.
#### 3. Complicated implementation
Now uses one single event queue, which requires C++98. Implemented similarly to std::priority_queue by using heap sort.
The "queue" I use currently is of type `std::deque`. `deque` does not provide preallocation. `std::vector` does provide it. However, `std::deque` has the huge advantage that appending additional elements is cheap. For `std::vector` appending new elements would require to reallocate all the memory and copy it to the new array. So,
* either use `std::deque` with the risk that memory allocation may occur during `fluid_sequencer_send_at()`, or
* use `std::vector` with a preallocated pool of events and make `fluid_sequencer_send_at()` when the `vector` runs out of capacity.
Comments?
#### 4. Events that have been processed are deleted and gone.
After having thought about this more, this is the correct behavior. After events have been dispatched, they must be released to free underlying memory, see point 3. For the very rare case that a client (e.g. fluid_player) may require those events in the future, the client should be responsible for storing the events somewhere.
#### 5. The sequencer supports the system timer as alternative time source.
The conclusion from the mailing list was that the system timer can be removed. This has been done.
#### 6. Time Scaling
Time scaling can now be used for arbitrary tempo changes. The previous implementation was capable of that as well, however, the time-scale was limited to 1000. The only limitation for the scale is now >0, see `test_seq_scale`.
### Other Points
* `fluid_sequencer_remove_events()` turned out to be broken before, as it did not remove all events from the queue. This has been fixed, see `test_seq_event_queue_remove`.
* Consider the following code executed by `threadA`:
```c
fluid_sequencer_send_at(event0);
fluid_sequencer_set_time_scale(); // new scale
fluid_sequencer_send_at(event1);
```
The new scale will be definitely applied to `event1`. However, if another concurrently running `threadB` executes `fluid_sequencer_process()`, it was previously not clear, whether the new scale was also applied to event0. This depends on whether `event0` was still in the `preQueue`, and this depends on `event0.time` and the tick count that `fluid_sequencer_process()` is being called with. This has been changed. As of now, events are queued with their timestamp AS-IS. And only the latest call to `fluid_sequencer_set_time_scale()` is being considered during `fluid_sequencer_process()`. This makes the implementation very simple, i.e. no events need to be changed and the sequencer doesn't have to be locked down. On the other hand, it means that `fluid_sequencer_set_time_scale()` can only be used for tempo changes when called from the sequencer callback. In other words, if `threadA` executes the code above followed by `fluid_sequencer_process()`, `event0` and `event1` will be executed with the same tempo, which is the latest scale provided to the seq. Is this acceptable? The old implementation had the same limitation. And when looking through the internet, I only find users who call `fluid_sequencer_set_time_scale()` from the sequencer callback. Still, this is a point I'm raising for discussion.
2020-05-26 15:16:22 +00:00
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wcast-align" )
2018-05-04 18:05:45 +00:00
2019-03-27 17:02:23 +00:00
if ( enable-ubsan )
2019-07-10 15:01:12 +00:00
set ( CMAKE_C_FLAGS "-fsanitize=address,undefined ${CMAKE_C_FLAGS}" )
Revise the sequencer's event queue (#604)
Proposing a new event queue for the sequencer, based on prior discussion:
https://lists.nongnu.org/archive/html/fluid-dev/2019-12/msg00001.html
With this change fluidsynth will require a C++98 compliant compiler.
Consider this as RFC, feedback is welcome.
The "pain-points" from the discussion:
#### 1. It is slow.
Done (thanks to heap sort), see runtime of `test_seq_event_queue_sort`.
#### 2. A meaningful ordering for events with the same tick has not been considered.
Done, see comments in `fluid_seq_queue.cpp`.
#### 3. Complicated implementation
Now uses one single event queue, which requires C++98. Implemented similarly to std::priority_queue by using heap sort.
The "queue" I use currently is of type `std::deque`. `deque` does not provide preallocation. `std::vector` does provide it. However, `std::deque` has the huge advantage that appending additional elements is cheap. For `std::vector` appending new elements would require to reallocate all the memory and copy it to the new array. So,
* either use `std::deque` with the risk that memory allocation may occur during `fluid_sequencer_send_at()`, or
* use `std::vector` with a preallocated pool of events and make `fluid_sequencer_send_at()` when the `vector` runs out of capacity.
Comments?
#### 4. Events that have been processed are deleted and gone.
After having thought about this more, this is the correct behavior. After events have been dispatched, they must be released to free underlying memory, see point 3. For the very rare case that a client (e.g. fluid_player) may require those events in the future, the client should be responsible for storing the events somewhere.
#### 5. The sequencer supports the system timer as alternative time source.
The conclusion from the mailing list was that the system timer can be removed. This has been done.
#### 6. Time Scaling
Time scaling can now be used for arbitrary tempo changes. The previous implementation was capable of that as well, however, the time-scale was limited to 1000. The only limitation for the scale is now >0, see `test_seq_scale`.
### Other Points
* `fluid_sequencer_remove_events()` turned out to be broken before, as it did not remove all events from the queue. This has been fixed, see `test_seq_event_queue_remove`.
* Consider the following code executed by `threadA`:
```c
fluid_sequencer_send_at(event0);
fluid_sequencer_set_time_scale(); // new scale
fluid_sequencer_send_at(event1);
```
The new scale will be definitely applied to `event1`. However, if another concurrently running `threadB` executes `fluid_sequencer_process()`, it was previously not clear, whether the new scale was also applied to event0. This depends on whether `event0` was still in the `preQueue`, and this depends on `event0.time` and the tick count that `fluid_sequencer_process()` is being called with. This has been changed. As of now, events are queued with their timestamp AS-IS. And only the latest call to `fluid_sequencer_set_time_scale()` is being considered during `fluid_sequencer_process()`. This makes the implementation very simple, i.e. no events need to be changed and the sequencer doesn't have to be locked down. On the other hand, it means that `fluid_sequencer_set_time_scale()` can only be used for tempo changes when called from the sequencer callback. In other words, if `threadA` executes the code above followed by `fluid_sequencer_process()`, `event0` and `event1` will be executed with the same tempo, which is the latest scale provided to the seq. Is this acceptable? The old implementation had the same limitation. And when looking through the internet, I only find users who call `fluid_sequencer_set_time_scale()` from the sequencer callback. Still, this is a point I'm raising for discussion.
2020-05-26 15:16:22 +00:00
set ( CMAKE_CXX_FLAGS "-fsanitize=address,undefined ${CMAKE_CXX_FLAGS}" )
2019-07-10 15:01:12 +00:00
set ( CMAKE_EXE_LINKER_FLAGS "-fsanitize=address,undefined ${CMAKE_EXE_LINKER_FLAGS}" )
set ( CMAKE_SHARED_LINKER_FLAGS "-fsanitize=address,undefined ${CMAKE_SHARED_LINKER_FLAGS}" )
2019-03-27 17:02:23 +00:00
set ( ENABLE_UBSAN 1 )
endif ( enable-ubsan )
2021-04-03 15:34:48 +00:00
if ( enable-coverage )
if ( CMAKE_COMPILER_IS_GNUCXX )
include ( CodeCoverage )
set ( CODE_COVERAGE_VERBOSE TRUE )
append_coverage_compiler_flags()
setup_target_for_coverage_gcovr_html (
NAME coverage
EXECUTABLE ${CMAKE_CTEST_COMMAND} -C $<CONFIG> --output-on-failure
DEPENDENCIES check )
set ( ENABLE_COVERAGE 1 )
else()
message ( SEND_ERROR "Code Coverage is currently only supported for GNU Compiler (GCC)" )
endif()
endif ()
2018-05-04 18:05:45 +00:00
endif (CMAKE_C_COMPILER_ID STREQUAL "Intel" )
2019-11-13 19:27:48 +00:00
endif ( CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID STREQUAL "Intel" )
2010-03-17 20:14:13 +00:00
# Windows
2010-10-16 15:36:06 +00:00
unset ( WINDOWS_LIBS CACHE )
2018-10-26 17:48:01 +00:00
unset ( DSOUND_SUPPORT CACHE )
2021-01-29 17:11:17 +00:00
unset ( WASAPI_SUPPORT CACHE )
2018-12-01 14:04:26 +00:00
unset ( WAVEOUT_SUPPORT CACHE )
2018-10-26 17:48:01 +00:00
unset ( WINMIDI_SUPPORT CACHE )
2010-10-16 15:36:06 +00:00
unset ( MINGW32 CACHE )
2010-03-17 20:14:13 +00:00
if ( WIN32 )
2010-04-10 10:45:44 +00:00
include ( CheckIncludeFiles )
2018-10-26 17:48:01 +00:00
2021-05-07 07:45:17 +00:00
# We have to set _WIN32_WINNT to make sure CMake gets correct results when probing for functions.
# windows-version is supposed to be non-official variable that can be used to tweak the Windows target version.
# Its value defaults to the Windows Version we are compiling for.
if ( NOT windows-version )
if(${CMAKE_SYSTEM_VERSION} EQUAL 10) # Windows 10
set ( windows-version "0x0A00" )
elseif(${CMAKE_SYSTEM_VERSION} EQUAL 6.3) # Windows 8.1
set ( windows-version "0x0603" )
elseif(${CMAKE_SYSTEM_VERSION} EQUAL 6.2) # Windows 8
set ( windows-version "0x0602" )
elseif(${CMAKE_SYSTEM_VERSION} EQUAL 6.1) # Windows 7
set ( windows-version "0x0601" )
elseif(${CMAKE_SYSTEM_VERSION} EQUAL 6.0) # Windows Vista
set ( windows-version "0x0600" )
elseif(${CMAKE_SYSTEM_VERSION} EQUAL 5.1) # Windows XP
set ( windows-version "0x0501" )
else()
set ( windows-version "0x0400" )
endif()
endif ()
message ( STATUS "Targetting Windows Version ${windows-version}" )
add_definitions ( -D _WIN32_WINNT=${windows-version} )
add_definitions ( -D WINVER=${windows-version} )
list ( APPEND CMAKE_REQUIRED_DEFINITIONS "-DWINVER=${windows-version}" )
list ( APPEND CMAKE_REQUIRED_DEFINITIONS "-D_WIN32_WINNT=${windows-version}" )
2018-10-26 17:48:01 +00:00
# Check presence of MS include files
2010-03-17 20:14:13 +00:00
check_include_file ( windows.h HAVE_WINDOWS_H )
2018-12-22 15:01:12 +00:00
check_include_file ( io.h HAVE_IO_H )
2010-03-17 20:14:13 +00:00
check_include_file ( dsound.h HAVE_DSOUND_H )
2010-04-10 10:45:44 +00:00
check_include_files ( "windows.h;mmsystem.h" HAVE_MMSYSTEM_H )
2021-01-29 17:11:17 +00:00
check_include_files ( "mmdeviceapi.h;audioclient.h" HAVE_WASAPI_HEADERS )
check_include_file ( objbase.h HAVE_OBJBASE_H )
2018-10-26 17:48:01 +00:00
2018-10-27 08:11:28 +00:00
if ( enable-network )
2018-10-26 17:48:01 +00:00
set ( WINDOWS_LIBS "${WINDOWS_LIBS};ws2_32" )
2018-10-27 08:11:28 +00:00
endif ( enable-network )
2018-10-26 17:48:01 +00:00
if ( enable-dsound AND HAVE_DSOUND_H )
2021-04-29 19:03:19 +00:00
set ( WINDOWS_LIBS "${WINDOWS_LIBS};dsound;ksuser" )
2018-10-26 17:48:01 +00:00
set ( DSOUND_SUPPORT 1 )
endif ()
if ( enable-winmidi AND HAVE_MMSYSTEM_H )
set ( WINDOWS_LIBS "${WINDOWS_LIBS};winmm" )
set ( WINMIDI_SUPPORT 1 )
endif ()
2018-12-01 14:04:26 +00:00
if ( enable-waveout AND HAVE_MMSYSTEM_H )
2021-04-29 19:03:19 +00:00
set ( WINDOWS_LIBS "${WINDOWS_LIBS};winmm;ksuser" )
2018-12-01 14:04:26 +00:00
set ( WAVEOUT_SUPPORT 1 )
endif ()
2021-01-29 17:11:17 +00:00
if ( enable-wasapi AND HAVE_WASAPI_HEADERS AND HAVE_OBJBASE_H)
set ( WINDOWS_LIBS "${WINDOWS_LIBS};ole32" )
set ( WASAPI_SUPPORT 1 )
endif ()
2017-10-01 08:17:22 +00:00
set ( LIBFLUID_CPPFLAGS "-DFLUIDSYNTH_DLL_EXPORTS" )
2010-03-17 20:14:13 +00:00
set ( FLUID_CPPFLAGS "-DFLUIDSYNTH_NOT_A_DLL" )
2021-04-13 19:12:25 +00:00
if ( NOT MSVC )
2018-08-08 18:12:37 +00:00
# only set debug postfix if not MSVS building
2018-02-11 16:07:38 +00:00
set ( CMAKE_DEBUG_POSTFIX "_debug" )
2021-04-13 19:12:25 +00:00
endif ( NOT MSVC )
2020-01-11 08:45:05 +00:00
2010-03-17 20:14:13 +00:00
# MinGW compiler (a Windows GCC port)
2010-10-31 16:15:32 +00:00
if ( MINGW )
2010-03-17 20:14:13 +00:00
set ( MINGW32 1 )
2018-10-26 17:49:27 +00:00
add_compile_options ( -mms-bitfields )
2010-03-17 20:14:13 +00:00
endif ( MINGW )
else ( WIN32 )
2010-10-31 16:15:32 +00:00
# Check PThreads, but not in Windows
2017-07-01 21:53:47 +00:00
find_package ( Threads REQUIRED )
set ( LIBFLUID_LIBS "m" ${CMAKE_THREAD_LIBS_INIT} )
2010-03-17 20:14:13 +00:00
endif ( WIN32 )
# IBM OS/2
2010-10-16 15:36:06 +00:00
unset ( DART_SUPPORT CACHE )
2010-10-31 16:15:32 +00:00
unset ( DART_LIBS CACHE )
2010-10-16 15:36:06 +00:00
unset ( DART_INCLUDE_DIRS CACHE )
2016-01-21 12:25:21 +00:00
if ( CMAKE_SYSTEM MATCHES "OS2" )
2010-03-17 20:14:13 +00:00
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Zbin-files" )
2010-11-21 15:12:37 +00:00
set ( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Zbin-files" )
2010-03-17 20:14:13 +00:00
if ( enable-dart )
2014-03-15 12:20:50 +00:00
check_include_files ( "os2.h;os2me.h" HAVE_DART_H )
2010-03-17 20:14:13 +00:00
set ( DART_SUPPORT ${HAVE_DART_H} )
2010-10-16 15:36:06 +00:00
unset ( DART_INCLUDE_DIRS CACHE )
2010-03-17 20:14:13 +00:00
endif ( enable-dart )
2016-01-21 12:25:21 +00:00
endif ( CMAKE_SYSTEM MATCHES "OS2" )
2010-03-17 20:14:13 +00:00
# Solaris / SunOS
2016-01-21 12:25:21 +00:00
if ( CMAKE_SYSTEM MATCHES "SunOS" )
2010-10-31 16:15:32 +00:00
set ( FLUID_LIBS "${FLUID_LIBS};nsl;socket" )
set ( LIBFLUID_LIBS "${LIBFLUID_LIBS};nsl;socket" )
2016-01-21 12:25:21 +00:00
endif ( CMAKE_SYSTEM MATCHES "SunOS" )
2010-03-17 20:14:13 +00:00
# Apple Mac OSX
2010-10-16 15:36:06 +00:00
unset ( COREAUDIO_SUPPORT CACHE )
2010-10-31 16:15:32 +00:00
unset ( COREAUDIO_LIBS CACHE )
2010-10-16 15:36:06 +00:00
unset ( COREMIDI_SUPPORT CACHE )
unset ( COREMIDI_LIBS CACHE )
2010-10-31 16:15:32 +00:00
unset ( DARWIN CACHE )
2010-10-16 15:36:06 +00:00
unset ( MACOSX_FRAMEWORK CACHE )
2016-01-21 12:25:21 +00:00
if ( CMAKE_SYSTEM MATCHES "Darwin" )
2010-03-17 20:14:13 +00:00
set ( DARWIN 1 )
2010-10-31 16:15:32 +00:00
set ( CMAKE_INSTALL_NAME_DIR
2018-02-20 16:05:16 +00:00
${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR} )
2010-03-17 20:14:13 +00:00
if ( enable-coreaudio )
check_include_file ( CoreAudio/AudioHardware.h COREAUDIO_FOUND )
if ( COREAUDIO_FOUND )
set ( COREAUDIO_SUPPORT ${COREAUDIO_FOUND} )
2010-10-17 18:12:30 +00:00
set ( COREAUDIO_LIBS "-Wl,-framework,CoreAudio,-framework,AudioUnit" )
2010-03-17 20:14:13 +00:00
endif ( COREAUDIO_FOUND )
endif ( enable-coreaudio )
if ( enable-coremidi )
check_include_file ( CoreMIDI/MIDIServices.h COREMIDI_FOUND )
if ( COREMIDI_FOUND )
set ( COREMIDI_SUPPORT ${COREMIDI_FOUND} )
set ( COREMIDI_LIBS "-Wl,-framework,CoreMIDI,-framework,CoreServices" )
endif ( COREMIDI_FOUND )
endif ( enable-coremidi )
2010-10-13 21:57:19 +00:00
if ( enable-framework )
set ( MACOSX_FRAMEWORK 1 )
endif ( enable-framework )
2016-01-21 12:25:21 +00:00
endif ( CMAKE_SYSTEM MATCHES "Darwin" )
2010-03-17 20:14:13 +00:00
2017-12-17 09:25:54 +00:00
unset ( NETWORK_SUPPORT )
if ( enable-network )
set ( NETWORK_SUPPORT 1 )
endif ( enable-network )
2010-10-16 15:36:06 +00:00
unset ( WITH_FLOAT CACHE )
2010-03-17 20:14:13 +00:00
if ( enable-floats )
set ( WITH_FLOAT 1 )
endif ( enable-floats )
2010-10-16 15:36:06 +00:00
unset ( WITH_PROFILING CACHE )
2010-03-17 20:14:13 +00:00
if ( enable-profiling )
set ( WITH_PROFILING 1 )
2018-01-03 15:40:53 +00:00
if ( CMAKE_C_COMPILER_ID STREQUAL "Clang" )
2019-08-08 18:48:15 +00:00
set ( OPT_FLAGS "-Rpass=loop-vectorize" ) # -Rpass-analysis=loop-vectorize" )
2018-01-03 15:40:53 +00:00
elseif ( CMAKE_C_COMPILER_ID STREQUAL "Intel" )
set ( OPT_FLAGS "-qopt-report=3" )
2018-02-11 15:56:53 +00:00
elseif ( CMAKE_C_COMPILER_ID STREQUAL "GNU" )
2018-04-25 15:28:37 +00:00
set ( OPT_FLAGS "" )
2018-01-03 15:40:53 +00:00
endif ( )
2018-06-02 10:50:57 +00:00
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OPT_FLAGS}" )
2018-12-01 12:56:51 +00:00
if ( CMAKE_VERSION VERSION_GREATER "3.6.0" )
find_program( CLANG_TIDY
NAMES "clang-tidy"
DOC "Path to clang-tidy executable" )
if ( CLANG_TIDY )
2019-08-08 17:23:16 +00:00
message ( STATUS "Found clang-tidy at ${CLANG_TIDY}" )
execute_process ( COMMAND ${CLANG_TIDY} "--version" )
set ( CMAKE_C_CLANG_TIDY ${CLANG_TIDY} )
2018-12-01 12:56:51 +00:00
endif ( CLANG_TIDY )
endif ( CMAKE_VERSION VERSION_GREATER "3.6.0" )
2010-10-31 16:15:32 +00:00
endif ( enable-profiling )
2010-03-17 20:14:13 +00:00
2010-10-16 15:36:06 +00:00
unset ( ENABLE_TRAPONFPE CACHE )
unset ( TRAP_ON_FPE CACHE )
2010-03-17 20:14:13 +00:00
if ( enable-trap-on-fpe AND NOT APPLE AND NOT WIN32 )
set ( ENABLE_TRAPONFPE 1 )
set ( TRAP_ON_FPE 1 )
endif ( enable-trap-on-fpe AND NOT APPLE AND NOT WIN32 )
2010-10-16 15:36:06 +00:00
unset ( ENABLE_FPECHECK CACHE )
2010-10-31 16:15:32 +00:00
unset ( FPE_CHECK CACHE )
2019-08-02 11:51:56 +00:00
if ( enable-fpe-check AND NOT APPLE AND NOT WIN32 )
2010-03-17 20:14:13 +00:00
set ( ENABLE_FPECHECK 1 )
set ( FPE_CHECK 1 )
2019-08-02 11:51:56 +00:00
endif ( enable-fpe-check AND NOT APPLE AND NOT WIN32 )
2010-10-31 16:15:32 +00:00
if ( enable-debug )
2010-03-17 20:14:13 +00:00
set ( CMAKE_BUILD_TYPE "Debug" CACHE STRING
2018-06-02 10:50:57 +00:00
"Choose the build type, options: Debug Release RelWithDebInfo MinSizeRel" FORCE )
2010-03-17 20:14:13 +00:00
endif ( enable-debug )
2012-08-04 16:58:48 +00:00
if ( NOT CMAKE_BUILD_TYPE )
set ( CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
2018-06-02 10:50:57 +00:00
"Choose the build type, options: Debug Release RelWithDebInfo MinSizeRel" FORCE )
2012-08-04 16:58:48 +00:00
endif ( NOT CMAKE_BUILD_TYPE )
2010-10-16 15:36:06 +00:00
unset ( ENABLE_DEBUG CACHE )
2010-03-17 20:14:13 +00:00
if ( CMAKE_BUILD_TYPE MATCHES "Debug" )
set ( ENABLE_DEBUG 1 )
Revise the sequencer's event queue (#604)
Proposing a new event queue for the sequencer, based on prior discussion:
https://lists.nongnu.org/archive/html/fluid-dev/2019-12/msg00001.html
With this change fluidsynth will require a C++98 compliant compiler.
Consider this as RFC, feedback is welcome.
The "pain-points" from the discussion:
#### 1. It is slow.
Done (thanks to heap sort), see runtime of `test_seq_event_queue_sort`.
#### 2. A meaningful ordering for events with the same tick has not been considered.
Done, see comments in `fluid_seq_queue.cpp`.
#### 3. Complicated implementation
Now uses one single event queue, which requires C++98. Implemented similarly to std::priority_queue by using heap sort.
The "queue" I use currently is of type `std::deque`. `deque` does not provide preallocation. `std::vector` does provide it. However, `std::deque` has the huge advantage that appending additional elements is cheap. For `std::vector` appending new elements would require to reallocate all the memory and copy it to the new array. So,
* either use `std::deque` with the risk that memory allocation may occur during `fluid_sequencer_send_at()`, or
* use `std::vector` with a preallocated pool of events and make `fluid_sequencer_send_at()` when the `vector` runs out of capacity.
Comments?
#### 4. Events that have been processed are deleted and gone.
After having thought about this more, this is the correct behavior. After events have been dispatched, they must be released to free underlying memory, see point 3. For the very rare case that a client (e.g. fluid_player) may require those events in the future, the client should be responsible for storing the events somewhere.
#### 5. The sequencer supports the system timer as alternative time source.
The conclusion from the mailing list was that the system timer can be removed. This has been done.
#### 6. Time Scaling
Time scaling can now be used for arbitrary tempo changes. The previous implementation was capable of that as well, however, the time-scale was limited to 1000. The only limitation for the scale is now >0, see `test_seq_scale`.
### Other Points
* `fluid_sequencer_remove_events()` turned out to be broken before, as it did not remove all events from the queue. This has been fixed, see `test_seq_event_queue_remove`.
* Consider the following code executed by `threadA`:
```c
fluid_sequencer_send_at(event0);
fluid_sequencer_set_time_scale(); // new scale
fluid_sequencer_send_at(event1);
```
The new scale will be definitely applied to `event1`. However, if another concurrently running `threadB` executes `fluid_sequencer_process()`, it was previously not clear, whether the new scale was also applied to event0. This depends on whether `event0` was still in the `preQueue`, and this depends on `event0.time` and the tick count that `fluid_sequencer_process()` is being called with. This has been changed. As of now, events are queued with their timestamp AS-IS. And only the latest call to `fluid_sequencer_set_time_scale()` is being considered during `fluid_sequencer_process()`. This makes the implementation very simple, i.e. no events need to be changed and the sequencer doesn't have to be locked down. On the other hand, it means that `fluid_sequencer_set_time_scale()` can only be used for tempo changes when called from the sequencer callback. In other words, if `threadA` executes the code above followed by `fluid_sequencer_process()`, `event0` and `event1` will be executed with the same tempo, which is the latest scale provided to the seq. Is this acceptable? The old implementation had the same limitation. And when looking through the internet, I only find users who call `fluid_sequencer_set_time_scale()` from the sequencer callback. Still, this is a point I'm raising for discussion.
2020-05-26 15:16:22 +00:00
add_definitions(-DDEBUG) # -D_GLIBCXX_DEBUG) # for additional C++ STL container debugging
2010-03-17 20:14:13 +00:00
endif ( CMAKE_BUILD_TYPE MATCHES "Debug" )
2018-03-22 19:40:54 +00:00
# Additional targets to perform clang-format/clang-tidy
# Get all project files
file(GLOB_RECURSE
ALL_SOURCE_FILES
LIST_DIRECTORIES false
${CMAKE_SOURCE_DIR}/*.[chi]
${CMAKE_SOURCE_DIR}/*.[chi]pp
${CMAKE_SOURCE_DIR}/*.[chi]xx
${CMAKE_SOURCE_DIR}/*.cc
${CMAKE_SOURCE_DIR}/*.hh
${CMAKE_SOURCE_DIR}/*.ii
${CMAKE_SOURCE_DIR}/*.[CHI]
)
2018-06-21 10:14:05 +00:00
find_program ( ASTYLE "astyle" )
if ( ASTYLE )
2018-03-22 19:40:54 +00:00
add_custom_target(
format
2018-06-21 10:14:05 +00:00
COMMAND ${ASTYLE}
-A1
-xb
-j
-k3
-p
-f
-n
-U
2018-03-22 19:40:54 +00:00
${ALL_SOURCE_FILES}
)
2018-06-21 10:14:05 +00:00
endif(ASTYLE)
2017-08-28 18:03:42 +00:00
if(NOT enable-pkgconfig)
2017-11-19 20:45:00 +00:00
FIND_LIBRARY( GLIB_LIB NAMES glib glib-2.0 PATH GLIB_LIBRARY_DIR )
FIND_LIBRARY( GTHREAD_LIB NAMES gthread gthread-2.0 PATH GTHREAD_LIBRARY_DIR )
FIND_PATH( GLIBH_DIR glib.h PATH GLIB_INCLUDE_DIR )
FIND_PATH( GLIBCONF_DIR glibconfig.h PATH GLIBCONF_INCLUDE_DIR )
2020-01-11 08:43:46 +00:00
2017-08-28 18:03:42 +00:00
IF( GLIB_LIB MATCHES "GLIB_LIB-NOTFOUND" OR
GTHREAD_LIB MATCHES "GTHREAD_LIB-NOTFOUND" OR
GLIBH_DIR MATCHES "GLIBH_DIR-NOTFOUND" OR
GLIBCONF_DIR MATCHES "GLIBCONF_DIR-NOTFOUND")
message( WARNING "Not sure if I found GLIB, continuing anyway.")
ENDIF()
2020-01-11 08:43:46 +00:00
2017-08-28 18:03:42 +00:00
SET( GLIB_INCLUDE_DIRS ${GLIBH_DIR} ${GLIBCONF_DIR} )
SET( GLIB_LIBRARIES ${GLIB_LIB} ${GTHREAD_LIB} )
2020-01-11 08:43:46 +00:00
2017-08-28 18:03:42 +00:00
message( STATUS "GLIB_INCLUDE_DIRS: " ${GLIB_INCLUDE_DIRS} )
message( STATUS "GLIB_LIBRARIES: " ${GLIB_LIBRARIES} )
else(NOT enable-pkgconfig)
find_package ( PkgConfig REQUIRED )
# Mandatory libraries: glib and gthread
pkg_check_modules ( GLIB REQUIRED glib-2.0>=2.6.5 gthread-2.0>=2.6.5 )
2019-02-08 18:59:46 +00:00
if ( GLIB_glib-2.0_VERSION AND GLIB_glib-2.0_VERSION VERSION_LESS "2.26.0" )
2019-02-03 15:35:19 +00:00
message ( WARNING "Your version of glib is very old. This may cause problems with fluidsynth's sample cache on Windows. Consider updating to glib 2.26 or newer!" )
2019-02-08 18:59:46 +00:00
endif ( GLIB_glib-2.0_VERSION AND GLIB_glib-2.0_VERSION VERSION_LESS "2.26.0" )
2019-02-03 15:35:19 +00:00
2017-08-28 18:03:42 +00:00
include ( UnsetPkgConfig )
# Optional features
unset ( LIBSNDFILE_SUPPORT CACHE )
unset ( LIBSNDFILE_HASVORBIS CACHE )
if ( enable-libsndfile )
pkg_check_modules ( LIBSNDFILE sndfile>=1.0.0 )
set ( LIBSNDFILE_SUPPORT ${LIBSNDFILE_FOUND} )
if ( LIBSNDFILE_SUPPORT )
pkg_check_modules ( LIBSNDFILE_VORBIS sndfile>=1.0.18 )
set ( LIBSNDFILE_HASVORBIS ${LIBSNDFILE_VORBIS_FOUND} )
endif ( LIBSNDFILE_SUPPORT )
else ( enable-libsndfile )
unset_pkg_config ( LIBSNDFILE )
unset_pkg_config ( LIBSNDFILE_VORBIS )
endif ( enable-libsndfile )
unset ( PULSE_SUPPORT CACHE )
if ( enable-pulseaudio )
pkg_check_modules ( PULSE libpulse-simple>=0.9.8 )
set ( PULSE_SUPPORT ${PULSE_FOUND} )
else ( enable-pulseaudio )
unset_pkg_config ( PULSE )
endif ( enable-pulseaudio )
unset ( ALSA_SUPPORT CACHE )
if ( enable-alsa )
pkg_check_modules ( ALSA alsa>=0.9.1 )
set ( ALSA_SUPPORT ${ALSA_FOUND} )
else ( enable-alsa )
unset_pkg_config ( ALSA )
endif ( enable-alsa )
unset ( PORTAUDIO_SUPPORT CACHE )
if ( enable-portaudio )
pkg_check_modules ( PORTAUDIO portaudio-2.0>=19 )
set ( PORTAUDIO_SUPPORT ${PORTAUDIO_FOUND} )
else ( enable-portaudio )
unset_pkg_config ( PORTAUDIO )
endif ( enable-portaudio )
2020-01-11 08:43:46 +00:00
2017-08-28 18:03:42 +00:00
unset ( JACK_SUPPORT CACHE )
if ( enable-jack )
pkg_check_modules ( JACK jack )
set ( JACK_SUPPORT ${JACK_FOUND} )
else ( enable-jack )
unset_pkg_config ( JACK )
endif ( enable-jack )
2020-01-11 08:43:46 +00:00
2017-08-28 18:03:42 +00:00
unset ( LASH_SUPPORT CACHE )
if ( enable-lash )
pkg_check_modules ( LASH lash-1.0>=0.3 )
if ( LASH_FOUND )
set ( LASH_SUPPORT 1 )
add_definitions ( -DHAVE_LASH )
endif ( LASH_FOUND )
else ( enable-lash )
unset_pkg_config ( LASH )
remove_definitions( -DHAVE_LASH )
endif ( enable-lash )
2019-02-26 08:05:49 +00:00
unset ( SYSTEMD_SUPPORT CACHE )
if ( enable-systemd )
pkg_check_modules ( SYSTEMD libsystemd )
set ( SYSTEMD_SUPPORT ${SYSTEMD_FOUND} )
else ( enable-systemd )
unset_pkg_config ( SYSTEMD )
endif ( enable-systemd )
2017-08-28 18:03:42 +00:00
unset ( DBUS_SUPPORT CACHE )
if ( enable-dbus )
pkg_check_modules ( DBUS dbus-1>=1.0.0 )
set ( DBUS_SUPPORT ${DBUS_FOUND} )
else ( enable-dbus )
unset_pkg_config ( DBUS )
endif ( enable-dbus )
2017-11-19 20:45:00 +00:00
unset ( LADSPA_SUPPORT CACHE )
if ( enable-ladspa )
check_include_file ( ladspa.h LADSPA_SUPPORT )
if ( LADSPA_SUPPORT )
pkg_check_modules ( GMODULE REQUIRED gmodule-2.0>=2.6.5 )
set ( LADSPA 1 )
endif ( LADSPA_SUPPORT )
endif ( enable-ladspa )
2019-05-11 03:31:56 +00:00
unset ( LIBINSTPATCH_SUPPORT CACHE )
if ( enable-libinstpatch )
2019-10-23 15:12:01 +00:00
pkg_check_modules ( LIBINSTPATCH libinstpatch-1.0>=1.1.0 )
2019-05-11 03:31:56 +00:00
set ( LIBINSTPATCH_SUPPORT ${LIBINSTPATCH_FOUND} )
endif ( enable-libinstpatch )
2019-04-06 07:10:50 +00:00
unset ( SDL2_SUPPORT CACHE )
if ( enable-sdl2 )
pkg_check_modules ( SDL2 sdl2 )
set ( SDL2_SUPPORT ${SDL2_FOUND} )
else ( enable-sdl2 )
unset_pkg_config ( SDL2 )
endif ( enable-sdl2 )
2020-01-11 08:43:46 +00:00
unset ( OBOE_SUPPORT CACHE )
unset ( OBOE_LIBS CACHE )
if ( enable-oboe )
Revise the sequencer's event queue (#604)
Proposing a new event queue for the sequencer, based on prior discussion:
https://lists.nongnu.org/archive/html/fluid-dev/2019-12/msg00001.html
With this change fluidsynth will require a C++98 compliant compiler.
Consider this as RFC, feedback is welcome.
The "pain-points" from the discussion:
#### 1. It is slow.
Done (thanks to heap sort), see runtime of `test_seq_event_queue_sort`.
#### 2. A meaningful ordering for events with the same tick has not been considered.
Done, see comments in `fluid_seq_queue.cpp`.
#### 3. Complicated implementation
Now uses one single event queue, which requires C++98. Implemented similarly to std::priority_queue by using heap sort.
The "queue" I use currently is of type `std::deque`. `deque` does not provide preallocation. `std::vector` does provide it. However, `std::deque` has the huge advantage that appending additional elements is cheap. For `std::vector` appending new elements would require to reallocate all the memory and copy it to the new array. So,
* either use `std::deque` with the risk that memory allocation may occur during `fluid_sequencer_send_at()`, or
* use `std::vector` with a preallocated pool of events and make `fluid_sequencer_send_at()` when the `vector` runs out of capacity.
Comments?
#### 4. Events that have been processed are deleted and gone.
After having thought about this more, this is the correct behavior. After events have been dispatched, they must be released to free underlying memory, see point 3. For the very rare case that a client (e.g. fluid_player) may require those events in the future, the client should be responsible for storing the events somewhere.
#### 5. The sequencer supports the system timer as alternative time source.
The conclusion from the mailing list was that the system timer can be removed. This has been done.
#### 6. Time Scaling
Time scaling can now be used for arbitrary tempo changes. The previous implementation was capable of that as well, however, the time-scale was limited to 1000. The only limitation for the scale is now >0, see `test_seq_scale`.
### Other Points
* `fluid_sequencer_remove_events()` turned out to be broken before, as it did not remove all events from the queue. This has been fixed, see `test_seq_event_queue_remove`.
* Consider the following code executed by `threadA`:
```c
fluid_sequencer_send_at(event0);
fluid_sequencer_set_time_scale(); // new scale
fluid_sequencer_send_at(event1);
```
The new scale will be definitely applied to `event1`. However, if another concurrently running `threadB` executes `fluid_sequencer_process()`, it was previously not clear, whether the new scale was also applied to event0. This depends on whether `event0` was still in the `preQueue`, and this depends on `event0.time` and the tick count that `fluid_sequencer_process()` is being called with. This has been changed. As of now, events are queued with their timestamp AS-IS. And only the latest call to `fluid_sequencer_set_time_scale()` is being considered during `fluid_sequencer_process()`. This makes the implementation very simple, i.e. no events need to be changed and the sequencer doesn't have to be locked down. On the other hand, it means that `fluid_sequencer_set_time_scale()` can only be used for tempo changes when called from the sequencer callback. In other words, if `threadA` executes the code above followed by `fluid_sequencer_process()`, `event0` and `event1` will be executed with the same tempo, which is the latest scale provided to the seq. Is this acceptable? The old implementation had the same limitation. And when looking through the internet, I only find users who call `fluid_sequencer_set_time_scale()` from the sequencer callback. Still, this is a point I'm raising for discussion.
2020-05-26 15:16:22 +00:00
pkg_check_modules ( OBOE oboe-1.0 )
if ( OBOE_FOUND )
2021-01-13 18:02:13 +00:00
set(CMAKE_CXX_STANDARD 14)
Revise the sequencer's event queue (#604)
Proposing a new event queue for the sequencer, based on prior discussion:
https://lists.nongnu.org/archive/html/fluid-dev/2019-12/msg00001.html
With this change fluidsynth will require a C++98 compliant compiler.
Consider this as RFC, feedback is welcome.
The "pain-points" from the discussion:
#### 1. It is slow.
Done (thanks to heap sort), see runtime of `test_seq_event_queue_sort`.
#### 2. A meaningful ordering for events with the same tick has not been considered.
Done, see comments in `fluid_seq_queue.cpp`.
#### 3. Complicated implementation
Now uses one single event queue, which requires C++98. Implemented similarly to std::priority_queue by using heap sort.
The "queue" I use currently is of type `std::deque`. `deque` does not provide preallocation. `std::vector` does provide it. However, `std::deque` has the huge advantage that appending additional elements is cheap. For `std::vector` appending new elements would require to reallocate all the memory and copy it to the new array. So,
* either use `std::deque` with the risk that memory allocation may occur during `fluid_sequencer_send_at()`, or
* use `std::vector` with a preallocated pool of events and make `fluid_sequencer_send_at()` when the `vector` runs out of capacity.
Comments?
#### 4. Events that have been processed are deleted and gone.
After having thought about this more, this is the correct behavior. After events have been dispatched, they must be released to free underlying memory, see point 3. For the very rare case that a client (e.g. fluid_player) may require those events in the future, the client should be responsible for storing the events somewhere.
#### 5. The sequencer supports the system timer as alternative time source.
The conclusion from the mailing list was that the system timer can be removed. This has been done.
#### 6. Time Scaling
Time scaling can now be used for arbitrary tempo changes. The previous implementation was capable of that as well, however, the time-scale was limited to 1000. The only limitation for the scale is now >0, see `test_seq_scale`.
### Other Points
* `fluid_sequencer_remove_events()` turned out to be broken before, as it did not remove all events from the queue. This has been fixed, see `test_seq_event_queue_remove`.
* Consider the following code executed by `threadA`:
```c
fluid_sequencer_send_at(event0);
fluid_sequencer_set_time_scale(); // new scale
fluid_sequencer_send_at(event1);
```
The new scale will be definitely applied to `event1`. However, if another concurrently running `threadB` executes `fluid_sequencer_process()`, it was previously not clear, whether the new scale was also applied to event0. This depends on whether `event0` was still in the `preQueue`, and this depends on `event0.time` and the tick count that `fluid_sequencer_process()` is being called with. This has been changed. As of now, events are queued with their timestamp AS-IS. And only the latest call to `fluid_sequencer_set_time_scale()` is being considered during `fluid_sequencer_process()`. This makes the implementation very simple, i.e. no events need to be changed and the sequencer doesn't have to be locked down. On the other hand, it means that `fluid_sequencer_set_time_scale()` can only be used for tempo changes when called from the sequencer callback. In other words, if `threadA` executes the code above followed by `fluid_sequencer_process()`, `event0` and `event1` will be executed with the same tempo, which is the latest scale provided to the seq. Is this acceptable? The old implementation had the same limitation. And when looking through the internet, I only find users who call `fluid_sequencer_set_time_scale()` from the sequencer callback. Still, this is a point I'm raising for discussion.
2020-05-26 15:16:22 +00:00
set(CMAKE_CXX_STANDARD_REQUIRED ON)
2020-01-11 08:43:46 +00:00
set ( OBOE_SUPPORT 1 )
set ( OBOE_LIBS ${OBOE_LIBRARIES} )
Revise the sequencer's event queue (#604)
Proposing a new event queue for the sequencer, based on prior discussion:
https://lists.nongnu.org/archive/html/fluid-dev/2019-12/msg00001.html
With this change fluidsynth will require a C++98 compliant compiler.
Consider this as RFC, feedback is welcome.
The "pain-points" from the discussion:
#### 1. It is slow.
Done (thanks to heap sort), see runtime of `test_seq_event_queue_sort`.
#### 2. A meaningful ordering for events with the same tick has not been considered.
Done, see comments in `fluid_seq_queue.cpp`.
#### 3. Complicated implementation
Now uses one single event queue, which requires C++98. Implemented similarly to std::priority_queue by using heap sort.
The "queue" I use currently is of type `std::deque`. `deque` does not provide preallocation. `std::vector` does provide it. However, `std::deque` has the huge advantage that appending additional elements is cheap. For `std::vector` appending new elements would require to reallocate all the memory and copy it to the new array. So,
* either use `std::deque` with the risk that memory allocation may occur during `fluid_sequencer_send_at()`, or
* use `std::vector` with a preallocated pool of events and make `fluid_sequencer_send_at()` when the `vector` runs out of capacity.
Comments?
#### 4. Events that have been processed are deleted and gone.
After having thought about this more, this is the correct behavior. After events have been dispatched, they must be released to free underlying memory, see point 3. For the very rare case that a client (e.g. fluid_player) may require those events in the future, the client should be responsible for storing the events somewhere.
#### 5. The sequencer supports the system timer as alternative time source.
The conclusion from the mailing list was that the system timer can be removed. This has been done.
#### 6. Time Scaling
Time scaling can now be used for arbitrary tempo changes. The previous implementation was capable of that as well, however, the time-scale was limited to 1000. The only limitation for the scale is now >0, see `test_seq_scale`.
### Other Points
* `fluid_sequencer_remove_events()` turned out to be broken before, as it did not remove all events from the queue. This has been fixed, see `test_seq_event_queue_remove`.
* Consider the following code executed by `threadA`:
```c
fluid_sequencer_send_at(event0);
fluid_sequencer_set_time_scale(); // new scale
fluid_sequencer_send_at(event1);
```
The new scale will be definitely applied to `event1`. However, if another concurrently running `threadB` executes `fluid_sequencer_process()`, it was previously not clear, whether the new scale was also applied to event0. This depends on whether `event0` was still in the `preQueue`, and this depends on `event0.time` and the tick count that `fluid_sequencer_process()` is being called with. This has been changed. As of now, events are queued with their timestamp AS-IS. And only the latest call to `fluid_sequencer_set_time_scale()` is being considered during `fluid_sequencer_process()`. This makes the implementation very simple, i.e. no events need to be changed and the sequencer doesn't have to be locked down. On the other hand, it means that `fluid_sequencer_set_time_scale()` can only be used for tempo changes when called from the sequencer callback. In other words, if `threadA` executes the code above followed by `fluid_sequencer_process()`, `event0` and `event1` will be executed with the same tempo, which is the latest scale provided to the seq. Is this acceptable? The old implementation had the same limitation. And when looking through the internet, I only find users who call `fluid_sequencer_set_time_scale()` from the sequencer callback. Still, this is a point I'm raising for discussion.
2020-05-26 15:16:22 +00:00
endif ( OBOE_FOUND )
2020-01-11 08:43:46 +00:00
endif ( enable-oboe )
unset ( WITH_READLINE CACHE )
unset ( READLINE_LIBS CACHE )
if ( enable-readline )
pkg_check_modules ( READLINE readline )
if ( NOT READLINE_FOUND )
2020-04-06 08:40:37 +00:00
find_package ( READLINE )
2020-01-11 08:43:46 +00:00
set ( READLINE_FOUND ${HAVE_READLINE} )
endif ( NOT READLINE_FOUND )
if ( READLINE_FOUND )
set ( WITH_READLINE 1 )
set ( READLINE_LIBS ${READLINE_LIBRARIES} )
endif ( READLINE_FOUND )
endif ( enable-readline )
2017-08-28 18:03:42 +00:00
endif(NOT enable-pkgconfig)
2010-03-17 20:14:13 +00:00
2010-10-16 15:36:06 +00:00
unset ( AUFILE_SUPPORT CACHE )
2010-03-17 20:14:13 +00:00
if ( enable-aufile )
set ( AUFILE_SUPPORT 1 )
endif ( enable-aufile )
2018-03-17 11:48:14 +00:00
unset ( OSS_SUPPORT CACHE )
if ( enable-oss )
find_package ( OSS QUIET )
set ( OSS_SUPPORT ${OSS_FOUND} )
endif ( enable-oss )
2010-03-17 20:14:13 +00:00
2010-10-16 15:36:06 +00:00
unset ( MIDISHARE_SUPPORT CACHE )
2018-03-17 12:08:19 +00:00
if ( enable-midishare )
2018-03-17 15:40:51 +00:00
find_package ( MidiShare QUIET )
2010-03-17 20:14:13 +00:00
set ( MIDISHARE_SUPPORT ${MidiShare_FOUND} )
2018-03-17 15:40:51 +00:00
if ( MidiShare_FOUND )
set ( MidiShare_LIBS ${MidiShare_LIBRARIES} )
else ( MidiShare_FOUND )
unset ( MidiShare_LIBS CACHE )
endif ( MidiShare_FOUND )
2018-03-17 12:08:19 +00:00
else ( enable-midishare )
2010-10-16 15:36:06 +00:00
unset ( MidiShare_LIBS CACHE )
2018-03-17 12:08:19 +00:00
endif ( enable-midishare )
2010-03-17 20:14:13 +00:00
2019-03-27 17:02:23 +00:00
unset ( OPENSLES_SUPPORT CACHE )
unset ( OpenSLES_LIBS CACHE )
if ( enable-opensles )
check_include_file ( SLES/OpenSLES.h OPENSLES_SUPPORT )
if ( OPENSLES_SUPPORT )
find_library ( OpenSLES_LIBS OpenSLES )
if ( NOT OpenSLES_LIBS )
unset ( OPENSLES_SUPPORT )
endif ( NOT OpenSLES_LIBS )
endif ( OPENSLES_SUPPORT )
endif ( enable-opensles )
2018-11-18 07:55:52 +00:00
unset ( ENABLE_MIXER_THREADS CACHE )
if ( enable-threads )
set ( ENABLE_MIXER_THREADS 1 )
endif ( enable-threads )
2018-04-25 12:38:28 +00:00
unset ( HAVE_OPENMP CACHE )
find_package ( OpenMP QUIET )
if ( OpenMP_FOUND OR OpenMP_C_FOUND )
message(STATUS "Found OpenMP ${OpenMP_C_SPEC_DATE}")
# require at least OMP 4.0
if ( ( NOT OpenMP_C_SPEC_DATE LESS "201307" ) OR NOT ( OpenMP_C_VERSION VERSION_LESS "4.0" ) )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}" )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}" )
2020-01-11 08:43:46 +00:00
2018-05-04 18:07:06 +00:00
# currently no need to link against openMP runtime lib(s). If need be, uncomment below.
# set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}" )
# set ( LIBFLUID_LIBS "${OpenMP_C_LIBRARIES};${LIBFLUID_LIBS}" )
2018-04-25 12:38:28 +00:00
set ( HAVE_OPENMP 1 )
endif()
endif()
2018-08-05 15:55:07 +00:00
# manipulate some variables to setup a proper test env
set(TEST_SOUNDFONT "${CMAKE_SOURCE_DIR}/sf2/VintageDreamsWaves-v2.sf2")
2020-12-22 09:34:44 +00:00
set(TEST_SOUNDFONT_UTF8 "${CMAKE_SOURCE_DIR}/sf2/\\xE2\\x96\\xA0VintageDreamsWaves-v2\\xE2\\x96\\xA0.sf2")
2018-08-05 15:55:07 +00:00
set(TEST_SOUNDFONT_SF3 "${CMAKE_SOURCE_DIR}/sf2/VintageDreamsWaves-v2.sf3")
2014-07-02 06:10:07 +00:00
2021-04-25 12:49:03 +00:00
# Make sure to link against libm before checking for math functions below
set ( CMAKE_REQUIRED_LIBRARIES "${LIBFLUID_LIBS};${WINDOWS_LIBS}" )
2019-07-07 09:02:31 +00:00
# Check for C99 float math
unset ( HAVE_SINF CACHE )
2021-04-25 12:49:03 +00:00
CHECK_SYMBOL_EXISTS ( sinf "math.h" HAVE_SINF )
2019-07-07 09:02:31 +00:00
if ( HAVE_SINF )
set ( HAVE_SINF 1 )
endif ( HAVE_SINF )
unset ( HAVE_COSF CACHE )
2021-04-25 12:49:03 +00:00
CHECK_SYMBOL_EXISTS ( cosf "math.h" HAVE_COSF )
2019-07-07 09:02:31 +00:00
if ( HAVE_COSF )
set ( HAVE_COSF 1 )
endif ( HAVE_COSF )
unset ( HAVE_FABSF CACHE )
2021-04-25 12:49:03 +00:00
CHECK_SYMBOL_EXISTS ( fabsf "math.h" HAVE_FABSF )
2019-07-07 09:02:31 +00:00
if ( HAVE_FABSF )
set ( HAVE_FABSF 1 )
endif ( HAVE_FABSF )
unset ( HAVE_POWF CACHE )
2021-04-25 12:49:03 +00:00
CHECK_SYMBOL_EXISTS ( powf "math.h" HAVE_POWF )
2019-07-07 09:02:31 +00:00
if ( HAVE_POWF )
set ( HAVE_POWF 1 )
endif ( HAVE_POWF )
unset ( HAVE_SQRTF CACHE )
2021-04-25 12:49:03 +00:00
CHECK_SYMBOL_EXISTS ( sqrtf "math.h" HAVE_SQRTF )
2019-07-07 09:02:31 +00:00
if ( HAVE_SQRTF )
set ( HAVE_SQRTF 1 )
endif ( HAVE_SQRTF )
unset ( HAVE_LOGF CACHE )
2021-04-25 12:49:03 +00:00
CHECK_SYMBOL_EXISTS ( logf "math.h" HAVE_LOGF )
2019-07-07 09:02:31 +00:00
if ( HAVE_LOGF )
set ( HAVE_LOGF 1 )
endif ( HAVE_LOGF )
2021-04-25 12:49:03 +00:00
unset ( HAVE_INETNTOP CACHE )
unset ( IPV6_SUPPORT CACHE )
if ( WIN32 )
CHECK_SYMBOL_EXISTS ( inet_ntop "ws2tcpip.h" HAVE_INETNTOP )
else ( WIN32 )
CHECK_SYMBOL_EXISTS ( inet_ntop "arpa/inet.h" HAVE_INETNTOP )
endif ( WIN32 )
if ( enable-ipv6 )
if ( HAVE_INETNTOP )
set ( IPV6_SUPPORT 1 )
endif ( HAVE_INETNTOP )
endif ( enable-ipv6 )
2010-03-17 20:14:13 +00:00
# General configuration file
2010-10-31 16:15:32 +00:00
configure_file ( ${CMAKE_SOURCE_DIR}/src/config.cmake
2010-03-17 20:14:13 +00:00
${CMAKE_BINARY_DIR}/config.h )
2018-08-07 13:19:05 +00:00
# Setup linker directories NOW, as the command will apply only to targets created after it has been called.
link_directories (
${GLIB_LIBRARY_DIRS}
${LASH_LIBRARY_DIRS}
${JACK_LIBRARY_DIRS}
${ALSA_LIBRARY_DIRS}
${PULSE_LIBRARY_DIRS}
${PORTAUDIO_LIBRARY_DIRS}
${LIBSNDFILE_LIBRARY_DIRS}
${DBUS_LIBRARY_DIRS}
2019-04-06 07:10:50 +00:00
${SDL2_LIBRARY_DIRS}
2019-03-27 17:02:23 +00:00
${OBOE_LIBRARY_DIRS}
2020-02-01 07:54:21 +00:00
${LIBINSTPATCH_LIBRARY_DIRS}
2018-08-07 13:19:05 +00:00
)
2018-04-06 20:52:54 +00:00
2021-04-03 15:34:48 +00:00
# required to allow ctest to be called from top-level build directory
ENABLE_TESTING()
2010-10-31 16:15:32 +00:00
# Process subdirectories
2010-03-17 20:14:13 +00:00
add_subdirectory ( src )
2018-08-07 13:19:05 +00:00
add_subdirectory ( test )
2010-03-17 20:14:13 +00:00
add_subdirectory ( doc )
2012-03-11 12:47:52 +00:00
# pkg-config support
set ( prefix "${CMAKE_INSTALL_PREFIX}" )
set ( exec_prefix "\${prefix}" )
2018-03-06 16:21:15 +00:00
if ( IS_ABSOLUTE "${LIB_INSTALL_DIR}" )
set ( libdir "${LIB_INSTALL_DIR}" )
else ()
set ( libdir "\${exec_prefix}/${LIB_INSTALL_DIR}" )
endif ()
if ( IS_ABSOLUTE "${INCLUDE_INSTALL_DIR}" )
set ( includedir "${INCLUDE_INSTALL_DIR}" )
else ()
set ( includedir "\${prefix}/${INCLUDE_INSTALL_DIR}" )
endif ()
2012-03-11 12:47:52 +00:00
configure_file ( fluidsynth.pc.in
${CMAKE_BINARY_DIR}/fluidsynth.pc IMMEDIATE @ONLY )
install ( FILES ${CMAKE_BINARY_DIR}/fluidsynth.pc
2018-02-20 16:05:16 +00:00
DESTINATION ${LIB_INSTALL_DIR}/pkgconfig )
2012-03-11 12:47:52 +00:00
2010-03-17 20:14:13 +00:00
# Extra targets for Unix build environments
if ( UNIX )
# RPM spec
2010-10-31 16:15:32 +00:00
configure_file ( fluidsynth.spec.in
${CMAKE_BINARY_DIR}/fluidsynth.spec IMMEDIATE @ONLY )
2018-02-20 17:05:06 +00:00
if ( DEFINED FLUID_DAEMON_ENV_FILE)
configure_file ( fluidsynth.service.in
${CMAKE_BINARY_DIR}/fluidsynth.service @ONLY )
configure_file ( fluidsynth.conf.in
${CMAKE_BINARY_DIR}/fluidsynth.conf @ONLY )
endif ( DEFINED FLUID_DAEMON_ENV_FILE )
2010-03-17 20:14:13 +00:00
# uninstall custom target
configure_file ( "${CMAKE_SOURCE_DIR}/cmake_admin/cmake_uninstall.cmake.in"
2010-10-16 18:27:29 +00:00
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY)
2010-03-17 20:14:13 +00:00
add_custom_target ( uninstall
2010-10-16 18:27:29 +00:00
"${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
2010-10-31 16:15:32 +00:00
2010-03-17 20:14:13 +00:00
# tarball custom target
add_custom_target ( tarball
COMMAND mkdir -p ${PACKAGE}-${VERSION}
COMMAND cp -r bindings ${PACKAGE}-${VERSION}
COMMAND cp -r cmake_admin ${PACKAGE}-${VERSION}
COMMAND cp -r doc ${PACKAGE}-${VERSION}
COMMAND cp -r include ${PACKAGE}-${VERSION}
COMMAND cp -r src ${PACKAGE}-${VERSION}
2017-09-17 15:50:09 +00:00
COMMAND cp AUTHORS ChangeLog CMakeLists.txt LICENSE ${PACKAGE}.* INSTALL NEWS README* THANKS TODO ${PACKAGE}-${VERSION}
2010-08-08 12:04:58 +00:00
# COMMAND tar -cj --exclude .svn --exclude Makefile.am -f ${PACKAGE}-${VERSION}.tar.bz2 ${PACKAGE}-${VERSION}
# COMMAND tar -cz --exclude .svn --exclude Makefile.am -f ${PACKAGE}-${VERSION}.tar.gz ${PACKAGE}-${VERSION}
# COMMAND zip -qr ${PACKAGE}-${VERSION}.zip ${PACKAGE}-${VERSION} -x '*.svn*' -x '*Makefile.am'
2010-09-01 06:00:27 +00:00
COMMAND tar -cj --exclude .svn -f ${PACKAGE}-${VERSION}.tar.bz2 ${PACKAGE}-${VERSION}
COMMAND tar -cz --exclude .svn -f ${PACKAGE}-${VERSION}.tar.gz ${PACKAGE}-${VERSION}
COMMAND zip -qr ${PACKAGE}-${VERSION}.zip ${PACKAGE}-${VERSION} -x '*.svn*'
COMMAND rm -rf ${PACKAGE}-${VERSION}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
2010-03-17 20:14:13 +00:00
endif ( UNIX )
include ( report )
2010-10-14 21:07:17 +00:00
2010-10-31 16:15:32 +00:00
# CPack support
2010-10-14 21:07:17 +00:00
set ( CPACK_PACKAGE_DESCRIPTION_SUMMARY "FluidSynth real-time synthesizer" )
set ( CPACK_PACKAGE_VENDOR "fluidsynth.org" )
2017-09-03 11:34:00 +00:00
set ( CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README.md" )
set ( CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE" )
2010-10-14 21:07:17 +00:00
set ( CPACK_PACKAGE_VERSION_MAJOR ${FLUIDSYNTH_VERSION_MAJOR} )
set ( CPACK_PACKAGE_VERSION_MINOR ${FLUIDSYNTH_VERSION_MINOR} )
set ( CPACK_PACKAGE_VERSION_PATCH ${FLUIDSYNTH_VERSION_MICRO} )
set ( CPACK_PACKAGE_EXECUTABLES "fluidsynth" "FluidSynth CLI" )
# source packages
set ( CPACK_SOURCE_GENERATOR TGZ;TBZ2;ZIP )
set ( CPACK_SOURCE_IGNORE_FILES "/.svn/;/build/;~$;.cproject;.project;/.settings/;${CPACK_SOURCE_IGNORE_FILES}" )
2010-10-31 16:15:32 +00:00
set ( CPACK_SOURCE_PACKAGE_FILE_NAME "${PACKAGE}-${VERSION}" )
2010-10-14 21:07:17 +00:00
set ( CPACK_SOURCE_STRIP_FILES OFF )
# binary packages
include ( InstallRequiredSystemLibraries )
set ( CPACK_GENERATOR STGZ;TGZ;TBZ2;ZIP )
set ( CPACK_PACKAGE_NAME ${PACKAGE} )
set ( CPACK_STRIP_FILES ON )
include ( CPack )