Line data Source code
1 : #pragma once
2 :
3 : #include <atomic>
4 : #include <memory>
5 : #include <vector>
6 :
7 : #include "audio/utils/spsc_queue.h"
8 :
9 : namespace Amplitron {
10 :
11 : class Effect;
12 : class AudioGraph;
13 : class AudioGraphExecutor;
14 :
15 : /**
16 : * @brief Dispatcher for dynamic parameters and UI commands sent to the audio thread.
17 : * Satisfies the Single Responsibility Principle (SRP).
18 : */
19 : class AudioCommandDispatcher {
20 : public:
21 1090 : AudioCommandDispatcher() = default;
22 : ~AudioCommandDispatcher() = default;
23 :
24 : void push_param_change(int effect_index, int param_index, float value);
25 : void push_mixer_gain_change(int node_id, int pin_index, float gain);
26 : void push_effect_enabled(int effect_index, float enabled);
27 : void push_effect_mix(int effect_index, float mix);
28 : void push_input_gain(float gain);
29 : void push_output_gain(float gain);
30 :
31 : // Audio thread side
32 : void drain_gain_commands(std::atomic<float>& input_gain, std::atomic<float>& output_gain,
33 : std::shared_ptr<AudioGraphExecutor>& executor);
34 :
35 : void drain_commands(std::atomic<float>& input_gain, std::atomic<float>& output_gain,
36 : std::shared_ptr<AudioGraphExecutor>& executor, AudioGraph& main_graph,
37 : std::vector<std::shared_ptr<Effect>>& dummy_effects);
38 :
39 : private:
40 : SPSCQueue<AudioCommand, 256> command_queue_;
41 : };
42 :
43 : } // namespace Amplitron
|