Jamoma API  0.6.0.a19
TTGraphDestination.h
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 #ifndef __TTGRAPH_DESTINATION_H__
18 #define __TTGRAPH_DESTINATION_H__
19 
20 #include "TTGraph.h"
21 #include "TTGraphOutlet.h"
22 
23 class TTGraphOutlet;
25 
26 
27 /******************************************************************************************/
28 
29 // NOTE: we don't need to keep a buffer of our own, be we just mirror the buffer of mSourceObject
30 
31 class TTGRAPH_EXPORT TTGraphDestination {
32  friend void TTGraphDestinationObserverCallback(TTGraphDestination* self, TTValue& arg);
33 
34 protected:
35 
36  TTGraphObjectBasePtr mDestinationObject; ///< the object from which we pull samples
37  TTUInt16 mInletNumber; ///< zero-based
38  TTObject mCallbackHandler;
39  TTGraphOutletPtr mOwner; ///< the owning inlet
40 
41 public:
42 
43  TTGraphDestination();
44  ~TTGraphDestination();
45 
46  /** Internal method shared/called by constructors. */
47  void create();
48 
49  TTBoolean match(TTGraphObjectBasePtr anObject, TTUInt16 anInletNumber)
50  {
51  if (anObject == mDestinationObject && anInletNumber == mInletNumber)
52  return YES;
53  else
54  return NO;
55  }
56 
57  void setOwner(TTGraphOutletPtr theOwningOutlet)
58  {
59  mOwner = theOwningOutlet;
60  }
61 
62  // Copying Functions -- critical due to use by std::vector
63 
64  TTGraphDestination(const TTGraphDestination& original) :
65  mDestinationObject(NULL),
66  mInletNumber(0),
67  mCallbackHandler(NULL),
68  mOwner(NULL)
69  {
70  create();
71  mOwner = original.mOwner;
72 
73  // NOTE: See notes below in TTGraphInlet copy constructor...
74  // NOTE: When vector of sources is resized, it is possible for an object to be created and immediately copied -- prior to a 'connect' method call
75  // NOTE: Are we ever called after connecting? If so, then we need to set up the connection...
76 
77  if (original.mDestinationObject)
78  connect(original.mDestinationObject, original.mInletNumber);
79  }
80 
81  // This one is called, for example, on the Mac when dropping a source and the vector has to be re-arranged.
82  TTGraphDestination& operator=(const TTGraphDestination& original)
83  {
84  mDestinationObject = NULL;
85  mInletNumber = 0;
86  mOwner = NULL;
87 
88  // TODO: We're probably leaking memory here, because mCallbackHandler is potentially never freed...
89  // However, if we don't NULL the mCallbackHandler
90  // then we end up with crashes when we do something like close a Max patcher after editing connections while running.
91 
92  create();
93  mOwner = original.mOwner;
94 
95  // TODO: evaluate if this is doing the correct thing:
96  // - we can copy the owner ptr for sure
97  // - we definitely can not copy the mCallbackHandler pointer
98  // - not certain about the mSourceObject
99 
100  if (original.mDestinationObject)
101  connect(original.mDestinationObject, original.mInletNumber);
102 
103  return *this;
104  }
105 
106  /** Compare two sources for equality. */
107  inline friend bool operator == (const TTGraphDestination& source1, const TTGraphDestination& source2)
108  {
109  if (source1.mDestinationObject == source2.mDestinationObject && source1.mInletNumber == source2.mInletNumber)
110  return true;
111  else
112  return false;
113  }
114 
115 
116  // Graph Methods
117 
118  void connect(TTGraphObjectBasePtr anObject, TTUInt16 fromOutletNumber);
119 
120 
121  TTErr push(const TTDictionary& aDictionary);
122 
123 };
124 
125 typedef TTGraphDestination* TTGraphDestinationPtr;
126 typedef std::vector<TTGraphDestination> TTGraphDestinationVector;
127 typedef TTGraphDestinationVector::iterator TTGraphDestinationIter;
128 
129 
130 #endif // __TTGRAPH_DESTINATION_H__
The TTGraphObjectBase wraps a TTDSP object such that it is possible to build a dynamic graph of audio...
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
std::uint16_t TTUInt16
16 bit unsigned integer
Definition: TTBase.h:176
Jamoma Asynchronous Object Graph Layer.
Create and use Jamoma object instances.
Definition: TTObject.h:29
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
Jamoma Asynchronous Object Graph Layer.
bool TTFOUNDATION_EXPORT operator==(const TTObject &anObject, const TTObject &anotherObject)
Compare two objects for equality.
Definition: TTObject.cpp:167
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
This object represents a single 'outlet' from a TTGraphObjectBase.
Definition: TTGraphOutlet.h:30
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34