score-avnd-amuencha/Amuencha/AmuenchaUi.hpp

58 lines
1.2 KiB
C++
Raw Normal View History

2024-10-12 22:18:42 +01:00
#pragma once
#include <Amuencha/AmuenchaModel.hpp>
#include <halp/layout.hpp>
#include "SpiralDisplay.hpp"
namespace Amuencha
{
struct Analyser::ui
{
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)
halp::item<&ins::min> min;
halp::item<&ins::max> max;
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
2024-10-23 00:22:31 +01:00
// Define the communication between UI and processor.
struct bus
{
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());
};
}
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-25 12:02:48 +01:00
self.spiral.set_min_max_notes(msg.min, msg.max);
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-12 22:18:42 +01:00
};
}