]> git.sesse.net Git - nageru/blob - input_mapping.h
Move InputMapping and friends into its own header file.
[nageru] / input_mapping.h
1 #ifndef _INPUT_MAPPING_H
2 #define _INPUT_MAPPING_H 1
3
4 #include <stdint.h>
5 #include <string>
6 #include <vector>
7
8 enum class InputSourceType { SILENCE, CAPTURE_CARD, ALSA_INPUT };
9 struct DeviceSpec {
10         InputSourceType type;
11         unsigned index;
12
13         bool operator== (const DeviceSpec &other) const {
14                 return type == other.type && index == other.index;
15         }
16
17         bool operator< (const DeviceSpec &other) const {
18                 if (type != other.type)
19                         return type < other.type;
20                 return index < other.index;
21         }
22 };
23 struct DeviceInfo {
24         std::string display_name;
25         unsigned num_channels;
26         std::string alsa_name, alsa_info, alsa_address;  // ALSA devices only, obviously.
27 };
28
29 static inline uint64_t DeviceSpec_to_key(const DeviceSpec &device_spec)
30 {
31         return (uint64_t(device_spec.type) << 32) | device_spec.index;
32 }
33
34 static inline DeviceSpec key_to_DeviceSpec(uint64_t key)
35 {
36         return DeviceSpec{ InputSourceType(key >> 32), unsigned(key & 0xffffffff) };
37 }
38
39 struct InputMapping {
40         struct Bus {
41                 std::string name;
42                 DeviceSpec device;
43                 int source_channel[2] { -1, -1 };  // Left and right. -1 = none.
44         };
45
46         std::vector<Bus> buses;
47 };
48
49 #endif  // !defined(_INPUT_MAPPING_H)