MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
ModalDampingOperator.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "NetworkOperator.hpp"
4
6
7class ModalNetwork;
8
9/**
10 * @struct ModalDampingControls
11 * @brief Controls of a ModalDampingOperator, each a number or a mapped node.
12 *
13 * set() changes that field of every mode and leaves the other fields of each
14 * mode as they were. set_mode() changes one mode from the same struct, numbers
15 * only. A network source is per element and is not used. A value that would
16 * make a response invalid is refused. The defaults are 1 second quiet, 0.2
17 * loud, 0.1 reference_rms and 0.05 smoothing.
18 */
25
27
28/**
29 * @brief Adjust each ModalNetwork mode's decay from its previous block's RMS.
30 *
31 * Processing runs before the next block is rendered. A mode at zero RMS uses
32 * quiet_seconds; one at or above reference_rms uses loud_seconds. Intermediate
33 * levels interpolate between them. The response is smoothed in block time.
34 * The network keeps the last applied decay when this operator is removed.
35 *
36 * @code{.cpp}
37 * auto damping = gong->add<ModalDampingOperator>();
38 * damping->set({ .quiet_seconds = 3.5, .loud_seconds = 0.18 });
39 * damping->set_mode(0, { .quiet_seconds = 7.0, .loud_seconds = 2.5 });
40 * @endcode
41 */
42class MAYAFLUX_API ModalDampingOperator final : public NetworkOperator {
43public:
45
46 explicit ModalDampingOperator(const std::shared_ptr<ModalNetwork>& network);
47
48 /**
49 * @brief Change one mode's response from the numbers @p controls holds.
50 *
51 * A pending set() is applied first, so calls take effect in the order made.
52 * An index past the last mode, or a value that would make the response
53 * invalid, is ignored with a warning. Like the other mode edits this
54 * belongs outside the block.
55 */
56 void set_mode(size_t index, const ModalDampingControls& controls);
57
58 void process(float frames) override;
59
60 /** @brief Sets the control of that name, so "loud_seconds" is the same as set({ .loud_seconds = ... }). */
61 void set_parameter(std::string_view name, double value) override;
62
63 /** @brief The control of that name as the operator holds it, or "mode_count". */
64 [[nodiscard]] std::optional<double> query_state(std::string_view name) const override;
65 [[nodiscard]] std::string_view get_type_name() const override { return "ModalDamping"; }
66
67 /** @brief Fills the controls whose value the operator holds outside the struct. */
68 void read_controls(ModalDampingControls& controls) const;
69
70private:
71 struct Response {
72 double quiet_seconds { 1.0 };
73 double loud_seconds { 0.2 };
74 double reference_rms { 0.1 };
75 double smoothing_seconds { 0.05 };
76 };
77
78 struct ModeState {
80 double decay_seconds {};
81 };
82
83 [[nodiscard]] static bool valid(const Response& response) noexcept;
84
85 bool apply_field(double Response::* member, double value);
86 void apply_controls();
87
89 std::weak_ptr<ModalNetwork> m_network;
91 std::vector<ModeState> m_modes;
92};
93
94}
#define MF_DESCRIBE(...)
Requests a generated member description for a struct at namespace scope.
Definition Describe.hpp:14
One named control of a network or operator: empty, a value, or a mapped source.
Definition Control.hpp:34
void process(float frames) override
Process for one batch cycle.
std::optional< double > query_state(std::string_view name) const override
The control of that name as the operator holds it, or "mode_count".
void set_parameter(std::string_view name, double value) override
Sets the control of that name, so "loud_seconds" is the same as set({ .loud_seconds = ....
ModalDampingOperator(const std::shared_ptr< ModalNetwork > &network)
std::string_view get_type_name() const override
Type name for introspection.
void set_mode(size_t index, const ModalDampingControls &controls)
Change one mode's response from the numbers controls holds.
Network of resonant modes for modal synthesis.
Domain-agnostic interpretive lens for network processing.
Controls of a ModalDampingOperator, each a number or a mapped node.