Repository navigation
Replies: 3 comments 3 replies
|
hello! In short: there is seamless translation, it just happens behind the scene - in libremidi's implementation if the backend does not support it, but otherwise it's the operating system API which is actually in charge of this automatic translation, all of CoreMIDI on macOS, Windows MIDI Services on Win32 and ALSA on Linux do it already. |
|
Thanks for the suggestion — I tried switching to UMP as recommended. void testMidi() override
{
std::cout << "\ninputs:\n";
libremidi::observer obs;
for (const libremidi::input_port &port : obs.get_input_ports())
std::cout << port.display_name << "\n";
std::cout << "\noutputs:\n";
for (const libremidi::output_port &port : obs.get_output_ports())
std::cout << port.display_name << "\n";
auto my_callback = [](const libremidi::ump &message)
{
std::cerr << message.size() << "\n";
std::cerr << message.timestamp << "\n";
};
libremidi::midi_in midi{
libremidi::ump_input_configuration{.on_message = my_callback}};
midi.open_port(obs.get_input_ports()[1]);
std::string userInput;
std::getline(std::cin, userInput);
}Issue 1 — No messages arriveWith this setup, unlike my original MIDI 1.0 callback, nothing is printed at all. Issue 2 — No way to check Note On / Note OffIn the UMP API I noticed that the old: message.get_message_type()is now just: message.message_type()But the enum only contains high‑level UMP group types: enum class message_type {
UTILITY,
SYSTEM,
MIDI_1_CHANNEL,
SYSEX7,
MIDI_2_CHANNEL,
SYSEX8_MDS,
};I couldn’t find an equivalent way to check whether a message is Note On, Note Off, CC, etc. Question about the state machine / collectorBased on the unit test here: midi1_collector c;
auto sm = c.make_state_machine();
sm.on_bytes(bytes, 0);Is this required when using the UMP callback as well? I’m also wondering whether libremidi automatically switch on the midi1_collector logic for things like NRPN, and what happens with 14‑bit CC messages and how do I defined that. Do I need to manually run a collector/state machine for these cases, or is this already taken care of internally especially when using the UMP callback path? If there’s a recommended way to:
|
system debug infoMidi 1 run debug infoall working as expected CMake installed withon main cmake set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)at the add_subdirectory cmake include(FetchContent)
FetchContent_Declare(
libremidi
GIT_REPOSITORY https://github.com/celtera/libremidi
GIT_TAG master
)
FetchContent_MakeAvailable(libremidi)
target_link_libraries(MyLib PRIVATE libremidi)midi2 run debug infofor void testMidi() override
{
std::cout << "\ninputs:\n";
libremidi::observer obs;
for (const libremidi::input_port &port : obs.get_input_ports())
std::cout << port.display_name << "\n";
std::cout << "\noutputs:\n";
for (const libremidi::output_port &port : obs.get_output_ports())
std::cout << port.display_name << "\n";
auto my_callback = [](const libremidi::ump &message)
{
std::cerr << message.size() << "\n";
std::cerr << message.timestamp << "\n";
};
libremidi::midi_in midi{
libremidi::ump_input_configuration{.on_message = my_callback}};
auto err = midi.open_port(obs.get_input_ports()[1]);
if (err == stdx::error{})
{
std::cout << "no error\n";
}
else
{
// Print the message from the error object
std::print("{}", err.message());
err.throw_exception();
}
std::string userInput;
std::getline(std::cin, userInput);
} |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi, I’m a bit new to libremidi, so apologies if I’m misunderstanding something.
I’ve noticed that libremidi allows listening either to
libremidi::message(MIDI 1.0) or to UMP (MIDI 2.0). For MIDI 1.0 messages, I can check things like:However, I’m running into two issues:
libremidi::messagedoesn’t provide helpers likeget_data_1(), so I have to manually index the raw data bytes.Because Microsoft’s new Windows MIDI 2.0 API exposes both MIDI 1.0 and MIDI 2.0 through a unified interface, I expected libremidi to have something similar — a single abstraction where I can treat both MIDI 1.0 and MIDI 2.0 messages the same way, without manually branching or accessing raw bytes.
On the other hand, I also understand that having a unified interface is not trivial. A common abstraction would require agreeing on things like value precision (e.g., pitch‑bend resolution) and normalizing multi‑byte MIDI 1.0 constructs such as 14‑bit CC or NRPN. In MIDI 2.0 these are already represented as single UMP packets with well‑defined 16‑bit or 32‑bit resolution, so the mapping is not always 1:1. Still, this is exactly why I expected a higher‑level API that hides these differences and exposes a consistent event model regardless of whether the source is MIDI 1.0 or MIDI 2.0.
My question:
Is there an existing unified message abstraction in libremidi that I missed, or is this something that is not currently supported?
Thanks!
reference: My test function for MIDI1 only
All reactions