[messages] working messages between ui and processor thread
This commit is contained in:
parent
50233de626
commit
8565037ac2
4 changed files with 24 additions and 23 deletions
|
@ -47,7 +47,7 @@ void Analyser::analyzer_setup(float max_buffer_duration)
|
|||
// Could also span more for even better measurements, with larger
|
||||
// computation cost and latency
|
||||
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);
|
||||
vector<float> window(window_size);
|
||||
vector<float> window_deriv(window_size);
|
||||
|
|
|
@ -22,7 +22,7 @@ public:
|
|||
int max;
|
||||
};
|
||||
|
||||
std::function<void(const processor_to_ui&)> send_message;
|
||||
std::function<void(processor_to_ui&&)> send_message;
|
||||
|
||||
// Define inputs and outputs ports.
|
||||
// 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});
|
||||
}
|
||||
} max;
|
||||
halp::spinbox_i32<"Analyze num. periods",
|
||||
halp::range{.min = 0, .max = 99, .init = 30}> periods_nb;
|
||||
halp::spinbox_i32<"Periods",
|
||||
halp::range{.min = 0, .max = 99, .init = 30}> periods;
|
||||
} inputs;
|
||||
|
||||
void process_message(const std::vector<float>& frequencies)
|
||||
|
|
|
@ -20,7 +20,7 @@ struct Analyser::ui
|
|||
halp_meta(layout, vbox)
|
||||
halp::item<&ins::min> min;
|
||||
halp::item<&ins::max> max;
|
||||
halp::item<&ins::periods_nb> periods;
|
||||
halp::item<&ins::periods> periods;
|
||||
} controls;
|
||||
|
||||
halp::custom_actions_item<SpiralDisplay> spiral{.x = 0, .y = 0};
|
||||
|
@ -29,16 +29,16 @@ struct Analyser::ui
|
|||
// Define the communication between UI and processor.
|
||||
struct bus
|
||||
{
|
||||
// std::function<void(const std::vector<float>&)> send_message;
|
||||
std::function<void(const std::vector<float>&)> send_message;
|
||||
|
||||
// // Set up connections
|
||||
// void init(ui& self)
|
||||
// {
|
||||
// self.spiral.on_new_frequencies = [&]
|
||||
// {
|
||||
// send_message(self.spiral.get_frequencies());
|
||||
// };
|
||||
// }
|
||||
// Set up connections
|
||||
void init(ui& self)
|
||||
{
|
||||
self.spiral.on_new_frequencies = [&]
|
||||
{
|
||||
send_message(self.spiral.get_frequencies());
|
||||
};
|
||||
}
|
||||
|
||||
// Receive a message on the UI thread from the processing thread
|
||||
static void process_message(ui& self, const processor_to_ui& msg)
|
||||
|
|
|
@ -4,6 +4,7 @@ Amuencha::SpiralDisplay::SpiralDisplay()
|
|||
: min_midi_note{24}
|
||||
, max_midi_note{72}
|
||||
, 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);
|
||||
|
||||
|
@ -90,7 +91,7 @@ void Amuencha::SpiralDisplay::compute_frequencies()
|
|||
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)
|
||||
|
|
Loading…
Add table
Reference in a new issue