新增imgui-knobs, 优化mixer_track_effect_list
This commit is contained in:
parent
1c76e93d29
commit
1f05cae067
@ -205,6 +205,8 @@ void mixer::thread_remove_track(mixer_track* track) {
|
||||
|
||||
g_main_thread_hub.push_message([track, this]() {
|
||||
on_remove_track_main_thread.broadcast(track);
|
||||
if (track == selected_track)
|
||||
selected_track = nullptr;
|
||||
delete track;
|
||||
});
|
||||
}
|
||||
|
@ -39,6 +39,9 @@ public:
|
||||
multicast_delegate<mixer_track*> on_add_track_main_thread;
|
||||
multicast_delegate<mixer_track*> on_remove_track;
|
||||
multicast_delegate<mixer_track*> on_remove_track_main_thread;
|
||||
|
||||
|
||||
mixer_track* selected_track = nullptr;
|
||||
private:
|
||||
void post_process(uint32_t in_frames) const;
|
||||
void thread_register_track(mixer_track* track);
|
||||
|
@ -83,6 +83,7 @@ std::string instrument_track::get_name() const {
|
||||
|
||||
void delete_effect(mixer_track* track, plugin_host* host) {
|
||||
track->remove_effect(host);
|
||||
host->try_close_editor();
|
||||
g_audio_thread_hub.push_message([host](){
|
||||
delete host;
|
||||
});
|
||||
|
@ -36,3 +36,41 @@ const std::string &host_param::get_label() const {
|
||||
label_ = host_->get_parameter_label(index_);
|
||||
return label_;
|
||||
}
|
||||
|
||||
float host_param::min_value() const {
|
||||
return host_->get_param_min_value(index_);
|
||||
}
|
||||
|
||||
float host_param::max_value() const {
|
||||
return host_->get_param_max_value(index_);
|
||||
}
|
||||
|
||||
const std::string &host_param::get_display() const {
|
||||
if (display_.empty())
|
||||
display_ = host_->get_parameter_display(index_);
|
||||
return display_;
|
||||
}
|
||||
|
||||
bool canConvertToFloat(const std::string& str) {
|
||||
try {
|
||||
std::size_t pos;
|
||||
std::stof(str, &pos);
|
||||
// Check if the entire string was converted
|
||||
return pos == str.size();
|
||||
} catch (const std::invalid_argument& e) {
|
||||
// str was not a valid float
|
||||
return false;
|
||||
} catch (const std::out_of_range& e) {
|
||||
// str was a valid float but out of range
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool host_param::is_toggle() const {
|
||||
if (!is_toggle_.has_value()) {
|
||||
auto label = get_display();
|
||||
// 判断是否可以转换成float
|
||||
is_toggle_ = !canConvertToFloat(label);
|
||||
}
|
||||
return is_toggle_.value();
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "extern.h"
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
|
||||
class plugin_host;
|
||||
|
||||
@ -12,9 +13,13 @@ public:
|
||||
[[nodiscard]] int32_t get_index() const { return index_; }
|
||||
[[nodiscard]] const std::string& get_name() const;
|
||||
[[nodiscard]] const std::string& get_label() const;
|
||||
[[nodiscard]] const std::string& get_display() const;
|
||||
[[nodiscard]] bool is_valid() const { return is_valid_; }
|
||||
void set_value(float in_value);
|
||||
[[nodiscard]] float get_value() const;
|
||||
[[nodiscard]] float min_value() const;
|
||||
[[nodiscard]] float max_value() const;
|
||||
[[nodiscard]] bool is_toggle() const;
|
||||
|
||||
explicit operator bool() const {
|
||||
return is_valid();
|
||||
@ -23,6 +28,8 @@ private:
|
||||
int32_t index_ = -1;
|
||||
mutable std::string name_;
|
||||
mutable std::string label_;
|
||||
mutable std::string display_;
|
||||
mutable std::optional<bool> is_toggle_;
|
||||
plugin_host* host_;
|
||||
bool is_valid_ = false;
|
||||
};
|
||||
|
@ -20,6 +20,10 @@ struct host_param_info {
|
||||
class CORE_API plugin_host {
|
||||
friend class window_manager;
|
||||
public:
|
||||
plugin_host() {
|
||||
static uint32_t id_counter = 0;
|
||||
id = ++id_counter;
|
||||
}
|
||||
virtual ~plugin_host();
|
||||
|
||||
virtual bool load_plugin(const char* path) = 0;
|
||||
@ -48,10 +52,13 @@ public:
|
||||
|
||||
[[nodiscard]] virtual std::string get_parameter_name(int index) const = 0;
|
||||
[[nodiscard]] virtual std::string get_parameter_label(int index) const { return ""; };
|
||||
[[nodiscard]] virtual std::string get_parameter_display(int index) const { return ""; };
|
||||
[[nodiscard]] virtual int32_t get_param_count() const = 0;
|
||||
[[nodiscard]] virtual bool is_param_index_valid(const int32_t index) const { return index >= 0 && index < get_param_count(); }
|
||||
virtual void set_param_value(int32_t index, float value) = 0;
|
||||
virtual float get_param_value(int32_t index) = 0;
|
||||
virtual float get_param_min_value(int32_t index) { return 0.0f; }
|
||||
virtual float get_param_max_value(int32_t index) { return 1.0f; }
|
||||
|
||||
void init_channel_interface();
|
||||
|
||||
@ -59,6 +66,10 @@ public:
|
||||
std::string vendor;
|
||||
channel_interface* channel = nullptr;
|
||||
std::vector<mixer_track*> owner_tracks;
|
||||
|
||||
[[nodiscard]] std::string get_imgui_id() const {
|
||||
return name + "##" + std::to_string(id);
|
||||
}
|
||||
std::shared_ptr<circular_buffer_vector_type> ui_buffers;
|
||||
multicast_delegate<void(int32_t index, float value)> on_param_changed;
|
||||
protected:
|
||||
@ -68,4 +79,5 @@ protected:
|
||||
virtual void on_close_editor() = 0;
|
||||
private:
|
||||
bool editor_opened = false;
|
||||
uint32_t id = 0;
|
||||
};
|
||||
|
@ -289,6 +289,12 @@ std::string vst2_plugin_host::get_parameter_label(int index) const {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
std::string vst2_plugin_host::get_parameter_display(int index) const {
|
||||
char buffer[64]{0};
|
||||
dispatch(effGetParamDisplay, index, 0, buffer);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
int32_t vst2_plugin_host::get_param_count() const
|
||||
{
|
||||
if (!effect_)
|
||||
|
@ -27,7 +27,8 @@ public:
|
||||
void get_editor_size(uint32_t& width, uint32_t& height) const override;
|
||||
// [[nodiscard]] ImVec2 get_editor_size() const override;
|
||||
[[nodiscard]] std::string get_parameter_name(int index) const override;
|
||||
[[nodiscard]]std::string get_parameter_label(int index) const override;
|
||||
[[nodiscard]] std::string get_parameter_label(int index) const override;
|
||||
[[nodiscard]] std::string get_parameter_display(int index) const override;
|
||||
[[nodiscard]] int32_t get_param_count() const override;
|
||||
void set_param_value(int32_t index, float value) override;
|
||||
float get_param_value(int32_t index) override;
|
||||
|
Loading…
x
Reference in New Issue
Block a user