|
1 | 1 | #pragma once |
2 | | -#include <libremidi/api.hpp> |
3 | | -#include <libremidi/config.hpp> |
4 | | -#include <libremidi/error.hpp> |
5 | | -#include <libremidi/types.hpp> |
6 | | - |
7 | | -#include <array> |
8 | | -#include <compare> |
9 | | -#include <string> |
10 | | -#include <variant> |
| 2 | +#include <libremidi/port_information.hpp> |
11 | 3 |
|
12 | 4 | namespace libremidi |
13 | 5 | { |
14 | | -struct LIBREMIDI_EXPORT port_information |
15 | | -{ |
16 | | - // Compat |
17 | | - using port_type = libremidi::transport_type; |
18 | | - |
19 | | - /// Which API is this port for. port_information objects are in general |
20 | | - /// not useable for different APIs than the API of the observer that created them. |
21 | | - libremidi::API api{}; |
22 | | - |
23 | | - /// Handle to the API client object if the API provides one |
24 | | - // ALSA Raw: unused |
25 | | - // ALSA Seq: snd_seq_t* |
26 | | - // CoreMIDI: MidiClientRef |
27 | | - // JACK: jack_client_t* |
28 | | - // PipeWire: unused // FIXME: pw_context? pw_main_loop? |
29 | | - // WebMIDI: unused |
30 | | - // WinMIDI: TODO |
31 | | - // WinMM: unused |
32 | | - // WinUWP: unused |
33 | | - client_handle client = static_cast<client_handle>(-1); |
34 | | - |
35 | | - /// Container identifier if the API provides one |
36 | | - // ALSA: device id (std::string), e.g. ID_PATH as returned by udev: "pci-0000:00:14.0-usb-0:12:1.0" |
37 | | - // CoreMIDI: USBLocationID (int32_t) |
38 | | - // WinMIDI: ContainerID GUID (bit_cast to a winapi or winrt::GUID ; |
39 | | - // this is not the string but the binary representation). |
40 | | - container_identifier container = std::monostate{}; |
41 | | - |
42 | | - /// Device identifier if the API provides one |
43 | | - // ALSA: sysfs path (std::string), e.g. "/sys/devices/pci0000:00/0000:00:02.2/0000:02:00.0/sound/card0/controlC0" |
44 | | - // CoreMIDI: USBVendorProduct (int32_t) |
45 | | - // WinMIDI: EndpointDeviceId (std::string), e.g. "\\?\swd#midisrv#midiu_ksa..." |
46 | | - // WinMM: MIDI{IN,OUT}CAPS mId / pId { uint16_t manufacturer_id, uint16_t product_id; } |
47 | | - device_identifier device = std::monostate{}; |
48 | | - |
49 | | - /// Handle to the port identifier if the API provides one |
50 | | - // ALSA Raw: bit_cast to struct { uint16_t card, device, sub, padding; }. |
51 | | - // ALSA Seq: bit_cast to struct { uint32_t client, port; } |
52 | | - // CoreMIDI: MidiObjectRef's kMIDIPropertyUniqueID (uint32_t) |
53 | | - // JACK: jack_port_id_t |
54 | | - // PipeWire: port.id |
55 | | - // WebMIDI: index of the MIDI device in the list provided by the browser. |
56 | | - // WinMIDI: uint64_t terminal_block_number; (MidiGroupTerminalBlock::Number(), index is 1-based) |
57 | | - // WinMM: port index between 0 and midi{In,Out}GetNumDevs() |
58 | | - // WinUWP: index of the MIDI device in the list provided by the OS. |
59 | | - port_handle port = static_cast<port_handle>(-1); |
60 | | - |
61 | | - /// User-readable information |
62 | | - // ALSA Raw: ID_VENDOR_FROM_DATABASE if provided by udev |
63 | | - // ALSA Seq: ID_VENDOR_FROM_DATABASE if provided by udev |
64 | | - // CoreMIDI: kMIDIPropertyManufacturer |
65 | | - // WinMIDI: MidiEndpointDeviceInformation::GetTransportSuppliedInfo().ManufacturerName |
66 | | - // WinMM: unavailable |
67 | | - std::string manufacturer{}; |
68 | | - |
69 | | - // ALSA Raw: ID_MODEL_FROM_DATABASE if provided by udev |
70 | | - // ALSA Seq: ID_MODEL_FROM_DATABASE if provided by udev |
71 | | - // WinMIDI: MidiEndpointDeviceInformation::GetTransportSuppliedInfo().Name |
72 | | - std::string product{}; |
73 | | - |
74 | | - /// "Unique" serial number. Note that this is super unreliable - pretty |
75 | | - /// much no MIDI device manufacturer bothers with unique per-device serial number |
76 | | - /// unlike most USB devices. |
77 | | - // ALSA Raw: ID_USB_SERIAL if provided by udev. |
78 | | - // ALSA Seq: ID_USB_SERIAL if provided by udev. |
79 | | - // WinMIDI: MidiEndpointDeviceInformation::GetTransportSuppliedInfo().SerialNumber |
80 | | - std::string serial{}; |
81 | | - |
82 | | - // ALSA Raw: Name returned by snd_rawmidi_info_get_name |
83 | | - // ALSA Seq: Name returned by snd_seq_client_info_get_name |
84 | | - // CoreMIDI: kMIDIPropertyModel |
85 | | - // WinMIDI: MidiEndpointDeviceInformation::Name |
86 | | - // WinMM: unavailable |
87 | | - std::string device_name{}; |
88 | | - |
89 | | - // ALSA Raw: Name returned by snd_rawmidi_info_get_subdevice_name |
90 | | - // ALSA Seq: Name returned by snd_seq_port_info_get_name |
91 | | - // CoreMIDI: kMIDIPropertyName |
92 | | - // WinMIDI: MidiGroupTerminalBlock::Name |
93 | | - // WinMM: szPname |
94 | | - std::string port_name{}; |
95 | | - |
96 | | - // CoreMIDI: kMIDIPropertyDisplayName |
97 | | - // Otherwise: the closest to a unique name we can get |
98 | | - std::string display_name{}; |
99 | | - |
100 | | - /// Port type |
101 | | - // CoreMIDI: available |
102 | | - // WinMIDI: available |
103 | | - // WinMM: unavailable |
104 | | - port_type type = port_type::unknown; |
105 | | - |
106 | | - // Equality and comparison operators are deleted as there is not one |
107 | | - // single correct way to compare two port_information: |
108 | | - // in some cases it may be useful to only compare the names, while in other cases |
109 | | - // it is necessary to check whether this is the exact same low-level identifier. |
110 | | - // Thus, the end-user must define their own custom equality operators |
111 | | - // if using std:: containers or algorithms |
112 | | - bool operator==(const port_information& other) const noexcept = delete; |
113 | | - std::strong_ordering operator<=>(const port_information& other) const noexcept = delete; |
114 | | -}; |
115 | | - |
116 | | -struct input_port : port_information |
117 | | -{ |
118 | | - bool operator==(const input_port& other) const noexcept = delete; |
119 | | - std::strong_ordering operator<=>(const input_port& other) const noexcept = delete; |
120 | | -}; |
121 | | -struct output_port : port_information |
122 | | -{ |
123 | | - bool operator==(const output_port& other) const noexcept = delete; |
124 | | - std::strong_ordering operator<=>(const output_port& other) const noexcept = delete; |
125 | | -}; |
126 | | - |
127 | 6 | using input_port_callback = std::function<void(const input_port&)>; |
128 | 7 | using output_port_callback = std::function<void(const output_port&)>; |
129 | 8 | struct observer_configuration |
|
0 commit comments