1
0
Fork 0
forked from hanez/xtc

Initial commit.

This commit is contained in:
Johannes Findeisen 2026-10-26 22:51:25 +01:00
commit 1d8f869b5b
39 changed files with 1671 additions and 0 deletions

8
src/backend/README.md Normal file
View file

@ -0,0 +1,8 @@
# Audio backend
No hardware backend is implemented yet. Keep backend-specific headers out of
public headers. The first backend should be selected after checking the target
Linux environment and its development packages.
A backend implementation must document callback threading, buffer sizes,
sample-rate negotiation, device loss, and shutdown semantics.

1
src/core/README.md Normal file
View file

@ -0,0 +1 @@
Core lifecycle and public C API implementation.

46
src/core/xtlite.c Normal file
View file

@ -0,0 +1,46 @@
#include "xtlite/xtlite.h"
#include <stdlib.h>
struct xt_app {
unsigned int reserved;
};
const char *xt_result_string(xt_result result)
{
switch (result) {
case XT_OK: return "success";
case XT_ERR_INVALID_ARGUMENT: return "invalid argument";
case XT_ERR_OUT_OF_MEMORY: return "out of memory";
case XT_ERR_NOT_FOUND: return "not found";
case XT_ERR_INVALID_STATE: return "invalid state";
case XT_ERR_IO: return "I/O error";
case XT_ERR_UNSUPPORTED: return "unsupported operation";
case XT_ERR_CAPACITY: return "capacity exceeded";
case XT_ERR_GRAPH_CYCLE: return "graph contains a cycle";
default: return "unknown error";
}
}
xt_result xt_app_create(xt_app **out_app)
{
xt_app *app;
if (out_app == NULL) {
return XT_ERR_INVALID_ARGUMENT;
}
*out_app = NULL;
app = (xt_app *)calloc(1U, sizeof(*app));
if (app == NULL) {
return XT_ERR_OUT_OF_MEMORY;
}
*out_app = app;
return XT_OK;
}
void xt_app_destroy(xt_app *app)
{
free(app);
}

1
src/dsp/README.md Normal file
View file

@ -0,0 +1 @@
Small, independently testable DSP primitives implemented in C.

15
src/dsp/gain.c Normal file
View file

@ -0,0 +1,15 @@
#include <stddef.h>
/* Kept as a separately testable DSP primitive. */
void xt_dsp_gain_process(const float *input, float *output,
size_t frame_count, float gain)
{
size_t frame;
if (input == NULL || output == NULL) {
return;
}
for (frame = 0U; frame < frame_count; frame++) {
output[frame] = input[frame] * gain;
}
}

1
src/engine/README.md Normal file
View file

@ -0,0 +1 @@
Offline and real-time processing coordination. Respect callback safety rules.

View file

@ -0,0 +1,13 @@
/*
* Offline engine integration point.
*
* The first scaffold exposes xt_graph_process_offline() from graph.c. This
* file is reserved for the next milestone: a compiled immutable graph plan,
* preallocated node buffers, and block-based processing independent of audio
* hardware. Keep hardware callbacks and real-time constraints out of this
* initial offline implementation.
*/
int xt_offline_engine_translation_unit_anchor(void)
{
return 0;
}

1
src/graph/README.md Normal file
View file

@ -0,0 +1 @@
Graph nodes, ports, connections, validation, and compiled execution plans.

189
src/graph/graph.c Normal file
View file

