add base markers

This commit is contained in:
2026-03-27 16:44:36 +03:00
parent 66e1f70141
commit a5f856b224
13 changed files with 20 additions and 183 deletions

View File

@@ -27,6 +27,8 @@ namespace monitor::components
public:
void toggle();
void pause();
// делать
void drop();
void set_pos(double pos);
void set_step(std::size_t step);

View File

@@ -50,10 +50,13 @@ namespace monitor::components
void audio::callback(sf::Time time, double pos)
{
m_current_audio.m_current_time = time;
// HERE
// начинаем тут, делаем установку мсаркера проигрывания
VE::event e { utils::event_type::INCREMENT_MARKER_AUDIO_POSITION, pos };
EMIT(e);
}
// делать
void audio::drop()
{
m_player.stop();

View File

@@ -12,15 +12,9 @@ namespace monitor::components
bool is_play = m_player.is_playing();
if (is_play)
{
ImGui::PushStyleColor(ImGuiCol_Button, VE_COLOR("#298FD4", 180));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, VE_COLOR("#298FD4", 255));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, VE_COLOR("#298FD4", 200));
}
else
{
ImGui::PushStyleColor(ImGuiCol_Button, VE_COLOR("#125C25", 180));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, VE_COLOR("#125C25", 255));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, VE_COLOR("#125C25", 200));
ImGui::PushStyleColor(ImGuiCol_Button, VE_COLOR("#4D4DA2", 180));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, VE_COLOR("#4D4DA2", 255));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, VE_COLOR("#4D4DA2", 200));
}
if (ImGui::Button(is_play ? "pause" : "play", ImVec2{70.f, 26.f} ))
@@ -29,7 +23,7 @@ namespace monitor::components
std::thread t(f);
t.detach();
}
ImGui::PopStyleColor(3);
if (is_play) ImGui::PopStyleColor(3);
ImGui::SameLine();

View File

@@ -5,21 +5,25 @@ namespace monitor::components
void graph::on_attach()
{
CONNECT(this);
m_markers.on_attach();
}
void graph::on_detach()
{
DISCONNECT();
m_markers.on_detach();
}
void graph::update()
{
m_markers.update();
}
void graph::init(std::string snapshot_id, hr::setup setup)
{
m_snapshot_id = snapshot_id;
m_setup = setup;
m_markers.init();
}
void graph::set_plugin(std::shared_ptr<utils::plugin> plugin) noexcept

View File

@@ -31,6 +31,7 @@ namespace monitor::components
ImPlot::PlotLine(VE_NAME(std::to_string(i)), m_plugin->m_ox.data(), m_plugin->m_line_data[i].data(), m_plugin->m_line_data[i].size());
}
m_markers.render();
m_is_first_render = false;
ImPlot::EndPlot();
}

View File

@@ -3,6 +3,7 @@
#include <VE.hpp>
#include <harmonica.hpp>
#include "monitor/utils/plugin.hpp"
#include "monitor/gui/components/markers/markers.hpp"
namespace monitor::components
{
@@ -25,5 +26,6 @@ namespace monitor::components
std::shared_ptr<utils::plugin> m_plugin;
hr::setup m_setup;
std::string m_snapshot_id;
markers m_markers;
};
}

View File

@@ -17,20 +17,9 @@ namespace monitor::components
{
}
void markers::set_status(utils::var::STATUS s)
{
m_status = s;
}
void markers::set_tag_show(bool v)
{
m_tag_show = v;
}
void markers::init()
{
m_marker_audio_color = ImGui::ColorConvertU32ToFloat4(VE_COLOR("#00FC7C", 180));
m_marker_mouse_color = ImGui::ColorConvertU32ToFloat4(VE_COLOR("#414243", 180));
m_marker_fixed_color = ImGui::ColorConvertU32ToFloat4(VE_COLOR("#B4CF16", 180));
m_marker_audio_color = ImGui::ColorConvertU32ToFloat4(VE_COLOR("#7DEFAC", 180));
m_marker_mouse_color = ImGui::ColorConvertU32ToFloat4(VE_COLOR("#8CA9C6", 180));
}
}

View File

