C++ API Reference RNBO: RNBO::CoreObject Class Reference

RNBO: RNBO::CoreObject Class Reference

Inheritance diagram for RNBO::CoreObject:
core_object RNBO::BaseInterface RNBO::ParameterInterface

Public Member Functions

 CoreObject (EventHandler *handler=nullptr)
 Construct a new CoreObject. More...
 
 CoreObject (UniquePtr< PatcherInterface > patcher, EventHandler *handler=nullptr)
 Construct a new CoreObject. More...
 
 CoreObject (const CoreObject &other)=delete
 
CoreObjectoperator= (const CoreObject &other)=delete
 
 CoreObject (CoreObject &&other)=default
 
CoreObjectoperator= (CoreObject &&other)=default
 
ParameterIndex getNumParameters () const override
 Get the number of visible parameters. More...
 
ConstCharPointer getParameterName (ParameterIndex index) const override
 Get the parameter name (may not be unique) More...
 
ConstCharPointer getParameterId (ParameterIndex index) const override
 Get the unique ID of a parameter. More...
 
void getParameterInfo (ParameterIndex index, ParameterInfo *info) const override
 Get detailed information about a parameter. More...
 
ParameterValue getParameterValue (ParameterIndex index) override
 
void setParameterValue (ParameterIndex index, ParameterValue value, MillisecondTime time=RNBOTimeNow) override
 Set a parameter's value. More...
 
void setParameterValueNormalized (ParameterIndex index, ParameterValue normalizedValue, MillisecondTime time=RNBOTimeNow) override
 Set a parameter's normalized [0..1] value. More...
 
ParameterValue convertToNormalizedParameterValue (ParameterIndex index, ParameterValue value) const override
 Convert a parameter value from its real value to a normalized representation [0..1]. More...
 
ParameterValue convertFromNormalizedParameterValue (ParameterIndex index, ParameterValue normalizedValue) const override
 Convert a parameter value from a normalized representation [0..1] to its real value. More...
 
ParameterValue constrainParameterValue (ParameterIndex index, ParameterValue value) const override
 Apply and get the constrained parameter value. More...
 
ParameterEventInterfaceUniquePtr createParameterInterface (ParameterEventInterface::Type type, EventHandler *handler)
 Create a lightweight interface for sending and receiving parameter values. More...
 
void scheduleEvent (EventVariant event)
 Schedule an event. More...
 
void sendMessage (MessageTag tag, number payload, MessageTag objectId=0, MillisecondTime eventTime=RNBOTimeNow)
 Send a number to named patcher inports. More...
 
void sendMessage (MessageTag tag, UniqueListPtr payload, MessageTag objectId=0, MillisecondTime eventTime=RNBOTimeNow)
 Send a list message to named patcher inports. More...
 
void sendMessage (MessageTag tag, MessageTag objectId=0, MillisecondTime eventTime=RNBOTimeNow)
 Send a bang to named patcher inports. More...
 
MessageTagInfo resolveTag (MessageTag tag) const
 Look up the name associated with a MessageTag. More...
 
MessageIndex getNumMessages () const
 
const MessageInfogetMessageInfo (MessageIndex index) const
 Get information about a named inport or outport. More...
 
Index getNumMidiInputPorts () const override
 
Index getNumMidiOutputPorts () const override
 
ExternalDataIndex getNumExternalDataRefs () const
 Get the number of external memory references. More...
 
ExternalDataId getExternalDataId (ExternalDataIndex index) const
 Get the name of an external data reference. More...
 
const ExternalDataInfo getExternalDataInfo (ExternalDataIndex index) const
 Get more information about an external data reference (like file type and filename) More...
 
void setExternalData (ExternalDataId memoryId, char *data, size_t sizeInBytes, DataType type, ReleaseCallback callback=nullptr)
 Set the contents of an external data reference (thread-safe) More...
 
void releaseExternalData (ExternalDataId memoryId)
 Release a block of memory (thread-safe) More...
 
void setExternalDataHandler (ExternalDataHandler *handler)
 Set handlers for an external data reference which will be called before and after processing. More...
 
number getSampleRate () const
 
Index getSamplesPerBlock () const
 
