VCV Rack API v2
Loading...
Searching...
No Matches
rack::engine::Port Struct Reference

#include <Port.hpp>

Inheritance diagram for rack::engine::Port:
[legend]
Collaboration diagram for rack::engine::Port:
[legend]

Public Types

enum  Type { INPUT , OUTPUT }
 

Public Member Functions

void setVoltage (float voltage, uint8_t channel=0)
 Sets the voltage of the given channel.
 
float getVoltage (uint8_t channel=0)
 Returns the voltage of the given channel.
 
float getPolyVoltage (uint8_t channel)
 Returns the given channel's voltage if the port is polyphonic, otherwise returns the first voltage (channel 0).
 
float getNormalVoltage (float normalVoltage, uint8_t channel=0)
 Returns the voltage if a cable is connected, otherwise returns the given normal voltage.
 
float getNormalPolyVoltage (float normalVoltage, uint8_t channel)
 
float * getVoltages (uint8_t firstChannel=0)
 Returns a pointer to the array of voltages beginning with firstChannel.
 
void readVoltages (float *v)
 Copies the port's voltages to an array of size at least channels.
 
void writeVoltages (const float *v)
 Copies an array of size at least channels to the port's voltages.
 
void clearVoltages ()
 Sets all voltages to 0.
 
float getVoltageSum ()
 Returns the sum of all voltages.
 
float getVoltageRMS ()
 Returns the root-mean-square of all voltages.
 
template<typename T >
getVoltageSimd (uint8_t firstChannel)
 
template<typename T >
getPolyVoltageSimd (uint8_t firstChannel)
 
template<typename T >
getNormalVoltageSimd (T normalVoltage, uint8_t firstChannel)
 
template<typename T >
getNormalPolyVoltageSimd (T normalVoltage, uint8_t firstChannel)
 
template<typename T >
void setVoltageSimd (T voltage, uint8_t firstChannel)
 
void setChannels (uint8_t channels)
 Sets the number of polyphony channels.
 
int getChannels ()
 Returns the number of channels.
 
bool isConnected ()
 Returns whether a cable is connected to the Port.
 
bool isMonophonic ()
 Returns whether the cable exists and has 1 channel.
 
bool isPolyphonic ()
 Returns whether the cable exists and has more than 1 channel.
 
DEPRECATED float normalize (float normalVoltage)
 Use getNormalVoltage() instead.
 

Public Attributes

union { 
 
   float   voltages [PORT_MAX_CHANNELS] = {} 
 Unstable API. More...
 
   float   value 
 DEPRECATED. More...
 
};  
 Voltage of the port.
 
union { 
 
   uint8_t   channels = 0 
 Number of polyphonic channels. More...
 
   uint8_t   active 
 DEPRECATED. More...
 
};  
 
Light plugLights [3]
 For rendering plug lights on cables.
 

Member Enumeration Documentation

◆ Type

Enumerator
INPUT 
OUTPUT 

Member Function Documentation

◆ setVoltage()

void rack::engine::Port::setVoltage ( float voltage,
uint8_t channel = 0 )
inline

Sets the voltage of the given channel.

◆ getVoltage()

float rack::engine::Port::getVoltage ( uint8_t channel = 0)
inline

Returns the voltage of the given channel.

Because of proper bookkeeping, all channels higher than the input port's number of channels should be 0V.

◆ getPolyVoltage()

float rack::engine::Port::getPolyVoltage ( uint8_t channel)
inline

Returns the given channel's voltage if the port is polyphonic, otherwise returns the first voltage (channel 0).

◆ getNormalVoltage()

float rack::engine::Port::getNormalVoltage ( float normalVoltage,
uint8_t channel = 0 )
inline

Returns the voltage if a cable is connected, otherwise returns the given normal voltage.

◆ getNormalPolyVoltage()

float rack::engine::Port::getNormalPolyVoltage ( float normalVoltage,
uint8_t channel )
inline

