2024-10-12 22:18:42 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <halp/layout.hpp>
|
2024-10-29 23:32:02 +00:00
|
|
|
|
|
|
|
#include <Amuencha/AmuenchaModel.hpp>
|
2024-10-12 22:18:42 +01:00
|
|
|
#include "SpiralDisplay.hpp"
|
2024-11-01 00:01:20 +00:00
|
|
|
#include "CustomSlider.hpp"
|
2024-10-12 22:18:42 +01:00
|
|
|
|
|
|
|
namespace Amuencha
|
|
|
|
{
|
2024-10-29 23:32:02 +00:00
|
|
|
struct Model::ui
|
2024-10-12 22:18:42 +01:00
|
|
|
{
|
|
|
|
using enum halp::colors;
|
|
|
|
using enum halp::layouts;
|
|
|
|
|
|
|
|
halp_meta(name, "Amuencha")
|
|
|
|
halp_meta(layout, hbox)
|
|
|
|
halp_meta(background, dark)
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
halp_meta(layout, vbox)
|
2024-11-01 00:01:20 +00:00
|
|
|
halp::custom_control<CustomSlider, &ins::min> min;
|
|
|
|
halp::custom_control<CustomSlider, &ins::max> max;
|
2024-10-28 11:12:04 +00:00
|
|
|
halp::item<&ins::periods> periods;
|
2024-10-12 22:18:42 +01:00
|
|
|
} controls;
|
|
|
|
|
2024-10-25 12:02:48 +01:00
|
|
|
halp::custom_actions_item<SpiralDisplay> spiral{.x = 0, .y = 0};
|
2024-10-23 00:22:31 +01:00
|
|
|
|
|
|
|
// Define the communication between UI and processor.
|
|
|
|
struct bus
|
|
|
|
{
|
2024-10-30 13:07:46 +00:00
|
|
|
std::function<void(std::vector<float>&&)> send_message;
|
2024-10-28 11:12:04 +00:00
|
|
|
|
|
|
|
// Set up connections
|
|
|
|
void init(ui& self)
|
|
|
|
{
|
2024-10-30 13:07:46 +00:00
|
|
|
self.spiral.set_frequencies_callback(
|
|
|
|
[&] { this->send_message(self.spiral.get_frequencies()); }
|
|
|
|
);
|
2024-11-01 00:01:20 +00:00
|
|
|
|
|
|
|
self.controls.min.on_changed = [&] (int min)
|
|
|
|
{
|
|
|
|
// self.spiral.set_min_max_notes(min, self.controls.max.value);
|
|
|
|
};
|
|
|
|
self.controls.max.on_changed = [&] (int max)
|
|
|
|
{
|
|
|
|
// self.spiral.set_min_max_notes(self.controls.min.value, max);
|
|
|
|
};
|
2024-10-28 11:12:04 +00:00
|
|
|
}
|
2024-10-25 12:02:48 +01:00
|
|
|
|
2024-10-23 00:22:31 +01:00
|
|
|
// Receive a message on the UI thread from the processing thread
|
2024-10-25 12:02:48 +01:00
|
|
|
static void process_message(ui& self, const processor_to_ui& msg)
|
2024-10-23 00:22:31 +01:00
|
|
|
{
|
2024-10-30 13:07:46 +00:00
|
|
|
if (!first_msg)
|
|
|
|
{
|
|
|
|
self.spiral.compute_frequencies();
|
|
|
|
first_msg = true;
|
|
|
|
}
|
|
|
|
|
2024-10-29 00:07:57 +00:00
|
|
|
if (msg.power_spectrum.empty() ||
|
|
|
|
msg.reassigned_frequencies.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
self.spiral.power_handler(msg.reassigned_frequencies,
|
|
|
|
msg.power_spectrum);
|
2024-10-23 00:22:31 +01:00
|
|
|
}
|
2024-10-30 13:07:46 +00:00
|
|
|
|
|
|
|
static bool first_msg;
|
2024-10-23 00:22:31 +01:00
|
|
|
};
|
2024-10-12 22:18:42 +01:00
|
|
|
};
|
|
|
|
}
|
2024-10-30 13:07:46 +00:00
|
|
|
|
|
|
|
inline bool Amuencha::Model::ui::bus::first_msg = false;
|