score-avnd-amuencha/Amuencha/AmuenchaUi.hpp

67 lines
1.4 KiB
C++

#pragma once
#include <halp/layout.hpp>
#include <Amuencha/AmuenchaModel.hpp>
#include "SpiralDisplay.hpp"
namespace Amuencha
{
struct Model::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;
} controls;
halp::custom_actions_item<SpiralDisplay> spiral{.x = 0, .y = 0};
// Define the communication between UI and processor.
struct bus
{
std::function<void(std::vector<float>&&)> send_message;
// Set up connections
void init(ui& self)
{
self.spiral.set_frequencies_callback(
[&] { this->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)
{
if (!first_msg)
{
self.spiral.compute_frequencies();
first_msg = true;
}
// self.spiral.set_min_max_notes(msg.min, msg.max);
if (msg.power_spectrum.empty() ||
msg.reassigned_frequencies.empty())
return;
self.spiral.power_handler(msg.reassigned_frequencies,
msg.power_spectrum);
}
static bool first_msg;
};
};
}
inline bool Amuencha::Model::ui::bus::first_msg = false;