bool prepareToProcess (number sampleRate, Index maxBlockSize, bool force=false)
 Set the sample rate and vector size before doing any processing. More...
 
MillisecondTime getCurrentTime ()
 Get the current time (in ms) More...
 
void setCurrentTime (MillisecondTime time)
 Set the current time (in ms) More...
 
void process (const SampleValue *const *audioInputs, Index numInputs, SampleValue *const *audioOutputs, Index numOutputs, Index sampleFrames, const MidiEventList *midiInput=nullptr, MidiEventList *midiOutput=nullptr)
 Process non-interleaved SampleValue* audio buffers with optional MIDI I/O. More...
 
template<typename I , typename O >
void process (I audioInputs, Index numInputs, O audioOutputs, Index numOutputs, Index sampleFrames, const MidiEventList *midiInput=nullptr, MidiEventList *midiOutput=nullptr)
 Convert and process a generic audio buffer with optional MIDI I/O. More...
 
Index getNumInputChannels () const override
 
Index getNumOutputChannels () const override
 
ParameterIndex getNumSignalInParameters () const
 Get the number of signal input parameters. More...
 
ParameterIndex getNumSignalOutParameters () const
 Get the number of signal output parameters. More...
 
bool setPatcher ()
 Set or replace the engine's patcher with a default patcher. More...
 
bool setPatcher (UniquePtr< PatcherInterface > patcher)
 Replace the engine's patcher with a new instance. More...
 
void setPreset (UniquePresetPtr preset)
 Schedule a preset change. More...
 
void setPresetSync (UniquePresetPtr preset)
 Set a preset immediately. More...
 
void getPreset (PresetCallback callback)
 Get a preset (asynchronous) More...
 
ConstPresetPtr getPresetSync ()
 Get a preset (synchronous) More...
 
void setPatcherChangedHandler (PatcherChangedHandler *handler)
 Set the handler for patcher change notifications. More...
 
ParameterIndex getParameterIndexForID (ConstCharPointer paramid) const
 Get the parameter index from a parameter ID. More...
 
Index getProbingChannels (MessageTag outletId) const override
 Get the number of probing channels associated with an outlet. More...
 
- Public Member Functions inherited from RNBO::BaseInterface
virtual void initialize ()
 
- Public Member Functions inherited from RNBO::ParameterInterface
virtual ParameterValue getParameterNormalized (ParameterIndex index)
 Get a parameter's normalized [0..1] value. More...
 

Protected Member Functions

void initializeEngine (EventHandler *handler)
 

Protected Attributes

UniquePtr< Engine > _engine
 

Constructor & Destructor Documentation

◆ CoreObject() [1/2]

RNBO::CoreObject::CoreObject ( EventHandler handler = nullptr)

Construct a new CoreObject.

The CoreObject is the main API for using exported C++ code in external projects. It holds all state and data necessary for using RNBO.

Parameters
handleran EventHandler for events generated by the CoreObject

◆ CoreObject() [2/2]

RNBO::CoreObject::CoreObject ( UniquePtr< PatcherInterface patcher,
EventHandler handler = nullptr 
)

Construct a new CoreObject.

The CoreObject is the main API for using exported C++ code in external projects. It holds all state and data necessary for using RNBO.

Parameters
patchera PatcherInterface to associate with the CoreObject
handleran EventHandler for events generated by the CoreObject

Member Function Documentation

◆ constrainParameterValue()

ParameterValue RNBO::CoreObject::constrainParameterValue ( ParameterIndex  index,
ParameterValue  value 
) const
overridevirtual

Apply and get the constrained parameter value.

Parameter constraints include a minimum/maximum value and step constraints

Parameters
indexthe parameter index
valuean unconstrained parameter value
Returns
the constrained parameter value

Reimplemented from RNBO::ParameterInterface.

◆ convertFromNormalizedParameterValue()

ParameterValue RNBO::CoreObject::convertFromNormalizedParameterValue ( ParameterIndex  index,
ParameterValue  normalizedValue 
) const
overridevirtual

Convert a parameter value from a normalized representation [0..1] to its real value.

Parameters
indexthe parameter index
normalizedValuethe normalized value
Returns
the real value of the parameter

