From 98b3c66ebc79597f5b54fff132eaafbebf581248 Mon Sep 17 00:00:00 2001 From: Ludvig Gunne Lindström Date: Fri, 17 Jul 2026 11:42:57 +0200 Subject: init --- include/melisma.h | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 include/melisma.h (limited to 'include/melisma.h') diff --git a/include/melisma.h b/include/melisma.h new file mode 100644 index 0000000..11133ec --- /dev/null +++ b/include/melisma.h @@ -0,0 +1,130 @@ +/* + * melisma - extensible and scriptable audio engine + * Copyright (C) 2026 Ludvig Gunne Lindström + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef MELISMA_H_INCLUDED +#define MELISMA_H_INCLUDED + +#include +#include +#include + +#define MELISMA_VERSION "0.1.0" +#define ml_check_version() ml__check_version(MELISMA_VERSION) +void ml__check_version(const char *s); + +/* Lua metatable tags for builtin types */ +#define MELISMA_NODE_TYPENAME "node" +#define MELISMA_INPUT_CHANNEL_TYPENAME "input channel" +#define MELISMA_OUTPUT_CHANNEL_TYPENAME "output channel" + +/* Structure passed to each nodes processing function */ +struct ml_proc_args +{ + /* Implementation specific data */ + void *userp; + + /* Number of frames to process */ + size_t nframes; + + /* Number of input buffers */ + size_t icnt; + + /* Number of output buffers */ + size_t ocnt; + + /* List of input buffers */ + float *const *in; + + /* List of output buffers */ + float **out; +}; +typedef struct ml_proc_args ml_proc_args; + +/* A node in the audio graph */ +typedef struct ml_node ml_node; + +/* An input/output channel of a node */ +typedef struct ml_channel ml_channel; + +/* Processing function called for each active node */ +typedef void (*ml_proc_fn)(const ml_proc_args*); + +/* Handler for pending IO operations */ +typedef void (*ml_io_handler)(int,int,void*); + +/* Create a new node */ +ml_node *ml_create_node(ml_proc_fn proc, void *userp); + +/* Add a label to a node */ +#ifdef __GNUC__ +__attribute__((format(printf,2,3))) +#endif +void ml_label_node(ml_node *node, const char *fmt, ...); + +/* Get a pointer to the root node in the audio graph */ +ml_node *ml_get_root_node(void); + +/* Get the user data pointer from a node */ +void *ml_get_userp(ml_node *node); + +/* Add an input channel to a node */ +ml_channel *ml_add_input(ml_node *node); + +/* Add an output channel to a node */ +ml_channel *ml_add_output(ml_node *node); + +/* Get a node input channel by index */ +ml_channel *ml_get_input(ml_node *node, size_t i); + +/* Get a node output channel by index */ +ml_channel *ml_get_output(ml_node *node, size_t i); + +/* Get the number of input channels for a node */ +size_t ml_num_inputs(ml_node *node); + +/* Get the number of output channels for a node */ +size_t ml_num_outputs(ml_node *node); + +/* Connect two channels */ +void ml_connect(ml_channel *src, ml_channel *dst); + +/* Get the current sample rate */ +unsigned long ml_sample_rate(void); + +/* Install a new IO handler for the given file descriptor. + * Flags are a combination of POLLIN, POLLOUT etc. */ +void ml_add_io_handler(int fd, int flags, ml_io_handler hdl, void *args); + +/* Remove a previously installed IO handler */ +void ml_remove_io_handler(int fd); + +typedef long ml_event_id; +typedef struct +{ + ml_event_id id; + unsigned long seq; +} ml_event_handle; + +/* Schedule an event from a Lua C function, t samples from the end + * of the current processing window. */ +ml_event_handle ml_schedule_event(unsigned long t, int fn, int arg); + +/* Cancel a scheduled event from a Lua C function. */ +void ml_cancel_event(const ml_event_handle *hdl); + +#endif -- cgit v1.3.1