@@ -5,8 +5,6 @@ namespace monitor::components
{
void markers::on_event(VE::event& e)
{
if (m_status != utils::var::STATUS::ACTIVE) return;
if (e.m_type.type() == typeid(VE::event_type))
{
auto type = std::any_cast<VE::event_type>(e.m_type);
@@ -54,20 +52,6 @@ namespace monitor::components
m_marker_audio_position = 0.0;
break;
}
case utils::event_type::SET_MARKER_MOUSE_POSITION:
{
auto pos = std::any_cast<double>(e.m_data);
m_marker_mouse_position = pos;
break;
}
// case utils::event_type::REMOVE_LAST_MARKER_SEGMENT:
// {
// if (m_marker_segment.size() > 0)
// m_marker_segment.pop_back();
// break;
// }
}
}
}

View File

@@ -23,35 +23,5 @@ namespace monitor::components
m_marker_mouse_position = ImPlot::GetPlotMousePos().x;
ImPlot::DragLineX(1000, &m_marker_mouse_position, m_marker_mouse_color, 0.1f, ImPlotDragToolFlags_NoCursors | ImPlotDragToolFlags_NoInputs);
}
// кликаем для установки тэгов
if (m_shift_press && ImGui::IsMouseClicked(ImGuiMouseButton_Right) && ImPlot::IsPlotHovered())
m_marker_fixed.push_back(ImPlot::GetPlotMousePos().x);
for (std::size_t i = 0; i < m_marker_fixed.size(); ++i)
{
ImPlot::DragLineX(i, &m_marker_fixed[i], m_marker_fixed_color, 0.1f, ImPlotDragToolFlags_NoCursors | ImPlotDragToolFlags_NoInputs);
if (m_tag_show) ImPlot::TagX(m_marker_fixed[i], m_marker_fixed_color, std::to_string(i).c_str());
}
if (m_shift_press)
{
auto p = ImPlot::GetPlotMousePos().x;
for (std::size_t i = 0; i < m_marker_fixed.size(); ++i)
{
if (std::abs(p - m_marker_fixed[i]) < m_tolerance)
{
ImPlot::DragLineX(i, &m_marker_fixed[i], m_marker_fixed_color, 2.7f, ImPlotDragToolFlags_NoCursors | ImPlotDragToolFlags_NoInputs);
if (ImGui::IsMouseClicked(ImGuiMouseButton_Left) && ImPlot::IsPlotHovered())
m_marker_fixed.erase(m_marker_fixed.begin() + i);
}
}
}
// показываем позицию при наведении мыши
auto p = ImPlot::GetPlotMousePos().x;
for (std::size_t i = 0; i < m_marker_fixed.size(); ++i)
if (std::abs(p - m_marker_fixed[i]) < m_tolerance * 4.0)
ImPlot::TagX(m_marker_fixed[i], m_marker_fixed_color, std::to_string(static_cast<int>(ImPlot::GetPlotMousePos().x)).c_str());
}
}

View File

@@ -1,7 +1,6 @@
#pragma once
#include <VE.hpp>
#include "monitor/utils/var.hpp"
namespace monitor::components
{
@@ -12,19 +11,12 @@ namespace monitor::components
public:
void init();
void set_status(utils::var::STATUS s);
void set_tag_show(bool v);
private:
utils::var::STATUS m_status;
ImVec4 m_marker_audio_color;
ImVec4 m_marker_mouse_color;
double m_marker_audio_position = 0.0;
double m_marker_mouse_position = 0.0;
double m_marker_audio_position = 100.0;
double m_marker_mouse_position = 100.0;
bool m_shift_press = false;
double m_tolerance = 2.7; // Настройте чувствительность приближения мыши к тэгу
bool m_tag_show = false; // эта штука не ставит тэг на графике наже первого(Magnitude)
ImVec4 m_marker_fixed_color;
std::vector<double> m_marker_fixed;
};
}

View File

