diff options
author | rcerc <88944439+rcerc@users.noreply.github.com> | 2025-06-19 16:39:47 -0400 |
---|---|---|
committer | rcerc <88944439+rcerc@users.noreply.github.com> | 2025-06-19 18:20:38 -0400 |
commit | 5179ace697f702d7103c9aa6e26478363e0f6a4d (patch) | |
tree | 92c3b9393f3ea2d197400368cf106ffa89f14c6b /midimcast.h |
Rudimentary streaming of raw MIDI over multicast UDP
Diffstat (limited to 'midimcast.h')
-rw-r--r-- | midimcast.h | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/midimcast.h b/midimcast.h new file mode 100644 index 0000000..26cab34 --- /dev/null +++ b/midimcast.h @@ -0,0 +1,111 @@ +#ifndef __MIDIMCAST_H__ +#define __MIDIMCAST_H__ + +#include <errno.h> +#include <stdbool.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#define debug(FMT, ...) \ + if (midimcast_debug) { \ + fprintf(stderr, \ + "[DEBUG] %s:%u:%s: " FMT "\n", \ + __FILE__, \ + __LINE__, \ + __func__ __VA_OPT__(,) \ + __VA_ARGS__); \ + } + +#define warn(FMT, ...) \ + fprintf(stderr, "[WARNING] %s:%u:%s: " FMT "\n", \ + __FILE__, \ + __LINE__, \ + __func__ __VA_OPT__(,) \ + __VA_ARGS__); + +#define err(FMT, ...) \ + ({ \ + fprintf(stderr, "[ERROR] %s:%u:%s: " FMT "\n", \ + __FILE__, \ + __LINE__, \ + __func__ __VA_OPT__(,) \ + __VA_ARGS__); \ + exit(EXIT_FAILURE); \ + }) + +#define err_std_nchk(CALLEE) \ + ({ \ + fprintf(stderr, "[ERROR] %s:%u:%s:%s: %s\n", \ + __FILE__, \ + __LINE__, \ + __func__, \ + #CALLEE, \ + strerror(errno)); \ + exit(EXIT_FAILURE); \ + }) + +#define err_std(CALLEE, ...) \ + if (CALLEE(__VA_ARGS__)) \ + err_std_nchk(CALLEE); + +#define err_std_neg(CALLEE, ...) \ + ({ \ + const typeof(CALLEE(__VA_ARGS__)) ret = \ + CALLEE(__VA_ARGS__); \ + if (ret < 0) \ + err_std_nchk(CALLEE); \ + ret; \ + }) + +#define err_std_null(CALLEE, ...) \ + ({ \ + const typeof(CALLEE(__VA_ARGS__)) ret = \ + CALLEE(__VA_ARGS__); \ + if (!ret) \ + err_std_nchk(CALLEE); \ + ret; \ + }) + +#define err_snd_nchk(CALLEE, ERR) \ + ({ \ + fprintf(stderr, "[ERROR] %s:%u:%s:%s: %s\n", \ + __FILE__, \ + __LINE__, \ + __func__, \ + #CALLEE, \ + snd_strerror(ERR)); \ + exit(EXIT_FAILURE); \ + }) + + +#define err_snd(CALLEE, ...) \ + ({ \ + const int err = CALLEE(__VA_ARGS__); \ + if (err) \ + err_snd_nchk(CALLEE, err); \ + }) + +#define err_snd_neg(CALLEE, ...) \ + ({ \ + const typeof(CALLEE(__VA_ARGS__)) ret \ + = CALLEE(__VA_ARGS__); \ + if (ret < 0) \ + err_snd_nchk(CALLEE, ret); \ + ret; \ + }) + +struct msg { + uint64_t ts; + uint8_t midi[0x10]; // Large enough buffer +} __attribute__((packed)); + +extern uint64_t now(); + +extern bool midimcast_debug; + +void env_read_common(const char **const mcast_group, + uint16_t *const mcast_port); + +#endif |