75 lines
1.8 KiB
C++
75 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include <halp/audio.hpp>
|
|
#include <halp/midi.hpp>
|
|
#include <halp/controls.hpp>
|
|
#include <halp/meta.hpp>
|
|
|
|
#include "FrequencyAnalyzer.hpp"
|
|
|
|
namespace Amuencha
|
|
{
|
|
class Model
|
|
{
|
|
public:
|
|
halp_meta(name, "Amuencha")
|
|
halp_meta(category, "Audio")
|
|
halp_meta(c_name, "amuencha")
|
|
halp_meta(uuid, "b37351b4-7b8d-4150-9e1c-708eec9182b2")
|
|
|
|
struct processor_to_ui
|
|
{
|
|
std::vector<float> reassigned_frequencies;
|
|
std::vector<float> power_spectrum;
|
|
};
|
|
|
|
std::function<void(processor_to_ui&&)> send_message;
|
|
|
|
// Define inputs and outputs ports.
|
|
// See the docs at https://github.com/celtera/avendish
|
|
struct ins
|
|
{
|
|
halp::fixed_audio_bus<"Input", float, 1> audio;
|
|
halp::hslider_i32<"Min", halp::range{.min = 0, .max = 127, .init = 24}> min;
|
|
halp::hslider_i32<"Max", halp::range{.min = 0, .max = 127, .init = 72}> max;
|
|
halp::spinbox_i32<"Periods", halp::range{.min = 0, .max = 99, .init = 30}> periods;
|
|
} inputs;
|
|
|
|
void process_message(const std::vector<float>& frequencies)
|
|
{
|
|
analyzer.setup(sampling_rate,
|
|
frequencies,
|
|
[&] (const std::vector<float>& r_f,
|
|
const std::vector<float>& p_s)
|
|
{
|
|
this->send_message({.reassigned_frequencies = r_f,
|
|
.power_spectrum = p_s});
|
|
},
|
|
inputs.periods);
|
|
|
|
if (!analyzer.isRunning())
|
|
analyzer.start(QThread::NormalPriority);
|
|
}
|
|
|
|
struct outs
|
|
{
|
|
halp::midi_bus<"Output"> midi;
|
|
} outputs;
|
|
|
|
using setup = halp::setup;
|
|
void prepare(setup info);
|
|
|
|
// Do our processing for N samples
|
|
using tick = halp::tick;
|
|
// Defined in the .cpp
|
|
void operator()(tick t);
|
|
|
|
// UI is defined in another file to keep things clear.
|
|
struct ui;
|
|
|
|
private:
|
|
float sampling_rate;
|
|
FrequencyAnalyzer analyzer;
|
|
};
|
|
|
|
}
|