Implements RNBO::ParameterInterface.

◆ convertToNormalizedParameterValue()

ParameterValue RNBO::CoreObject::convertToNormalizedParameterValue ( ParameterIndex  index,
ParameterValue  value 
) const
overridevirtual

Convert a parameter value from its real value to a normalized representation [0..1].

Parameters
indexthe parameter index
valuethe real value of the parameter
Returns
a normalized ParameterValue

Implements RNBO::ParameterInterface.

◆ createParameterInterface()

ParameterEventInterfaceUniquePtr RNBO::CoreObject::createParameterInterface ( ParameterEventInterface::Type  type,
EventHandler handler 
)

Create a lightweight interface for sending and receiving parameter values.

The CoreObject, by default, holds a parameter interface for sending and receiving events with the thread-safe MultiProducer interface type.

See also
RNBO::ParameterEventInterface
Parameters
typethe type of parameter event interface to create
handleran event handler
Returns
a ParameterEventInterfaceUniquePtr

NOTE: if you create a thread safe async parameter interface you will NOT get any events and values out unless you use a handler which correctly drains these events

◆ getCurrentTime()

MillisecondTime RNBO::CoreObject::getCurrentTime ( )

Get the current time (in ms)

This method is only accurate when called from the audio/processing thread

Returns
the current time in milliseconds

◆ getExternalDataId()

ExternalDataId RNBO::CoreObject::getExternalDataId ( ExternalDataIndex  index) const

Get the name of an external data reference.

See also
RNBO::ExternalDataRef
Parameters
indexthe external data reference index
Returns
a C-style string containing the name of the external data

◆ getExternalDataInfo()

const ExternalDataInfo RNBO::CoreObject::getExternalDataInfo ( ExternalDataIndex  index) const

Get more information about an external data reference (like file type and filename)

See also
RNBO::ExternalDataRef
Parameters
indexthe index of the external data
Returns
a struct containing information about the external data

◆ getMessageInfo()

const MessageInfo& RNBO::CoreObject::getMessageInfo ( MessageIndex  index) const

Get information about a named inport or outport.

Parameters
indexthe MessageIndex
Returns
a reference to the MessageInfo

◆ getNumExternalDataRefs()

ExternalDataIndex RNBO::CoreObject::getNumExternalDataRefs ( ) const

Get the number of external memory references.

See also
RNBO::ExternalDataRef
Returns
the number of external data references

◆ getNumInputChannels()

Index RNBO::CoreObject::getNumInputChannels ( ) const
overridevirtual
Returns
the number of audio input channels processed by the current patcher

Implements RNBO::BaseInterface.

◆ getNumMessages()

MessageIndex RNBO::CoreObject::getNumMessages ( ) const
Returns
the count of named inports and outports

◆ getNumMidiInputPorts()

Index RNBO::CoreObject::getNumMidiInputPorts ( ) const
overridevirtual
Returns
the number of MIDI inputs

Implements RNBO::BaseInterface.

◆ getNumMidiOutputPorts()

Index RNBO::CoreObject::getNumMidiOutputPorts ( ) const
overridevirtual
Returns
the number of MIDI outputs

Implements RNBO::BaseInterface.

◆ getNumOutputChannels()

Index RNBO::CoreObject::getNumOutputChannels ( ) const
overridevirtual
Returns
the number of audio output channels processed by the current patcher

Implements RNBO::BaseInterface.

◆ getNumParameters()

ParameterIndex RNBO::CoreObject::getNumParameters ( ) const
overridevirtual

Get the number of visible parameters.

Note that not all parameters are visible (for example, params in gen~ are not automatically exposed as RNBO parameters). The count of visible parameters is usually the same as the number of param/param~ objects in a RNBO~ patch.

Returns
the number of visible parameters

Implements RNBO::ParameterInterface.

◆ getNumSignalInParameters()

ParameterIndex RNBO::CoreObject::getNumSignalInParameters ( ) const

Get the number of signal input parameters.

Signal input parameters can be handed into the processing function as additional audio inputs.

Returns
the number of signal input parameters

◆ getNumSignalOutParameters()

