add base change marker position

This commit is contained in:
2026-04-07 15:02:06 +03:00
parent fc8467086a
commit a279cdf3e3
14 changed files with 74 additions and 139 deletions

View File

@@ -2,6 +2,5 @@
auto main(int argc, char* args[]) -> int auto main(int argc, char* args[]) -> int
{ {
// test sshd
run(); run();
} }

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include <VE.hpp> #include <VE.hpp>
#include <harmonica.hpp>
#include "monitor/libs/audio/audio.hpp" #include "monitor/libs/audio/audio.hpp"
#include "monitor/utils/var.hpp" #include "monitor/utils/var.hpp"
@@ -18,7 +19,7 @@ namespace monitor::components
{ {
std::string m_id; std::string m_id;
sf::Time m_current_time; sf::Time m_current_time;
std::filesystem::path m_file; hr::setup m_setup;
} m_current_audio; } m_current_audio;
std::map<std::string, music> m_audio_data; std::map<std::string, music> m_audio_data;
@@ -33,7 +34,7 @@ namespace monitor::components
void set_pos(double pos); void set_pos(double pos);
private: private:
void init(std::string snapshot_id, std::filesystem::path file); void init(std::string snapshot_id, hr::setup& setup);
void change(std::string snapshot_id); void change(std::string snapshot_id);
void callback(sf::Time time); void callback(sf::Time time);
}; };

View File

@@ -31,10 +31,11 @@ namespace monitor::components
m_player.pause(); m_player.pause();
} }
void audio::init(std::string snapshot_id, std::filesystem::path file) void audio::init(std::string snapshot_id, hr::setup& setup)
{ {
m_player.stop(); m_player.stop();
m_audio_data[snapshot_id] = music{ .m_id = snapshot_id, .m_current_time = sf::Time(), .m_file = file }; m_audio_data[snapshot_id] = music{ .m_id = snapshot_id, .m_current_time = sf::Time(), .m_setup = setup };
m_status = utils::var::STATUS::ACTIVE;
} }
void audio::change(std::string snapshot_id) void audio::change(std::string snapshot_id)
@@ -42,18 +43,23 @@ namespace monitor::components
m_audio_data[m_current_audio.m_id].m_current_time = m_current_audio.m_current_time; m_audio_data[m_current_audio.m_id].m_current_time = m_current_audio.m_current_time;
m_player.stop(); m_player.stop();
m_current_audio = m_audio_data[snapshot_id]; m_current_audio = m_audio_data[snapshot_id];
m_player.set_file(m_current_audio.m_file); m_player.set_file(m_current_audio.m_setup.m_file);
m_player.set_audio_pos(m_current_audio.m_current_time); m_player.set_audio_pos(m_current_audio.m_current_time);
} }
void audio::callback(sf::Time time) void audio::callback(sf::Time time)
{ {
m_current_audio.m_current_time = time; m_current_audio.m_current_time = time;
VE::event e { utils::event_type::INCREMENT_MARKER_AUDIO_POSITION, time }; double seconds = time.asSeconds();
int current_sample_index = (int)(seconds * m_current_audio.m_setup.m_sample_rate);
// send to:: components/markers
VE::event e { utils::event_type::INCREMENT_MARKER_AUDIO_POSITION, current_sample_index };
EMIT(e); EMIT(e);
} }
// делать // HERE
// делать нужно, но надо разобраться зачем?
void audio::drop() void audio::drop()
{ {
m_player.stop(); m_player.stop();

View File

@@ -29,9 +29,8 @@ namespace monitor::components
{ {
case utils::event_type::INIT_AUDIO: case utils::event_type::INIT_AUDIO:
{ {
auto [snapshot_id, file] = std::any_cast<std::pair<std::string, std::filesystem::path>>(e.m_data); auto [snapshot_id, setup] = std::any_cast<std::pair<std::string, hr::setup>>(e.m_data);
init(snapshot_id, file); init(snapshot_id, setup);
m_status = utils::var::STATUS::ACTIVE;
break; break;
} }

View File

@@ -29,6 +29,9 @@ namespace monitor::components
public: public:
void init(std::string snapshot_id, hr::setup setup); void init(std::string snapshot_id, hr::setup setup);
private:
void calculate_plugin(std::shared_ptr<utils::plugin> plugin);
}; };
} }

View File