◆ getVoltages()

float * rack::engine::Port::getVoltages ( uint8_t firstChannel = 0)
inline

Returns a pointer to the array of voltages beginning with firstChannel.

The pointer can be used for reading and writing.

◆ readVoltages()

void rack::engine::Port::readVoltages ( float * v)
inline

Copies the port's voltages to an array of size at least channels.

◆ writeVoltages()

void rack::engine::Port::writeVoltages ( const float * v)
inline

Copies an array of size at least channels to the port's voltages.

Remember to set the number of channels before calling this method.

◆ clearVoltages()

void rack::engine::Port::clearVoltages ( )
inline

Sets all voltages to 0.

◆ getVoltageSum()

float rack::engine::Port::getVoltageSum ( )
inline

Returns the sum of all voltages.

◆ getVoltageRMS()

float rack::engine::Port::getVoltageRMS ( )
inline

Returns the root-mean-square of all voltages.

Uses sqrt() which is slow, so use a custom approximation if calling frequently.

◆ getVoltageSimd()

template<typename T >
T rack::engine::Port::getVoltageSimd ( uint8_t firstChannel)
inline

◆ getPolyVoltageSimd()

template<typename T >
T rack::engine::Port::getPolyVoltageSimd ( uint8_t firstChannel)
inline

◆ getNormalVoltageSimd()

template<typename T >
T rack::engine::Port::getNormalVoltageSimd ( T normalVoltage,
uint8_t firstChannel )
inline

◆ getNormalPolyVoltageSimd()

template<typename T >
T rack::engine::Port::getNormalPolyVoltageSimd ( T normalVoltage,
uint8_t firstChannel )
inline

◆ setVoltageSimd()

template<typename T >
void rack::engine::Port::setVoltageSimd ( T voltage,
uint8_t firstChannel )
inline

◆ setChannels()

void rack::engine::Port::setChannels ( uint8_t channels)
inline

Sets the number of polyphony channels.

Also clears voltages of higher channels. If disconnected, this does nothing (channels remains 0). If 0 is given, channels is set to 1 but all voltages are cleared.

◆ getChannels()

int rack::engine::Port::getChannels ( )
inline

Returns the number of channels.

If the port is disconnected, it has 0 channels.

◆ isConnected()

bool rack::engine::Port::isConnected ( )
inline

Returns whether a cable is connected to the Port.

You can use this for skipping code that generates output voltages.

◆ isMonophonic()

bool rack::engine::Port::isMonophonic ( )
inline

Returns whether the cable exists and has 1 channel.

◆ isPolyphonic()

bool rack::engine::Port::isPolyphonic ( )
inline

Returns whether the cable exists and has more than 1 channel.

◆ normalize()

DEPRECATED float rack::engine::Port::normalize ( float normalVoltage)
inline

Use getNormalVoltage() instead.

Member Data Documentation

◆ voltages

float rack::engine::Port::voltages[PORT_MAX_CHANNELS] = {}

Unstable API.

Use getVoltage() and setVoltage() instead.

◆ value

float rack::engine::Port::value

DEPRECATED.

Unstable API. Use getVoltage() and setVoltage() instead.

◆ [union]

union { ... } rack::engine::Port

Voltage of the port.

◆ channels

uint8_t rack::engine::Port::channels = 0

Number of polyphonic channels.

DEPRECATED. Unstable API. Use set/getChannels() instead. May be 0 to PORT_MAX_CHANNELS. 0 channels means disconnected.

◆ active

uint8_t rack::engine::Port::active

DEPRECATED.

Unstable API. Use isConnected() instead.

◆ [union]

union { ... } rack::engine::Port

◆ plugLights

Light rack::engine::Port::plugLights[3]

For rendering plug lights on cables.

Green for positive, red for negative, and blue for polyphonic.


The documentation for this struct was generated from the following file: