Loading...
Searching...
No Matches
Tuner.hpp
1#pragma once
2#include <Process/Dataflow/Port.hpp>
3#include <Process/Monitoring/MonitorLink.hpp>
4#include <Process/Monitoring/SampleRing.hpp>
5
6#include <Effect/EffectLayer.hpp>
7
8#include <Ui/Monitor/SpectrumAnalysis.hpp>
9#include <halp/audio.hpp>
10#include <halp/controls.hpp>
11#include <halp/meta.hpp>
12
13#include <memory>
14#include <vector>
15
20namespace Ui::Tuner
21{
23{
24 Process::SampleRing ring{1 << 14};
25};
26
27struct Layer;
28
29struct Node
30{
31 halp_meta(name, "Tuner")
32 halp_meta(c_name, "Tuner")
33 halp_meta(category, "Monitoring/Audio")
34 halp_meta(author, "ossia score")
35 halp_meta(manual_url, "")
36 halp_meta(description, "Shows the note the signal plays, and how many cents it is off")
37 halp_meta(uuid, "bc22f3ed-7ee8-4de4-80c4-cae2f372b2d7")
38 halp_flag(fully_custom_item);
39 using Layer = Ui::Tuner::Layer;
40
41 struct
42 {
43 halp::dynamic_audio_bus<"Audio", double> audio;
44 struct : halp::spinbox_f32<"A4", halp::range{400., 480., 440.}>
45 {
46 halp_meta(description, "Frequency of the A above middle C, in Hz")
47 } reference;
48 } inputs;
49
50 struct
51 {
52 } outputs;
53
54 std::shared_ptr<TunerMonitor> monitor = std::make_shared<TunerMonitor>();
55
56 void prepare(halp::setup s) { monitor->ring.set_rate(s.rate > 0 ? s.rate : 48000.); }
57
58 void operator()(int frames)
59 {
60 const int nch = inputs.audio.channels;
61 if(nch > 0 && frames > 0 && monitor->watched())
62 monitor->ring.write(nch, frames, [&](int c) { return inputs.audio[c]; });
63 }
64};
65
67{
69 static constexpr std::size_t frame = 2048;
70
71 Layer(
72 const Process::ProcessModel& process, const Process::Context& doc,
73 QGraphicsItem* parent);
74
75 void paint_impl(QPainter* p) const override;
76
77private:
78 void refresh(TunerMonitor& mon);
79 double reference() const;
80
81 const Process::ControlInlet* m_reference{};
82 Process::MonitorLink* m_link{};
84 std::vector<std::vector<float>> m_in;
85 std::vector<float> m_mix;
86 double m_freq{};
87 bool m_signal{};
88};
89}
Definition Port.hpp:247
Definition EffectLayer.hpp:17
The Process class.
Definition score-lib-process/Process/Process.hpp:82
Definition SampleRing.hpp:35
Definition SpectrumAnalysis.hpp:156
Definition Tuner.cpp:13
Definition ProcessContext.hpp:12
Definition Monitor.hpp:27
Definition Tuner.hpp:67
static constexpr std::size_t frame
YIN costs the square of the frame: 2048 samples reach 23 Hz at 48 kHz.
Definition Tuner.hpp:69
Definition Tuner.hpp:30
Definition Tuner.hpp:23