4#ifndef __AUDIO_EXT_PORT_H__
5#define __AUDIO_EXT_PORT_H__
13#include "zrythm-config.h"
15#include "gui/dsp/port.h"
16#include "utils/serialization.h"
20# include "weakjack/weak_libjack.h"
28enum class AudioBackend;
29enum class MidiBackend;
55 using PortType = zrythm::dsp::PortType;
56 using PortFlow = zrythm::dsp::PortFlow;
64 bool is_in_active_project ()
const override;
95 friend bool operator== (
const ExtPort &a,
const ExtPort &b);
165 std::vector<ExtPort> &ports,
169 static constexpr std::string_view kTypeKey =
"type";
170 static constexpr std::string_view kFullNameKey =
"fullName";
171 static constexpr std::string_view kShortNameKey =
"shortName";
172 static constexpr std::string_view kAlias1Key =
"alias1";
173 static constexpr std::string_view kAlias2Key =
"alias2";
174 static constexpr std::string_view kNumAliasesKey =
"numAliases";
175 static constexpr std::string_view kRtAudioDeviceNameKey =
"rtAudioDeviceName";
176 static constexpr std::string_view kRtAudioChannelIndexKey =
177 "rtAudioChannelIndex";
178 static constexpr std::string_view kIsMidiKey =
"isMidi";
179 friend void to_json (nlohmann::json &j,
const ExtPort &port)
182 { kTypeKey, port.type_ },
187 { kNumAliasesKey, port.num_aliases_ },
193 friend void from_json (
const nlohmann::json &j, ExtPort &port)
195 j.at (kTypeKey).get_to (port.type_);
198 j.at (kAlias1Key).get_to (port.
alias1_);
199 j.at (kAlias2Key).get_to (port.
alias2_);
200 j.at (kNumAliasesKey).get_to (port.num_aliases_);
203 j.at (kIsMidiKey).get_to (port.
is_midi_);
209 jack_port_t *
jport_ =
nullptr;
226 int num_aliases_ = 0;
239 bool rtaudio_is_duplex_ =
false;
void disconnect(Port *port, int src)
Disconnects the Port from the ExtPort.
utils::Utf8String alias2_
Alias #2 if any.
unsigned int rtmidi_id_
RtMidi port index.
HardwareProcessor * hw_processor_
Pointer to owner hardware processor, if any.
utils::Utf8String full_name_
Full port name, used also as ID.
bool is_midi_
True if MIDI, false if audio.
float * get_buffer(nframes_t nframes) const
Returns the buffer of the external port.
void print() const
Prints the port info.
utils::Utf8String short_name_
Short port name.
utils::Utf8String alias1_
Alias #1 if any.
void clear_buffer(nframes_t nframes)
Clears the buffer of the external port.
int hw_processor_index_
Index in the HW processor (cache for real-time use)
bool get_enabled() const
Checks in the GSettings whether this port is marked as enabled by the user.
unsigned int rtaudio_id_
RtAudio device ID (NOT index!
static void ext_ports_get(PortType type, PortFlow flow, bool hw, std::vector< ExtPort > &ports, AudioEngine &engine)
Collects external ports of the given type.
utils::Utf8String get_id() const
Returns a unique identifier (full name prefixed with backend type).
bool rtaudio_is_input_
Whether the channel is input.
unsigned int rtaudio_channel_idx_
RtAudio channel index.
bool active_
Whether the port is active and receiving events (for use by hw processor).
utils::Utf8String get_friendly_name() const
Returns a user-friendly display name (eg, to be used in dropdowns).
bool matches_backend() const
Returns if the ext port matches the current backend.
bool activate(Port *port, bool activate)
Activates the port (starts receiving data) or deactivates it.
void init_loaded(HardwareProcessor *hw_processor)
Inits the ExtPort after loading a project.
bool pending_reconnect_
Set to true when a hardware port is disconnected.
void set_port_metadata_from_owner(dsp::PortIdentifier &id, PortRange &range) const override
Function that will be called by the Port to update the identifier's relevant members based on this po...
Port * port_
Temporary port to receive data.
utils::Utf8String rtaudio_dev_name_
RtAudio device name.
The Port class represents a port in the audio processing graph.
Struct used to identify Ports in the project.
Lightweight UTF-8 string wrapper with safe conversions.
uint32_t nframes_t
Frame count.