1d5ac70f0Sopenharmony_ci/* SPDX-License-Identifier: LGPL-2.1+ */
2d5ac70f0Sopenharmony_ci/**
3d5ac70f0Sopenharmony_ci * \file include/ump.h
4d5ac70f0Sopenharmony_ci * \brief API library for ALSA rawmidi/UMP interface
5d5ac70f0Sopenharmony_ci *
6d5ac70f0Sopenharmony_ci * API library for ALSA rawmidi/UMP interface
7d5ac70f0Sopenharmony_ci */
8d5ac70f0Sopenharmony_ci
9d5ac70f0Sopenharmony_ci#ifndef __ALSA_UMP_H
10d5ac70f0Sopenharmony_ci#define __ALSA_UMP_H
11d5ac70f0Sopenharmony_ci
12d5ac70f0Sopenharmony_ci#ifdef __cplusplus
13d5ac70f0Sopenharmony_ciextern "C" {
14d5ac70f0Sopenharmony_ci#endif
15d5ac70f0Sopenharmony_ci
16d5ac70f0Sopenharmony_ci/** UMP (Endpoint) RawMIDI device */
17d5ac70f0Sopenharmony_citypedef struct _snd_ump snd_ump_t;
18d5ac70f0Sopenharmony_ci/** UMP Endpoint information container */
19d5ac70f0Sopenharmony_citypedef struct snd_ump_endpoint_info snd_ump_endpoint_info_t;
20d5ac70f0Sopenharmony_ci/** UMP Block information container */
21d5ac70f0Sopenharmony_citypedef struct snd_ump_block_info snd_ump_block_info_t;
22d5ac70f0Sopenharmony_ci
23d5ac70f0Sopenharmony_ciint snd_ump_open(snd_ump_t **inputp, snd_ump_t **outputp, const char *name, int mode);
24d5ac70f0Sopenharmony_ciint snd_ump_close(snd_ump_t *ump);
25d5ac70f0Sopenharmony_cisnd_rawmidi_t *snd_ump_rawmidi(snd_ump_t *ump);
26d5ac70f0Sopenharmony_ciconst char *snd_ump_name(snd_ump_t *ump);
27d5ac70f0Sopenharmony_ciint snd_ump_poll_descriptors_count(snd_ump_t *ump);
28d5ac70f0Sopenharmony_ciint snd_ump_poll_descriptors(snd_ump_t *ump, struct pollfd *pfds, unsigned int space);
29d5ac70f0Sopenharmony_ciint snd_ump_poll_descriptors_revents(snd_ump_t *ump, struct pollfd *pfds, unsigned int nfds, unsigned short *revents);
30d5ac70f0Sopenharmony_ciint snd_ump_nonblock(snd_ump_t *ump, int nonblock);
31d5ac70f0Sopenharmony_ciint snd_ump_rawmidi_info(snd_ump_t *ump, snd_rawmidi_info_t *info);
32d5ac70f0Sopenharmony_ciint snd_ump_rawmidi_params(snd_ump_t *ump, snd_rawmidi_params_t *params);
33d5ac70f0Sopenharmony_ciint snd_ump_rawmidi_params_current(snd_ump_t *ump, snd_rawmidi_params_t *params);
34d5ac70f0Sopenharmony_ciint snd_ump_rawmidi_status(snd_ump_t *ump, snd_rawmidi_status_t *status);
35d5ac70f0Sopenharmony_ciint snd_ump_drop(snd_ump_t *ump);
36d5ac70f0Sopenharmony_ciint snd_ump_drain(snd_ump_t *ump);
37d5ac70f0Sopenharmony_cissize_t snd_ump_write(snd_ump_t *ump, const void *buffer, size_t size);
38d5ac70f0Sopenharmony_cissize_t snd_ump_read(snd_ump_t *ump, void *buffer, size_t size);
39d5ac70f0Sopenharmony_cissize_t snd_ump_tread(snd_ump_t *ump, struct timespec *tstamp, void *buffer, size_t size);
40d5ac70f0Sopenharmony_ci
41d5ac70f0Sopenharmony_ci/** Max number of UMP Groups */
42d5ac70f0Sopenharmony_ci#define SND_UMP_MAX_GROUPS		16
43d5ac70f0Sopenharmony_ci/** Max number of UMP Blocks */
44d5ac70f0Sopenharmony_ci#define SND_UMP_MAX_BLOCKS		32
45d5ac70f0Sopenharmony_ci
46d5ac70f0Sopenharmony_ci/** UMP direction */
47d5ac70f0Sopenharmony_cienum _snd_ump_direction {
48d5ac70f0Sopenharmony_ci	/** Input only */
49d5ac70f0Sopenharmony_ci	SND_UMP_DIR_INPUT =		0x01,
50d5ac70f0Sopenharmony_ci	/** Output only */
51d5ac70f0Sopenharmony_ci	SND_UMP_DIR_OUTPUT =		0x02,
52d5ac70f0Sopenharmony_ci	/** Bidirectional */
53d5ac70f0Sopenharmony_ci	SND_UMP_DIR_BIDIRECTION	=	0x03,
54d5ac70f0Sopenharmony_ci};
55d5ac70f0Sopenharmony_ci
56d5ac70f0Sopenharmony_ci/** UMP EP holds only static blocks */
57d5ac70f0Sopenharmony_ci#define SND_UMP_EP_INFO_STATIC_BLOCKS		0x01
58d5ac70f0Sopenharmony_ci
59d5ac70f0Sopenharmony_ci/** Bitmask for UMP EP MIDI protocols */
60d5ac70f0Sopenharmony_ci#define SND_UMP_EP_INFO_PROTO_MIDI_MASK		0x0300
61d5ac70f0Sopenharmony_ci/** Bit flag for MIDI 1.0 protocol */
62d5ac70f0Sopenharmony_ci#define SND_UMP_EP_INFO_PROTO_MIDI1		0x0100
63d5ac70f0Sopenharmony_ci/** Bit flag for MIDI 2.0 protocol */
64d5ac70f0Sopenharmony_ci#define SND_UMP_EP_INFO_PROTO_MIDI2		0x0200
65d5ac70f0Sopenharmony_ci/** Bitmask for UMP Jitter-reduction timestamp */
66d5ac70f0Sopenharmony_ci#define SND_UMP_EP_INFO_PROTO_JRTS_MASK		0x0003
67d5ac70f0Sopenharmony_ci/** Bit flag for JRTS in Transmit */
68d5ac70f0Sopenharmony_ci#define SND_UMP_EP_INFO_PROTO_JRTS_TX		0x0001
69d5ac70f0Sopenharmony_ci/** Bit flag for JRTS in Receive */
70d5ac70f0Sopenharmony_ci#define SND_UMP_EP_INFO_PROTO_JRTS_RX		0x0002
71d5ac70f0Sopenharmony_ci
72d5ac70f0Sopenharmony_cisize_t snd_ump_endpoint_info_sizeof(void);
73d5ac70f0Sopenharmony_ci/** \hideinitializer
74d5ac70f0Sopenharmony_ci * \brief allocate an invalid #snd_ump_endpoint_info_t using standard alloca
75d5ac70f0Sopenharmony_ci * \param ptr returned pointer
76d5ac70f0Sopenharmony_ci */
77d5ac70f0Sopenharmony_ci#define snd_ump_endpoint_info_alloca(ptr) __snd_alloca(ptr, snd_ump_endpoint_info)
78d5ac70f0Sopenharmony_ciint snd_ump_endpoint_info_malloc(snd_ump_endpoint_info_t **info);
79d5ac70f0Sopenharmony_civoid snd_ump_endpoint_info_free(snd_ump_endpoint_info_t *info);
80d5ac70f0Sopenharmony_civoid snd_ump_endpoint_info_copy(snd_ump_endpoint_info_t *dst, const snd_ump_endpoint_info_t *src);
81d5ac70f0Sopenharmony_ciint snd_ump_endpoint_info_get_card(const snd_ump_endpoint_info_t *info);
82d5ac70f0Sopenharmony_ciint snd_ump_endpoint_info_get_device(const snd_ump_endpoint_info_t *info);
83d5ac70f0Sopenharmony_ciunsigned int snd_ump_endpoint_info_get_flags(const snd_ump_endpoint_info_t *info);
84d5ac70f0Sopenharmony_ciunsigned int snd_ump_endpoint_info_get_protocol_caps(const snd_ump_endpoint_info_t *info);
85d5ac70f0Sopenharmony_ciunsigned int snd_ump_endpoint_info_get_protocol(const snd_ump_endpoint_info_t *info);
86d5ac70f0Sopenharmony_ciunsigned int snd_ump_endpoint_info_get_num_blocks(const snd_ump_endpoint_info_t *info);
87d5ac70f0Sopenharmony_ciunsigned int snd_ump_endpoint_info_get_version(const snd_ump_endpoint_info_t *info);
88d5ac70f0Sopenharmony_ciunsigned int snd_ump_endpoint_info_get_manufacturer_id(const snd_ump_endpoint_info_t *info);
89d5ac70f0Sopenharmony_ciunsigned int snd_ump_endpoint_info_get_family_id(const snd_ump_endpoint_info_t *info);
90d5ac70f0Sopenharmony_ciunsigned int snd_ump_endpoint_info_get_model_id(const snd_ump_endpoint_info_t *info);
91d5ac70f0Sopenharmony_ciconst unsigned char *snd_ump_endpoint_info_get_sw_revision(const snd_ump_endpoint_info_t *info);
92d5ac70f0Sopenharmony_ciconst char *snd_ump_endpoint_info_get_name(const snd_ump_endpoint_info_t *info);
93d5ac70f0Sopenharmony_ciconst char *snd_ump_endpoint_info_get_product_id(const snd_ump_endpoint_info_t *info);
94d5ac70f0Sopenharmony_ciint snd_ump_endpoint_info(snd_ump_t *ump, snd_ump_endpoint_info_t *info);
95d5ac70f0Sopenharmony_ci
96d5ac70f0Sopenharmony_ci/** Bit flag for MIDI 1.0 port w/o restrict in UMP Block info flags */
97d5ac70f0Sopenharmony_ci#define SND_UMP_BLOCK_IS_MIDI1		(1U << 0)
98d5ac70f0Sopenharmony_ci/** Bit flag for 31.25Kbps B/W MIDI1 port in UMP Block info flags */
99d5ac70f0Sopenharmony_ci#define SND_UMP_BLOCK_IS_LOWSPEED	(1U << 1)
100d5ac70f0Sopenharmony_ci
101d5ac70f0Sopenharmony_ci/** UMP block user-interface hint */
102d5ac70f0Sopenharmony_cienum _snd_ump_block_ui_hint {
103d5ac70f0Sopenharmony_ci	/** Unknown or undeclared */
104d5ac70f0Sopenharmony_ci	SND_UMP_BLOCK_UI_HINT_UNKNOWN	=	0x00,
105d5ac70f0Sopenharmony_ci	/** Primarily a receiver or a destination for MIDI messages */
106d5ac70f0Sopenharmony_ci	SND_UMP_BLOCK_UI_HINT_RECEIVER =	0x01,
107d5ac70f0Sopenharmony_ci	/** Primarily a sender or a source of MIDI messages */
108d5ac70f0Sopenharmony_ci	SND_UMP_BLOCK_UI_HINT_SENDER =		0x02,
109d5ac70f0Sopenharmony_ci	/** Both a sender and receiver of MIDI messages */
110d5ac70f0Sopenharmony_ci	SND_UMP_BLOCK_UI_HINT_BOTH =		0x03,
111d5ac70f0Sopenharmony_ci};
112d5ac70f0Sopenharmony_ci
113d5ac70f0Sopenharmony_cisize_t snd_ump_block_info_sizeof(void);
114d5ac70f0Sopenharmony_ci/** \hideinitializer
115d5ac70f0Sopenharmony_ci * \brief allocate an invalid #snd_ump_block_info_t using standard alloca
116d5ac70f0Sopenharmony_ci * \param ptr returned pointer
117d5ac70f0Sopenharmony_ci */
118d5ac70f0Sopenharmony_ci#define snd_ump_block_info_alloca(ptr) __snd_alloca(ptr, snd_ump_block_info)
119d5ac70f0Sopenharmony_ciint snd_ump_block_info_malloc(snd_ump_block_info_t **info);
120d5ac70f0Sopenharmony_civoid snd_ump_block_info_free(snd_ump_block_info_t *info);
121d5ac70f0Sopenharmony_civoid snd_ump_block_info_copy(snd_ump_block_info_t *dst, const snd_ump_block_info_t *src);
122d5ac70f0Sopenharmony_ciint snd_ump_block_info_get_card(const snd_ump_block_info_t *info);
123d5ac70f0Sopenharmony_ciint snd_ump_block_info_get_device(const snd_ump_block_info_t *info);
124d5ac70f0Sopenharmony_ciunsigned int snd_ump_block_info_get_block_id(const snd_ump_block_info_t *info);
125d5ac70f0Sopenharmony_civoid snd_ump_block_info_set_block_id(snd_ump_block_info_t *info, unsigned int id);
126d5ac70f0Sopenharmony_ciunsigned int snd_ump_block_info_get_active(const snd_ump_block_info_t *info);
127d5ac70f0Sopenharmony_ciunsigned int snd_ump_block_info_get_flags(const snd_ump_block_info_t *info);
128d5ac70f0Sopenharmony_ciunsigned int snd_ump_block_info_get_direction(const snd_ump_block_info_t *info);
129d5ac70f0Sopenharmony_ciunsigned int snd_ump_block_info_get_first_group(const snd_ump_block_info_t *info);
130d5ac70f0Sopenharmony_ciunsigned int snd_ump_block_info_get_num_groups(const snd_ump_block_info_t *info);
131d5ac70f0Sopenharmony_ciunsigned int snd_ump_block_info_get_midi_ci_version(const snd_ump_block_info_t *info);
132d5ac70f0Sopenharmony_ciunsigned int snd_ump_block_info_get_sysex8_streams(const snd_ump_block_info_t *info);
133d5ac70f0Sopenharmony_ciunsigned int snd_ump_block_info_get_ui_hint(const snd_ump_block_info_t *info);
134d5ac70f0Sopenharmony_ciconst char *snd_ump_block_info_get_name(const snd_ump_block_info_t *info);
135d5ac70f0Sopenharmony_ciint snd_ump_block_info(snd_ump_t *ump, snd_ump_block_info_t *info);
136d5ac70f0Sopenharmony_ci
137d5ac70f0Sopenharmony_ci#ifdef __cplusplus
138d5ac70f0Sopenharmony_ci}
139d5ac70f0Sopenharmony_ci#endif
140d5ac70f0Sopenharmony_ci
141d5ac70f0Sopenharmony_ci#endif /* __ALSA_UMP_H */
142