@ -0,0 +1,189 @@
#include "xtlite/xtlite_engine.h"
#include <stdlib.h>
#include <string.h>
typedef struct {
size_t source;
size_t destination;
} xt_edge;
typedef struct {
float gain;
} xt_gain_node;
struct xt_graph {
size_t max_nodes;
size_t node_count;
size_t edge_count;
xt_gain_node *nodes;
xt_edge *edges;
};
xt_result xt_graph_create(size_t max_nodes, xt_graph **out_graph)
{
xt_graph *graph;
if (out_graph == NULL || max_nodes == 0U) {
return XT_ERR_INVALID_ARGUMENT;
}
*out_graph = NULL;
graph = (xt_graph *)calloc(1U, sizeof(*graph));
if (graph == NULL) {
return XT_ERR_OUT_OF_MEMORY;
}
graph->nodes = (xt_gain_node *)calloc(max_nodes, sizeof(*graph->nodes));
graph->edges = (xt_edge *)calloc(max_nodes * max_nodes, sizeof(*graph->edges));
if (graph->nodes == NULL || graph->edges == NULL) {
free(graph->nodes);
free(graph->edges);
free(graph);
return XT_ERR_OUT_OF_MEMORY;
}
graph->max_nodes = max_nodes;
*out_graph = graph;
return XT_OK;
}
void xt_graph_destroy(xt_graph *graph)
{
if (graph != NULL) {
free(graph->nodes);
free(graph->edges);
free(graph);
}
}
xt_result xt_graph_add_gain(xt_graph *graph, float gain, size_t *out_node_id)
{
if (graph == NULL || out_node_id == NULL) {
return XT_ERR_INVALID_ARGUMENT;
}
if (graph->node_count >= graph->max_nodes) {
return XT_ERR_CAPACITY;
}
graph->nodes[graph->node_count].gain = gain;
*out_node_id = graph->node_count;
graph->node_count++;
return XT_OK;
}
xt_result xt_graph_connect(xt_graph *graph, size_t source_node,
size_t destination_node)
{
size_t i;
size_t edge_capacity;
if (graph == NULL) {
return XT_ERR_INVALID_ARGUMENT;
}
if (source_node >= graph->node_count || destination_node >= graph->node_count) {
return XT_ERR_NOT_FOUND;
}
edge_capacity = graph->max_nodes * graph->max_nodes;
if (graph->edge_count >= edge_capacity) {
return XT_ERR_CAPACITY;
}
for (i = 0U; i < graph->edge_count; i++) {
if (graph->edges[i].source == source_node &&
graph->edges[i].destination == destination_node) {
return XT_ERR_INVALID_STATE;
}
}
graph->edges[graph->edge_count].source = source_node;
graph->edges[graph->edge_count].destination = destination_node;
graph->edge_count++;
return XT_OK;
}
xt_result xt_graph_validate(const xt_graph *graph)
{
size_t *indegree;
size_t *queue;
size_t head = 0U;
size_t tail = 0U;
size_t visited = 0U;
size_t i;
if (graph == NULL) {
return XT_ERR_INVALID_ARGUMENT;
}
if (graph->node_count == 0U) {
return XT_OK;
}
indegree = (size_t *)calloc(graph->node_count, sizeof(*indegree));
queue = (size_t *)calloc(graph->node_count, sizeof(*queue));
if (indegree == NULL || queue == NULL) {
free(indegree);
free(queue);
return XT_ERR_OUT_OF_MEMORY;
}
for (i = 0U; i < graph->edge_count; i++) {
if (graph->edges[i].source >= graph->node_count ||
graph->edges[i].destination >= graph->node_count) {
free(indegree);
free(queue);
return XT_ERR_INVALID_STATE;
}
indegree[graph->edges[i].destination]++;
}
for (i = 0U; i < graph->node_count; i++) {
if (indegree[i] == 0U) {
queue[tail++] = i;
}
}
while (head < tail) {
size_t node = queue[head++];
visited++;
for (i = 0U; i < graph->edge_count; i++) {
if (graph->edges[i].source == node) {
size_t dest = graph->edges[i].destination;
if (indegree[dest] > 0U) {
indegree[dest]--;
if (indegree[dest] == 0U) {
queue[tail++] = dest;
}
}
}
}
}
free(indegree);
free(queue);
return visited == graph->node_count ? XT_OK : XT_ERR_GRAPH_CYCLE;
}
xt_result xt_graph_process_offline(xt_graph *graph, const float *input,
float *output, size_t frame_count,
float input_gain)
{
size_t i;
float cumulative_gain = input_gain;
if (graph == NULL || input == NULL || output == NULL) {
return XT_ERR_INVALID_ARGUMENT;
}
if (xt_graph_validate(graph) != XT_OK) {
return XT_ERR_INVALID_STATE;
}
/* Temporary starter behavior: apply gains in node insertion order.
This is not yet graph-plan execution and is only for offline tests. */
for (i = 0U; i < graph->node_count; i++) {
cumulative_gain *= graph->nodes[i].gain;
}
for (i = 0U; i < frame_count; i++) {
output[i] = input[i] * cumulative_gain;
}
return XT_OK;
}

