Jamoma API  0.6.0.a19
TTGraphSource.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_SOURCE_H__
18 #define __TTGRAPH_SOURCE_H__
19 
20 #include "TTGraph.h"
21 //#include "TTGraphObjectBase.h"
22 
23 class TTGraphInlet;
25 class TTGraphDescription;
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 TTGraphSource {
32  friend void TTGraphSourceObserverCallback(TTGraphSource* self, TTValue& arg);
33 
34 protected:
35 
36  TTGraphObjectBasePtr mSourceObject; ///< The object from which we pull samples
37  TTUInt16 mOutletNumber; ///< Number of the outlet (zero-based)
38  TTObject mCallbackHandler;
39  TTGraphInletPtr mOwner; ///< The owning inlet
40 
41 public:
42 
43  TTGraphSource();
44  ~TTGraphSource();
45 
46  /** Internal method shared/called by constructors. */
47  void create();
48 
49  TTBoolean match(TTGraphObjectBasePtr anObject, TTUInt16 anOutletNumber)
50  {
51  if (anObject == mSourceObject && anOutletNumber == mOutletNumber)
52  return YES;
53  else
54  return NO;
55  }
56 
57  void setOwner(TTGraphInletPtr theOwningInlet)
58  {
59  mOwner = theOwningInlet;
60  }
61 
62  // Copying Functions -- critical due to use by std::vector
63 
64  TTGraphSource(const TTGraphSource& original) :
65  mSourceObject(NULL),
66  mOutletNumber(0),
67  mCallbackHandler("callback"),
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.mSourceObject)
78  connect(original.mSourceObject, original.mOutletNumber);
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  TTGraphSource& operator=(const TTGraphSource& original)
83  {
84  if (mSourceObject && mCallbackHandler.valid())
85  ((TTObjectBasePtr)mSourceObject)->unregisterObserverForNotifications(mCallbackHandler);
86 
87  mCallbackHandler = original.mCallbackHandler;
88  mOwner = original.mOwner;
89 
90  // TODO: evaluate if this is doing the correct thing:
91  // - we can copy the owner ptr for sure
92  // - we definitely can not copy the mCallbackHandler pointer
93  // - not certain about the mSourceObject
94 
95  if (original.mSourceObject)
96  connect(original.mSourceObject, original.mOutletNumber);
97 
98  return *this;
99  }
100 
101  /** Compare two sources for equality. */
102  inline friend bool operator == (const TTGraphSource& source1, const TTGraphSource& source2)
103  {
104  if (source1.mSourceObject == source2.mSourceObject && source1.mOutletNumber == source2.mOutletNumber)
105  return true;
106  else
107  return false;
108  }
109 
110 
111  // Info Methods
112 
113  void prepareDescription();
114  void getDescription(TTGraphDescription& desc);
115 
116  // Graph Methods
117 
118  void connect(TTGraphObjectBasePtr anObject, TTUInt16 fromOutletNumber);
119 
120 };
121 
122 typedef TTGraphSource* TTGraphSourcePtr;
123 typedef std::vector<TTGraphSource> TTGraphSourceVector;
124 typedef TTGraphSourceVector::iterator TTGraphSourceIter;
125 
126 
127 #endif // __TTGRAPH_SOURCE_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
Base class for all first-class Jamoma objects.
Definition: TTObjectBase.h:109
bool TTFOUNDATION_EXPORT operator==(const TTObject &anObject, const TTObject &anotherObject)
Compare two objects for equality.
Definition: TTObject.cpp:167
This object represents a single 'inlet' to a TTGraphObjectBase.
Definition: TTGraphInlet.h:30
TTBoolean valid() const
Determine if the object contained by this TTObject is truly ready for use.
Definition: TTObject.cpp:179
This object represents a single 'outlet' from a TTGraphObjectBase.
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34