Something went wrong. Try again.
Monorepo for Aesthetic.Computer aesthetic.computer
Something went wrong. Try again.
C
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061#pragma once
// Raw UDP client for fairy point co-presence (ac-native bare metal)// Background thread sends/recvs small packets to session server.
#include <pthread.h>#include <netinet/in.h>
#define UDP_MAX_FAIRIES 16#define UDP_FAIRY_PORT 10010
typedef struct { float x; // 0.0-1.0 normalized float y;} UDPFairy;
typedef struct { // Background recv thread pthread_t thread; int thread_running; int sock; // UDP socket fd (-1 = not connected)
// Server address struct sockaddr_in server_addr; int connected; // 1 = resolved + socket open
// Outgoing: main thread writes, thread sends float send_x, send_y; int send_pending;
// Incoming: thread writes, main thread reads during paint UDPFairy fairies[UDP_MAX_FAIRIES]; int fairy_count;
// Identity char handle[64]; char machine_id[64];
pthread_mutex_t mu;} ACUdp;
ACUdp *udp_create(void);void udp_destroy(ACUdp *udp);
// Connect to session server's raw UDP relayvoid udp_connect(ACUdp *udp, const char *host, int port);
// Queue a fairy point to send (non-blocking, main thread)void udp_send_fairy(ACUdp *udp, float x, float y);
// Update identifying metadata used by outgoing packets.void udp_set_identity(ACUdp *udp, const char *handle, const char *machine_id);
// Send note relay events to the session server over UDP.void udp_send_midi(ACUdp *udp, const char *event, int note, int velocity, int channel, const char *piece);void udp_send_midi_heartbeat(ACUdp *udp, const char *piece);
// Poll received fairies (returns count, fills out[] up to max)// Clears the buffer after reading.int udp_poll_fairies(ACUdp *udp, UDPFairy *out, int max);