10
src/gui/main.cpp Normal file
View file

@ -0,0 +1,10 @@
#include <FL/Fl.H>
#include "main_window.hpp"
int main(int argc, char **argv)
{
MainWindow window;
window.show(argc, argv);
return Fl::run();
}

52
src/gui/main_window.cpp Normal file
View file

@ -0,0 +1,52 @@
#include "main_window.hpp"
#include <FL/Fl_Box.H>
#include <FL/Fl_Menu_Bar.H>
#include <FL/Fl_Tabs.H>
#include <FL/Fl_Group.H>
extern "C" {
#include "xtlite/xtlite.h"
}
MainWindow::MainWindow()
: Fl_Double_Window(1000, 680, "xtlite — modular audio workstation")
{
begin();
Fl_Menu_Bar *menu = new Fl_Menu_Bar(0, 0, 1000, 28);
menu->add("File/New", 0, nullptr);
menu->add("File/Open...", 0, nullptr);
menu->add("File/Save", 0, nullptr);
menu->add("Help/About", 0, nullptr);
Fl_Tabs *tabs = new Fl_Tabs(8, 36, 984, 600);
tabs->begin();
Fl_Group *sequencer = new Fl_Group(8, 60, 984, 576, "Sequencer");
sequencer->begin();
new Fl_Box(24, 84, 940, 40,
"Sequencer placeholder — timeline and clips are not implemented yet.");
sequencer->end();
Fl_Group *mixer = new Fl_Group(8, 60, 984, 576, "Mixer");
mixer->begin();
new Fl_Box(24, 84, 940, 40,
"Mixer placeholder — channels and meters are not implemented yet.");
mixer->end();
Fl_Group *graph = new Fl_Group(8, 60, 984, 576, "Modular Graph");
graph->begin();
new Fl_Box(24, 84, 940, 40,
"Modular graph placeholder — the C graph API is the current prototype.");
graph->end();
tabs->end();
end();
resizable(tabs);
}
void MainWindow::show(int argc, char **argv)
{
Fl_Double_Window::show(argc, argv);
}

12
src/gui/main_window.hpp Normal file
View file

@ -0,0 +1,12 @@
#ifndef XTLITE_MAIN_WINDOW_HPP
#define XTLITE_MAIN_WINDOW_HPP
#include <FL/Fl_Double_Window.H>
class MainWindow : public Fl_Double_Window {
public:
MainWindow();
void show(int argc, char **argv);
};
#endif

5
src/midi/README.md Normal file
View file

@ -0,0 +1,5 @@
# MIDI and events
MIDI input, MIDI clips, event scheduling, panic behavior, and device handling
are not implemented yet. Define a bounded event representation and explicit
sample-offset semantics before adding real-time event delivery.

View file

@ -0,0 +1,5 @@
# Persistence
Project save/load is intentionally unimplemented in this scaffold. The project
format must be versioned, validated, and saved atomically. File I/O must never
occur in the audio callback. See `docs/PROJECT_FORMAT.md`.

1
src/project/README.md Normal file
View file

@ -0,0 +1 @@
Project domain model will live here. Keep it in C and separate from FLTK widgets.

5
src/util/README.md Normal file
View file

@ -0,0 +1,5 @@
# Utilities
Put small, reusable C helpers here only when they have a clear owner and tests.
Avoid creating a generic utility framework. Validate sizes and allocation
arithmetic, and document ownership for allocated data.