[display] first working extremly dirty poc

This commit is contained in:
thibaud keller 2024-10-30 13:07:46 +00:00
parent 29283ede63
commit eaf8314a68
4 changed files with 29 additions and 14 deletions

View file

@ -58,7 +58,7 @@ public:
[&] (const std::vector<float>& r_f, [&] (const std::vector<float>& r_f,
const std::vector<float>& p_s) const std::vector<float>& p_s)
{ {
send_message({.min = inputs.min, this->send_message({.min = inputs.min,
.max = inputs.max, .max = inputs.max,
.reassigned_frequencies = r_f, .reassigned_frequencies = r_f,
.power_spectrum = p_s}); .power_spectrum = p_s});

View file

@ -30,20 +30,25 @@ struct Model::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(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.set_frequencies_callback(
{ [&] { this->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)
{ {
if (!first_msg)
{
self.spiral.compute_frequencies();
first_msg = true;
}
// self.spiral.set_min_max_notes(msg.min, msg.max); // self.spiral.set_min_max_notes(msg.min, msg.max);
if (msg.power_spectrum.empty() || if (msg.power_spectrum.empty() ||
@ -53,6 +58,10 @@ struct Model::ui
self.spiral.power_handler(msg.reassigned_frequencies, self.spiral.power_handler(msg.reassigned_frequencies,
msg.power_spectrum); msg.power_spectrum);
} }
static bool first_msg;
}; };
}; };
} }
inline bool Amuencha::Model::ui::bus::first_msg = false;

View file

@ -29,6 +29,11 @@ std::vector<float> Amuencha::SpiralDisplay::get_frequencies() const noexcept
return frequencies; return frequencies;
} }
void Amuencha::SpiralDisplay::set_frequencies_callback(std::function<void ()> &&callback)
{
on_new_frequencies = callback;
}
void Amuencha::SpiralDisplay::compute_frequencies() void Amuencha::SpiralDisplay::compute_frequencies()
{ {
// Now the spiral // Now the spiral

View file

@ -58,7 +58,7 @@ struct SpiralDisplay
for (int b{0}; b < display_spectrum.size(); ++b) for (int b{0}; b < display_spectrum.size(); ++b)
{ {
float amplitude = 0.8 / num_octaves * std::min(1.f, display_spectrum[b] * gain); float amplitude = 0.8 / num_octaves * std::min(1.f, display_spectrum[b] * 100);
//if (display_spectrum[b]>0) cout << display_spectrum[b] << endl; //if (display_spectrum[b]>0) cout << display_spectrum[b] << endl;
// power normalised between 0 and 1 => 0.1 = spiral branch // power normalised between 0 and 1 => 0.1 = spiral branch
float r = spiral_r_a[b].r + amplitude; float r = spiral_r_a[b].r + amplitude;
@ -69,8 +69,8 @@ struct SpiralDisplay
ctx.line_to(x(p.real()), y(p.imag())); ctx.line_to(x(p.real()), y(p.imag()));
} }
for (int b = spiral_positions.size() - 1; b >= 0; --b) // for (int b = spiral_positions.size() - 1; b >= 0; --b)
ctx.line_to(x(spiral_positions[b].real()), y(spiral_positions[b].imag())); // ctx.line_to(x(spiral_positions[b].real()), y(spiral_positions[b].imag()));
ctx.stroke(); ctx.stroke();
ctx.update(); ctx.update();
@ -78,13 +78,14 @@ struct SpiralDisplay
[[nodiscard]] std::vector<float> get_frequencies() const noexcept; [[nodiscard]] std::vector<float> get_frequencies() const noexcept;
std::function<void()> on_new_frequencies; void set_frequencies_callback(std::function<void()>&& callback);
// // Callback when the power spectrum is available at the prescribed frequencies // // Callback when the power spectrum is available at the prescribed frequencies
// // The ID is that of the caller, setting the color of the display // // The ID is that of the caller, setting the color of the display
void power_handler(const std::vector<float>& reassigned_frequencies, void power_handler(const std::vector<float>& reassigned_frequencies,
const std::vector<float>& power_spectrum); const std::vector<float>& power_spectrum);
void compute_frequencies();
private: private:
static const constexpr std::string_view note_names[12] static const constexpr std::string_view note_names[12]
{"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"}; {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"};
@ -134,7 +135,7 @@ private:
return half - y * half; return half - y * half;
} }
void compute_frequencies(); std::function<void()> on_new_frequencies;
}; };
} }