xtc/src/gui/main.cpp

62 lines
2.3 KiB
C++

#include <FL/Fl.H>
#include <cstdio>
#include <cstdlib>
#include <exception>
#include "main_window.hpp"
#include "xtc/xtc_version.h"
#include "xtc/xtc.h"
#include <cstring>
/**
* @brief Runs the FLTK application and reports command-line or startup failures.
*
* @param argc Number of command-line arguments including the program name.
* @param argv Command-line argument vector.
* @return EXIT_SUCCESS after the event loop exits, or EXIT_FAILURE for invalid usage or startup failure.
*/
int main(int argc, char **argv)
{
if (argc == 2 && !std::strcmp(argv[1], "--version")) {
std::printf("%s %s\n", XTC_PROJECT_NAME, XTC_VERSION_STRING);
return EXIT_SUCCESS;
}
if (argc == 2 && !std::strcmp(argv[1], "--diagnose")) {
unsigned int features = xtc_build_features();
std::printf("xtc %s; project formats 1..%u; JACK %s; LADSPA %s\nFor limits and recovery commands run xtc-check --diagnose/--help.\n",
XTC_VERSION_STRING,XTC_PROJECT_FORMAT_VERSION,features & XTC_FEATURE_JACK ? "compiled" : "disabled",
features & XTC_FEATURE_LADSPA ? "compiled" : "disabled");
return EXIT_SUCCESS;
}
if (argc == 2 && !std::strcmp(argv[1], "--help")) {
std::puts(
"Usage: xtc [PROJECT] or xtc [FLTK options]\n--version, --diagnose and --help work without a display or audio server.");
return EXIT_SUCCESS;
}
const char *project_path = nullptr;
if (argc == 2 && argv[1][0] != '-') {
project_path = argv[1];
argc = 1;
argv[1] = nullptr;
}
try {
Fl::scheme("flat");
Fl::background(34, 36, 40);
Fl::background2(24, 26, 30);
Fl::foreground(230, 232, 236);
MainWindow window;
if (project_path) {
xtc_result result = window.open_project(project_path);
if (result != XTC_OK) {
std::fprintf(stderr, "Cannot open project: %s\n", xtc_result_string(result));
return EXIT_FAILURE;
}
}
window.show(argc, argv);
return Fl::run();
} catch (const std::exception &error) {
std::fprintf(stderr, "GUI startup/runtime failure: %s\n", error.what());
} catch (...) {
std::fputs("Unexpected GUI startup/runtime failure.\n", stderr);
}
return EXIT_FAILURE;
}