@@ -36,12 +36,49 @@ namespace monitor::components
{ {
m_snapshot_id = snapshot_id; m_snapshot_id = snapshot_id;
m_setup = setup; m_setup = setup;
calculate_plugin(m_base_plugins[0]);
m_graph.init(m_snapshot_id, m_setup); m_graph.init(m_snapshot_id, m_setup);
m_graph.set_plugin(m_base_plugins[0]); m_graph.set_plugin(m_base_plugins[0]);
hack::log()(m_base_plugins[0]->m_result.m_size, m_setup.m_sample_rate);
// m_fft_scaled.init(m_snapshot_id, m_setup); // m_fft_scaled.init(m_snapshot_id, m_setup);
// send to: components/audio // send to: components/audio
VE::event e { utils::event_type::INIT_AUDIO, std::pair<std::string, std::filesystem::path>(m_snapshot_id, setup.m_file) }; VE::event e { utils::event_type::INIT_AUDIO, std::pair<std::string, hr::setup>(m_snapshot_id, m_setup) };
EMIT(e); EMIT(e);
} }
void base_plugins::calculate_plugin(std::shared_ptr<utils::plugin> plugin)
{
if (!plugin->empty()) return;
switch (plugin->m_type)
{
case utils::plugin::TYPE::RAW_DATA:
{
m_setup.m_domain = hr::DOMAIN_PLUGIN::TIME;
plugin->m_result = hr::run<hr::plugins::raw_data>(m_setup);
break;
}
case utils::plugin::TYPE::MAGNITUDE:
{
m_setup.m_domain = hr::DOMAIN_PLUGIN::FREQUENSY;
plugin->m_result = hr::run<hr::plugins::magnitude>(m_setup);
break;
}
}
if (!plugin->empty())
{
plugin->init();
plugin->fill();
}
else
{
hack::error()("NOT SET DATA!");
}
}
} }

View File

@@ -25,6 +25,7 @@ namespace monitor::components
if (ImGui::IsItemClicked()) if (ImGui::IsItemClicked())
{ {
m_current_open_index = i; m_current_open_index = i;
calculate_plugin(m_base_plugins[i]);
m_graph.set_plugin(m_base_plugins[i]); m_graph.set_plugin(m_base_plugins[i]);
} }
} }

View File

@@ -8,7 +8,7 @@ namespace monitor::components
float spacing = ImGui::GetStyle().ItemInnerSpacing.x; float spacing = ImGui::GetStyle().ItemInnerSpacing.x;
std::size_t step = 256; std::size_t step = 256;
// block_size // BLOCK SIZE
ImGui::Text("block size:"); ImGui::Text("block size:");
ImGui::SameLine(0.0f, spacing); ImGui::SameLine(0.0f, spacing);
@@ -37,11 +37,11 @@ namespace monitor::components
ImGui::PopID(); ImGui::PopID();
VE_POP_FONT(); VE_POP_FONT();
ImGui::PopItemFlag(); ImGui::PopItemFlag();
// end // end BLOCK SIZE
ImGui::SameLine(0.f, 3.f * spacing); ImGui::SameLine(0.f, 3.f * spacing);
// step size // STEP SIZE
ImGui::Text("step size:"); ImGui::Text("step size:");
ImGui::SameLine(0.0f, spacing); ImGui::SameLine(0.0f, spacing);
@@ -70,6 +70,6 @@ namespace monitor::components
ImGui::PopID(); ImGui::PopID();
VE_POP_FONT(); VE_POP_FONT();
ImGui::PopItemFlag(); ImGui::PopItemFlag();
// end // end STEP SIZE
} }
} }

View File

@@ -25,6 +25,8 @@ namespace monitor::components
private: private:
void render_setup(); void render_setup();
void render_spinner(ImVec2 pos = { 10.f, 8.f }); void render_spinner(ImVec2 pos = { 10.f, 8.f });
private:
void create(); void create();
void clear(); void clear();
}; };

View File

@@ -30,35 +30,6 @@ namespace monitor::components
{ {
m_plugin = std::move(plugin); m_plugin = std::move(plugin);
if (!m_plugin) hack::error()("The object is not installed"); if (!m_plugin) hack::error()("The object is not installed");
if (m_plugin->empty())
{
switch (m_plugin->m_type)
{
case utils::plugin::TYPE::RAW_DATA:
{
m_setup.m_domain = hr::DOMAIN_PLUGIN::TIME;
m_plugin->m_result = hr::run<hr::plugins::raw_data>(m_setup);
hack::log()(m_plugin->m_result.m_size);
break;
}
case utils::plugin::TYPE::MAGNITUDE:
{
m_setup.m_domain = hr::DOMAIN_PLUGIN::FREQUENSY;
m_plugin->m_result = hr::run<hr::plugins::magnitude>(m_setup);
break;
}
}
if (!m_plugin->empty())
{
m_plugin->init();
m_plugin->fill();
}
else
{
hack::error()("NOT SET RAW DATA!");
}
}
} }
std::size_t graph::get_plugin_size() noexcept std::size_t graph::get_plugin_size() noexcept

View File

