7#include "gui/dsp/port.h"
8#include "utils/icloneable.h"
10#include "utils/monotonic_time_provider.h"
15class ControlPort final
49 PortIdentifier::Flags
flag{};
67 : val_ (val), label_ (std::move (label))
71 friend auto operator<=> (
const ScalePoint &lhs,
const ScalePoint &rhs)
73 return lhs.val_ <=> rhs.val_;
76 friend bool operator== (
const ScalePoint &lhs,
const ScalePoint &rhs)
134 s32 >= std::numeric_limits<int>::min ()
135 && s32 <= std::numeric_limits<int>::max ());
136 return static_cast<int> (s32);
236 automation_reader_ = reader;
239 RtTimePoint ms_since_last_change ()
const
241 return time_provider_->get_monotonic_time_usecs () - last_change_time_;
256 friend void init_from (
262 static constexpr std::string_view kControlKey =
"control";
263 static constexpr std::string_view kRangeKey =
"range";
264 static constexpr std::string_view kDefaultValueKey =
"defaultValue";
265 static constexpr std::string_view kCarlaParameterIdKey =
"carlaParameterId";
266 static constexpr std::string_view kBaseValueKey =
"baseValue";
267 friend void to_json (nlohmann::json &j,
const ControlPort &p)
269 to_json (j,
static_cast<const Port &
> (p));
271 j[kRangeKey] = p.range_;
272 j[kDefaultValueKey] = p.
deff_;
276 friend void from_json (
const nlohmann::json &j, ControlPort &p)
278 from_json (j,
static_cast<Port &
> (p));
279 j.at (kControlKey).get_to (p.
control_);
280 j.at (kRangeKey).get_to (p.range_);
281 j.at (kDefaultValueKey).get_to (p.
deff_);
358 RtTimePoint last_change_time_{};
360 std::optional<AutomationValueGetter> automation_reader_;
362 std::unique_ptr<utils::QElapsedTimeProvider> time_provider_;
midi_byte_t midi_channel_
MIDI channel, starting from 1.
float normalized_val_to_real(float normalized_val) const
Converts normalized value (0.0 to 1.0) to real value (eg.
float get_control_value(bool normalize) const
Gets the given control value from the corresponding underlying structure in the Port.
float get_snapped_val_from_val(float val) const
Returns the snapped value (eg, if toggle, returns 0.f or 1.f).
bool automating_
Whether this value was set via automation.
static bool is_val_toggled(float val)
Checks if the given value is toggled.
static int get_int_from_val(float val)
Gets the control value for an integer port.
float control_
To be called when a control's value changes so that a message can be sent to the plugin UI.
int get_int() const
Gets the control value for an integer port.
float real_val_to_normalized(float real_val) const
Converts real value (eg.
float deff_
Default value.
float get_val() const
Get the current real value of the control.
void set_toggled(bool toggled, bool forward_events)
Wrapper over port_set_control_value() for toggles.
void set_real_val_w_events(float val)
Set the default real value of the control and sends UI events.
float get_default_val() const
Get the default real value of the control.
bool is_toggled() const
Returns if the control port is toggled.
int carla_param_id_
Index of the control parameter (for Carla plugin ports).
bool value_changed_from_reading_
Flag that the value of the port changed from reading automation.
std::function< std::optional< float >(signed_frame_t global_frame)> AutomationValueGetter
Gets the current automation value if available (eg, from an automation track).
void set_val_from_normalized(float val, bool automating)
Updates the actual value.
float unsnapped_control_
Unsnapped value, used by widgets.
float get_unsnapped_val() const
Get the current real unsnapped value of the control.
void set_unit_from_str(const utils::Utf8String &str)
Set the identifier's port unit from the given string.
std::vector< ScalePoint > scale_points_
Scale points.
void set_automation_value_reader(AutomationValueGetter reader)
Sets the automation value reader.
void clear_buffer(std::size_t block_length) override
Clears the port buffer.
void set_real_val(float val)
Get the default real value of the control.
midi_byte_t midi_cc_no_
MIDI CC number, if not pitchbend/poly key/channel pressure.
bool received_ui_event_
Whether the port received a UI event from the plugin UI in this cycle.
float get_snapped_val() const
Returns the snapped value (eg, if toggle, returns 0.f or 1.f).
float get_normalized_val() const
Get the current normalized value of the control.
void set_control_value(float val, bool is_normalized, bool forward_event_to_plugin)
Sets the given control value to the corresponding underlying structure in the Port.
float base_value_
For control ports, when a modulator is attached to the port the previous value will be saved here.
The Port class represents a port in the audio processing graph.
Lightweight UTF-8 string wrapper with safe conversions.
int_fast64_t signed_frame_t
Signed type for frame index.
uint8_t midi_byte_t
MIDI byte.
constexpr bool floats_equal(T a, T b)
Checks if 2 floating point numbers are equal.
constexpr long round_to_signed_32(T x)
Rounds a double to a (minimum) signed 32-bit integer.
Used for queueing changes to be applied during processing.
PortIdentifier::Flags flag
Flag to identify the port the change is for.
float real_val
Real (not normalized) value to set.
Common struct to pass around during processing to avoid repeating the data in function arguments.