Added tons of documentation headers to functions in source files.

This commit is contained in:
Johannes Findeisen 2026-10-27 01:58:27 +01:00
commit 4eb2080933
43 changed files with 3953 additions and 43 deletions

View file

@ -10,6 +10,12 @@ struct xtc_history {
size_t next_node;
};
/**
* @brief Raises history's identifier high-water marks to include the project's allocations.
*
* @param h Snapshot history handle.
* @param p Project model; borrowed for this call.
*/
static void remember_ids(xtc_history *h, const xtc_project *p)
{
if (p->next_track_id > h->next_track)
@ -22,6 +28,11 @@ static void remember_ids(xtc_history *h, const xtc_project *p)
h->next_node = p->graph->next_id;
}
/**
* @brief Releases all retained snapshots and history storage; accepts NULL.
*
* @param h Snapshot history handle.
*/
void xtc_history_destroy(xtc_history *h)
{
size_t i;
@ -32,6 +43,13 @@ void xtc_history_destroy(xtc_history *h)
free(h);
}
/**
* @brief Creates snapshot history with an independent copy of the initial project.
*
* @param p Project model; borrowed for this call.
* @param out Receives the newly allocated object; caller owns it on success.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_history_create(const xtc_project *p, xtc_history **out)
{
xtc_history *h;
@ -55,6 +73,13 @@ xtc_result xtc_history_create(const xtc_project *p, xtc_history **out)
return XTC_OK;
}
/**
* @brief Appends a project snapshot, discarding redo states and evicting the oldest state if full.
*
* @param h Snapshot history handle.
* @param p Project model; borrowed for this call.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_history_record(xtc_history *h, const xtc_project *p)
{
xtc_project *copy;
@ -79,11 +104,26 @@ xtc_result xtc_history_record(xtc_history *h, const xtc_project *p)
return XTC_OK;
}
/**
* @brief Checks whether an adjacent undo or redo snapshot exists.
*
* @param h Snapshot history handle.
* @param redo Zero for undo, one for redo.
* @return Nonzero when the requested history state exists, zero otherwise.
*/
static int available(const xtc_history *h, int redo)
{
return redo ? h->cursor + 1 < h->count : h->cursor > 0;
}
/**
* @brief Clones the adjacent undo or redo state without moving the history cursor.
*
* @param h Snapshot history handle.
* @param redo Zero for undo, one for redo.
* @param out Receives the newly allocated object; caller owns it on success.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_history_checkout(const xtc_history *h, int redo, xtc_project **out)
{
if (!out)
@ -105,6 +145,13 @@ xtc_result xtc_history_checkout(const xtc_history *h, int redo, xtc_project **ou
}
}
/**
* @brief Moves the history cursor after the checked-out project has been installed.
*
* @param h Snapshot history handle.
* @param redo Zero for undo, one for redo.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_history_accept(xtc_history *h, int redo)
{
if (!h || (redo != 0 && redo != 1))

View file

@ -5,6 +5,12 @@
#include <math.h>
#include <string.h>
/**
* @brief Checks for a nonempty UTF-8 name of at most 63 bytes without ASCII controls.
*
* @param name NUL-terminated name.
* @return Nonzero for a valid name, zero otherwise.
*/
int xtc_project_valid_name(const char *name)
{
size_t length = 0U, i = 0U;
@ -43,6 +49,13 @@ int xtc_project_valid_name(const char *name)
return 1;
}
/**
* @brief Finds a project's dense track index by stable identifier.
*
* @param project Project model; borrowed for this call.
* @param id Stable identifier of the object to find or edit.
* @return Dense track index, or SIZE_MAX if absent.
*/
static size_t track_index(const xtc_project *project, uint64_t id)
{
size_t i;
@ -52,6 +65,13 @@ static size_t track_index(const xtc_project *project, uint64_t id)
return SIZE_MAX;
}
/**
* @brief Finds a project's dense clip index by stable identifier.
*
* @param project Project model; borrowed for this call.
* @param id Stable identifier of the object to find or edit.
* @return Dense clip index, or SIZE_MAX if absent.
*/
static size_t clip_index(const xtc_project *project, uint64_t id)
{
size_t i;
@ -61,12 +81,27 @@ static size_t clip_index(const xtc_project *project, uint64_t id)
return SIZE_MAX;
}
/**
* @brief Checks that a nonempty timeline range and its source slice fit their bounds.
*
* @param start Timeline start tick.
* @param length Nonzero duration in ticks.
* @param offset Source offset in ticks.
* @param source Source duration in ticks.
* @return Nonzero if both timeline and source bounds are valid, zero otherwise.
*/
static int valid_range(uint64_t start, uint64_t length, uint64_t offset, uint64_t source)
{
return start <= XTC_PROJECT_MAX_TICK && length != 0U && length <= XTC_PROJECT_MAX_TICK - start &&
source <= XTC_PROJECT_MAX_TICK && offset <= source && length <= source - offset;
}
/**
* @brief Allocates an empty project with an output-only graph policy and 120 BPM tempo.
*
* @param out_project Receives the newly allocated project; caller owns it on success.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_create(xtc_project **out_project)
{
xtc_project *project;
@ -88,6 +123,11 @@ xtc_result xtc_project_create(xtc_project **out_project)
return XTC_OK;
}
/**
* @brief Releases a project and its graph; accepts NULL.
*
* @param project Project model; borrowed for this call.
*/
void xtc_project_destroy(xtc_project *project)
{
if (project != NULL) {
@ -96,11 +136,24 @@ void xtc_project_destroy(xtc_project *project)
}
}
/**
* @brief Returns the project's borrowed graph, or NULL for a NULL project.
*
* @param project Project model; borrowed for this call.
* @return Borrowed graph valid until project mutation or destruction, or NULL for NULL.
*/
const xtc_graph *xtc_project_graph(const xtc_project *project)
{
return project == NULL ? NULL : project->graph;
}
/**
* @brief Copies and validates a graph before replacing the project's graph.
*
* @param project Project model; borrowed for this call.
* @param source Graph model; borrowed for this call.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_set_graph(xtc_project *project, const xtc_graph *source)
{
xtc_graph *copy;
@ -126,6 +179,13 @@ xtc_result xtc_project_set_graph(xtc_project *project, const xtc_graph *source)
return XTC_OK;
}
/**
* @brief Allocates an independent copy of project metadata and its graph.
*
* @param source Project model; borrowed for this call.
* @param out_project Receives the newly allocated project; caller owns it on success.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_clone(const xtc_project *source, xtc_project **out_project)
{
xtc_project *copy;
@ -149,6 +209,14 @@ xtc_result xtc_project_clone(const xtc_project *source, xtc_project **out_projec
return XTC_OK;
}
/**
* @brief Copies the current track and clip counts.
*
* @param project Project model; borrowed for this call.
* @param tracks Receives the number of tracks.
* @param clips Receives the number of clips.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_get_counts(const xtc_project *project, size_t *tracks, size_t *clips)
{
if (project == NULL || tracks == NULL || clips == NULL)
@ -158,6 +226,14 @@ xtc_result xtc_project_get_counts(const xtc_project *project, size_t *tracks, si
return XTC_OK;
}
/**
* @brief Copies a track snapshot selected by dense list index.
*
* @param project Project model; borrowed for this call.
* @param index Zero-based index in the dense list.
* @param track Receives a copy of the track metadata.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_get_track(const xtc_project *project, size_t index, xtc_track_info *track)
{
if (project == NULL || track == NULL)
@ -168,6 +244,14 @@ xtc_result xtc_project_get_track(const xtc_project *project, size_t index, xtc_t
return XTC_OK;
}
/**
* @brief Copies a clip snapshot selected by dense list index.
*
* @param project Project model; borrowed for this call.
* @param index Zero-based index in the dense list.
* @param clip Receives a copy of the clip metadata.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_get_clip(const xtc_project *project, size_t index, xtc_clip_info *clip)
{
if (project == NULL || clip == NULL)
@ -178,6 +262,14 @@ xtc_result xtc_project_get_clip(const xtc_project *project, size_t index, xtc_cl
return XTC_OK;
}
/**
* @brief Copies a clip snapshot selected by stable identifier.
*
* @param project Project model; borrowed for this call.
* @param id Stable identifier of the object to find or edit.
* @param clip Receives a copy of the clip metadata.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_find_clip(const xtc_project *project, uint64_t id, xtc_clip_info *clip)
{
if (project == NULL)
@ -185,6 +277,14 @@ xtc_result xtc_project_find_clip(const xtc_project *project, uint64_t id, xtc_cl
return xtc_project_get_clip(project, clip_index(project, id), clip);
}
/**
* @brief Appends a track with unity gain and a new stable identifier.
*
* @param project Project model; borrowed for this call.
* @param name NUL-terminated name.
* @param id Receives the new stable identifier.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_add_track(xtc_project *project, const char *name, uint64_t *id)
{
xtc_track_info track = {0};
@ -200,6 +300,13 @@ xtc_result xtc_project_add_track(xtc_project *project, const char *name, uint64_
return XTC_OK;
}
/**
* @brief Removes a track and its clips, notes, and automation.
*
* @param project Project model; borrowed for this call.
* @param id Stable identifier of the object to find or edit.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_remove_track(xtc_project *project, uint64_t id)
{
size_t index, i, count = 0U;
@ -228,6 +335,17 @@ xtc_result xtc_project_remove_track(xtc_project *project, uint64_t id)
return XTC_OK;
}
/**
* @brief Appends a silent region on an existing track with a new stable identifier.
*
* @param project Project model; borrowed for this call.
* @param track Stable track identifier.
* @param name NUL-terminated name.
* @param start Start position in musical ticks.
* @param length Duration in musical ticks.
* @param id Receives the new stable identifier.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_add_clip(xtc_project *project, uint64_t track, const char *name, uint64_t start, uint64_t length,
uint64_t *id)
{
@ -248,6 +366,13 @@ xtc_result xtc_project_add_clip(xtc_project *project, uint64_t track, const char
return XTC_OK;
}
/**
* @brief Removes a clip and its notes.
*
* @param project Project model; borrowed for this call.
* @param id Stable identifier of the object to find or edit.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_remove_clip(xtc_project *project, uint64_t id)
{
size_t index;
@ -269,6 +394,17 @@ xtc_result xtc_project_remove_clip(xtc_project *project, uint64_t id)
return XTC_OK;
}
/**
* @brief Atomically moves or trims a clip within its existing source bounds.
*
* @param project Project model; borrowed for this call.
* @param id Stable identifier of the object to find or edit.
* @param track Stable track identifier.
* @param start Start position in musical ticks.
* @param length Duration in musical ticks.
* @param offset Sample offset within the current block.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_edit_clip(xtc_project *project, uint64_t id, uint64_t track, uint64_t start, uint64_t length,
uint64_t offset)
{
@ -287,11 +423,24 @@ xtc_result xtc_project_edit_clip(xtc_project *project, uint64_t id, uint64_t tra
return XTC_OK;
}
/**
* @brief Returns the constant tempo in milli-BPM, or zero for a NULL project.
*
* @param project Project model; borrowed for this call.
* @return Tempo in milli-BPM, or zero for NULL.
*/
unsigned int xtc_project_tempo(const xtc_project *project)
{
return project == NULL ? 0U : project->tempo;
}
/**
* @brief Sets the constant tempo within the range 20000 to 300000 milli-BPM.
*
* @param project Project model; borrowed for this call.
* @param tempo Tempo in milli-BPM.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_set_tempo(xtc_project *project, unsigned int tempo)
{
if (project == NULL || tempo < 20000U || tempo > 300000U)
@ -300,6 +449,15 @@ xtc_result xtc_project_set_tempo(xtc_project *project, unsigned int tempo)
return XTC_OK;
}
/**
* @brief Converts a musical tick to an absolute sample position, rounding down.
*
* @param project Project model; borrowed for this call.
* @param tick Musical position in ticks.
* @param rate Sample rate in hertz.
* @param sample Receives the sample position.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_tick_to_sample(const xtc_project *project, uint64_t tick, unsigned int rate, uint64_t *sample)
{
if (project == NULL || sample == NULL || rate == 0U || rate > 768000U)
@ -310,6 +468,15 @@ xtc_result xtc_project_tick_to_sample(const xtc_project *project, uint64_t tick,
return XTC_OK;
}
/**
* @brief Converts an absolute sample position to a musical tick, rounding down.
*
* @param project Project model; borrowed for this call.
* @param sample Absolute sample position.
* @param rate Sample rate in hertz.
* @param tick Receives the musical tick.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_sample_to_tick(const xtc_project *project, uint64_t sample, unsigned int rate, uint64_t *tick)
{
uint64_t scale, value, divisor, whole;
@ -327,6 +494,12 @@ xtc_result xtc_project_sample_to_tick(const xtc_project *project, uint64_t sampl
return XTC_OK;
}
/**
* @brief Validates project IDs, timeline ranges, names, graph, notes, and automation.
*
* @param project Project model; borrowed for this call.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_validate(const xtc_project *project)
{
size_t i, j;
@ -395,6 +568,14 @@ xtc_result xtc_project_validate(const xtc_project *project)
return XTC_OK;
}
/**
* @brief Sets an absolute audio asset reference, or clears it to make a region silent.
*
* @param project Project model; borrowed for this call.
* @param id Stable identifier of the object to find or edit.
* @param path NUL-terminated file or asset path.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_set_clip_asset(xtc_project *project, uint64_t id, const char *path)
{
size_t index, length = 0U, i;

View file

@ -19,6 +19,18 @@ struct xtc_project {
xtc_clip_info clips[XTC_PROJECT_MAX_CLIPS];
};
/**
* @brief Checks for a nonempty UTF-8 name of at most 63 bytes without ASCII controls.
*
* @param name NUL-terminated name.
* @return Nonzero for a valid name, zero otherwise.
*/
int xtc_project_valid_name(const char *name);
/**
* @brief Validates project IDs, timeline ranges, names, graph, notes, and automation.
*
* @param project Project model; borrowed for this call.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_validate(const xtc_project *project);
#endif