@@ -9,32 +9,22 @@ namespace monitor::components
CONNECT(this);
m_base_plugins.on_attach();
m_base_controls.on_attach();
// HERE
// то что ниже будем убирать
m_markers.on_attach();
// m_plugins.emplace_back(combo{ .m_id = 0, .m_name = "Magnitude", .m_type = utils::var::PLUGIN_TYPE::MAGNITUDE });
// m_plugins.emplace_back(combo{ .m_id = 1, .m_name = "Energy", .m_type = utils::var::PLUGIN_TYPE::ENERGY });
}
void snapshot::on_detach()
{
DISCONNECT();
m_base_plugins.on_detach();
m_markers.on_detach();
}
void snapshot::update()
{
m_base_plugins.update();
m_markers.update();
}
void snapshot::set_status(utils::var::STATUS s)
{
m_status = s;
m_markers.set_status(m_status);
}
void snapshot::init(hr::setup setup)
@@ -48,87 +38,5 @@ namespace monitor::components
VE::event e2 { utils::event_type::SET_AUDIO_FILE, std::pair<std::string, std::filesystem::path>(m_snapshot_id, setup.m_file) };
EMIT(e2);
// HERE
// auto r = hr::run<hr::plugins::raw_data>(m_setup);
// if (fill_raw_data(r))
// {
// m_audio.init(m_setup.m_file);
// m_audio.set_step(r.m_data.size());
// m_markers.init();
// set_status(utils::var::STATUS::ACTIVE);
// }
}
bool snapshot::fill(hr::result& r)
{
bool is_ok = false;
// auto base_size = r.m_data.size();
// utils::types::graph_data data;
//
// if (base_size > utils::var::MAX_RENDER_SIZE)
// {
// hack::warn()("Данный файл превышает максимально допустимый размер рендеринга");
// hack::log()("Возможно пришло время чтобы написать тут код... см. dspv.v3");
// hack::log()("но там есть tmp, которая может ту быть сомнительной...");
// }
// else if (base_size == 0)
// {
// hack::error()("Пусто в расчетах!");
// hack::warn()("Нет данных для отрисовки, возможно что-то не так с плагином...");
// }
// else
// {
// // резервируем кол-во линий графиков исходя из того сколько данных нужно отрисовать в каждом бине из dsp
// auto graph_count = r.m_data[0].m_value.size();
// data.m_render_data.reserve(graph_count);
// for (std::size_t i = 0; i < graph_count; ++i) data.m_render_data.push_back(hr::fvec_t());
//
// // тут резирвируем именно длинну по оси X всех линий
// data.m_ox.reserve(base_size);
//
// // заполняем данными все линии графиков
// for (auto el : r.m_data)
// {
// for (std::size_t i = 0; i < graph_count; ++i)
// {
// data.m_max_element = hack::math::max(el.m_value[i], data.m_max_element);
// data.m_render_data[i].push_back(el.m_value[i]);
// }
// }
// for (std::size_t i = 0; i < data.m_render_data[0].size(); ++i) data.m_ox.push_back(i);
// data.m_name = m_plugin.m_name;
// data.m_type = m_plugin.m_type;
// m_graphs.push_back(data);
// is_ok = true;
// }
return is_ok;
}
void snapshot::add_plugin()
{
hr::result r;
// switch (m_plugin.m_type)
// {
// case utils::var::PLUGIN_TYPE::MAGNITUDE:
// {
// // HERE
// // это нужно устанавливать в combo
// m_setup.m_domain = hr::DOMAIN_PLUGIN::FREQUENSY;
// r = hr::run<hr::plugins::magnitude>(m_setup);
// hack::log()("asdf");
// break;
// }
//
// // case utils::var::PLUGIN_TYPE::ENERGY:
// // {
// // r = hr::run<hr::plugins::energy>(m_setup);
// // break;
// // }
// }
fill(r);
m_plugin.clear();
}
}

View File

@@ -3,7 +3,6 @@
#include <VE.hpp>
#include <harmonica.hpp>
#include "monitor/utils/var.hpp"
#include "monitor/gui/components/markers/markers.hpp"
#include "monitor/gui/components/base_plugins/base_plugins.hpp"
#include "monitor/gui/components/base_controls/base_controls.hpp"
@@ -35,7 +34,6 @@ namespace monitor::components
// то нужно при первом рендеренге разрешить его, чтобы он установли график как нужно, а потом
// снять чтобы можно было манипулировать мышкой.
bool is_first_render = true;
components::markers m_markers;
private:
struct combo
@@ -52,9 +50,5 @@ namespace monitor::components
public:
void set_status(utils::var::STATUS s);
void init(hr::setup setup);
private:
bool fill(hr::result& r);
void add_plugin();
};
}

View File

@@ -60,12 +60,6 @@ namespace monitor::libs
void audio::play()
{
m_music.play();
// ATTENTION: это нужно делать тут именно ПОСЛЕ начала воспроизведения
// а НЕ перед воспроизведением. т.к. установка времени перед проигрыванием не работает
// см. https://www.sfml-dev.org/documentation/2.6.1/classsf_1_1SoundStream.php#af416a5f84c8750d2acb9821d78bc8646
// m_music.setPlayingOffset(m_ct);
emit();
}