Jamoma API  0.6.0.a19
TTGraphSource.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup graphLibrary
4  *
5  * @brief Jamoma Asynchronous Object Graph Layer
6  *
7  * @details Creates a wrapper for TTObjectBases that can be used to build a control graph for asynchronous message passing
8  *
9  * @authors Timothy Place
10  *
11  * @copyright Copyright © 2010 by Timothy Place @n
12  * This code is licensed under the terms of the "New BSD License" @n
13  * http://creativecommons.org/licenses/BSD/
14  */
15 
16 
17 #include "TTGraphSource.h"
18 #include "TTGraphInlet.h"
19 #include "TTCallback.h"
20 #include "TTGraphObjectBase.h"
21 
22 // C Callback from any Audio Graph Source objects we are observing
23 void TTGraphSourceObserverCallback(TTGraphSourcePtr self, TTValue& arg)
24 {
25  // at the moment we only receive one callback, which is for the object being deleted
26  self->mSourceObject = NULL;
27  self->mOutletNumber = 0;
28  self->mOwner->drop(*self);
29 }
30 
31 
32 // Implementation for Audio Graph Source class
33 
34 TTGraphSource::TTGraphSource() :
35  mSourceObject(NULL),
36  mOutletNumber(0),
37  mCallbackHandler("callback"),
38  mOwner(NULL)
39 {
40  create();
41 }
42 
43 
44 TTGraphSource::~TTGraphSource()
45 {
46  if (mSourceObject)
47  mSourceObject->unregisterObserverForNotifications(mCallbackHandler);
48 
49  mSourceObject = NULL;
50  mOutletNumber = 0;
51 }
52 
53 
54 void TTGraphSource::create()
55 {
56  mCallbackHandler.set(TT("owner"), TT("TTGraphSource"));
57  mCallbackHandler.set(TT("function"), TTPtr(&TTGraphSourceObserverCallback));
58  mCallbackHandler.set(TT("baton"), TTPtr(this));
59 }
60 
61 
62 void TTGraphSource::prepareDescription()
63 {
64  mSourceObject->prepareDescription();
65 }
66 
67 
68 void TTGraphSource::getDescription(TTGraphDescription& desc)
69 {
70  mSourceObject->getDescription(desc);
71 }
72 
73 
74 void TTGraphSource::connect(TTGraphObjectBasePtr anObject, TTUInt16 fromOutletNumber)
75 {
76  mSourceObject = anObject;
77  mOutletNumber = fromOutletNumber;
78 
79  // dynamically add a message to the callback object so that it can handle the 'objectFreeing' notification
80  mCallbackHandler.instance()->registerMessage(TT("objectFreeing"), (TTMethod)&TTCallback::notify, kTTMessagePassValue);
81 
82  // tell the source that is passed in that we want to watch it
83  mSourceObject->registerObserverForNotifications(mCallbackHandler);
84 }
The TTGraphObjectBase wraps a TTDSP object such that it is possible to build a dynamic graph of audio...
std::uint16_t TTUInt16
16 bit unsigned integer
Definition: TTBase.h:176
Jamoma Asynchronous Object Graph Layer.
TTErr(TTObjectBase::* TTMethod)(const TTSymbol methodName, const TTValue &anInputValue, TTValue &anOutputValue)
A type that can be used to store a pointer to a message for an object.
Definition: TTObjectBase.h:46
Jamoma Asynchronous Object Graph Layer.
TTErr registerMessage(const TTSymbol name, TTMethod method)
Register a message with this object.
#define TT
This macro is defined as a shortcut for doing a lookup in the symbol table.
Definition: TTSymbol.h:155
void * TTPtr
A generic pointer.
Definition: TTBase.h:248
This class is used to create a backward communication channel to notify a client that something chang...
Jamoma Asynchronous Object Graph Layer.
Set this flag if the method you are binding to this message is prototyped with a single TTValue& argu...
Definition: TTObjectBase.h:87
TTErr notify(const TTValue &anInputValue, TTValue &anUnusedOutputValue)
Message called because we are registered as an observer to some other object, and then calls our exte...
Definition: TTCallback.cpp:69
This object represents a single 'outlet' from a TTGraphObjectBase.
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34