2024-10-09 02:01:23 +02:00
|
|
|
#pragma once
|
|
|
|
|
#include <libremidi/backends/alsa_raw/helpers.hpp>
|
|
|
|
|
#include <libremidi/config.hpp>
|
|
|
|
|
#include <libremidi/detail/observer.hpp>
|
|
|
|
|
|
2025-06-13 19:06:09 +02:00
|
|
|
#include <cstdio>
|
|
|
|
|
|
2024-10-09 02:01:23 +02:00
|
|
|
namespace libremidi::alsa_raw_ump
|
|
|
|
|
{
|
|
|
|
|
struct midi2_enumerator : alsa_raw::enumerator
|
|
|
|
|
{
|
2024-10-28 19:24:18 +01:00
|
|
|
using alsa_raw::enumerator::enumerator;
|
2024-10-09 02:01:23 +02:00
|
|
|
void enumerate_devices(int card) override
|
|
|
|
|
{
|
2024-10-28 19:24:18 +01:00
|
|
|
using namespace std::literals;
|
2024-10-09 02:01:23 +02:00
|
|
|
char name[128];
|
|
|
|
|
|
|
|
|
|
sprintf(name, "hw:%d", card);
|
|
|
|
|
|
|
|
|
|
// Open card.
|
|
|
|
|
alsa_raw::snd_ctl_wrapper ctl{*this, name};
|
|
|
|
|
if (!ctl)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Enumerate devices.
|
|
|
|
|
int device = -1;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
const int status = snd.ctl.ump.next_device(ctl, &device);
|
|
|
|
|
if (device == -1)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (status < 0)
|
|
|
|
|
{
|
2024-10-28 19:24:18 +01:00
|
|
|
handler.libremidi_handle_error(
|
|
|
|
|
configuration, "Cannot determine device number: "s + snd.strerror(status));
|
2024-10-09 02:01:23 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (device >= 0)
|
|
|
|
|
{
|
|
|
|
|
enumerate_blocks(ctl, card, device);
|
|
|
|
|
enumerate_endpoints(ctl, card, device);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} while (device >= 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void enumerate_endpoints(snd_ctl_t* ctl, [[maybe_unused]] int card, [[maybe_unused]] int device)
|
|
|
|
|
{
|
|
|
|
|
snd_ump_endpoint_info_t* info{};
|
|
|
|
|
snd_ump_endpoint_info_alloca(&info);
|
|
|
|
|
snd.ctl.ump.endpoint_info(ctl, info);
|
|
|
|
|
|
|
|
|
|
fprintf(stderr, "UMP endpoint: %s", snd.ump.endpoint_info_get_name(info));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void enumerate_blocks(snd_ctl_t* ctl, [[maybe_unused]] int card, [[maybe_unused]] int device)
|
|
|
|
|
{
|
|
|
|
|
snd_ump_block_info_t* info{};
|
|
|
|
|
snd_ump_block_info_alloca(&info);
|
|
|
|
|
snd.ctl.ump.block_info(ctl, info);
|
|
|
|
|
|
|
|
|
|
fprintf(stderr, "UMP block: %s", snd.ump.block_info_get_name(info));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|