Jamoma API  0.6.0.a19
TTGraphDestination.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 "TTGraphOutlet.h"
18 #include "TTCallback.h"
19 #include "TTGraphDestination.h"
20 #include "TTGraphObjectBase.h"
21 
22 
23 // C Callback from any Graph Destination objects we are observing
24 void TTGraphDestinationObserverCallback(TTGraphDestinationPtr self, TTValue& arg)
25 {
26  // at the moment we only receive one callback, which is for the object being deleted
27  self->mDestinationObject = NULL;
28  self->mInletNumber = 0;
29  self->mOwner->drop(*self);
30 }
31 
32 
33 // Implementation for Graph Destination class
34 
35 TTGraphDestination::TTGraphDestination() :
36  mDestinationObject(NULL),
37  mInletNumber(0),
38  mCallbackHandler("callback"),
39  mOwner(NULL)
40 {
41  create();
42 }
43 
44 
45 TTGraphDestination::~TTGraphDestination()
46 {
47  if (mDestinationObject)
48  mDestinationObject->unregisterObserverForNotifications(mCallbackHandler);
49 
50  mDestinationObject = NULL;
51  mInletNumber = 0;
52 }
53 
54 
55 void TTGraphDestination::create()
56 {
57  mCallbackHandler.set(TT("owner"), TT("TTGraphDestination"));
58  mCallbackHandler.set(TT("function"), TTPtr(&TTGraphDestinationObserverCallback));
59  mCallbackHandler.set(TT("baton"), TTPtr(this));
60 }
61 
62 
63 void TTGraphDestination::connect(TTGraphObjectBasePtr anObject, TTUInt16 fromOutletNumber)
64 {
65  mDestinationObject = anObject;
66  mInletNumber = fromOutletNumber;
67 
68  // dynamically add a message to the callback object so that it can handle the 'objectFreeing' notification
69  mCallbackHandler.instance()->registerMessage(TT("objectFreeing"), (TTMethod)&TTCallback::notify, kTTMessagePassValue);
70 
71  // tell the source that is passed in that we want to watch it
72  mDestinationObject->registerObserverForNotifications(mCallbackHandler);
73 }
74 
75 
76 /*************************************************************/
77 
78 
79 TTErr TTGraphDestination::push(const TTDictionary& aDictionary)
80 {
81  // TODO: We need to append the inlet number into the dictionary before sending it
82  return mDestinationObject->push(aDictionary);
83 }
84 
85 
86 
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
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.
A type that represents the key as a C-String and the value as a pointer to the matching TTSymbol obje...
Definition: TTDictionary.h:47
#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
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
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
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
Jamoma Asynchronous Object Graph Layer.