ParameterIndex RNBO::CoreObject::getNumSignalOutParameters ( ) const

Get the number of signal output parameters.

Signal input parameters will be handed out of the processing function as additional audio outputs.

Returns
the number of signal output parameters

◆ getParameterId()

ConstCharPointer RNBO::CoreObject::getParameterId ( ParameterIndex  index) const
overridevirtual

Get the unique ID of a parameter.

The unique ID of a parameter can be the same as the parameter ID. If a parameter is nested in a subpatcher, a prefix is added to the parameter name in order to disambiguate. Examples of parameter IDs:

  • "my_toplevel_param"
  • "p_obj-2/my_nested_param"
  • "poly/p_obj-18/my_nested_poly_param"
Parameters
indexthe parameter index
Returns
a C-style string containing the parameter ID

Implements RNBO::ParameterInterface.

◆ getParameterIndexForID()

ParameterIndex RNBO::CoreObject::getParameterIndexForID ( ConstCharPointer  paramid) const

Get the parameter index from a parameter ID.

Parameters
paramidthe parameter ID
Returns
the parameter index

◆ getParameterInfo()

void RNBO::CoreObject::getParameterInfo ( ParameterIndex  index,
ParameterInfo info 
) const
overridevirtual

Get detailed information about a parameter.

Parameters
indexthe parameter index
infoa pointer to a ParameterInfo object to fill

Implements RNBO::ParameterInterface.

◆ getParameterName()

ConstCharPointer RNBO::CoreObject::getParameterName ( ParameterIndex  index) const
overridevirtual

Get the parameter name (may not be unique)

Parameters
indexthe parameter index
Returns
a C-style string containing the parameter name

Implements RNBO::ParameterInterface.

◆ getParameterValue()

ParameterValue RNBO::CoreObject::getParameterValue ( ParameterIndex  index)
overridevirtual
Parameters
indexthe parameter index
Returns
the value of the parameter

Implements RNBO::ParameterInterface.

◆ getPreset()

void RNBO::CoreObject::getPreset ( PresetCallback  callback)

Get a preset (asynchronous)

The callback is called in the audio thread, so it is inadvisable to do any potentially blocking operations like opening files or allocating/freeing memory.

Parameters
callbacka PresetCallback to execute when the preset is available

◆ getPresetSync()

ConstPresetPtr RNBO::CoreObject::getPresetSync ( )

Get a preset (synchronous)

Pause event and audio processing to get a preset immediately.

Returns
the preset

◆ getProbingChannels()

Index RNBO::CoreObject::getProbingChannels ( MessageTag  outletId) const
override

Get the number of probing channels associated with an outlet.

Call with outletId = 0 or TAG("") to get the maximum possible number of probing channels

Parameters
outletIdthe ID of the outlet
Returns
the number of probing channels

◆ getSampleRate()

number RNBO::CoreObject::getSampleRate ( ) const
Returns
the current sample rate

◆ getSamplesPerBlock()

Index RNBO::CoreObject::getSamplesPerBlock ( ) const
Returns
the current vector size

◆ prepareToProcess()

bool RNBO::CoreObject::prepareToProcess ( number  sampleRate,
Index  maxBlockSize,
bool  force = false 
)

Set the sample rate and vector size before doing any processing.

This method is almost a no-op when there is no change in sample rate or vector size and force is false (the default) so it is suitable to call before each processing call. Note that an increase of maxBlockSize will allocate memory, however.

If this method returns false, do not call process() afterwards. Instead, call prepareToProcess() again.

Parameters
sampleRatethe sample rate to use
maxBlockSizethe maximum vector size; actual processing could be made in smaller chunks
forceif true, ensures the dspsetup methods of patcher objects are called
Returns
false if called during setPatcher, true otherwise

◆ process() [1/2]

void RNBO::CoreObject::process ( const SampleValue *const *  audioInputs,
Index  numInputs,
SampleValue *const *  audioOutputs,
Index  numOutputs,
Index  sampleFrames,
const MidiEventList *  midiInput = nullptr,
MidiEventList *  midiOutput = nullptr 
)

Process non-interleaved SampleValue* audio buffers with optional MIDI I/O.

