Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support finding a compiled api with API::UNSPECIFIED #116

Open
ejconlon opened this issue Aug 26, 2024 · 7 comments
Open

Support finding a compiled api with API::UNSPECIFIED #116

ejconlon opened this issue Aug 26, 2024 · 7 comments

Comments

@ejconlon
Copy link
Contributor

ejconlon commented Aug 26, 2024

Hello, I'm working on Haskell FFI bindings for this library and found that using API::UNSPECIFIED doesn't quite behave as I expect. Creating an observer simply fails, rather than picking a valid API. Here's a diff that works for me:

diff --git a/libremidi/vendor/libremidi/backends.hpp b/libremidi/vendor/libremidi/backends.hpp
index a101f46..bbf7161 100644
--- a/libremidi/vendor/libremidi/backends.hpp
+++ b/libremidi/vendor/libremidi/backends.hpp
@@ -156,7 +156,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 || api == libremidi::API::UNSPECIFIED; };
   std::apply([&](auto&&... b) { ((is_api(b, api) && (f(b), true)) || ...); }, available_backends);
 }
 }

Is this the solution?

Thanks!

@jcelerier
Copy link
Member

jcelerier commented Aug 27, 2024

hello ! I actually pushed some commits that change this behaviour this very morning, could you try on the latest commit if that was not the case?

nevermind, I didn't push the change for observers

@jcelerier
Copy link
Member

Patch looks sound nevertheless, will apply

@jcelerier
Copy link
Member

btw, are you ok with me linking the bindings in the README ? :)

@ejconlon
Copy link
Contributor Author

Thanks for addressing this!

Linking is fine with me.

Would you be open to exposing more methods in the C API? For example, finding which APIs are available, and what their names are. At the moment I’m trying to but the new bindings to use, but I might have time later to send a patch for those new methods.

@jcelerier
Copy link
Member

yes definitely, the C api is very provisional right now and not stable yet. For instance all the names aren't homogenous. Stable version will be part of the 5.0 release.

@jcelerier
Copy link
Member

heya! I just added some of the requested methods. there will still be a bit of breakage before stable release..

@ejconlon
Copy link
Contributor Author

ejconlon commented Sep 7, 2024

Thank you. I am still wrangling foreign pointers and the Haskell side! Will pull and try the new methods soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@ejconlon @jcelerier and others