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.c |
Rudimentary streaming of raw MIDI over multicast UDP
Diffstat (limited to 'midimcast.c')
-rw-r--r-- | midimcast.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/midimcast.c b/midimcast.c new file mode 100644 index 0000000..6ad047f --- /dev/null +++ b/midimcast.c @@ -0,0 +1,33 @@ +#include <inttypes.h> +#include <stdint.h> +#include <stdlib.h> +#include <time.h> + +#include "midimcast.h" + +void env_read_common(const char **const mcast_group, uint16_t *const mcast_port) +{ + midimcast_debug = getenv("DEBUG") != NULL; + + *mcast_group = getenv("MCAST_GROUP"); + if (!*mcast_group) + *mcast_group = "224.212.21.175"; + debug("Using multicast group %s", *mcast_group); + + const char *const mcast_port_str = getenv("MCAST_PORT"); + if (mcast_port_str) { + const long mcast_port_untrunc = strtol(mcast_port_str, NULL, 0); + if (mcast_port_untrunc < 0 || mcast_port_untrunc > UINT16_MAX) + err("Port %ld does not exist", mcast_port_untrunc); + *mcast_port = mcast_port_untrunc; + } else { + *mcast_port = 8000; + } + debug("Using multicast port %" PRIu16, *mcast_port); +} + +uint64_t now() { + struct timespec ts; + err_std(clock_gettime, CLOCK_REALTIME, &ts); + return ts.tv_sec * 1000 + ts.tv_nsec / 1000000; +} |