00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef __JUCE_AUDIOPROCESSORGRAPH_JUCEHEADER__
00033 #define __JUCE_AUDIOPROCESSORGRAPH_JUCEHEADER__
00034
00035 #include "juce_AudioProcessor.h"
00036 #include "../plugins/juce_AudioPluginFormatManager.h"
00037 #include "../plugins/juce_KnownPluginList.h"
00038 #include "../../../juce_core/containers/juce_ReferenceCountedArray.h"
00039
00040
00041
00055 class JUCE_API AudioProcessorGraph : public AudioProcessor,
00056 public AsyncUpdater
00057 {
00058 public:
00059
00062 AudioProcessorGraph();
00063
00068 ~AudioProcessorGraph();
00069
00070
00075 class Node : public ReferenceCountedObject
00076 {
00077 public:
00080 ~Node();
00081
00082
00087 const uint32 id;
00088
00091 AudioProcessor* const processor;
00092
00099 PropertySet properties;
00100
00101
00104 typedef ReferenceCountedObjectPtr <Node> Ptr;
00105
00106
00107 juce_UseDebuggingNewOperator
00108
00109 private:
00110 friend class AudioProcessorGraph;
00111
00112 bool isPrepared;
00113
00114 Node (const uint32 id, AudioProcessor* const processor) throw();
00115
00116 void prepare (const double sampleRate, const int blockSize, AudioProcessorGraph* const graph);
00117 void unprepare();
00118
00119 Node (const Node&);
00120 const Node& operator= (const Node&);
00121 };
00122
00123
00128 struct Connection
00129 {
00130 public:
00131
00135 uint32 sourceNodeId;
00136
00144 int sourceChannelIndex;
00145
00149 uint32 destNodeId;
00150
00158 int destChannelIndex;
00159
00160
00161 juce_UseDebuggingNewOperator
00162
00163 private:
00164 };
00165
00166
00171 void clear();
00172
00174 int getNumNodes() const throw() { return nodes.size(); }
00175
00181 Node* getNode (const int index) const throw() { return nodes [index]; }
00182
00188 Node* getNodeForId (const uint32 nodeId) const throw();
00189
00201 Node* addNode (AudioProcessor* const newProcessor,
00202 uint32 nodeId = 0);
00203
00208 bool removeNode (const uint32 nodeId);
00209
00210
00212 int getNumConnections() const throw() { return connections.size(); }
00213
00215 const Connection* getConnection (const int index) const throw() { return connections [index]; }
00216
00221 const Connection* getConnectionBetween (const uint32 sourceNodeId,
00222 const int sourceChannelIndex,
00223 const uint32 destNodeId,
00224 const int destChannelIndex) const throw();
00225
00229 bool isConnected (const uint32 possibleSourceNodeId,
00230 const uint32 possibleDestNodeId) const throw();
00231
00234 bool canConnect (const uint32 sourceNodeId, const int sourceChannelIndex,
00235 const uint32 destNodeId, const int destChannelIndex) const throw();
00236
00242 bool addConnection (const uint32 sourceNodeId, const int sourceChannelIndex,
00243 const uint32 destNodeId, const int destChannelIndex);
00244
00249 void removeConnection (const int index);
00250
00255 bool removeConnection (const uint32 sourceNodeId, const int sourceChannelIndex,
00256 const uint32 destNodeId, const int destChannelIndex);
00257
00260 bool disconnectNode (const uint32 nodeId);
00261
00267 bool removeIllegalConnections();
00268
00269
00275 static const int midiChannelIndex;
00276
00277
00278
00292 class AudioGraphIOProcessor : public AudioPluginInstance
00293 {
00294 public:
00297 enum IODeviceType
00298 {
00299 audioInputNode,
00302 audioOutputNode,
00305 midiInputNode,
00308 midiOutputNode
00311 };
00312
00313
00315 IODeviceType getType() const throw() { return type; }
00316
00319 AudioProcessorGraph* getParentGraph() const throw() { return graph; }
00320
00322 bool isInput() const throw();
00324 bool isOutput() const throw();
00325
00326
00327 AudioGraphIOProcessor (const IODeviceType type);
00328 ~AudioGraphIOProcessor();
00329
00330 const String getName() const;
00331 void fillInPluginDescription (PluginDescription& d) const;
00332
00333 void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
00334 void releaseResources();
00335 void processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages);
00336
00337 const String getInputChannelName (const int channelIndex) const;
00338 const String getOutputChannelName (const int channelIndex) const;
00339 bool isInputChannelStereoPair (int index) const;
00340 bool isOutputChannelStereoPair (int index) const;
00341 bool acceptsMidi() const;
00342 bool producesMidi() const;
00343
00344 AudioProcessorEditor* createEditor();
00345
00346 int getNumParameters();
00347 const String getParameterName (int);
00348 float getParameter (int);
00349 const String getParameterText (int);
00350 void setParameter (int, float);
00351
00352 int getNumPrograms();
00353 int getCurrentProgram();
00354 void setCurrentProgram (int);
00355 const String getProgramName (int);
00356 void changeProgramName (int, const String&);
00357
00358 void getStateInformation (JUCE_NAMESPACE::MemoryBlock& destData);
00359 void setStateInformation (const void* data, int sizeInBytes);
00360
00362 void setParentGraph (AudioProcessorGraph* const graph) throw();
00363
00364 juce_UseDebuggingNewOperator
00365
00366 private:
00367 const IODeviceType type;
00368 AudioProcessorGraph* graph;
00369
00370 AudioGraphIOProcessor (const AudioGraphIOProcessor&);
00371 const AudioGraphIOProcessor& operator= (const AudioGraphIOProcessor&);
00372 };
00373
00374
00375
00376
00377 const String getName() const;
00378
00379 void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
00380 void releaseResources();
00381 void processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages);
00382
00383 const String getInputChannelName (const int channelIndex) const;
00384 const String getOutputChannelName (const int channelIndex) const;
00385 bool isInputChannelStereoPair (int index) const;
00386 bool isOutputChannelStereoPair (int index) const;
00387
00388 bool acceptsMidi() const;
00389 bool producesMidi() const;
00390
00391 AudioProcessorEditor* createEditor() { return 0; }
00392
00393 int getNumParameters() { return 0; }
00394 const String getParameterName (int) { return String::empty; }
00395 float getParameter (int) { return 0; }
00396 const String getParameterText (int) { return String::empty; }
00397 void setParameter (int, float) { }
00398
00399 int getNumPrograms() { return 0; }
00400 int getCurrentProgram() { return 0; }
00401 void setCurrentProgram (int) { }
00402 const String getProgramName (int) { return String::empty; }
00403 void changeProgramName (int, const String&) { }
00404
00405 void getStateInformation (JUCE_NAMESPACE::MemoryBlock& destData);
00406 void setStateInformation (const void* data, int sizeInBytes);
00407
00409 void handleAsyncUpdate();
00410
00411
00412 juce_UseDebuggingNewOperator
00413
00414 private:
00415 ReferenceCountedArray <Node> nodes;
00416 OwnedArray <Connection> connections;
00417 int lastNodeId;
00418 AudioSampleBuffer renderingBuffers;
00419 OwnedArray <MidiBuffer> midiBuffers;
00420
00421 CriticalSection renderLock;
00422 VoidArray renderingOps;
00423
00424 friend class AudioGraphIOProcessor;
00425 AudioSampleBuffer* currentAudioInputBuffer;
00426 AudioSampleBuffer currentAudioOutputBuffer;
00427 MidiBuffer* currentMidiInputBuffer;
00428 MidiBuffer currentMidiOutputBuffer;
00429
00430 void clearRenderingSequence();
00431 void buildRenderingSequence();
00432
00433 bool isAnInputTo (const uint32 possibleInputId,
00434 const uint32 possibleDestinationId,
00435 const int recursionCheck) const throw();
00436
00437 AudioProcessorGraph (const AudioProcessorGraph&);
00438 const AudioProcessorGraph& operator= (const AudioProcessorGraph&);
00439 };
00440
00441
00442 #endif // __JUCE_AUDIOPROCESSORGRAPH_JUCEHEADER__