add audio player
This commit is contained in:
@@ -11,23 +11,29 @@ namespace monitor::components
|
|||||||
VE_OVERIDE();
|
VE_OVERIDE();
|
||||||
VE_EVENT_OVERIDE();
|
VE_EVENT_OVERIDE();
|
||||||
|
|
||||||
|
private:
|
||||||
|
utils::var::STATUS m_status = utils::var::STATUS::EMPTY;
|
||||||
|
libs::audio m_player;
|
||||||
|
struct music
|
||||||
|
{
|
||||||
|
std::string m_id;
|
||||||
|
sf::Time m_current_time;
|
||||||
|
std::filesystem::path m_file;
|
||||||
|
} m_current_audio;
|
||||||
|
std::map<std::string, music> m_audio_data;
|
||||||
|
|
||||||
|
std::vector<std::string> m_domains = { "time", "frequensy"};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void init(std::filesystem::path file);
|
|
||||||
void set_step(std::size_t step);
|
|
||||||
void set_pos(double pos);
|
|
||||||
void set_bs(std::string type, std::size_t bs);
|
|
||||||
void toggle();
|
void toggle();
|
||||||
void pause();
|
void pause();
|
||||||
void drop();
|
void drop();
|
||||||
void set_status(utils::var::STATUS s);
|
void set_pos(double pos);
|
||||||
|
void set_step(std::size_t step);
|
||||||
private:
|
|
||||||
utils::var::STATUS m_status;
|
|
||||||
libs::audio m_player;
|
|
||||||
std::filesystem::path m_file;
|
|
||||||
std::vector<std::string> m_domains = { "time", "frequensy"};
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void init(std::string snapshot_id, std::filesystem::path file);
|
||||||
|
void change(std::string snapshot_id);
|
||||||
void callback(sf::Time time, double pos);
|
void callback(sf::Time time, double pos);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,25 +31,25 @@ namespace monitor::components
|
|||||||
m_player.pause();
|
m_player.pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
void audio::init(std::filesystem::path file)
|
void audio::init(std::string snapshot_id, std::filesystem::path file)
|
||||||
{
|
{
|
||||||
m_file = file;
|
m_player.stop();
|
||||||
m_player.set_file(m_file);
|
m_current_audio = music{ .m_id = snapshot_id, .m_current_time = sf::Time(), .m_file = file };
|
||||||
|
m_audio_data[snapshot_id] = m_current_audio;
|
||||||
}
|
}
|
||||||
|
|
||||||
void audio::set_status(utils::var::STATUS s)
|
void audio::change(std::string snapshot_id)
|
||||||
{
|
{
|
||||||
m_status = s;
|
m_audio_data[m_current_audio.m_id].m_current_time = m_current_audio.m_current_time;
|
||||||
}
|
m_player.stop();
|
||||||
|
m_current_audio = m_audio_data[snapshot_id];
|
||||||
// step - шаг отправки сигнала на смещение маркера. он же кол-во block_size-ов на все произведение
|
m_player.set_file(m_current_audio.m_file);
|
||||||
void audio::set_step(std::size_t step)
|
m_player.set_audio_pos(m_current_audio.m_current_time);
|
||||||
{
|
|
||||||
m_player.set_step(step);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void audio::callback(sf::Time time, double pos)
|
void audio::callback(sf::Time time, double pos)
|
||||||
{
|
{
|
||||||
|
m_current_audio.m_current_time = time;
|
||||||
VE::event e { utils::event_type::INCREMENT_MARKER_AUDIO_POSITION, pos };
|
VE::event e { utils::event_type::INCREMENT_MARKER_AUDIO_POSITION, pos };
|
||||||
EMIT(e);
|
EMIT(e);
|
||||||
}
|
}
|
||||||
@@ -65,4 +65,10 @@ namespace monitor::components
|
|||||||
{
|
{
|
||||||
m_player.set_audio_pos(pos);
|
m_player.set_audio_pos(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// step - шаг отправки сигнала на смещение маркера. он же кол-во block_size-ов на все произведение
|
||||||
|
void audio::set_step(std::size_t step)
|
||||||
|
{
|
||||||
|
m_player.set_step(step);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include <harmonica.hpp>
|
||||||
#include "monitor/gui/components/audio/audio.hpp"
|
#include "monitor/gui/components/audio/audio.hpp"
|
||||||
#include "monitor/utils/event_type.hpp"
|
#include "monitor/utils/event_type.hpp"
|
||||||
|
|
||||||
@@ -5,8 +6,6 @@ namespace monitor::components
|
|||||||
{
|
{
|
||||||
void audio::on_event(VE::event& e)
|
void audio::on_event(VE::event& e)
|
||||||
{
|
{
|
||||||
if (m_status != utils::var::STATUS::ACTIVE) return;
|
|
||||||
|
|
||||||
if (e.m_type.type() == typeid(VE::event_type))
|
if (e.m_type.type() == typeid(VE::event_type))
|
||||||
{
|
{
|
||||||
auto type = std::any_cast<VE::event_type>(e.m_type);
|
auto type = std::any_cast<VE::event_type>(e.m_type);
|
||||||
@@ -28,6 +27,27 @@ namespace monitor::components
|
|||||||
|
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
|
case utils::event_type::SET_AUDIO_STATUS:
|
||||||
|
{
|
||||||
|
m_status = std::any_cast<utils::var::STATUS>(e.m_data);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case utils::event_type::SET_AUDIO_FILE:
|
||||||
|
{
|
||||||
|
auto [snapshot_id, file] = std::any_cast<std::pair<std::string, std::filesystem::path>>(e.m_data);
|
||||||
|
init(snapshot_id, file);
|
||||||
|
change(snapshot_id);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case utils::event_type::CHANGE_AUDIO_FILE:
|
||||||
|
{
|
||||||
|
auto snapshot_id = std::any_cast<std::string>(e.m_data);
|
||||||
|
change(snapshot_id);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case utils::event_type::AUDIO_PAUSE:
|
case utils::event_type::AUDIO_PAUSE:
|
||||||
{
|
{
|
||||||
pause();
|
pause();
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ namespace monitor::components
|
|||||||
{
|
{
|
||||||
void audio::render()
|
void audio::render()
|
||||||
{
|
{
|
||||||
|
if (m_status != utils::var::STATUS::ACTIVE) return;
|
||||||
|
|
||||||
|
ImGui::SameLine( ImGui::GetWindowSize().x / 2.2f );
|
||||||
|
|
||||||
bool is_play = m_player.is_playing();
|
bool is_play = m_player.is_playing();
|
||||||
if (is_play)
|
if (is_play)
|
||||||
{
|
{
|
||||||
@@ -27,7 +31,7 @@ namespace monitor::components
|
|||||||
}
|
}
|
||||||
ImGui::PopStyleColor(3);
|
ImGui::PopStyleColor(3);
|
||||||
|
|
||||||
ImGui::SameLine(80.f);
|
ImGui::SameLine();
|
||||||
|
|
||||||
if (ImGui::Button("<<<"))
|
if (ImGui::Button("<<<"))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ namespace monitor::components
|
|||||||
{
|
{
|
||||||
m_status = utils::var::STATUS::COMPLETED;
|
m_status = utils::var::STATUS::COMPLETED;
|
||||||
auto future = std::async(std::launch::async, [this]() {
|
auto future = std::async(std::launch::async, [this]() {
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
m_file_path.clear();
|
m_file_path.clear();
|
||||||
m_status = utils::var::STATUS::EMPTY;
|
m_status = utils::var::STATUS::EMPTY;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ namespace monitor::components
|
|||||||
{
|
{
|
||||||
CONNECT(this);
|
CONNECT(this);
|
||||||
m_creator.on_attach();
|
m_creator.on_attach();
|
||||||
|
m_audio.on_attach();
|
||||||
m_helpers.on_attach();
|
m_helpers.on_attach();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -13,16 +14,16 @@ namespace monitor::components
|
|||||||
{
|
{
|
||||||
DISCONNECT();
|
DISCONNECT();
|
||||||
m_creator.on_detach();
|
m_creator.on_detach();
|
||||||
|
m_audio.on_detach();
|
||||||
m_helpers.on_detach();
|
m_helpers.on_detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
void panel::update()
|
void panel::update()
|
||||||
{
|
{
|
||||||
m_size.x = VE::application::get()->get_glfw()->width();
|
m_size.x = VE::application::get()->get_glfw()->width();
|
||||||
auto ctx = ImGui::GetCurrentContext();
|
|
||||||
// m_size.x -= ctx->Style.FramePadding.x * 2.f;
|
|
||||||
|
|
||||||
m_creator.update();
|
m_creator.update();
|
||||||
|
m_audio.update();
|
||||||
m_helpers.update();
|
m_helpers.update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ namespace monitor::components
|
|||||||
ImGui::SetNextWindowSize(m_size);
|
ImGui::SetNextWindowSize(m_size);
|
||||||
if (!ImGui::Begin(VE_NO_NAME("panel"), &m_open, m_win_flags)) ImGui::End();
|
if (!ImGui::Begin(VE_NO_NAME("panel"), &m_open, m_win_flags)) ImGui::End();
|
||||||
m_creator.render();
|
m_creator.render();
|
||||||
|
m_audio.render();
|
||||||
m_helpers.render();
|
m_helpers.render();
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <harmonica.hpp>
|
#include <harmonica.hpp>
|
||||||
#include "monitor/gui/components/creator/creator.hpp"
|
#include "monitor/gui/components/creator/creator.hpp"
|
||||||
#include "monitor/gui/components/helpers/helpers.hpp"
|
#include "monitor/gui/components/helpers/helpers.hpp"
|
||||||
|
#include "monitor/gui/components/audio/audio.hpp"
|
||||||
|
|
||||||
namespace monitor::components
|
namespace monitor::components
|
||||||
{
|
{
|
||||||
@@ -14,7 +15,8 @@ namespace monitor::components
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
ImVec2 m_size = { 950.f, 37.f };
|
ImVec2 m_size = { 950.f, 37.f };
|
||||||
components::creator m_creator;
|
creator m_creator;
|
||||||
components::helpers m_helpers;
|
audio m_audio;
|
||||||
|
helpers m_helpers;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "monitor/gui/components/snapshot/snapshot.hpp"
|
#include "monitor/gui/components/snapshot/snapshot.hpp"
|
||||||
#include "monitor/utils/var.hpp"
|
#include "monitor/utils/var.hpp"
|
||||||
|
#include "monitor/utils/event_type.hpp"
|
||||||
|
|
||||||
namespace monitor::components
|
namespace monitor::components
|
||||||
{
|
{
|
||||||
@@ -12,7 +13,6 @@ namespace monitor::components
|
|||||||
|
|
||||||
// HERE
|
// HERE
|
||||||
// то что ниже будем убирать
|
// то что ниже будем убирать
|
||||||
m_audio.on_attach();
|
|
||||||
m_markers.on_attach();
|
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 = 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 });
|
// m_plugins.emplace_back(combo{ .m_id = 1, .m_name = "Energy", .m_type = utils::var::PLUGIN_TYPE::ENERGY });
|
||||||
@@ -22,16 +22,12 @@ namespace monitor::components
|
|||||||
{
|
{
|
||||||
DISCONNECT();
|
DISCONNECT();
|
||||||
m_base_plugins.on_detach();
|
m_base_plugins.on_detach();
|
||||||
|
|
||||||
m_audio.on_detach();
|
|
||||||
m_markers.on_detach();
|
m_markers.on_detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
void snapshot::update()
|
void snapshot::update()
|
||||||
{
|
{
|
||||||
m_base_plugins.update();
|
m_base_plugins.update();
|
||||||
|
|
||||||
m_audio.update();
|
|
||||||
m_markers.update();
|
m_markers.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,14 +35,20 @@ namespace monitor::components
|
|||||||
{
|
{
|
||||||
m_status = s;
|
m_status = s;
|
||||||
m_markers.set_status(m_status);
|
m_markers.set_status(m_status);
|
||||||
m_audio.set_status(m_status);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void snapshot::init(hr::setup setup)
|
void snapshot::init(hr::setup setup)
|
||||||
{
|
{
|
||||||
|
m_snapshot_id = hack::security::generate_uuid();
|
||||||
m_setup = setup;
|
m_setup = setup;
|
||||||
m_base_plugins.init(m_snapshot_id, m_setup);
|
m_base_plugins.init(m_snapshot_id, m_setup);
|
||||||
|
|
||||||
|
VE::event e1 { utils::event_type::SET_AUDIO_STATUS, utils::var::STATUS::ACTIVE };
|
||||||
|
EMIT(e1);
|
||||||
|
|
||||||
|
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
|
// HERE
|
||||||
// auto r = hr::run<hr::plugins::raw_data>(m_setup);
|
// auto r = hr::run<hr::plugins::raw_data>(m_setup);
|
||||||
// if (fill_raw_data(r))
|
// if (fill_raw_data(r))
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
#include <VE.hpp>
|
#include <VE.hpp>
|
||||||
#include <harmonica.hpp>
|
#include <harmonica.hpp>
|
||||||
#include "monitor/utils/var.hpp"
|
#include "monitor/utils/var.hpp"
|
||||||
#include "monitor/gui/components/audio/audio.hpp"
|
|
||||||
#include "monitor/gui/components/markers/markers.hpp"
|
#include "monitor/gui/components/markers/markers.hpp"
|
||||||
#include "monitor/gui/components/base_plugins/base_plugins.hpp"
|
#include "monitor/gui/components/base_plugins/base_plugins.hpp"
|
||||||
#include "monitor/gui/components/base_controls/base_controls.hpp"
|
#include "monitor/gui/components/base_controls/base_controls.hpp"
|
||||||
@@ -23,7 +22,6 @@ namespace monitor::components
|
|||||||
std::string m_snapshot_id;
|
std::string m_snapshot_id;
|
||||||
utils::var::STATUS m_status;
|
utils::var::STATUS m_status;
|
||||||
hr::setup m_setup;
|
hr::setup m_setup;
|
||||||
audio m_audio;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ImVec2 m_size = { 0.f, 0.f };
|
ImVec2 m_size = { 0.f, 0.f };
|
||||||
|
|||||||
@@ -29,17 +29,17 @@ namespace monitor::components
|
|||||||
s->init(setup);
|
s->init(setup);
|
||||||
m_snapshots.push_back(s);
|
m_snapshots.push_back(s);
|
||||||
|
|
||||||
VE::event e { utils::event_type::CREATE_SNAPSHOT_COMPLETED, nullptr };
|
VE::event e0 { utils::event_type::CREATE_SNAPSHOT_COMPLETED, nullptr };
|
||||||
EMIT(e);
|
EMIT(e0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tabs::change_tab(std::size_t i)
|
void tabs::change_tab(std::size_t i)
|
||||||
{
|
{
|
||||||
VE::event e { utils::event_type::AUDIO_PAUSE, m_current_open_index };
|
|
||||||
EMIT(e);
|
|
||||||
|
|
||||||
m_snapshots[m_current_open_index]->set_status(utils::var::STATUS::INACTIVE);
|
m_snapshots[m_current_open_index]->set_status(utils::var::STATUS::INACTIVE);
|
||||||
m_snapshots[i]->set_status(utils::var::STATUS::ACTIVE);
|
m_snapshots[i]->set_status(utils::var::STATUS::ACTIVE);
|
||||||
m_current_open_index = i;
|
m_current_open_index = i;
|
||||||
|
|
||||||
|
VE::event e { utils::event_type::CHANGE_AUDIO_FILE, m_snapshots[i]->m_snapshot_id };
|
||||||
|
EMIT(e);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,15 +35,20 @@ namespace monitor::libs
|
|||||||
m_callback = c;
|
m_callback = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void audio::set_audio_pos(sf::Time t)
|
||||||
|
{
|
||||||
|
m_music.setPlayingOffset(t);
|
||||||
|
}
|
||||||
|
|
||||||
void audio::set_step(std::size_t step)
|
void audio::set_step(std::size_t step)
|
||||||
{
|
{
|
||||||
m_step = sf::microseconds(m_music.getDuration().asMicroseconds() / step);
|
// m_step = sf::microseconds(m_music.getDuration().asMicroseconds() / step);
|
||||||
}
|
}
|
||||||
|
|
||||||
void audio::set_audio_pos(double s)
|
void audio::set_audio_pos(double s)
|
||||||
{
|
{
|
||||||
m_ct = sf::microseconds(s * m_step.asMicroseconds());
|
// m_ct = sf::microseconds(s * m_step.asMicroseconds());
|
||||||
m_music.setPlayingOffset(m_ct);
|
// m_music.setPlayingOffset(m_ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
void audio::toggle_play()
|
void audio::toggle_play()
|
||||||
@@ -59,7 +64,7 @@ namespace monitor::libs
|
|||||||
// ATTENTION: это нужно делать тут именно ПОСЛЕ начала воспроизведения
|
// ATTENTION: это нужно делать тут именно ПОСЛЕ начала воспроизведения
|
||||||
// а НЕ перед воспроизведением. т.к. установка времени перед проигрыванием не работает
|
// а НЕ перед воспроизведением. т.к. установка времени перед проигрыванием не работает
|
||||||
// см. https://www.sfml-dev.org/documentation/2.6.1/classsf_1_1SoundStream.php#af416a5f84c8750d2acb9821d78bc8646
|
// см. https://www.sfml-dev.org/documentation/2.6.1/classsf_1_1SoundStream.php#af416a5f84c8750d2acb9821d78bc8646
|
||||||
m_music.setPlayingOffset(m_ct);
|
// m_music.setPlayingOffset(m_ct);
|
||||||
|
|
||||||
emit();
|
emit();
|
||||||
}
|
}
|
||||||
@@ -68,8 +73,7 @@ namespace monitor::libs
|
|||||||
{
|
{
|
||||||
while (is_playing())
|
while (is_playing())
|
||||||
{
|
{
|
||||||
m_ct = m_music.getPlayingOffset();
|
m_callback(m_music.getPlayingOffset(), 1.0);
|
||||||
m_callback(sf::Time(), 1.0);
|
|
||||||
sf::sleep(m_step);
|
sf::sleep(m_step);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ namespace monitor::libs
|
|||||||
void set_callback(std::function<void(sf::Time, float)> c);
|
void set_callback(std::function<void(sf::Time, float)> c);
|
||||||
void set_step(std::size_t step);
|
void set_step(std::size_t step);
|
||||||
void set_audio_pos(double s);
|
void set_audio_pos(double s);
|
||||||
|
void set_audio_pos(sf::Time t);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void emit();
|
void emit();
|
||||||
@@ -31,7 +32,7 @@ namespace monitor::libs
|
|||||||
std::filesystem::path m_file;
|
std::filesystem::path m_file;
|
||||||
sf::Music m_music;
|
sf::Music m_music;
|
||||||
sf::Time m_ct = sf::Time::Zero;
|
sf::Time m_ct = sf::Time::Zero;
|
||||||
sf::Time m_step;
|
sf::Time m_step = sf::Time::Zero;
|
||||||
std::function<void(sf::Time, float)> m_callback;
|
std::function<void(sf::Time, float)> m_callback;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,9 @@ namespace monitor::utils
|
|||||||
CREATE_SNAPSHOT_COMPLETED,
|
CREATE_SNAPSHOT_COMPLETED,
|
||||||
STATUS_PROCESS,
|
STATUS_PROCESS,
|
||||||
STATUS_COMPLETED,
|
STATUS_COMPLETED,
|
||||||
|
SET_AUDIO_STATUS,
|
||||||
|
SET_AUDIO_FILE,
|
||||||
|
CHANGE_AUDIO_FILE,
|
||||||
|
|
||||||
|
|
||||||
/// делать
|
/// делать
|
||||||
|
|||||||
Reference in New Issue
Block a user