Skip to content

Commit

Permalink
[rawmidi] Only enable for rawmidi versions that have all the function…
Browse files Browse the repository at this point in the history
…s we need
  • Loading branch information
jcelerier committed Oct 29, 2023
1 parent 249c528 commit 469e7f5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 18 deletions.
17 changes: 13 additions & 4 deletions include/libremidi/backends.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@
#endif

#if defined(LIBREMIDI_ALSA)
#include <libremidi/backends/alsa_raw.hpp>
#include <libremidi/backends/alsa_seq.hpp>
#if __has_include(<alsa/ump.h>)
#include <libremidi/backends/linux/alsa.hpp>

#if LIBREMIDI_ALSA_HAS_RAMWIDI
#include <libremidi/backends/alsa_raw.hpp>
#endif

#if LIBREMIDI_ALSA_HAS_UMP
#include <libremidi/backends/alsa_raw_ump.hpp>
#include <libremidi/backends/alsa_seq_ump.hpp>
#endif
Expand Down Expand Up @@ -62,7 +67,11 @@ static constexpr auto available_backends = make_tl(
0
#if defined(LIBREMIDI_ALSA)
,
alsa_seq::backend{}, alsa_raw::backend{}
alsa_seq::backend{}
#if LIBREMIDI_ALSA_HAS_RAMWIDI
,
alsa_raw::backend{}
#endif
#endif
#if defined(LIBREMIDI_COREMIDI)
,
Expand Down Expand Up @@ -110,7 +119,7 @@ namespace midi2
{
static constexpr auto available_backends = make_tl(
0
#if defined(LIBREMIDI_ALSA) && __has_include(<alsa/ump.h>)
#if defined(LIBREMIDI_ALSA) && LIBREMIDI_ALSA_HAS_UMP
,
alsa_seq_ump::backend{}, alsa_raw_ump::backend{}
#endif
Expand Down
36 changes: 22 additions & 14 deletions include/libremidi/backends/linux/alsa.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@

#include <alsa/asoundlib.h>

#if __has_include(<alsa/rawmidi.h>) && SND_LIB_VERSION >= SND_LIB_VER(1,2,6)
#define LIBREMIDI_ALSA_HAS_RAMWIDI 1
#endif

#if __has_include(<alsa/ump.h>) && SND_LIB_VERSION >= SND_LIB_VER(1,2,10)
#define LIBREMIDI_ALSA_HAS_UMP 1
#endif

namespace libremidi
{

Expand Down Expand Up @@ -59,9 +67,9 @@ struct libasound
{
explicit ctl_t(const dylib_loader& library)
: rawmidi{library}
#if __has_include(<alsa/ump.h>)
#if LIBREMIDI_ALSA_HAS_UMP
, ump{library}
#endif
#endif
{
if (!library)
{
Expand Down Expand Up @@ -95,7 +103,7 @@ struct libasound
LIBREMIDI_SYMBOL_DEF(snd_ctl_rawmidi, next_device);
} rawmidi;

#if __has_include(<alsa/ump.h>)
#if LIBREMIDI_ALSA_HAS_UMP
struct ump_t
{
explicit ump_t(const dylib_loader& library)
Expand Down Expand Up @@ -147,7 +155,7 @@ struct libasound
LIBREMIDI_SYMBOL_DEF(snd_midi, event_resize_buffer);
} midi{library};

#if __has_include(<alsa/rawmidi.h>)
#if LIBREMIDI_ALSA_HAS_RAMWIDI
struct rawmidi_t
{
explicit rawmidi_t(const dylib_loader& library)
Expand Down Expand Up @@ -216,9 +224,9 @@ struct libasound
struct seq_t
{
explicit seq_t(const dylib_loader& library)
#if __has_include(<alsa/ump.h>)
#if LIBREMIDI_ALSA_HAS_UMP
: ump{library}
#endif
#endif
{
if (!library)
{
Expand Down Expand Up @@ -339,7 +347,7 @@ struct libasound
LIBREMIDI_SYMBOL_DEF(snd_seq, subscribe_port);
LIBREMIDI_SYMBOL_DEF(snd_seq, unsubscribe_port);

#if __has_include(<alsa/ump.h>)
#if LIBREMIDI_ALSA_HAS_UMP
struct ump_t
{
explicit ump_t(const dylib_loader& library)
Expand All @@ -363,7 +371,7 @@ struct libasound
#endif
} seq{library};

#if __has_include(<alsa/ump.h>)
#if LIBREMIDI_ALSA_HAS_UMP
struct ump_t
{
explicit ump_t(const dylib_loader& library)
Expand Down Expand Up @@ -435,10 +443,10 @@ struct libasound
#undef snd_seq_queue_tempo_alloca
#define snd_seq_queue_tempo_alloca(ptr) snd_dylib_alloca(ptr, seq, queue_tempo)

#if __has_include(<alsa/ump.h>)
#undef snd_ump_block_info_alloca
#define snd_ump_block_info_alloca(ptr) snd_dylib_alloca(ptr, ump, block_info)
#undef snd_ump_endpoint_info_alloca
#define snd_ump_endpoint_info_alloca(ptr) snd_dylib_alloca(ptr, ump, endpoint_info)
#endif
#if LIBREMIDI_ALSA_HAS_UMP
#undef snd_ump_block_info_alloca
#define snd_ump_block_info_alloca(ptr) snd_dylib_alloca(ptr, ump, block_info)
#undef snd_ump_endpoint_info_alloca
#define snd_ump_endpoint_info_alloca(ptr) snd_dylib_alloca(ptr, ump, endpoint_info)
#endif
}

0 comments on commit 469e7f5

Please sign in to comment.