#include #include #include #include #include #include #include #include #include #include #include #include namespace VIZ { void VisPlugins::init(HIDHelper *hidHelper, AudioGrabber *audioGrabber) { grabber = audioGrabber; keyboard = new Vulcan121(hidHelper); viz[0] = new Spectrum(grabber, keyboard); viz[1] = new Loudness(grabber, keyboard); viz[2] = new PoliceLike(grabber, keyboard); viz[3] = new RainbowLine(grabber, keyboard); viz[4] = new Random(grabber, keyboard); viz[5] = new RainbowMap(grabber, keyboard); viz[6] = new Spectral(grabber, keyboard); viz[7] = new BassHistory(grabber, keyboard); viz[8] = new TheUnknown(grabber, keyboard); viz[9] = new Strobo(grabber, keyboard); currentVis = viz[mode]; } void VisPlugins::onStartup() { std::lock_guard lockGuard(guard); if (!keyboard->sendInitSequence()) { ERR("FAILED TO INIT KEYBOARD") exit(1); } currentVis->onSetup(); start = std::chrono::high_resolution_clock::now(); } void VisPlugins::onTick() { std::lock_guard lockGuard(guard); auto stop = std::chrono::high_resolution_clock::now(); auto delta = std::chrono::duration_cast(stop - start).count() / 1000000.0; currentVis->onTick((float) delta); frames++; #ifdef DEBUG auto fps = std::chrono::duration_cast(stop - frameStart).count(); if (fps > 1000) { frameStart = stop; DBG("FPS: %.2f, time-needed: %d ms", double(frames) / (int) fps * 1000.0, (int) fps) frames = 0; } #endif start = stop; } void VisPlugins::onShutdown() { std::lock_guard lockGuard(guard); int16_t r = env->getAsInt("shutdown_color_red", 0); int16_t g = env->getAsInt("shutdown_color_green", 0); int16_t b = env->getAsInt("shutdown_color_blue", 150); int16_t a = env->getAsInt("shutdown_brightness", 100); keyboard->sendToLEDs({ r, g, b, a }); } VisPlugins::~VisPlugins() { delete grabber; delete keyboard; for (auto &i : viz) { delete i; } } void VisPlugins::setCurrentMode(int m) { std::lock_guard lockGuard(guard); if (m < 1 || m > VIZSIZE) { ERR("Mode Setting Failed >> Mode is not in the available range 1 - %d", VIZSIZE) return; } grabber->env->setNumber("visual_mode", m); m -= 1; currentVis = viz[m]; LOG("Now Using: %s", currentVis->name()); currentVis->onSetup(); mode = m; } }