Skip to content

Commit

Permalink
bump
Browse files Browse the repository at this point in the history
  • Loading branch information
ejconlon committed Sep 10, 2024
1 parent e2eaf76 commit ba75b2f
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 20 deletions.
2 changes: 1 addition & 1 deletion libremidi/vendor/libremidi/api-c.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ typedef enum libremidi_api
WINDOWS_MIDI_SERVICES, /*!< Windows API for MIDI 2.0. Requires Windows 11 */
KEYBOARD_UMP, /*!< Computer keyboard input */

DUMMY /*!< A compilable but non-functional API. */
DUMMY = 0xFFFF /*!< A compilable but non-functional API. */
} libremidi_api;

#if __cplusplus
Expand Down
15 changes: 15 additions & 0 deletions libremidi/vendor/libremidi/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <libremidi/api-c.h>
#include <libremidi/config.hpp>

#include <any>
#include <string_view>
#include <vector>

Expand Down Expand Up @@ -30,6 +31,9 @@ LIBREMIDI_EXPORT std::vector<libremidi::API> available_apis() noexcept;
*/
LIBREMIDI_EXPORT std::vector<libremidi::API> available_ump_apis() noexcept;

LIBREMIDI_EXPORT
libremidi::API midi_api(const std::any& conf);

//! A static function to determine the current version.
LIBREMIDI_EXPORT std::string_view get_version() noexcept;

Expand All @@ -40,6 +44,17 @@ LIBREMIDI_EXPORT std::string_view get_api_display_name(libremidi::API api);
//! Look-up an API through its name
LIBREMIDI_EXPORT libremidi::API get_compiled_api_by_name(std::string_view api);

inline constexpr bool is_midi1(libremidi::API api)
{
return (static_cast<int>(api) >= 0x1 && static_cast<int>(api) < 0x1000)
|| api == libremidi::API::DUMMY;
}

inline constexpr bool is_midi2(libremidi::API api)
{
return static_cast<int>(api) >= 0x1000;
}

namespace midi1
{
//! Returns the default MIDI 1.0 backend to use for the target OS.
Expand Down
2 changes: 1 addition & 1 deletion libremidi/vendor/libremidi/backends.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ template <typename F>
auto for_backend(libremidi::API api, F&& f)
{
static constexpr auto is_api
= [](auto& backend, libremidi::API api) { return backend.API == api; };
= [](auto& backend, libremidi::API api) { return backend.API == api || libremidi::API::UNSPECIFIED == api; };
std::apply([&](auto&&... b) { ((is_api(b, api) && (f(b), true)) || ...); }, available_backends);
}
}
Expand Down
15 changes: 14 additions & 1 deletion libremidi/vendor/libremidi/libremidi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,20 @@ LIBREMIDI_INLINE libremidi::API get_compiled_api_by_name(std::string_view name)
midi2::for_all_backends([&](auto b) { apis.push_back(b.API); });
return apis;
}

LIBREMIDI_INLINE
libremidi::API midi_api(const std::any& conf)
{
libremidi::API ret = libremidi::API::UNSPECIFIED;
midi_any::for_all_backends([&]<typename T>(T) {
if (std::any_cast<typename T::midi_in_configuration>(&conf)
|| std::any_cast<typename T::midi_out_configuration>(&conf)
|| std::any_cast<typename T::midi_observer_configuration>(&conf))
{
ret = T::API;
}
});
return ret;
}
LIBREMIDI_INLINE
std::any midi_in_configuration_for(libremidi::API api)
{
Expand Down
78 changes: 72 additions & 6 deletions libremidi/vendor/libremidi/midi_in.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,47 @@ make_midi1_in(const input_configuration& base_conf, const std::any& api_conf)
{
return make_midi1_in(base_conf);
}
else if (auto api = std::any_cast<libremidi::API>(&api_conf))
else if (auto api_p = std::any_cast<libremidi::API>(&api_conf))
{
return make_midi_in(base_conf, midi_in_configuration_for(*api), midi1::available_backends);
if (*api_p == libremidi::API::UNSPECIFIED)
{
if (auto backend = make_midi_in(
base_conf, midi_in_configuration_for(libremidi::midi1::default_api()),
midi1::available_backends))
return backend;

auto c2 = convert_midi1_to_midi2_input_configuration(base_conf);
if (auto backend = make_midi_in(
c2, midi_in_configuration_for(libremidi::midi2::default_api()),
midi2::available_backends))
return backend;
}
else if (is_midi1(*api_p))
{
// all good
return make_midi_in(base_conf, midi_in_configuration_for(*api_p), midi1::available_backends);
}
else if (is_midi2(*api_p))
{
auto c2 = convert_midi1_to_midi2_input_configuration(base_conf);
return make_midi_in(c2, midi_in_configuration_for(*api_p), midi2::available_backends);
}
}
else
{
return make_midi_in(base_conf, api_conf, midi1::available_backends);
const auto api = libremidi::midi_api(api_conf);
if (libremidi::is_midi1(api))
{
return make_midi_in(base_conf, api_conf, midi1::available_backends);
}
else if (libremidi::is_midi2(api))
{
auto c2 = convert_midi1_to_midi2_input_configuration(base_conf);
return make_midi_in(c2, api_conf, midi2::available_backends);
}
}

return std::make_unique<midi_in_dummy>(input_configuration{}, dummy_configuration{});
}

