[ui] update Spiral from processor

This commit is contained in:
thibaud keller 2024-10-25 12:02:48 +01:00
parent bf657b668b
commit c3adc2be38
5 changed files with 42 additions and 15 deletions

View file

@ -4,6 +4,15 @@ namespace Amuencha
{ {
void Analyser::operator()(halp::tick t) void Analyser::operator()(halp::tick t)
{ {
if (inputs.min != previous_min ||
inputs.max != previous_max)
{
send_message(processor_to_ui{.min = inputs.min,
.max = inputs.max});
previous_min = inputs.min;
previous_max = inputs.max;
}
// Process the input buffer // Process the input buffer
auto* in = inputs.audio[0]; auto* in = inputs.audio[0];

View file

@ -52,6 +52,9 @@ public:
// UI is defined in another file to keep things clear. // UI is defined in another file to keep things clear.
struct ui; struct ui;
private:
double previous_min{24}, previous_max{72};
}; };
} }

View file

@ -22,22 +22,20 @@ struct Analyser::ui
halp::item<&ins::max> max; halp::item<&ins::max> max;
} controls; } controls;
struct halp::custom_actions_item<SpiralDisplay> spiral{.x = 0, .y = 0};
{
halp_meta(layout, halp::layouts::vbox)
halp_meta(background, halp::colors::mid)
halp_meta(width, 500)
halp_meta(height, 500)
halp::custom_actions_item<SpiralDisplay> widget{.x = 0, .y = 0};
} spiral;
// Define the communication between UI and processor. // Define the communication between UI and processor.
struct bus struct bus
{ {
// // Set up connections
// init(ui& self)
// {
// }
// 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, processor_to_ui msg) static void process_message(ui& self, const processor_to_ui& msg)
{ {
self.spiral.set_min_max_notes(msg.min, msg.max);
} }
}; };
}; };

View file

@ -3,12 +3,26 @@
Amuencha::SpiralDisplay::SpiralDisplay() Amuencha::SpiralDisplay::SpiralDisplay()
: min_midi_note{24} : min_midi_note{24}
, max_midi_note{72} , max_midi_note{72}
, gain{1.f}
{ {
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);
display_spectrum.resize(num_ID); display_spectrum.resize(num_ID);
} }
void Amuencha::SpiralDisplay::set_min_max_notes(int min_midi_note, int max_midi_note)
{
if (max_midi_note < min_midi_note) std::swap(min_midi_note, max_midi_note);
this->min_midi_note = min_midi_note;
this->max_midi_note = max_midi_note;
display_bins.clear();
// QPainterPath empty;
// base_spiral.swap(empty);
// for(int id=0; id<num_ID; ++id) all_spirals[id].clear();
// update();
}
void Amuencha::SpiralDisplay::compute_frequencies() void Amuencha::SpiralDisplay::compute_frequencies()
{ {
// Now the spiral // Now the spiral

View file

@ -19,6 +19,10 @@ struct SpiralDisplay
static consteval int width() { return 500; } static consteval int width() { return 500; }
static consteval int height() { return 500; } static consteval int height() { return 500; }
void set_min_max_notes(int min_midi_note, int max_midi_note);
float gain;
void paint(avnd::painter auto ctx) void paint(avnd::painter auto ctx)
{ {
half = height() * .5f; half = height() * .5f;
@ -36,8 +40,6 @@ struct SpiralDisplay
note_names[i]); note_names[i]);
} }
ctx.stroke();
int num_octaves = (max_midi_note - min_midi_note + 11) / 12; int num_octaves = (max_midi_note - min_midi_note + 11) / 12;
for (int id{0}; id < num_ID; ++id) for (int id{0}; id < num_ID; ++id)
@ -62,6 +64,7 @@ struct SpiralDisplay
} }
// Overlay the base spiral in black // Overlay the base spiral in black
// FIXME : find the avendish way to store a painter
// if (base_spiral.isEmpty()) { // if (base_spiral.isEmpty()) {
ctx.move_to(x(spiral_positions.back().real()), y(spiral_positions.back().imag())); ctx.move_to(x(spiral_positions.back().real()), y(spiral_positions.back().imag()));
for (int b = spiral_positions.size() - 1; b >= 0; --b) for (int b = spiral_positions.size() - 1; b >= 0; --b)
@ -91,6 +94,8 @@ private:
std::array<std::complex<float>, 12> note_positions{}; std::array<std::complex<float>, 12> note_positions{};
int min_midi_note, max_midi_note, visual_fading;
// central frequencies (log space) // central frequencies (log space)
std::vector<float> frequencies; std::vector<float> frequencies;
@ -109,9 +114,7 @@ private:
struct Radius_Angle {float r, a;}; struct Radius_Angle {float r, a;};
std::vector<Radius_Angle> spiral_r_a; std::vector<Radius_Angle> spiral_r_a;
int min_midi_note, max_midi_note, visual_fading; float half;
float gain{1.f}, half;
float x(float x) const float x(float x) const
{ {