diff --git a/src/monitor/gui/components/audio/cpp/base.cpp b/src/monitor/gui/components/audio/cpp/base.cpp index fa0543a..97d7756 100755 --- a/src/monitor/gui/components/audio/cpp/base.cpp +++ b/src/monitor/gui/components/audio/cpp/base.cpp @@ -7,6 +7,7 @@ namespace monitor::components { CONNECT(this); m_player.set_callback(std::bind(&audio::callback, this, std::placeholders::_1, std::placeholders::_2)); + m_player.set_device(); } void audio::on_detach() diff --git a/src/monitor/gui/components/creator/cpp/base.cpp b/src/monitor/gui/components/creator/cpp/base.cpp index c245455..2351869 100644 --- a/src/monitor/gui/components/creator/cpp/base.cpp +++ b/src/monitor/gui/components/creator/cpp/base.cpp @@ -22,18 +22,12 @@ namespace monitor::components void creator::create() { m_status = utils::var::STATUS::PROCESS; + m_setup.m_file = utils::var::DIR / m_dir.m_name / m_file.m_name; + // send to: tabs + VE::event e { utils::event_type::CREATE_SNAPSHOT, m_setup }; + EMIT(e); + clear(); - auto f = [this]() { - auto file = utils::var::DIR / m_dir.m_name / m_file.m_name; - - // send to: tabs - m_setup.m_file = file; - VE::event e { utils::event_type::CREATE_SNAPSHOT, m_setup }; - EMIT(e); - clear(); - }; - std::thread th(f); - th.detach(); } void creator::clear() diff --git a/src/monitor/gui/components/creator/cpp/render/combo.cpp b/src/monitor/gui/components/creator/cpp/render/combo.cpp index dd954e2..b3f4d90 100644 --- a/src/monitor/gui/components/creator/cpp/render/combo.cpp +++ b/src/monitor/gui/components/creator/cpp/render/combo.cpp @@ -5,18 +5,18 @@ namespace monitor::components { void creator::render_combo() { - ImGui::SetNextItemWidth(400.f); - if (ImGui::BeginCombo(VE_NO_NAME("select_dir"), m_dir.m_id < 0 ? "---" : m_dirs[m_dir.m_id].c_str())) + ImGui::SetNextItemWidth(200.f); + if (ImGui::BeginCombo(VE_NO_NAME("select_signal_type"), m_signal_type.m_id < 0 ? "---" : hr::all_types()[m_signal_type.m_id].get_name().c_str())) { - for (std::size_t i = 0; i < m_dirs.size(); ++i) + for (std::size_t i = 0; i < hr::all_types().size(); ++i) { - const bool is_selected = (m_dir.m_id == static_cast(i)); - if (ImGui::Selectable(m_dirs[i].c_str(), is_selected)) + const bool is_selected = (m_signal_type.m_id == static_cast(i)); + if (ImGui::Selectable(hr::all_types()[i].get_name().c_str(), is_selected)) { - m_files.clear(); - m_dir.init(i, m_dirs[i]); - for (const auto& entry : std::filesystem::directory_iterator(utils::var::DIR/m_dir.m_name)) - if (entry.is_regular_file()) m_files.push_back(entry.path().filename().string()); + m_signal_type.init(i, hr::all_types()[i].get_name()); + m_setup.m_signal_type = hr::all_types()[i]; + if (m_setup.m_signal_type.m_type != hr::signal_type::type::FILE) + m_status = utils::var::STATUS::READY; } if (is_selected) ImGui::SetItemDefaultFocus(); } @@ -26,6 +26,31 @@ namespace monitor::components auto ctx = ImGui::GetCurrentContext(); ImGui::SameLine(0.f, ctx->Style.FramePadding.x); + + ImGui::SetNextItemWidth(400.f); + if (ImGui::BeginCombo(VE_NO_NAME("select_dir"), m_dir.m_id < 0 ? "---" : m_dirs[m_dir.m_id].c_str())) + { + if (m_setup.m_signal_type.m_type == hr::signal_type::type::FILE) + { + for (std::size_t i = 0; i < m_dirs.size(); ++i) + { + const bool is_selected = (m_dir.m_id == static_cast(i)); + if (ImGui::Selectable(m_dirs[i].c_str(), is_selected)) + { + m_files.clear(); + m_dir.init(i, m_dirs[i]); + for (const auto& entry : std::filesystem::directory_iterator(utils::var::DIR/m_dir.m_name)) + if (entry.is_regular_file()) m_files.push_back(entry.path().filename().string()); + } + if (is_selected) ImGui::SetItemDefaultFocus(); + } + } + + ImGui::EndCombo(); + } + + ctx = ImGui::GetCurrentContext(); + ImGui::SameLine(0.f, ctx->Style.FramePadding.x); ImGui::SetNextItemWidth(400.f); if (ImGui::BeginCombo(VE_NO_NAME("select_file"), m_file.m_id < 0 ? "---" : m_files[m_file.m_id].c_str())) diff --git a/src/monitor/gui/components/creator/cpp/render/setup.cpp b/src/monitor/gui/components/creator/cpp/render/setup.cpp index f889dce..096f55e 100644 --- a/src/monitor/gui/components/creator/cpp/render/setup.cpp +++ b/src/monitor/gui/components/creator/cpp/render/setup.cpp @@ -27,7 +27,7 @@ namespace monitor::components ImGui::SameLine(0.0f, spacing); ImGui::Text("%zu", m_setup.m_block_size); // тут нужно жестко, а то при изменении циферек прагает в сторону поле - ImGui::SameLine(1000.0f); + ImGui::SameLine(1200.0f); ImGui::SetCursorPosY(8.f); VE_PUSH_FONT(ICON, 12); @@ -60,7 +60,7 @@ namespace monitor::components ImGui::SameLine(0.0f, spacing); ImGui::Text("%zu", m_setup.m_step_size); // тут нужно жестко, а то при изменении циферек прагает в сторону поле - ImGui::SameLine(1195.0f); + ImGui::SameLine(1395.0f); ImGui::SetCursorPosY(8.f); VE_PUSH_FONT(ICON, 12); @@ -71,39 +71,5 @@ namespace monitor::components VE_POP_FONT(); ImGui::PopItemFlag(); // end - - ImGui::SameLine(0.f, 4.f * spacing); - - // compression - hr::base_t step_compression = 0.1; - ImGui::Text("compression:"); - ImGui::SameLine(0.0f, spacing); - - ImGui::PushItemFlag(ImGuiItemFlags_ButtonRepeat, true); - ImGui::SetCursorPosY(8.f); - VE_PUSH_FONT(ICON, 12); - ImGui::PushID(VE_NO_NAME("4")); - if (ImGui::Button(VE::style::icon::ICON_MINUS, ImVec2{24, 20})) - { - m_setup.m_compression -= step_compression; - m_setup.m_compression = std::fmax(0.0, m_setup.m_compression); - } - ImGui::PopID(); - VE_POP_FONT(); - - ImGui::SameLine(0.0f, spacing); - ImGui::Text("%.2f", m_setup.m_compression); - // тут нужно жестко, а то при изменении циферек прагает в сторону поле - ImGui::SameLine(1420.0f); - - ImGui::SetCursorPosY(8.f); - VE_PUSH_FONT(ICON, 12); - ImGui::PushID(VE_NO_NAME("5")); - if (ImGui::Button(VE::style::icon::ICON_PLUS, ImVec2{24, 20})) - m_setup.m_compression += step_compression; - ImGui::PopID(); - VE_POP_FONT(); - ImGui::PopItemFlag(); - // end } } diff --git a/src/monitor/gui/components/creator/cpp/render/spinner.cpp b/src/monitor/gui/components/creator/cpp/render/spinner.cpp index 06d1da7..84c7ecb 100644 --- a/src/monitor/gui/components/creator/cpp/render/spinner.cpp +++ b/src/monitor/gui/components/creator/cpp/render/spinner.cpp @@ -9,7 +9,7 @@ namespace monitor::components { auto ctx = ImGui::GetCurrentContext(); auto s = ctx->CurrentWindow->Size; - ImVec2 pos{ 830.f, s.y / 2.f }; + ImVec2 pos{ 1030.f, s.y / 2.f }; if (m_status == utils::var::STATUS::COMPLETED) m_spinner.render(pos); else if (m_status == utils::var::STATUS::READY) m_spinner.render(pos, "#B4CF16"); diff --git a/src/monitor/gui/components/creator/creator.hpp b/src/monitor/gui/components/creator/creator.hpp index 3d3f629..c2790f0 100644 --- a/src/monitor/gui/components/creator/creator.hpp +++ b/src/monitor/gui/components/creator/creator.hpp @@ -15,7 +15,7 @@ namespace monitor::components private: struct combo { - std::string m_name; + std::string m_name = "no selected"; int m_id = -1; void init(int id, std::string name) { m_id = id; m_name = name; } void clear() @@ -28,6 +28,7 @@ namespace monitor::components private: std::vector m_dirs; std::vector m_files; + combo m_signal_type; combo m_dir; combo m_file; utils::var::STATUS m_status = utils::var::STATUS::EMPTY; @@ -41,6 +42,7 @@ namespace monitor::components void render_spinner(); void render_buttons(); void render_setup(); + void render_combo_signals(); }; } diff --git a/src/monitor/gui/components/snapshot/cpp/base.cpp b/src/monitor/gui/components/snapshot/cpp/base.cpp index 842ad14..f85b989 100755 --- a/src/monitor/gui/components/snapshot/cpp/base.cpp +++ b/src/monitor/gui/components/snapshot/cpp/base.cpp @@ -9,9 +9,6 @@ namespace monitor::components CONNECT(this); m_audio.on_attach(); m_markers.on_attach(); - - m_plugins.emplace_back(combo{ .m_id = 0, .m_name = "Energy", .m_type = utils::var::PLUGIN_TYPE::ENERGY }); - m_plugins.emplace_back(combo{ .m_id = 1, .m_name = "Segmenter", .m_type = utils::var::PLUGIN_TYPE::SEGMENTER }); } void snapshot::on_detach() @@ -39,10 +36,23 @@ namespace monitor::components void snapshot::init(hr::setup setup) { m_setup = setup; - auto r = hr::run(m_setup); + + hr::result r; + + if (m_setup.m_signal_type.m_type != hr::signal_type::type::FILE) + { + hr::signal_generator sg; + r = sg.generate(setup.m_signal_type); + } + else + { + r = hr::run(m_setup); + } fill(r); + // HERE + // когда генерируем то нужно и звук сделать !!! m_audio.init(m_setup.m_file); m_audio.set_step(r.m_data.size()); m_markers.init(); @@ -94,17 +104,17 @@ namespace monitor::components switch (m_plugin.m_type) { - case utils::var::PLUGIN_TYPE::SEGMENTER: - { - r = hr::run(m_setup); - break; - } - - case utils::var::PLUGIN_TYPE::ENERGY: - { - r = hr::run(m_setup); - break; - } + // case utils::var::PLUGIN_TYPE::SEGMENTER: + // { + // r = hr::run(m_setup); + // break; + // } + // + // case utils::var::PLUGIN_TYPE::ENERGY: + // { + // r = hr::run(m_setup); + // break; + // } } fill(r); diff --git a/src/monitor/libs/audio/audio.cpp b/src/monitor/libs/audio/audio.cpp index f9a3e72..5069180 100644 --- a/src/monitor/libs/audio/audio.cpp +++ b/src/monitor/libs/audio/audio.cpp @@ -3,9 +3,29 @@ namespace monitor::libs { + void audio::set_device() + { + std::vector devices = sf::PlaybackDevice::getAvailableDevices(); + if (devices.size() < 1) + { + hack::error()("Не удалось найти устройство воспроизведения"); + return; + } + // поставь, то которое есть в списке устройств + // for (auto& d : devices) std::cout << d << std::endl; + std::string target_device = devices[1]; + if (sf::PlaybackDevice::setDevice(target_device)) + hack::log()("Устройство успешно установлено: ", target_device); + else + hack::error()("Не удалось установить устройство: ", target_device); + } + void audio::set_file(std::filesystem::path p) { if (!m_music.openFromFile(p)) hack::error()("dont open file:", p.string()); + + std::vector devices = sf::PlaybackDevice::getAvailableDevices(); + std::string targetDevice = devices[1]; } void audio::set_callback(std::function c) diff --git a/src/monitor/libs/audio/audio.hpp b/src/monitor/libs/audio/audio.hpp index 78a0925..c3071b6 100644 --- a/src/monitor/libs/audio/audio.hpp +++ b/src/monitor/libs/audio/audio.hpp @@ -13,6 +13,7 @@ namespace monitor::libs ~audio() =default; public: + void set_device(); void set_file(std::filesystem::path p); void play(); void stop();