![]() |
Cinder
0.9.1
|
#include <Context.h>
Inherits enable_shared_from_this< Context >.
Inherited by cinder::audio::cocoa::ContextAudioUnit.
Public Member Functions | |
virtual | ~Context () |
virtual OutputDeviceNodeRef | createOutputDeviceNode (const DeviceRef &device=Device::getDefaultOutput(), const Node::Format &format=Node::Format())=0 |
virtual InputDeviceNodeRef | createInputDeviceNode (const DeviceRef &device=Device::getDefaultInput(), const Node::Format &format=Node::Format())=0 |
template<typename NodeT > | |
std::shared_ptr< NodeT > | makeNode (NodeT *node) |
template<typename NodeT , typename... Args> | |
std::shared_ptr< NodeT > | makeNode (Args &&...args) |
virtual void | setOutput (const OutputNodeRef &output) |
virtual const OutputNodeRef & | getOutput () |
virtual void | enable () |
virtual void | disable () |
void | setEnabled (bool enable) |
bool | isEnabled () const |
virtual void | connectionsDidChange (const NodeRef &node) |
size_t | getSampleRate () |
size_t | getFramesPerBlock () |
uint64_t | getNumProcessedFrames () const |
double | getNumProcessedSeconds () |
void | initializeNode (const NodeRef &node) |
void | uninitializeNode (const NodeRef &node) |
void | initializeAllNodes () |
void | uninitializeAllNodes () |
virtual void | disconnectAllNodes () |
void | addAutoPulledNode (const NodeRef &node) |
void | removeAutoPulledNode (const NodeRef &node) |
void | schedule (double when, const NodeRef &node, bool enable, const std::function< void()> &func) |
std::mutex & | getMutex () const |
bool | isAudioThread () const |
void | preProcess () |
void | postProcess () |
std::string | printGraphToString () |
Static Public Member Functions | |
static Context * | master () |
static DeviceManager * | deviceManager () |
static void | setMaster (Context *masterContext, DeviceManager *deviceManager) |
Protected Member Functions | |
Context () | |
Manages the creation, connections, and lifecycle of audio::Node's.
The Context class manages platform specific audio processing and thread synchronization between the 'audio' (real-time) and 'user' (typically UI/main, but not limited to) threads. There is one 'master', which is the only hardware-facing Context.
All Node's are created using the Context, which is necessary for thread synchronization.
|
virtual |
|
protected |
|
static |
Returns the master Context that manages hardware I/O and real-time processing, which is platform specific. If none is available, returns null.
|
static |
Returns the platform-specific DeviceManager singleton instance, which is platform specific. If none is available, returns null.
|
static |
Allows the user to set the master Context and DeviceManager, overriding the defaults.
|
pure virtual |
Creates and returns a platform-specific OutputDeviceNode, which delivers audio to the hardware output device specified by device.
Implemented in cinder::audio::cocoa::ContextAudioUnit.
|
pure virtual |
Creates and returns a platform-specific InputDeviceNode, which captures audio from the hardware input device specified by device.
Implemented in cinder::audio::cocoa::ContextAudioUnit.
std::shared_ptr< NodeT > cinder::audio::Context::makeNode | ( | NodeT * | node | ) |
std::shared_ptr< NodeT > cinder::audio::Context::makeNode | ( | Args &&... | args | ) |
|
virtual |
Sets the new output of this Context to output. You should do this before making any connections because when Node's are initialized they use the format of the OutputNode to configure their buffers.
|
virtual |
Returns the OutputNode for the Context (currently always an OutputDeviceNode that sends audio to your speakers). This can be thought of as the 'heartbeat', it is the one who initiates the pulling and processing of all other Node's in the audio graph. note If the output has not already been set, it is the default OutputDeviceNode.
|
virtual |
Enables audio processing. Effectively the same as calling getOutput()->enable()
|
virtual |
Enables audio processing. Effectively the same as calling getOutput()->disable()
void cinder::audio::Context::setEnabled | ( | bool | enable | ) |
start / stop audio processing via boolean
bool cinder::audio::Context::isEnabled | ( | ) | const |
Returns whether or not this Context is current enabled and processing audio.
|
virtual |
Called by node when it's connections have changed, default implementation is empty.
size_t cinder::audio::Context::getSampleRate | ( | ) |
Returns the samplerate of this Context, which is governed by the current OutputNode.
size_t cinder::audio::Context::getFramesPerBlock | ( | ) |
Returns the number of frames processed in one block by this Node, which is governed by the current OutputNode.
uint64_t cinder::audio::Context::getNumProcessedFrames | ( | ) | const |
Returns the total number of frames that have been processed in the dsp loop.
double cinder::audio::Context::getNumProcessedSeconds | ( | ) |
Returns the total number of seconds that have been processed in the dsp loop.
void cinder::audio::Context::initializeNode | ( | const NodeRef & | node | ) |
Initializes node, ensuring that Node::initialze() gets called and that its internal buffers are ready for processing. Useful for initializing a heavy Node at an opportune time so as to not cause audio drop-outs or UI snags.
void cinder::audio::Context::uninitializeNode | ( | const NodeRef & | node | ) |
Un-initializes node, ensuring that Node::uninitialze() gets called.
void cinder::audio::Context::uninitializeAllNodes | ( | ) |
|
virtual |
void cinder::audio::Context::addAutoPulledNode | ( | const NodeRef & | node | ) |
Add node to the list of auto-pulled nodes, who will have their Node::pullInputs() method called after a OutputDeviceNode implementation finishes pulling its inputs.
void cinder::audio::Context::removeAutoPulledNode | ( | const NodeRef & | node | ) |
Remove node from the list of auto-pulled nodes.
void cinder::audio::Context::schedule | ( | double | when, |
const NodeRef & | node, | ||
bool | enable, | ||
const std::function< void()> & | func | ||
) |
Schedule node to be enabled or disabled with with func on the audio thread, to be called at when seconds measured against getNumProcessedSeconds(). node is owned until the scheduled event completes.
std::mutex& cinder::audio::Context::getMutex | ( | ) | const |
Returns the mutex used to synchronize the audio thread. This is also used internally by the Node class when making connections.
bool cinder::audio::Context::isAudioThread | ( | ) | const |
Returns true if the current thread is the thread used for audio processing, false otherwise.
void cinder::audio::Context::preProcess | ( | ) |
OutputNode implementations should call this before each rendering block.
void cinder::audio::Context::postProcess | ( | ) |
OutputNode implementations should call this after each rendering block.
string cinder::audio::Context::printGraphToString | ( | ) |
Returns a string representation of the Node graph for debugging purposes.