Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
cinder::audio::Context Class Referenceabstract

Manages the creation, connections, and lifecycle of audio::Node's. More...

#include <Context.h>

Inheritance diagram for cinder::audio::Context:
[legend]

Public Member Functions

virtual ~Context ()
 
virtual OutputDeviceNodeRef createOutputDeviceNode (const DeviceRef &device=Device::getDefaultOutput(), const Node::Format &format=Node::Format())=0
 Creates and returns a platform-specific OutputDeviceNode, which delivers audio to the hardware output device specified by device. More...
 
virtual InputDeviceNodeRef createInputDeviceNode (const DeviceRef &device=Device::getDefaultInput(), const Node::Format &format=Node::Format())=0
 Creates and returns a platform-specific InputDeviceNode, which captures audio from the hardware input device specified by device. More...
 
template<typename NodeT >
std::shared_ptr< NodeT > makeNode (NodeT *node)
 Interface for creating new Node's of type NodeT, which are thereafter owned by this Context. All Node's must be created using this method in order for them to correctly have a parent Context. More...
 
virtual void setOutput (const OutputNodeRef &output)
 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. More...
 
virtual const OutputNodeRefgetOutput ()
 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. More...
 
std::mutex & getMutex () const
 Returns the mutex used to synchronize the audio thread. This is also used internally by the Node class when making connections. More...
 
virtual void enable ()
 Enables audio processing. Effectively the same as calling getOutput()->enable() More...
 
virtual void disable ()
 Enables audio processing. Effectively the same as calling getOutput()->disable() More...
 
void setEnabled (bool enable=true)
 start / stop audio processing via boolean More...
 
bool isEnabled () const
 Returns whether or not this Context is current enabled and processing audio. More...
 
virtual void connectionsDidChange (const NodeRef &node)
 Called by node when it's connections have changed, default implementation is empty. More...
 
size_t getSampleRate ()
 Returns the samplerate of this Context, which is governed by the current OutputNode. More...
 
size_t getFramesPerBlock ()
 Returns the number of frames processed in one block by this Node, which is governed by the current OutputNode. More...
 
uint64_t getNumProcessedFrames () const
 Returns the total number of frames that have been processed in the dsp loop. More...
 
double getNumProcessedSeconds ()
 Returns the total number of seconds that have been processed in the dsp loop. More...
 
void 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. More...
 
void uninitializeNode (const NodeRef &node)
 Un-initializes node, ensuring that Node::uninitialze() gets called. More...
 
void initializeAllNodes ()
 Initialize all Node's related by this Context. More...
 
void uninitializeAllNodes ()
 Uninitialize all Node's related by this Context. More...
 
virtual void disconnectAllNodes ()
 Disconnect all Node's related by this Context. More...
 
void addAutoPulledNode (const NodeRef &node)
 
void removeAutoPulledNode (const NodeRef &node)
 
void postProcess ()
 OutputNode implmenentations should call this at the end of each rendering block. More...
 
std::string printGraphToString ()
 Returns a string representation of the Node graph for debugging purposes. More...
 

Static Public Member Functions

static Contextmaster ()
 Returns the master Context that manages hardware I/O and real-time processing, which is platform specific. If none is available, returns null. More...
 
static DeviceManagerdeviceManager ()
 Returns the platform-specific DeviceManager singleton instance, which is platform specific. If none is available, returns null. More...
 
static void setMaster (Context *masterContext, DeviceManager *deviceManager)
 Allows the user to set the master Context and DeviceManager, overriding the defaults. More...
 

Protected Member Functions

 Context ()
 

Detailed Description

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.

Constructor & Destructor Documentation

cinder::audio::Context::~Context ( )
virtual
cinder::audio::Context::Context ( )
protected

Member Function Documentation

Context * cinder::audio::Context::master ( )
static

Returns the master Context that manages hardware I/O and real-time processing, which is platform specific. If none is available, returns null.

DeviceManager * cinder::audio::Context::deviceManager ( )
static

Returns the platform-specific DeviceManager singleton instance, which is platform specific. If none is available, returns null.

void cinder::audio::Context::setMaster ( Context masterContext,
DeviceManager deviceManager 
)
static

Allows the user to set the master Context and DeviceManager, overriding the defaults.

virtual OutputDeviceNodeRef cinder::audio::Context::createOutputDeviceNode ( const DeviceRef device = Device::getDefaultOutput(),
const Node::Format format = Node::Format() 
)
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.

virtual InputDeviceNodeRef cinder::audio::Context::createInputDeviceNode ( const DeviceRef device = Device::getDefaultInput(),
const Node::Format format = Node::Format() 
)
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.

template<typename NodeT >
std::shared_ptr< NodeT > cinder::audio::Context::makeNode ( NodeT *  node)

Interface for creating new Node's of type NodeT, which are thereafter owned by this Context. All Node's must be created using this method in order for them to correctly have a parent Context.

void cinder::audio::Context::setOutput ( const OutputNodeRef output)
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.

const OutputNodeRef & cinder::audio::Context::getOutput ( )
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.

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.

void cinder::audio::Context::enable ( )
virtual

Enables audio processing. Effectively the same as calling getOutput()->enable()

void cinder::audio::Context::disable ( )
virtual

Enables audio processing. Effectively the same as calling getOutput()->disable()

void cinder::audio::Context::setEnabled ( bool  enable = true)

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 void cinder::audio::Context::connectionsDidChange ( const NodeRef node)
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::initializeAllNodes ( )

Initialize all Node's related by this Context.

void cinder::audio::Context::uninitializeAllNodes ( )

Uninitialize all Node's related by this Context.

void cinder::audio::Context::disconnectAllNodes ( )
virtual

Disconnect all Node's related by this Context.

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.

Note
Callers on the non-audio thread must synchronize with getMutex().
void cinder::audio::Context::removeAutoPulledNode ( const NodeRef node)

Remove node from the list of auto-pulled nodes.

Note
Callers on the non-audio thread must synchronize with getMutex().
void cinder::audio::Context::postProcess ( )

OutputNode implmenentations should call this at the end of each rendering block.

string cinder::audio::Context::printGraphToString ( )

Returns a string representation of the Node graph for debugging purposes.


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