score-avnd-amuencha/Amuencha/AmuenchaUi.hpp

59 lines
1.3 KiB
C++
Raw Normal View History

2024-10-12 22:18:42 +01:00
#pragma once
#include <halp/layout.hpp>
#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
{
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;
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
{
// Set up connections
void init(ui& self)
{
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);
2024-11-01 00:01:20 +00:00
};
self.controls.max.on_changed = [&] (int max)
{
self.spiral.set_min_max_notes(self.controls.min.value, max);
2024-11-01 00:01:20 +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-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
};
}