/// MIDI 1 constructors
Expand Down Expand Up @@ -195,14 +228,47 @@ make_midi2_in(const ump_input_configuration& base_conf, const std::any& api_conf
{
return make_midi2_in(base_conf);
}
else if (auto api = std::any_cast<libremidi::API>(&api_conf))
else if (auto api_p = std::any_cast<libremidi::API>(&api_conf))
{
return make_midi_in(base_conf, midi_in_configuration_for(*api), midi2::available_backends);
if (*api_p == libremidi::API::UNSPECIFIED)
{
if (auto backend = make_midi_in(
base_conf, midi_in_configuration_for(libremidi::midi2::default_api()),
midi2::available_backends))
return backend;

auto c2 = convert_midi2_to_midi1_input_configuration(base_conf);
if (auto backend = make_midi_in(
c2, midi_in_configuration_for(libremidi::midi1::default_api()),
midi1::available_backends))
return backend;
}
else if (is_midi2(*api_p))
{
// all good
return make_midi_in(base_conf, midi_in_configuration_for(*api_p), midi2::available_backends);
}
else if (is_midi1(*api_p))
{
auto c2 = convert_midi2_to_midi1_input_configuration(base_conf);
return make_midi_in(c2, midi_in_configuration_for(*api_p), midi1::available_backends);
}
}
else
{
return make_midi_in(base_conf, api_conf, midi2::available_backends);
const auto api = libremidi::midi_api(api_conf);
if (libremidi::is_midi2(api))
{
return make_midi_in(base_conf, api_conf, midi2::available_backends);
}
else if (libremidi::is_midi1(api))
{
auto c2 = convert_midi2_to_midi1_input_configuration(base_conf);
return make_midi_in(c2, api_conf, midi1::available_backends);
}
}

return std::make_unique<midi_in_dummy>(input_configuration{}, dummy_configuration{});
}

/// MIDI 2 constructors
Expand Down
19 changes: 17 additions & 2 deletions libremidi/vendor/libremidi/midi_out.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,24 @@ make_midi_out(const output_configuration& base_conf, const std::any& api_conf)
{
return make_midi_out(base_conf);
}
else if (auto api = std::any_cast<libremidi::API>(&api_conf))
else if (auto api_p = std::any_cast<libremidi::API>(&api_conf))
{
return make_midi_out_impl(base_conf, midi_out_configuration_for(*api));
if (*api_p == libremidi::API::UNSPECIFIED)
{
if (auto backend = make_midi_out_impl(
base_conf, midi_out_configuration_for(libremidi::midi1::default_api())))
return backend;

if (auto backend = make_midi_out_impl(
base_conf, midi_out_configuration_for(libremidi::midi2::default_api())))
return backend;

return std::make_unique<midi_out_dummy>(output_configuration{}, dummy_configuration{});
}
else
{
return make_midi_out_impl(base_conf, midi_out_configuration_for(*api_p));
}
}
else
{
Expand Down
21 changes: 18 additions & 3 deletions libremidi/vendor/libremidi/observer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,30 @@ LIBREMIDI_INLINE auto make_observer_impl(auto base_conf, std::any api_conf)
return ptr;
}

LIBREMIDI_INLINE auto make_observer(auto base_conf, std::any api_conf)
LIBREMIDI_INLINE std::unique_ptr<observer_api> make_observer(auto base_conf, std::any api_conf)
{
if (!api_conf.has_value())
{
return make_observer(base_conf);
}
else if (auto api = std::any_cast<libremidi::API>(&api_conf))
else if (auto api_p = std::any_cast<libremidi::API>(&api_conf))
{
return make_observer_impl(base_conf, observer_configuration_for(*api));
if (*api_p == libremidi::API::UNSPECIFIED)
{
if (auto backend = make_observer_impl(
base_conf, observer_configuration_for(libremidi::midi1::default_api())))
return backend;

if (auto backend = make_observer_impl(
base_conf, observer_configuration_for(libremidi::midi2::default_api())))
return backend;

return std::make_unique<observer_dummy>(observer_configuration{}, dummy_configuration{});
}
else
{
return make_observer_impl(base_conf, observer_configuration_for(*api_p));
}
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resolver: lts-22.33
resolver: lts-22.34

ghc-options:
"$everything": -haddock
Expand Down
8 changes: 4 additions & 4 deletions stack.yaml.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
packages: []
snapshots:
- completed:
sha256: 098936027eaa1ef14e2b8eb39d9933a973894bb70a68684a1bbf00730249879b
size: 720001
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/33.yaml
original: lts-22.33
sha256: edbd50d7e7c85c13ad5f5835ae2db92fab1e9cf05ecf85340e2622ec0a303df1
size: 720020
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/34.yaml
original: lts-22.34

0 comments on commit ba75b2f

Please sign in to comment.