[messages] working messages between ui and processor thread

This commit is contained in:
thibaud keller 2024-10-28 11:12:04 +00:00
parent 50233de626
commit 8565037ac2
4 changed files with 24 additions and 23 deletions

View file

@ -47,7 +47,7 @@ void Analyser::analyzer_setup(float max_buffer_duration)
// Could also span more for even better measurements, with larger // Could also span more for even better measurements, with larger
// computation cost and latency // computation cost and latency
float f = frequencies[idx]; float f = frequencies[idx];
int window_size = (int)(min(inputs.periods_nb.value / f, max_buffer_duration * 0.001f) int window_size = (int)(min(inputs.periods.value / f, max_buffer_duration * 0.001f)
* sampling_rate); * sampling_rate);
vector<float> window(window_size); vector<float> window(window_size);
vector<float> window_deriv(window_size); vector<float> window_deriv(window_size);

View file

@ -22,7 +22,7 @@ public:
int max; int max;
}; };
std::function<void(const processor_to_ui&)> send_message; std::function<void(processor_to_ui&&)> send_message;
// Define inputs and outputs ports. // Define inputs and outputs ports.
// See the docs at https://github.com/celtera/avendish // See the docs at https://github.com/celtera/avendish
@ -43,8 +43,8 @@ public:
self.send_message({.min = self.inputs.min.value, .max = this->value}); self.send_message({.min = self.inputs.min.value, .max = this->value});
} }
} max; } max;
halp::spinbox_i32<"Analyze num. periods", halp::spinbox_i32<"Periods",
halp::range{.min = 0, .max = 99, .init = 30}> periods_nb; halp::range{.min = 0, .max = 99, .init = 30}> periods;
} inputs; } inputs;
void process_message(const std::vector<float>& frequencies) void process_message(const std::vector<float>& frequencies)

View file

@ -20,7 +20,7 @@ struct Analyser::ui
halp_meta(layout, vbox) halp_meta(layout, vbox)
halp::item<&ins::min> min; halp::item<&ins::min> min;
halp::item<&ins::max> max; halp::item<&ins::max> max;
halp::item<&ins::periods_nb> periods; halp::item<&ins::periods> periods;
} controls; } controls;
halp::custom_actions_item<SpiralDisplay> spiral{.x = 0, .y = 0}; halp::custom_actions_item<SpiralDisplay> spiral{.x = 0, .y = 0};
@ -29,16 +29,16 @@ struct Analyser::ui
// Define the communication between UI and processor. // Define the communication between UI and processor.
struct bus struct bus
{ {
// std::function<void(const std::vector<float>&)> send_message; std::function<void(const std::vector<float>&)> send_message;
// // Set up connections // Set up connections
// void init(ui& self) void init(ui& self)
// { {
// self.spiral.on_new_frequencies = [&] self.spiral.on_new_frequencies = [&]
// { {
// send_message(self.spiral.get_frequencies()); send_message(self.spiral.get_frequencies());
// }; };
// } }
// Receive a message on the UI thread from the processing thread // Receive a message on the UI thread from the processing thread
static void process_message(ui& self, const processor_to_ui& msg) static void process_message(ui& self, const processor_to_ui& msg)

View file

@ -4,6 +4,7 @@ Amuencha::SpiralDisplay::SpiralDisplay()
: min_midi_note{24} : min_midi_note{24}
, max_midi_note{72} , max_midi_note{72}
, gain{1.f} , gain{1.f}
, on_new_frequencies{[]{}}
{ {
for (int i{0}; i < 12; i++) note_positions[i] = std::polar(.9f, half_pi - i * two_pi / 12); for (int i{0}; i < 12; i++) note_positions[i] = std::polar(.9f, half_pi - i * two_pi / 12);
@ -90,7 +91,7 @@ void Amuencha::SpiralDisplay::compute_frequencies()
fill(display_spectrum[id].begin(), display_spectrum[id].end(), 0.); fill(display_spectrum[id].begin(), display_spectrum[id].end(), 0.);
} }
// on_new_frequencies(); on_new_frequencies();
} }
void Amuencha::SpiralDisplay::power_handler(int ID, const std::vector<float> &reassigned_frequencies, const std::vector<float> &power_spectrum) void Amuencha::SpiralDisplay::power_handler(int ID, const std::vector<float> &reassigned_frequencies, const std::vector<float> &power_spectrum)