Parameters
audioInputsnon-interleaved audio inputs (e.g. a 2D array: SampleValues[numInputs][sampleFrames])
numInputsthe number of audio input buffers
audioOutputsnon-interleaved audio outputs (e.g. a 2D array: SampleValues[numOutputs][sampleFrames])
numOutputsthe number of audio output buffers
sampleFramesthe number of samples in a single input or output
midiInputan optional pointer to a MidiEventList of input events associated with this audio vector
midiOutputan optional pointer to a MidiEventList which can receive MIDI output generated during the audio vector

◆ process() [2/2]

template<typename I , typename O >
void RNBO::CoreObject::process ( audioInputs,
Index  numInputs,
audioOutputs,
Index  numOutputs,
Index  sampleFrames,
const MidiEventList *  midiInput = nullptr,
MidiEventList *  midiOutput = nullptr 
)
inline

Convert and process a generic audio buffer with optional MIDI I/O.

In situations where non-interleaved SampleValue* audio buffers are not available (e.g. the audio buffers are not sizeof(SampleValue) or the buffers are interleaved), use this method to convert and process the audio buffers.

Template Parameters
Ithe type of input audio buffer
Othe type of output audio buffer
Parameters
audioInputsaudio input buffers
numInputsthe number of audio input buffers
audioOutputsaudio output buffers
numOutputsthe number of audio output buffers
sampleFramesthe number of samples in a single input or output
midiInputan optional pointer to a MidiEventList of input events associated with this audio vector
midiOutputan optional pointer to a

◆ releaseExternalData()

void RNBO::CoreObject::releaseExternalData ( ExternalDataId  memoryId)

Release a block of memory (thread-safe)

Call releaseExternalData() on an external data reference to tell RNBO to stop using a block of memory in a thread-safe way. If a ReleaseCallback is associated with the data reference, it will be called when the data is no longer in use.

Parameters
memoryIdthe name of the data reference

◆ resolveTag()

MessageTagInfo RNBO::CoreObject::resolveTag ( MessageTag  tag) const

Look up the name associated with a MessageTag.

Parameters
taga MessageTag
Returns
the name associated with the tag as a C-style string

◆ scheduleEvent()

void RNBO::CoreObject::scheduleEvent ( EventVariant  event)

Schedule an event.

There are a number of event variants that can be scheduled (like MIDI events, tempo events, and parameter events). For all of the variants available, see the related documentation.

See also
RNBO::EventVariant
Parameters
eventan event to schedule

◆ sendMessage() [1/3]

void RNBO::CoreObject::sendMessage ( MessageTag  tag,
MessageTag  objectId = 0,
MillisecondTime  eventTime = RNBOTimeNow 
)

Send a bang to named patcher inports.

Parameters
tagthe inport name MessageTag created from a char* or const char* via the TAG() function
objectIdoptionally specify a receiving object (mostly used internally)
eventTimetime the message should be scheduled for (use RNBOTimeNow or 0 for "as soon as possible")

For example:

sendMessage(TAG("myinport"), TAG(""), RNBOTimeNow);

◆ sendMessage() [2/3]

void RNBO::CoreObject::sendMessage ( MessageTag  tag,
number  payload,
MessageTag  objectId = 0,
MillisecondTime  eventTime = RNBOTimeNow 
)

Send a number to named patcher inports.

Parameters
tagthe inport name MessageTag created from a char* or const char* via the TAG() function
payloada number
objectIdoptionally specify a receiving object (mostly used internally)
eventTimetime the message should be scheduled for (use RNBOTimeNow or 0 for "as soon as possible")

For example:

sendMessage(TAG("myinport"), 74, TAG(""), RNBOTimeNow);

◆ sendMessage() [3/3]

void RNBO::CoreObject::sendMessage ( MessageTag  tag,
UniqueListPtr  payload,
MessageTag  objectId = 0,
MillisecondTime  eventTime = RNBOTimeNow 
)

Send a list message to named patcher inports.

Parameters
tagthe inport name MessageTag created from a char* or const char* via the TAG() function
payloada UniqueListPtr of numbers
objectIdoptionally specify a receiving object (mostly used internally)
eventTimetime the message should be scheduled for (use RNBOTimeNow or 0 for "as soon as possible")

