Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 289 lines (217 sloc) 10.549 kB
266e394 @mhroth First commit of PdContext.
authored
1 /*
6848813 Update PdContext to new PdMessage syntax.
Martin Roth authored
2 * Copyright 2010,2011 Reality Jockey, Ltd.
266e394 @mhroth First commit of PdContext.
authored
3 * info@rjdj.me
4 * http://rjdj.me/
5 *
6 * This file is part of ZenGarden.
7 *
8 * ZenGarden is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * ZenGarden is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with ZenGarden. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23 #ifndef _PD_CONTEXT_H_
24 #define _PD_CONTEXT_H_
25
7329847 @mhroth Add static factory method to all objects in order to create an object…
authored
26 #include <map>
266e394 @mhroth First commit of PdContext.
authored
27 #include <pthread.h>
a3b0aca @mhroth Add global message processing to PdContext::process().
authored
28 #include "OrderedMessageQueue.h"
266e394 @mhroth First commit of PdContext.
authored
29 #include "PdGraph.h"
30 #include "ZGCallbackFunction.h"
31
eed621f @mhroth Move BufferPool to PdContext. When computing process order, make it g…
authored
32 class BufferPool;
a5bc02d @mhroth Add registration of throw~ and catch~ to PdContext.
authored
33 class DspCatch;
6bdd427 @mhroth Add registration of delay lines and receivers to PdContext.
authored
34 class DelayReceiver;
35 class DspDelayWrite;
266e394 @mhroth First commit of PdContext.
authored
36 class DspReceive;
37 class DspSend;
a5bc02d @mhroth Add registration of throw~ and catch~ to PdContext.
authored
38 class DspThrow;
3792ca8 @mhroth Remove errant forward declaration of MessageSendController in PdGraph.
authored
39 class MessageSendController;
07e6b58 @mhroth Add MessageTable and TableReceiver registrations to PdContext.
authored
40 class MessageTable;
d94e9cd @mhroth Massive refactor to use concept of a global context. Unfortunately th…
authored
41 class PdFileParser;
42 class RemoteMessageReceiver;
fc33fd3 @mhroth Remove the TableReceiver heirarchy, add a TableReceiverInterface. Thi…
authored
43 class TableReceiverInterface;
7329847 @mhroth Add static factory method to all objects in order to create an object…
authored
44 class PdMessage;
40ec372 @mhroth Create separate ObjectFactoryMap. Refactor PdContext to extract Objec…
authored
45 class ObjectFactoryMap;
cc8e606 @Kyew Added functions to register abstraction from memory
Kyew authored
46 class PdAbstractionDataBase;
266e394 @mhroth First commit of PdContext.
authored
47
a3b0aca @mhroth Add global message processing to PdContext::process().
authored
48 /**
49 * The <code>PdContext</code> is a container for a set of <code>PdGraph</code>s operating in
50 * a common environment. The <code>PdContext</code> tracks all relevent global variables.
51 */
266e394 @mhroth First commit of PdContext.
authored
52 class PdContext {
53
54 public:
55 PdContext(int numInputChannels, int numOutputChannels, int blockSize, float sampleRate,
7329847 @mhroth Add static factory method to all objects in order to create an object…
authored
56 void *(*function)(ZGCallbackFunction, void *, void *), void *userData);
266e394 @mhroth First commit of PdContext.
authored
57 ~PdContext();
58
59 int getNumInputChannels();
60 int getNumOutputChannels();
61 int getBlockSize();
62 float getSampleRate();
63
d94e9cd @mhroth Massive refactor to use concept of a global context. Unfortunately th…
authored
64 /**
65 * Attach the given <code>graph</code> to this <code>context</code>, also registering all
66 * necessary objects, and computing the dsp object compute order if necessary.
67 */
68 void attachGraph(PdGraph *graph);
777c7c9 @mhroth Correctly attach root-graph to context in ZenGarden.cpp.
authored
69 void unattachGraph(PdGraph *graph);
266e394 @mhroth First commit of PdContext.
authored
70
a3b0aca @mhroth Add global message processing to PdContext::process().
authored
71 void process(float *inputBuffers, float *outputBuffers);
266e394 @mhroth First commit of PdContext.
authored
72
5818427 @mhroth Only update inlet buffer refs when a dsp connection is added (or remo…
authored
73 void lock() { pthread_mutex_lock(&contextLock); }
74 void unlock() { pthread_mutex_unlock(&contextLock); }
266e394 @mhroth First commit of PdContext.
authored
75
d94e9cd @mhroth Massive refactor to use concept of a global context. Unfortunately th…
authored
76 /** Globally register a remote message receiver (e.g. [send] or [notein]). */
77 void registerRemoteMessageReceiver(RemoteMessageReceiver *receiver);
45bba91 @mhroth first commit of removeObject and associated functionality
authored
78 void unregisterRemoteMessageReceiver(RemoteMessageReceiver *receiver);
d94e9cd @mhroth Massive refactor to use concept of a global context. Unfortunately th…
authored
79
266e394 @mhroth First commit of PdContext.
authored
80 /** Globally register a [receive~] object. Connect to registered [send~] objects with the same name. */
81 void registerDspReceive(DspReceive *dspReceive);
fc31e99 @mhroth Implement unregistration functions for [r~]/[s~], table receivers.
authored
82 void unregisterDspReceive(DspReceive *dspReceive);
266e394 @mhroth First commit of PdContext.
authored
83
84 /** Globally register a [send~] object. Connect to registered [receive~] objects with the same name. */
85 void registerDspSend(DspSend *dspSend);
fc31e99 @mhroth Implement unregistration functions for [r~]/[s~], table receivers.
authored
86 void unregisterDspSend(DspSend *dspSend);
266e394 @mhroth First commit of PdContext.
authored
87
88 /** Returns the named global <code>DspSend</code> object. */
e77250f @mhroth send~ and receive~ do not process audio.
authored
89 DspSend *getDspSend(const char *name);
b86ea1d @mhroth Send~ and Receive~ are now working.
authored
90
91 /** Updates the input buffers all attached objects to the DspReceives associated with the given DspSend. */
92 void updateDspReceiveForSendWitBuffer(const char *name, float *buffer);
d94e9cd @mhroth Massive refactor to use concept of a global context. Unfortunately th…
authored
93
6bdd427 @mhroth Add registration of delay lines and receivers to PdContext.
authored
94 /**
95 * Globally register a [delwrite~] object. Registration is necessary such that they can
96 * be connected to [delread~] and [vd~] objects as are they are added to the graph.
97 */
98 void registerDelayline(DspDelayWrite *delayline);
99
100 /** Returns the named global <code>DspDelayWrite</code> object. */
0f9e3f4 @mhroth Convert delread~ and del write~ to new dsp architecture.
authored
101 DspDelayWrite *getDelayline(const char *name);
6bdd427 @mhroth Add registration of delay lines and receivers to PdContext.
authored
102
103 /**
104 * Globally register a [delread~] or [vd~] object. Registration is necessary such that they can
105 * be connected to [delwrite~] objects are they are added to the graph.
106 */
107 void registerDelayReceiver(DelayReceiver *delayReceiver);
d94e9cd @mhroth Massive refactor to use concept of a global context. Unfortunately th…
authored
108
a5bc02d @mhroth Add registration of throw~ and catch~ to PdContext.
authored
109 void registerDspThrow(DspThrow *dspThrow);
110
111 void registerDspCatch(DspCatch *dspCatch);
d94e9cd @mhroth Massive refactor to use concept of a global context. Unfortunately th…
authored
112
07e6b58 @mhroth Add MessageTable and TableReceiver registrations to PdContext.
authored
113 void registerTable(MessageTable *table);
114
fc33fd3 @mhroth Remove the TableReceiver heirarchy, add a TableReceiverInterface. Thi…
authored
115 void registerTableReceiver(TableReceiverInterface *tableReceiver);
6e7def6 @mhroth Add PdContext::unregisterTableReceiver + nits.
authored
116 void unregisterTableReceiver(TableReceiverInterface *tableReceiver);
d94e9cd @mhroth Massive refactor to use concept of a global context. Unfortunately th…
authored
117
15ae2da @mhroth Update catch~ with new architecture.
authored
118 MessageTable *getTable(const char *name);
d94e9cd @mhroth Massive refactor to use concept of a global context. Unfortunately th…
authored
119
a5bc02d @mhroth Add registration of throw~ and catch~ to PdContext.
authored
120 /** Returns the named global <code>DspCatch</code> object. */
15ae2da @mhroth Update catch~ with new architecture.
authored
121 DspCatch *getDspCatch(const char *name);
d94e9cd @mhroth Massive refactor to use concept of a global context. Unfortunately th…
authored
122
123 /**
124 * Sends the given message to all [receive] objects with the given <code>name</code>.
125 * This function is used by message boxes to send messages described be the syntax:
126 * ;
127 * name message;
128 */
b555c64 @mhroth rename PdContext::dispatchMessageToNamedReceivers to PdContext::sendM…
authored
129 void sendMessageToNamedReceivers(char *name, PdMessage *message);
d94e9cd @mhroth Massive refactor to use concept of a global context. Unfortunately th…
authored
130
131 /**
132 * Schedules a message to be sent to all receivers at the start of the next block.
133 * @returns The <code>PdMessage</code> which will be sent. It is intended that the programmer
134 * will set the values of the message with a call to <code>setMessage()</code>.
135 */
136 void scheduleExternalMessageV(const char *receiverName, double timestamp,
137 const char *messageFormat, va_list ap);
138
20b7f81 @mhroth Expanded support for messages in ZenGarden.h
authored
139 /** Schedules a message to be sent to all receivers at the start of the next block. */
140 void scheduleExternalMessage(const char *receiverName, PdMessage *message);
141
d94e9cd @mhroth Massive refactor to use concept of a global context. Unfortunately th…
authored
142 /**
3fa0b34 @mhroth Allow a message to be sent in a context, as described by a string.
authored
143 * Schedules a message described by the given string to be sent to named receivers at the
144 * given timestamp.
145 */
ed0ccfe @mhroth nit. Bad syntax.
authored
146 void scheduleExternalMessage(const char *receiverName, double timestamp,
3fa0b34 @mhroth Allow a message to be sent in a context, as described by a string.
authored
147 const char *initString);
148
149 /**
d94e9cd @mhroth Massive refactor to use concept of a global context. Unfortunately th…
authored
150 * Schedules a <code>PdMessage</code> to be sent by the <code>MessageObject</code> from the
29f83db Towards an a stack-based messaging system. First commit.
Martin Roth authored
151 * <code>outletIndex</code> at the specified <code>time</code>. The message will be copied
152 * to the heap and the context will thereafter take over ownership and be responsible for
153 * freeing it. The pointer to the heap-message is returned.
d94e9cd @mhroth Massive refactor to use concept of a global context. Unfortunately th…
authored
154 */
f3c0bff Update to new PdMessage syntax. Comment out difficult parts of Messag…
Martin Roth authored
155 PdMessage *scheduleMessage(MessageObject *messageObject, unsigned int outletIndex, PdMessage *message);
d94e9cd @mhroth Massive refactor to use concept of a global context. Unfortunately th…
authored
156
29f83db Towards an a stack-based messaging system. First commit.
Martin Roth authored
157 /**
158 * Cancel a scheduled <code>PdMessage</code> according to its id. The message memory will
159 * be freed.
160 */
d94e9cd @mhroth Massive refactor to use concept of a global context. Unfortunately th…
authored
161 void cancelMessage(MessageObject *messageObject, int outletIndex, PdMessage *message);
162
163 /** Receives and processes messages sent to the Pd system by sending to "pd". */
164 void receiveSystemMessage(PdMessage *message);
165
166 /** Returns the global dsp buffer at the given inlet. Exclusively used by <code>DspAdc</code>. */
167 float *getGlobalDspBufferAtInlet(int inletIndex);
168
169 /** Returns the global dsp buffer at the given outlet. Exclusively used by <code>DspDac</code>. */
170 float *getGlobalDspBufferAtOutlet(int outletIndex);
171
172 /** Returns the timestamp of the beginning of the current block. */
173 double getBlockStartTimestamp();
174
175 /** Returns the duration in milliseconds of one block. */
176 double getBlockDuration();
a5bc02d @mhroth Add registration of throw~ and catch~ to PdContext.
authored
177
266e394 @mhroth First commit of PdContext.
authored
178 /** Prints the given message to error output. */
179 void printErr(char *msg);
180 void printErr(const char *msg, ...);
d94e9cd @mhroth Massive refactor to use concept of a global context. Unfortunately th…
authored
181
266e394 @mhroth First commit of PdContext.
authored
182 /** Prints the given message to standard output. */
183 void printStd(char *msg);
184 void printStd(const char *msg, ...);
185
09e7286 @mhroth Fix bug in which [pd] objects would not receive save graph id as parent.
authored
186 /** Returns the next globally unique graph id. */
3e851a7 @mhroth Create independent PdFileParser, pull functionality out of PdContext.
authored
187 int getNextGraphId();
d94e9cd @mhroth Massive refactor to use concept of a global context. Unfortunately th…
authored
188
5f29ece @mhroth Add a skeleton (non-functional) implementation of [value].
authored
189 /** Used with MessageValue for keeping track of global variables. */
1ad8044 @mhroth Add implementation for value object.
authored
190 void setValueForName(const char *name, float constant);
191 float getValueForName(const char *name);
5f29ece @mhroth Add a skeleton (non-functional) implementation of [value].
authored
192
55a1cd6 @mhroth More or less fill in all of initObjectMap
authored
193 /** Create a new object in a graph. */
3ca91d3 @mhroth Test object init map. Add additional objects (e.g. list family).
authored
194 MessageObject *newObject(const char *objectLabel, PdMessage *initMessage, PdGraph *graph);
3388398 Allow objects to be created and added to graphs, and add connections …
Martin Roth authored
195
8176164 @mhroth Update ZenGarden.h to work with Java API.
authored
196 void registerExternalReceiver(const char *receiverName);
197 void unregisterExternalReceiver(const char *receiverName);
198
199 /** User-provided data associated with the callback function. */
200 void *callbackUserData;
201
34045e7 @mhroth Implement external receiver registration.
authored
202 /** The registered callback function for sending data outside of the graph. */
7329847 @mhroth Add static factory method to all objects in order to create an object…
authored
203 void *(*callbackFunction)(ZGCallbackFunction, void *, void *);
204
3e851a7 @mhroth Create independent PdFileParser, pull functionality out of PdContext.
authored
205 /** Register an object label and its associated factory method. */
40ec372 @mhroth Create separate ObjectFactoryMap. Refactor PdContext to extract Objec…
authored
206 void registerExternalObject(const char *objectLabel,
7329847 @mhroth Add static factory method to all objects in order to create an object…
authored
207 MessageObject *(*newObject)(PdMessage *, PdGraph *));
208
3e851a7 @mhroth Create independent PdFileParser, pull functionality out of PdContext.
authored
209 /** Unregister an object label. */
40ec372 @mhroth Create separate ObjectFactoryMap. Refactor PdContext to extract Objec…
authored
210 void unregisterExternalObject(const char *objectLabel);
34045e7 @mhroth Implement external receiver registration.
authored
211
eed621f @mhroth Move BufferPool to PdContext. When computing process order, make it g…
authored
212 BufferPool *getBufferPool() { return bufferPool; }
cc8e606 @Kyew Added functions to register abstraction from memory
Kyew authored
213
214 PdAbstractionDataBase *getAbstractionDataBase();
eed621f @mhroth Move BufferPool to PdContext. When computing process order, make it g…
authored
215
d94e9cd @mhroth Massive refactor to use concept of a global context. Unfortunately th…
authored
216 private:
217 /** Returns <code>true</code> if the graph was successfully configured. <code>false</code> otherwise. */
218 bool configureEmptyGraphWithParser(PdGraph *graph, PdFileParser *fileParser);
7329847 @mhroth Add static factory method to all objects in order to create an object…
authored
219
220 void initObjectInitMap();
2aefdf2 @mhroth merge dspDirectRef into master
authored
221
266e394 @mhroth First commit of PdContext.
authored
222 int numInputChannels;
223 int numOutputChannels;
224 int blockSize;
225 float sampleRate;
d94e9cd @mhroth Massive refactor to use concept of a global context. Unfortunately th…
authored
226
227 /** Keeps track of the current global graph id. */
3e851a7 @mhroth Create independent PdFileParser, pull functionality out of PdContext.
authored
228 unsigned int globalGraphId;
d94e9cd @mhroth Massive refactor to use concept of a global context. Unfortunately th…
authored
229
230 /** A list of all top-level graphs in this context. */
c858cbc @mhroth Further use of the stl vector in order to replace the custom List obj…
authored
231 vector<PdGraph *> graphList;
d94e9cd @mhroth Massive refactor to use concept of a global context. Unfortunately th…
authored
232
233 /** A thread lock used to access critical sections of this context. */
266e394 @mhroth First commit of PdContext.
authored
234 pthread_mutex_t contextLock;
235
236 int numBytesInInputBuffers;
237 int numBytesInOutputBuffers;
238
239 float *globalDspInputBuffers;
240 float *globalDspOutputBuffers;
241
a3b0aca @mhroth Add global message processing to PdContext::process().
authored
242 /** A message queue keeping track of all scheduled messages. */
243 OrderedMessageQueue *messageCallbackQueue;
244
245 /** The start of the current block in milliseconds. */
246 double blockStartTimestamp;
247
248 /** The duration of one block in milliseconds. */
249 double blockDurationMs;
250
d94e9cd @mhroth Massive refactor to use concept of a global context. Unfortunately th…
authored
251 /** The global send controller. */
252 MessageSendController *sendController;
253
266e394 @mhroth First commit of PdContext.
authored
254 /** A global list of all [send~] objects. */
20ae5be @mhroth Begin to replace object lists (for objec registration) in PdContext.
authored
255 list<DspSend *> dspSendList;
266e394 @mhroth First commit of PdContext.
authored
256
257 /** A global list of all [receive~] objects. */
b86ea1d @mhroth Send~ and Receive~ are now working.
authored
258 map<string, list<DspReceive *> > dspReceiveMap;
266e394 @mhroth First commit of PdContext.
authored
259
b599733 @mhroth Convert delaylineList and delayReceiverList to std list objects.
authored
260 /** A global list of all [delwrite~] objects. */
261 list<DspDelayWrite *> delaylineList;
266e394 @mhroth First commit of PdContext.
authored
262
263 /** A global list of all [delread~] and [vd~] objects. */
b599733 @mhroth Convert delaylineList and delayReceiverList to std list objects.
authored
264 list<DelayReceiver *> delayReceiverList;
266e394 @mhroth First commit of PdContext.
authored
265
266 /** A global list of all [throw~] objects. */
20ae5be @mhroth Begin to replace object lists (for objec registration) in PdContext.
authored
267 list<DspThrow *> throwList;
266e394 @mhroth First commit of PdContext.
authored
268
269 /** A global list of all [catch~] objects. */
20ae5be @mhroth Begin to replace object lists (for objec registration) in PdContext.
authored
270 list<DspCatch *> catchList;
266e394 @mhroth First commit of PdContext.
authored
271
272 /** A global list of all [table] objects. */
20ae5be @mhroth Begin to replace object lists (for objec registration) in PdContext.
authored
273 list<MessageTable *> tableList;
266e394 @mhroth First commit of PdContext.
authored
274
55e8dbf @mhroth Upgrade tableReceiverList to a stl list.
authored
275 /** A global list of all table receivers (e.g., [tabread4~] and [tabplay~]) */
276 list<TableReceiverInterface *> tableReceiverList;
7329847 @mhroth Add static factory method to all objects in order to create an object…
authored
277
40ec372 @mhroth Create separate ObjectFactoryMap. Refactor PdContext to extract Objec…
authored
278 ObjectFactoryMap *objectFactoryMap;
eed621f @mhroth Move BufferPool to PdContext. When computing process order, make it g…
authored
279
280 BufferPool *bufferPool;
1ad8044 @mhroth Add implementation for value object.
authored
281
282 /** A global map storing values for Value objects. */
283 map<string,float> valueMap;
cc8e606 @Kyew Added functions to register abstraction from memory
Kyew authored
284
285 PdAbstractionDataBase *abstractionDatabase;
266e394 @mhroth First commit of PdContext.
authored
286 };
287
288 #endif // _PD_CONTEXT_H_
Something went wrong with that request. Please try again.