#include "mainwindow.h"
#include "audio/audioengine.h"
#include "config/pluginregistry.h"
#include "data/graph.h"
#include "fileops.h"

#include <vector>

#include <QDebug>
#include <QFontDatabase>
#include <QApplication>
#include <QSurfaceFormat>

int main(int argc, char *argv[]) {
    qRegisterMetaType<Xybrid::Data::Port>();
    // enable antialiasing on accelerated graphicsview
    QSurfaceFormat fmt;
    fmt.setSamples(10);

    QSurfaceFormat::setDefaultFormat(fmt);
    QApplication a(argc, argv);




    // make sure bundled fonts are loaded
    QFontDatabase::addApplicationFont(":/fonts/iosevka-term-light.ttf");
    QFontDatabase::addApplicationFont(":/fonts/Arcon-Rounded-Regular.otf");

    Xybrid::FileOps::loadConfig();

    Xybrid::Config::PluginRegistry::init();
    Xybrid::Audio::AudioEngine::init();

    auto* w = new Xybrid::MainWindow();
    w->show();

    // hook up exit event
    QObject::connect(&a, &QCoreApplication::aboutToQuit, [] {
        Xybrid::FileOps::saveConfig();
    });

    return a.exec();
}