For example:

UniqueListPtr payload = make_unique<list>();
payload.push(0.1);
payload.push(0.2);
sendMessage(TAG("myinport"), payload, TAG(""), RNBOTimeNow);

◆ setCurrentTime()

void RNBO::CoreObject::setCurrentTime ( MillisecondTime  time)

Set the current time (in ms)

This can be used to tightly sync RNBO and host time. Jumping, rather than forwarding time according to the processed samples, may result in unpredictable results.

Do not call this method outside of the audio/processing thread.

Parameters
timethe new time in milliseconds

◆ setExternalData()

void RNBO::CoreObject::setExternalData ( ExternalDataId  memoryId,
char *  data,
size_t  sizeInBytes,
DataType  type,
ReleaseCallback  callback = nullptr 
)

Set the contents of an external data reference (thread-safe)

Note: From the moment setExternalData() is called, memory can and will be used at any given time by RNBO, so do not reallocate or change the size unless the memory has been released via releaseExternalData().

Parameters
memoryIdthe name of the data reference
databyte array of data
sizeInBytessize of the data array in bytes
typebuffer type:
callbacksynchronous callback to be called when the engine releases the memory after releaseExternalData()
SampleValue buffer[1024];
Float32AudioBuffer bufferType(1, 44100); // 1 channel, 44100 Hz samplerate
setExternalData("myBuffer", (char *)buffer, 1024 * sizeof(SampleValue), bufferType);

◆ setExternalDataHandler()

void RNBO::CoreObject::setExternalDataHandler ( ExternalDataHandler handler)

Set handlers for an external data reference which will be called before and after processing.

Some clients need to lock and unlock the memory at the beginning and end of processing, and this can be done by creating an ExternalDataHandler and implementing its processBeginCallback() and processEndCallback() methods. These will be called synchronously in the audio thread before and after processing, respectively.

See also
RNBO::ExternalDataHandler
Parameters
handlerthe ExternalDataHandler to associate with the data reference

◆ setParameterValue()

void RNBO::CoreObject::setParameterValue ( ParameterIndex  index,
ParameterValue  value,
MillisecondTime  time = RNBOTimeNow 
)
overridevirtual

Set a parameter's value.

Parameters
indexthe parameter index
valueparameter value to set
timewhen the parameter change should happen (default is RNBOTimeNow)

Implements RNBO::ParameterInterface.

◆ setParameterValueNormalized()

void RNBO::CoreObject::setParameterValueNormalized ( ParameterIndex  index,
ParameterValue  normalizedValue,
MillisecondTime  time = RNBOTimeNow 
)
overridevirtual

Set a parameter's normalized [0..1] value.

Parameters
indexthe parameter index
normalizedValueparameter normalized value to set
timewhen the parameter change should happen (default is RNBOTimeNow)

Reimplemented from RNBO::ParameterInterface.

◆ setPatcher() [1/2]

bool RNBO::CoreObject::setPatcher ( )

Set or replace the engine's patcher with a default patcher.

Note: this blocks audio and event processing.

Returns
true on success, false on failure

◆ setPatcher() [2/2]

bool RNBO::CoreObject::setPatcher ( UniquePtr< PatcherInterface patcher)

Replace the engine's patcher with a new instance.

Note: this blocks audio and event processing.

Parameters
patcherthe new patcher instance
Returns
true on success, false on failure

◆ setPatcherChangedHandler()

void RNBO::CoreObject::setPatcherChangedHandler ( PatcherChangedHandler handler)

Set the handler for patcher change notifications.

The handler is called synchronously at the end of the setPatcher call and before any audio processing happens. As such, be aware of taking too much time in the handler.

Parameters
handlera pointer to a PatcherChangedHandler

◆ setPreset()

void RNBO::CoreObject::setPreset ( UniquePresetPtr  preset)

Schedule a preset change.

Parameters
presetthe new preset

◆ setPresetSync()

void RNBO::CoreObject::setPresetSync ( UniquePresetPtr  preset)

Set a preset immediately.

Note: this blocks audio and event processing.

Parameters
presetthe new preset

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