修复mixer渲染问题, 绑定渲染线程核心
This commit is contained in:
parent
398ae268c9
commit
c28543f65e
@ -45,6 +45,7 @@ void configure_imgui(ImGuiIO& io) {
|
||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f);
|
||||
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, nullptr, io.Fonts->GetGlyphRangesJapanese());
|
||||
//IM_ASSERT(font != nullptr);
|
||||
io.Fonts->AddFontFromFileTTF("GenJyuuGothic-Normal-2.ttf", 18.f);
|
||||
}
|
||||
|
||||
void draw_imgui(float delta_time) {
|
||||
|
@ -143,9 +143,9 @@ namespace ImGuiKnobs {
|
||||
};
|
||||
|
||||
template<typename DataType>
|
||||
knob<DataType> knob_with_drag(const char *label, ImGuiDataType data_type, DataType *p_value, DataType v_min, DataType v_max, float _speed, const char *format, float size, ImGuiKnobFlags flags) {
|
||||
knob<DataType> knob_with_drag(ImGuiID id, const char* label, ImGuiDataType data_type, DataType *p_value, DataType v_min, DataType v_max, float _speed, const char *format, float size, ImGuiKnobFlags flags) {
|
||||
auto speed = _speed == 0 ? (v_max - v_min) / 250.f : _speed;
|
||||
ImGui::PushID(label);
|
||||
ImGui::PushID(id);
|
||||
auto width = size == 0 ? ImGui::GetTextLineHeight() * 4.0f : size * ImGui::GetIO().FontGlobalScale;
|
||||
ImGui::PushItemWidth(width);
|
||||
|
||||
@ -226,8 +226,8 @@ namespace ImGuiKnobs {
|
||||
|
||||
|
||||
template<typename DataType>
|
||||
bool BaseKnob(const char *label, ImGuiDataType data_type, DataType *p_value, DataType v_min, DataType v_max, float speed, const char *format, ImGuiKnobVariant variant, float size, ImGuiKnobFlags flags, int steps = 10) {
|
||||
auto knob = detail::knob_with_drag(label, data_type, p_value, v_min, v_max, speed, format, size, flags);
|
||||
bool BaseKnob(ImGuiID id, const char* label, ImGuiDataType data_type, DataType *p_value, DataType v_min, DataType v_max, float speed, const char *format, ImGuiKnobVariant variant, float size, ImGuiKnobFlags flags, int steps = 10) {
|
||||
auto knob = detail::knob_with_drag(id, label, data_type, p_value, v_min, v_max, speed, format, size, flags);
|
||||
|
||||
switch (variant) {
|
||||
case ImGuiKnobVariant_Tick: {
|
||||
@ -290,14 +290,14 @@ namespace ImGuiKnobs {
|
||||
return knob.value_changed;
|
||||
}
|
||||
|
||||
bool Knob(const char *label, float *p_value, float v_min, float v_max, float speed, const char *format, ImGuiKnobVariant variant, float size, ImGuiKnobFlags flags, int steps) {
|
||||
bool Knob(ImGuiID id, const char *label, float *p_value, float v_min, float v_max, float speed, const char *format, ImGuiKnobVariant variant, float size, ImGuiKnobFlags flags, int steps) {
|
||||
const char *_format = format == NULL ? "%.3f" : format;
|
||||
return BaseKnob(label, ImGuiDataType_Float, p_value, v_min, v_max, speed, _format, variant, size, flags, steps);
|
||||
return BaseKnob(id, label, ImGuiDataType_Float, p_value, v_min, v_max, speed, _format, variant, size, flags, steps);
|
||||
}
|
||||
|
||||
bool KnobInt(const char *label, int *p_value, int v_min, int v_max, float speed, const char *format, ImGuiKnobVariant variant, float size, ImGuiKnobFlags flags, int steps) {
|
||||
bool KnobInt(ImGuiID id, const char *label, int *p_value, int v_min, int v_max, float speed, const char *format, ImGuiKnobVariant variant, float size, ImGuiKnobFlags flags, int steps) {
|
||||
const char *_format = format == NULL ? "%i" : format;
|
||||
return BaseKnob(label, ImGuiDataType_S32, p_value, v_min, v_max, speed, _format, variant, size, flags, steps);
|
||||
return BaseKnob(id, label, ImGuiDataType_S32, p_value, v_min, v_max, speed, _format, variant, size, flags, steps);
|
||||
}
|
||||
|
||||
}// namespace ImGuiKnobs
|
||||
|
@ -40,6 +40,6 @@ namespace ImGuiKnobs {
|
||||
}
|
||||
};
|
||||
|
||||
bool Knob(const char *label, float *p_value, float v_min, float v_max, float speed = 0, const char *format = NULL, ImGuiKnobVariant variant = ImGuiKnobVariant_Tick, float size = 0, ImGuiKnobFlags flags = 0, int steps = 10);
|
||||
bool KnobInt(const char *label, int *p_value, int v_min, int v_max, float speed = 0, const char *format = NULL, ImGuiKnobVariant variant = ImGuiKnobVariant_Tick, float size = 0, ImGuiKnobFlags flags = 0, int steps = 10);
|
||||
bool Knob(ImGuiID id, const char *label, float *p_value, float v_min, float v_max, float speed = 0, const char *format = NULL, ImGuiKnobVariant variant = ImGuiKnobVariant_Tick, float size = 0, ImGuiKnobFlags flags = 0, int steps = 10);
|
||||
bool KnobInt(ImGuiID id, const char *label, int *p_value, int v_min, int v_max, float speed = 0, const char *format = NULL, ImGuiKnobVariant variant = ImGuiKnobVariant_Tick, float size = 0, ImGuiKnobFlags flags = 0, int steps = 10);
|
||||
}// namespace ImGuiKnobs
|
||||
|
@ -9,8 +9,14 @@
|
||||
#include "audio/device/audio_device_manager.h"
|
||||
#include "imgui-knobs.h"
|
||||
|
||||
struct volume_bar_peak_info {
|
||||
sample_t peak;
|
||||
float left_time;
|
||||
};
|
||||
|
||||
bool show_instrument_track = true;
|
||||
bool show_mixer = true;
|
||||
std::unordered_map<uint64_t, std::vector<volume_bar_peak_info>> volume_bar_peak_map;
|
||||
|
||||
void draw_instrument_track() {
|
||||
ImGui::Begin("Instrument", &show_instrument_track);
|
||||
@ -21,6 +27,8 @@ void draw_instrument_track() {
|
||||
if (ImGui::Button(button_label.c_str())) {
|
||||
host->toggle_editor();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
draw_volume_bar(host->get_uid(), 50, *host->ui_buffers);
|
||||
}
|
||||
if (ImGui::Button("Add")) {
|
||||
get_arona_application()->test();
|
||||
@ -33,24 +41,21 @@ void draw_mixer() {
|
||||
auto mixer = get_mixer();
|
||||
auto mixer_tracks = mixer->get_tracks();
|
||||
float delta_time = ImGui::GetIO().DeltaTime;
|
||||
int32_t delta_sample_count = get_audio_device_manager()->get_sample_rate() * delta_time;
|
||||
|
||||
for (int32_t i = 0; i < mixer_tracks.size(); ++i) {
|
||||
mixer_track* track = mixer_tracks.at(i);
|
||||
draw_mixer_track(delta_sample_count, track, i);
|
||||
for (mixer_track* track : mixer_tracks) {
|
||||
draw_mixer_track(track);
|
||||
ImGui::SameLine();
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void draw_mixer_track(uint32_t delta_sample_count, mixer_track* track, int32_t index) {
|
||||
float delta_time = ImGui::GetIO().DeltaTime;
|
||||
void draw_mixer_track(mixer_track* track) {
|
||||
ImGuiWindow* window = ImGui::GetCurrentWindow();
|
||||
|
||||
std::string track_label = track->get_name();
|
||||
std::string child_id = "MixerTrack" + std::to_string(index);
|
||||
std::string slider_id = "MixerTrackVolume##" + std::to_string(index);
|
||||
std::string volume_bar_id = "VolumeBar" + std::to_string(index);
|
||||
std::string child_id = "MixerTrack" + std::to_string(track->get_uid());
|
||||
std::string slider_id = "MixerTrackVolume##" + std::to_string(track->get_uid());
|
||||
std::string volume_bar_id = "VolumeBar" + std::to_string(track->get_uid());
|
||||
|
||||
ImGui::BeginGroup();
|
||||
window->DC.CurrLineTextBaseOffset = 0;
|
||||
@ -63,14 +68,27 @@ void draw_mixer_track(uint32_t delta_sample_count, mixer_track* track, int32_t i
|
||||
track->set_volume(volume);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
draw_volume_bar(track->get_uid(), widget_height, *track->ui_buffers);
|
||||
ImGui::EndGroup();
|
||||
if (ImGui::IsItemClicked(ImGuiMouseButton_Left)) {
|
||||
get_mixer()->selected_track = track;
|
||||
}
|
||||
}
|
||||
|
||||
void draw_volume_bar(uint64_t uid, float height, circular_buffer_vector_type& in_buffer) {
|
||||
float delta_time = ImGui::GetIO().DeltaTime;
|
||||
uint32_t delta_sample_count = get_audio_device_manager()->get_sample_rate() * delta_time;
|
||||
|
||||
std::vector<sample_t> temp_buffer;
|
||||
temp_buffer.reserve(delta_sample_count);
|
||||
std::vector<float> sample_value;
|
||||
std::vector<float> sample_peak;
|
||||
for (int32_t i = 0; i < track->ui_buffers->size(); ++i) {
|
||||
auto& buffer = track->ui_buffers->at(i);
|
||||
auto& peak_info = track->ui_buffer_peaks.at(i);
|
||||
for (int32_t i = 0; i < in_buffer.size(); ++i) {
|
||||
auto& buffer = in_buffer.at(i);
|
||||
if (!volume_bar_peak_map.contains(uid)) {
|
||||
volume_bar_peak_map[uid].resize(in_buffer.size());
|
||||
}
|
||||
volume_bar_peak_info& peak_info = volume_bar_peak_map[uid].at(i);
|
||||
|
||||
// calculate peak
|
||||
uint32_t count = std::min(delta_sample_count, buffer.Num());
|
||||
@ -96,16 +114,10 @@ void draw_mixer_track(uint32_t delta_sample_count, mixer_track* track, int32_t i
|
||||
sample_value.push_back(peak);
|
||||
sample_peak.push_back(peak_info.peak);
|
||||
}
|
||||
draw_volume_bar(volume_bar_id.c_str(), widget_height, sample_value, sample_peak);
|
||||
ImGui::SameLine();
|
||||
|
||||
ImGui::EndGroup();
|
||||
if (ImGui::IsItemClicked(ImGuiMouseButton_Left)) {
|
||||
get_mixer()->selected_track = track;
|
||||
}
|
||||
draw_volume_bar(uid, height, sample_value, sample_peak);
|
||||
}
|
||||
|
||||
void draw_volume_bar(const char* id, float height, std::vector<float> sample_value, std::vector<float> sample_peak) {
|
||||
void draw_volume_bar(ImGuiID id, float height, const std::vector<float>& sample_value, const std::vector<float>& sample_peak) {
|
||||
#if BUILD_DEBUG
|
||||
if (sample_value.size() != sample_peak.size()) {
|
||||
spdlog::error("sample_value size is not equal to sample_peak size");
|
||||
@ -125,7 +137,7 @@ void draw_volume_bar(const char* id, float height, std::vector<float> sample_val
|
||||
ImVec2 size = ImGui::CalcItemSize(size_arg, widget_width, widget_height);
|
||||
ImRect bb(pos, pos + size);
|
||||
ImGui::ItemSize(bb);
|
||||
if (!ImGui::ItemAdd(bb, ImGui::GetID(id))) {
|
||||
if (!ImGui::ItemAdd(bb, 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -270,6 +282,8 @@ void draw_mixer_track_effect_list(mixer_track* track) {
|
||||
for (auto effect: track->effects) {
|
||||
draw_mixer_track_effect(effect);
|
||||
ImGui::SameLine();
|
||||
draw_volume_bar(effect->get_uid(), 100, *effect->ui_buffers);
|
||||
ImGui::SameLine();
|
||||
}
|
||||
|
||||
if (ImGui::Button("Add")) {
|
||||
@ -290,7 +304,7 @@ void draw_selected_mixer_track_effect_list() {
|
||||
void draw_mixer_track_effect(plugin_host* effect) {
|
||||
auto effect_id = effect->get_imgui_id();
|
||||
ImGui::BeginGroup();
|
||||
if (ImGui::Button(effect->name.c_str())) {
|
||||
if (ImGui::Button(effect_id.c_str())) {
|
||||
effect->toggle_editor();
|
||||
}
|
||||
|
||||
@ -302,26 +316,23 @@ void draw_mixer_track_effect(plugin_host* effect) {
|
||||
if (label == "%") {
|
||||
label += "%";
|
||||
}
|
||||
auto id_str = param_name + "##" + std::to_string(effect->get_uid());
|
||||
ImGuiID id = ImGui::GetID(id_str.c_str());
|
||||
const auto& param_display = param_info.get_display() + label;
|
||||
auto slider_id = param_name + "##" + std::to_string(i);
|
||||
bool is_toggle = param_info.is_toggle();
|
||||
|
||||
if (is_toggle) {
|
||||
bool param_value = param_info.get_value() > 0.5f;
|
||||
if (ImGui::Checkbox(slider_id.c_str(), ¶m_value)) {
|
||||
if (ImGui::Checkbox(id_str.c_str(), ¶m_value)) {
|
||||
param_info.set_value(param_value);
|
||||
}
|
||||
} else {
|
||||
float param_value = param_info.get_value();
|
||||
if (ImGuiKnobs::Knob(param_name.c_str(), ¶m_value, param_info.min_value(), param_info.max_value(), 0,
|
||||
if (ImGuiKnobs::Knob(id, param_name.c_str(), ¶m_value, param_info.min_value(), param_info.max_value(), 0,
|
||||
param_display.c_str())) {
|
||||
param_info.set_value(param_value);
|
||||
}
|
||||
}
|
||||
// if (i % 2 == 0)
|
||||
// ImGui::SameLine();
|
||||
// else
|
||||
// ImGui::NewLine();
|
||||
}
|
||||
ImGui::EndGroup();
|
||||
// right click open menu
|
||||
|
@ -4,7 +4,9 @@
|
||||
#include <cmath>
|
||||
#include "extern.h"
|
||||
#include "imgui.h"
|
||||
#include "audio/misc/circular_audio_buffer.h"
|
||||
|
||||
class audio_buffer;
|
||||
class mixer_track;
|
||||
class plugin_host;
|
||||
|
||||
@ -52,8 +54,9 @@ bool vertical_volume_slider(const char* id, ImVec2 size, float* volume, float mi
|
||||
|
||||
void draw_instrument_track();
|
||||
void draw_mixer();
|
||||
void draw_mixer_track(uint32_t delta_sample_count, mixer_track* track, int32_t index);
|
||||
void draw_volume_bar(const char* id, float height, std::vector<float> sample_value, std::vector<float> sample_peak);
|
||||
void draw_mixer_track(mixer_track* track);
|
||||
void draw_volume_bar(uint64_t uid, float height, circular_buffer_vector_type& in_buffer);
|
||||
void draw_volume_bar(ImGuiID id, float height, const std::vector<float>& sample_value, const std::vector<float>& sample_peak);
|
||||
|
||||
void draw_mixer_track_effect_list(mixer_track* track);
|
||||
void draw_selected_mixer_track_effect_list();
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 1f05cae06721ef488a9d5b97c87b67aa0f64af7d
|
||||
Subproject commit 0bcc52da17151db56224d20f66840a0de76c7ca3
|
Loading…
x
Reference in New Issue
Block a user