Skip to content

Commit be9f94f

Browse files
committed
c api: fix raw / vs non-raw by checking which enum member waas set
fixes #150
1 parent 8e58747 commit be9f94f

3 files changed

Lines changed: 6 additions & 5 deletions

File tree

book/src/midi-2-integrations.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ See a basic `midi2_echo.cpp` example: it uses the following printing function:
1313
std::ostream& operator<<(std::ostream& s, const libremidi::ump& message)
1414
{
1515
// Automatic conversion from libremidi::ump& to cmidi2_ump*
16+
// Note that cmidi2_ump is just a typedef for uint32_t.
1617
const cmidi2_ump* b = message;
1718

1819
// Read MIDI 2 information

book/src/polling.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ which can then be injected into your app's main loop.
77

88
Thus, this enables complete control over threading (and can also remove the need for synchronisation as this allows to make a callback-based yet single-threaded app, for simple applications which do not wish to reimplement MIDI filtering & parsing for back-ends such as ALSA Sequencer or RawMidi).
99

10-
Since this feature is pretty complicated to implement correctly, we recommend checking the examples:
10+
Since this feature is pretty complicated to implement correctly unless you already have an easily accessible `poll` loop in your app, we recommend checking the examples:
1111

1212
See:
1313
- `poll_share.cpp` for a complete example for ALSA RawMidi (recommended).

include/libremidi/libremidi-c.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,11 @@ int libremidi_midi_in_new(
276276
= [cb = c->get_timestamp](int64_t msg) { return cb.callback(cb.context, msg); };
277277
}
278278

279-
if (c->on_midi1_message.callback)
279+
if (c->version == libremidi_midi_configuration::MIDI1 && c->on_midi1_message.callback)
280280
conf.on_message = [cb = c->on_midi1_message](const libremidi::message& msg) {
281281
cb.callback(cb.context, msg.timestamp, msg.bytes.data(), msg.size());
282282
};
283-
else if (c->on_midi1_raw_data.callback)
283+
else if (c->version == libremidi_midi_configuration::MIDI1_RAW && c->on_midi1_raw_data.callback)
284284
{
285285
conf.on_raw_data = [cb = c->on_midi1_raw_data](std::span<const uint8_t> msg, int64_t ts) {
286286
cb.callback(cb.context, ts, msg.data(), msg.size());
@@ -319,11 +319,11 @@ int libremidi_midi_in_new(
319319
= [cb = c->get_timestamp](int64_t msg) { return cb.callback(cb.context, msg); };
320320
}
321321

322-
if (c->on_midi2_message.callback)
322+
if (c->version == libremidi_midi_configuration::MIDI2 && c->on_midi2_message.callback)
323323
conf.on_message = [cb = c->on_midi2_message](const libremidi::ump& msg) {
324324
cb.callback(cb.context, msg.timestamp, msg.data, msg.size());
325325
};
326-
else if (c->on_midi2_raw_data.callback)
326+
else if (c->version == libremidi_midi_configuration::MIDI2_RAW && c->on_midi2_raw_data.callback)
327327
{
328328
conf.on_raw_data = [cb = c->on_midi2_raw_data](std::span<const uint32_t> msg, int64_t ts) {
329329
cb.callback(cb.context, ts, msg.data(), msg.size());

0 commit comments

Comments
 (0)