1
0
Fork 0
forked from hanez/xtc
xtc/src/main.c

86 lines
3.5 KiB
C

#include "xtc/xtc.h"
#include "xtc/xtc_version.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "xtc/xtc_project.h"
#include "xtc/xtc_audio.h"
#include "xtc/xtc_midi.h"
#include <limits.h>
/**
* @brief Runs the xtc-check command-line entry point.
*
* Supports --version, --help, and --validate PROJECT. With no arguments it
* creates and destroys the application shell to check core startup/shutdown.
* Any other argument count prints usage to stderr.
*
* @param argc Number of command-line arguments, including the program name.
* @param argv Command-line argument vector; argv[0] is the program name.
* @return EXIT_SUCCESS on success, or EXIT_FAILURE for invalid usage,
* validation failure, or core initialization failure.
*/
int main(int argc, char **argv)
{
if (argc == 2 && !strcmp(argv[1], "--version")) {
printf("%s %s\n", XTC_PROJECT_NAME, XTC_VERSION_STRING);
return EXIT_SUCCESS;
}
if (argc == 2 && !strcmp(argv[1], "--diagnose")) {
unsigned int features = xtc_build_features();
printf("xtc %s; %zu-bit process\nProject formats: 1..%u\nJACK compiled: %s\nLADSPA compiled: %s\n"
"Limits: 256 graph nodes (64/project), %u tracks, %u clips, %u notes, 65536 frames/block\n"
"No server, device or plugin probed. Runtime errors appear in GUI status/stderr.\n",
XTC_VERSION_STRING,sizeof(void *)*CHAR_BIT,XTC_PROJECT_FORMAT_VERSION,
features & XTC_FEATURE_JACK ? "yes" : "no",features & XTC_FEATURE_LADSPA ? "yes" : "no",
XTC_PROJECT_MAX_TRACKS,XTC_PROJECT_MAX_CLIPS,XTC_PROJECT_MAX_NOTES);
return EXIT_SUCCESS;
}
if (argc == 2 && !strcmp(argv[1], "--help")) {
puts("Usage: xtc-check [--version | --help | --diagnose | --validate PROJECT | --recover-recording TEMP NEW.wav]\nNo arguments checks core startup/shutdown. "
"Validation checks metadata only.");
return EXIT_SUCCESS;
}
if (argc == 4 && !strcmp(argv[1], "--recover-recording")) {
xtc_result result = xtc_recorder_recover(argv[2], argv[3]);
if (result != XTC_OK) {
fprintf(stderr, "Recording recovery failed: %s. Source retained; choose a new writable destination.\n",
xtc_result_string(result));
return EXIT_FAILURE;
}
puts("Complete recorded frames recovered; source retained.");
return EXIT_SUCCESS;
}
if (argc == 3 && !strcmp(argv[1], "--validate")) {
xtc_project *project = NULL;
xtc_result result = xtc_project_create(&project);
if (result == XTC_OK)
result = xtc_project_load(project, argv[2]);
xtc_project_destroy(project);
if (result != XTC_OK) {
fprintf(stderr, "Project validation failed: %s\n", xtc_result_string(result));
return EXIT_FAILURE;
}
puts("Project metadata valid (external assets not loaded).");
return EXIT_SUCCESS;
}
if (argc != 1) {
fputs("Usage: xtc-check [--version | --help | --diagnose | --validate PROJECT | --recover-recording TEMP NEW.wav]\n", stderr);
return EXIT_FAILURE;
}
xtc_app *app = NULL;
xtc_result result = xtc_app_create(&app);
if (result != XTC_OK) {
(void)fprintf(stderr, "Application initialization failed: %s\n", xtc_result_string(result));
return EXIT_FAILURE;
}
xtc_app_destroy(app);
if (printf("%s %s: core startup/shutdown OK\n", XTC_PROJECT_NAME, XTC_VERSION_STRING) < 0) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}