#include #include // services #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include const char* argv0; using namespace entt::literals; class ImGuiSpeechy : public MM::Services::Service { private: SoLoud::Speech speech; SoLoud::Sfxr sfxr; SoLoud::FreeverbFilter freeverb; SoLoud::EchoFilter echo; SoLoud::LofiFilter lofi; public: const char* name(void) override { return "TestWindow"; } bool enable(MM::Engine& engine, std::vector& task_array) override { auto& sound = engine.getService().engine; speech.setText("Test text. 1. 2. 3."); sfxr.loadPreset(SoLoud::Sfxr::COIN, 0); sound.setGlobalFilter(0, &lofi); sound.setGlobalFilter(1, &echo); sound.setGlobalFilter(2, &freeverb); task_array.push_back( MM::UpdateStrategies::TaskInfo{"testwindow"} .fn([this](MM::Engine& engine) { renderImGui(engine); }) ); return true; } void disable(MM::Engine&) override {} void renderImGui(MM::Engine& engine) { auto& sound = *engine.tryService(); if (ImGui::Begin("Inputs")) { if (ImGui::Button("play sfx")) { sound.engine.play(sfxr); } //ImGui::Text("Active Voice Count: %d", sound.engine.getActiveVoiceCount()); if (ImGui::Button("Read")) { sound.engine.play(speech); } } ImGui::End(); if (ImGui::Begin("Sfxr plain")) { MM::ImGuiWidgets::SoLoudSfxrPlain("plain_sfxr", &sfxr.mParams); } ImGui::End(); if (ImGui::Begin("Sfxr fancy")) { MM::ImGuiWidgets::SoLoudSfxrFancy("fancy_sfxr", &sfxr.mParams); } ImGui::End(); if (ImGui::Begin("filter lofi")) { MM::ImGuiWidgets::SoLoudFilterLiveParams("filter lofi", &sound.engine, &lofi, 0); } ImGui::End(); if (ImGui::Begin("filter echo")) { MM::ImGuiWidgets::SoLoudFilterLiveParams("filter echo", &sound.engine, &echo, 1); } ImGui::End(); if (ImGui::Begin("filter freeverb")) { MM::ImGuiWidgets::SoLoudFilterLiveParams("filter freeverb", &sound.engine, &freeverb, 2); } ImGui::End(); if (ImGui::Begin("filter fancy lofi")) { ImGui::TextDisabled("LoFi"); MM::ImGuiWidgets::SoLoudFilterLiveParamsFancy("filter fancy lofi", &sound.engine, &lofi, 0); } ImGui::End(); if (ImGui::Begin("filter fancy echo")) { ImGui::TextDisabled("Echo"); MM::ImGuiWidgets::SoLoudFilterLiveParamsFancy("filter fancy echo", &sound.engine, &echo, 1); } ImGui::End(); if (ImGui::Begin("filter fancy freeverb")) { ImGui::TextDisabled("Rev"); MM::ImGuiWidgets::SoLoudFilterLiveParamsFancy("filter fancy freeverb", &sound.engine, &freeverb, 2); } ImGui::End(); if (ImGui::Begin("Sfxr json")) { std::string json_text = nlohmann::json(sfxr).dump(2); ImGui::InputTextMultiline("json", &json_text); } ImGui::End(); } }; TEST(imgui_sound, basic) { MM::Engine engine; auto& sdl_ss = engine.addService(); ASSERT_TRUE(engine.enableService()); sdl_ss.createGLWindow("imgui_sound_test", 800, 600); engine.addService(argv0, "imgui_sound_test"); ASSERT_TRUE(engine.enableService()); auto& sound = engine.addService(); ASSERT_TRUE(engine.enableService()); sound.engine.setVisualizationEnable(true); engine.addService(); ASSERT_TRUE(engine.enableService()); engine.addService(); ASSERT_TRUE(engine.enableService()); engine.addService(); ASSERT_TRUE(engine.enableService()); engine.addService(); ASSERT_TRUE(engine.enableService()); auto& rs = engine.addService(); ASSERT_TRUE(engine.enableService()); rs.addRenderTask(engine); engine.addService(); ASSERT_TRUE(engine.enableService()); #ifdef MM_AUTOTEST engine.addService(50); // 50 frames ASSERT_TRUE(engine.enableService()); #endif engine.run(); sdl_ss.destroyWindow(); } int main(int argc, char** argv) { argv0 = argv[0]; ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }