1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
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 <https://www.gnu.org/licenses/>.
*/
#ifndef MELISMA_H_INCLUDED
#define MELISMA_H_INCLUDED
#include <lua.h>
#include <stddef.h>
#include <sys/poll.h>
#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
|