@@ -36,10 +36,10 @@ namespace monitor::components
{ {
case utils::event_type::INCREMENT_MARKER_AUDIO_POSITION: case utils::event_type::INCREMENT_MARKER_AUDIO_POSITION:
{ {
auto t = std::any_cast<sf::Time>(e.m_data); auto t = std::any_cast<int>(e.m_data);
static int index = 0;
if (index%16 == 0) ++m_marker_audio_position; m_marker_audio_position = (double)t/11;
++index; hack::log()(t, m_marker_audio_position);
break; break;
} }

View File

@@ -11,94 +11,5 @@ namespace monitor::components
ImGui::PushID("scale"); ImGui::PushID("scale");
m_base_controls.render(); m_base_controls.render();
ImGui::PopID(); ImGui::PopID();
// m_audio.render();
//
// ImGui::SameLine();
//
// // HERE
// // выбор домена для плагина
// auto ctx = ImGui::GetCurrentContext();
// ImGui::SameLine(0.f, ctx->Style.FramePadding.x);
// ImGui::SetNextItemWidth(120.f);
// static std::size_t domain_id = 0;
// if (ImGui::BeginCombo(VE_NO_NAME("select_domain"), m_domains[domain_id].c_str()))
// {
// for (std::size_t i = 0; i < m_domains.size(); ++i)
// {
// const bool is_selected = (domain_id == i);
// if (ImGui::Selectable(m_domains[i].c_str(), is_selected))
// domain_id = i;
// if (is_selected) ImGui::SetItemDefaultFocus();
// }
// ImGui::EndCombo();
// }
//
// ImGui::SameLine();
//
// ImGui::SetNextItemWidth(400.f);
// if (ImGui::BeginCombo(VE_NO_NAME("select_plugin"), m_plugin.m_id < 0 ? "---" : m_plugins[m_plugin.m_id].m_name.c_str()))
// {
// for (std::size_t i = 0; i < m_plugins.size(); ++i)
// {
// const bool is_selected = (m_plugin.m_id == static_cast<int>(i));
// if (ImGui::Selectable(m_plugins[i].m_name.c_str(), is_selected))
// m_plugin = m_plugins[i];
// if (is_selected) ImGui::SetItemDefaultFocus();
// }
// ImGui::EndCombo();
// }
//
// ImGui::SameLine();
//
// if (ImGui::Button("add plugin", ImVec2{ 94.f, 27.f })) add_plugin();
//
// if (ImPlot::BeginSubplots(VE_NO_NAME("graph" + m_snapshot_id), m_rows, m_cols, ImVec2(-1, -1), ImPlotSubplotFlags_LinkRows | ImPlotSubplotFlags_LinkCols))
// {
// for (const auto& graph : m_graphs)
// {
// if (ImPlot::BeginPlot(VE_NAME(graph.m_name), ImVec2(-1, 0), ImPlotFlags_NoMenus))
// {
// // по оси X
// ImPlot::SetupAxes(nullptr, nullptr, ImPlotAxisFlags_Opposite | // смена полюсов у надписей оси x. они вверху
// ImPlotAxisFlags_NoSideSwitch | // нельзя перетаскивать оси по сторонам
// (is_first_render ? ImPlotAxisFlags_AutoFit : ImPlotAxisFlags_None) | // авто подстройка размера по горизонтале
// ImPlotAxisFlags_NoHighlight, // не разобрался что это там подсвечивается, что-то с фоном оси
// // по оси Y
// ImPlotAxisFlags_AutoFit | // авто подстройка размера по вертикале
// ImPlotAxisFlags_NoSideSwitch |
// ImPlotAxisFlags_NoHighlight |
// ImPlotAxisFlags_NoTickLabels // текстовые надписи отображаться не будут
// );
//
// ImPlot::SetupAxisLimits(ImAxis_X1, 0.f, graph.m_render_data[0].size());
// ImPlot::SetupAxisLimits(ImAxis_Y1, 0.f, graph.m_max_element);
// ImPlot::SetupAxisLimitsConstraints(ImAxis_X1, 0, INFINITY);
// ImPlot::SetupLegend(ImPlotLocation_NorthEast);
//
//
// std::size_t index = 0;
// for (auto& line : graph.m_render_data)
// {
// if (graph.m_type == utils::var::PLUGIN_TYPE::SEGMENTER)
// ImPlot::PlotStems(VE_NAME(std::to_string(index)), graph.m_ox.data(), line.data(), line.size());
// else
// ImPlot::PlotLine(VE_NAME(std::to_string(index)), graph.m_ox.data(), line.data(), line.size());
// ++index;
// }
//
// if (graph.m_type != utils::var::PLUGIN_TYPE::MAGNITUDE) m_markers.set_tag_show(false);
// else m_markers.set_tag_show(true);
//
// m_markers.render();
//
// ImPlot::EndPlot();
// }
// }
// ImPlot::EndSubplots();
// }
//
// is_first_render = false;
} }
} }

View File

@@ -58,7 +58,11 @@ namespace monitor::libs
void audio::emit() void audio::emit()
{ {
while (is_playing()) m_callback(m_music.getPlayingOffset()); while (is_playing())
{
m_callback(m_music.getPlayingOffset());
sf::sleep(sf::milliseconds(20));
}
} }
bool audio::is_playing() bool audio::is_playing()

View File

@@ -57,6 +57,7 @@ namespace monitor::utils
try try
{ {
m_comporession = m_result.m_size > m_size; m_comporession = m_result.m_size > m_size;
hack::log()(m_comporession);
if (!m_comporession) m_size = m_result.m_size; if (!m_comporession) m_size = m_result.m_size;
m_line_count = m_result.m_data.size(); m_line_count = m_result.m_data.size();