Browse Source

tags/2021-05-28
jules 17 years ago
parent
commit
08e0f81b54
3 changed files with 1867 additions and 1841 deletions
  1. +59
    -59
      src/juce_appframework/audio/plugins/formats/juce_VSTPluginFormat.cpp
  2. +1366
    -1342
      src/juce_appframework/audio/processors/juce_AudioProcessorGraph.cpp
  3. +442
    -440
      src/juce_appframework/audio/processors/juce_AudioProcessorGraph.h

+ 59
- 59
src/juce_appframework/audio/plugins/formats/juce_VSTPluginFormat.cpp View File

@@ -169,9 +169,9 @@ struct fxProgramSet
#ifdef JUCE_LITTLE_ENDIAN #ifdef JUCE_LITTLE_ENDIAN
static long swap (const long x) throw() { return (long) swapByteOrder ((uint32) x); }
static long vst_swap (const long x) throw() { return (long) swapByteOrder ((uint32) x); }
static float swapFloat (const float x) throw()
static float vst_swapFloat (const float x) throw()
{ {
union { uint32 asInt; float asFloat; } n; union { uint32 asInt; float asFloat; } n;
n.asFloat = x; n.asFloat = x;
@@ -179,8 +179,8 @@ struct fxProgramSet
return n.asFloat; return n.asFloat;
} }
#else #else
#define swap(x) (x)
#define swapFloat(x) (x)
#define vst_swap(x) (x)
#define vst_swapFloat(x) (x)
#endif #endif
//============================================================================== //==============================================================================
@@ -1206,7 +1206,7 @@ void VSTPluginInstance::handleMidiFromPlugin (const VstEvents* const events)
} }
//============================================================================== //==============================================================================
static Array <VSTPluginWindow*> activeWindows;
static Array <VSTPluginWindow*> activeVSTWindows;
//============================================================================== //==============================================================================
class VSTPluginWindow : public AudioProcessorEditor, class VSTPluginWindow : public AudioProcessorEditor,
@@ -1236,7 +1236,7 @@ public:
movementWatcher = new CompMovementWatcher (this); movementWatcher = new CompMovementWatcher (this);
activeWindows.add (this);
activeVSTWindows.add (this);
setSize (1, 1); setSize (1, 1);
setOpaque (true); setOpaque (true);
@@ -1249,7 +1249,7 @@ public:
closePluginWindow(); closePluginWindow();
activeWindows.removeValue (this);
activeVSTWindows.removeValue (this);
plugin.editorBeingDeleted (this); plugin.editorBeingDeleted (this);
} }
@@ -1474,8 +1474,8 @@ public:
void broughtToFront() void broughtToFront()
{ {
activeWindows.removeValue (this);
activeWindows.add (this);
activeVSTWindows.removeValue (this);
activeVSTWindows.add (this);
#if JUCE_MAC #if JUCE_MAC
dispatch (effEditTop, 0, 0, 0, 0); dispatch (effEditTop, 0, 0, 0, 0);
@@ -1753,9 +1753,9 @@ private:
#if JUCE_WIN32 #if JUCE_WIN32
static LRESULT CALLBACK vstHookWndProc (HWND hW, UINT message, WPARAM wParam, LPARAM lParam) static LRESULT CALLBACK vstHookWndProc (HWND hW, UINT message, WPARAM wParam, LPARAM lParam)
{ {
for (int i = activeWindows.size(); --i >= 0;)
for (int i = activeVSTWindows.size(); --i >= 0;)
{ {
const VSTPluginWindow* const w = (const VSTPluginWindow*) activeWindows.getUnchecked (i);
const VSTPluginWindow* const w = (const VSTPluginWindow*) activeVSTWindows.getUnchecked (i);
if (w->pluginHWND == hW) if (w->pluginHWND == hW)
{ {
@@ -1965,12 +1965,12 @@ void VSTPluginInstance::handleAsyncUpdate()
//============================================================================== //==============================================================================
bool VSTPluginInstance::restoreProgramSettings (const fxProgram* const prog) bool VSTPluginInstance::restoreProgramSettings (const fxProgram* const prog)
{ {
if (swap (prog->chunkMagic) == 'CcnK' && swap (prog->fxMagic) == 'FxCk')
if (vst_swap (prog->chunkMagic) == 'CcnK' && vst_swap (prog->fxMagic) == 'FxCk')
{ {
changeProgramName (getCurrentProgram(), prog->prgName); changeProgramName (getCurrentProgram(), prog->prgName);
for (int i = 0; i < swap (prog->numParams); ++i)
setParameter (i, swapFloat (prog->params[i]));
for (int i = 0; i < vst_swap (prog->numParams); ++i)
setParameter (i, vst_swapFloat (prog->params[i]));
return true; return true;
} }
@@ -1986,20 +1986,20 @@ bool VSTPluginInstance::loadFromFXBFile (const void* const data,
const fxSet* const set = (const fxSet*) data; const fxSet* const set = (const fxSet*) data;
if ((swap (set->chunkMagic) != 'CcnK' && swap (set->chunkMagic) != 'KncC')
|| swap (set->version) > fxbVersionNum)
if ((vst_swap (set->chunkMagic) != 'CcnK' && vst_swap (set->chunkMagic) != 'KncC')
|| vst_swap (set->version) > fxbVersionNum)
return false; return false;
if (swap (set->fxMagic) == 'FxBk')
if (vst_swap (set->fxMagic) == 'FxBk')
{ {
// bank of programs // bank of programs
if (swap (set->numPrograms) >= 0)
if (vst_swap (set->numPrograms) >= 0)
{ {
const int oldProg = getCurrentProgram(); const int oldProg = getCurrentProgram();
const int numParams = swap (((const fxProgram*) (set->programs))->numParams);
const int numParams = vst_swap (((const fxProgram*) (set->programs))->numParams);
const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float); const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
for (int i = 0; i < swap (set->numPrograms); ++i)
for (int i = 0; i < vst_swap (set->numPrograms); ++i)
{ {
if (i != oldProg) if (i != oldProg)
{ {
@@ -2007,7 +2007,7 @@ bool VSTPluginInstance::loadFromFXBFile (const void* const data,
if (((const char*) prog) - ((const char*) set) >= dataSize) if (((const char*) prog) - ((const char*) set) >= dataSize)
return false; return false;
if (swap (set->numPrograms) > 0)
if (vst_swap (set->numPrograms) > 0)
setCurrentProgram (i); setCurrentProgram (i);
if (! restoreProgramSettings (prog)) if (! restoreProgramSettings (prog))
@@ -2015,7 +2015,7 @@ bool VSTPluginInstance::loadFromFXBFile (const void* const data,
} }
} }
if (swap (set->numPrograms) > 0)
if (vst_swap (set->numPrograms) > 0)
setCurrentProgram (oldProg); setCurrentProgram (oldProg);
const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + oldProg * progLen); const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + oldProg * progLen);
@@ -2026,38 +2026,38 @@ bool VSTPluginInstance::loadFromFXBFile (const void* const data,
return false; return false;
} }
} }
else if (swap (set->fxMagic) == 'FxCk')
else if (vst_swap (set->fxMagic) == 'FxCk')
{ {
// single program // single program
const fxProgram* const prog = (const fxProgram*) data; const fxProgram* const prog = (const fxProgram*) data;
if (swap (prog->chunkMagic) != 'CcnK')
if (vst_swap (prog->chunkMagic) != 'CcnK')
return false; return false;
changeProgramName (getCurrentProgram(), prog->prgName); changeProgramName (getCurrentProgram(), prog->prgName);
for (int i = 0; i < swap (prog->numParams); ++i)
setParameter (i, swapFloat (prog->params[i]));
for (int i = 0; i < vst_swap (prog->numParams); ++i)
setParameter (i, vst_swapFloat (prog->params[i]));
} }
else if (swap (set->fxMagic) == 'FBCh' || swap (set->fxMagic) == 'hCBF')
else if (vst_swap (set->fxMagic) == 'FBCh' || vst_swap (set->fxMagic) == 'hCBF')
{ {
// non-preset chunk // non-preset chunk
const fxChunkSet* const cset = (const fxChunkSet*) data; const fxChunkSet* const cset = (const fxChunkSet*) data;
if (swap (cset->chunkSize) + sizeof (fxChunkSet) - 8 > (unsigned int) dataSize)
if (vst_swap (cset->chunkSize) + sizeof (fxChunkSet) - 8 > (unsigned int) dataSize)
return false; return false;
setChunkData (cset->chunk, swap (cset->chunkSize), false);
setChunkData (cset->chunk, vst_swap (cset->chunkSize), false);
} }
else if (swap (set->fxMagic) == 'FPCh' || swap (set->fxMagic) == 'hCPF')
else if (vst_swap (set->fxMagic) == 'FPCh' || vst_swap (set->fxMagic) == 'hCPF')
{ {
// preset chunk // preset chunk
const fxProgramSet* const cset = (const fxProgramSet*) data; const fxProgramSet* const cset = (const fxProgramSet*) data;
if (swap (cset->chunkSize) + sizeof (fxProgramSet) - 8 > (unsigned int) dataSize)
if (vst_swap (cset->chunkSize) + sizeof (fxProgramSet) - 8 > (unsigned int) dataSize)
return false; return false;
setChunkData (cset->chunk, swap (cset->chunkSize), true);
setChunkData (cset->chunk, vst_swap (cset->chunkSize), true);
changeProgramName (getCurrentProgram(), cset->name); changeProgramName (getCurrentProgram(), cset->name);
} }
@@ -2074,18 +2074,18 @@ void VSTPluginInstance::setParamsInProgramBlock (fxProgram* const prog) throw()
{ {
const int numParams = getNumParameters(); const int numParams = getNumParameters();
prog->chunkMagic = swap ('CcnK');
prog->chunkMagic = vst_swap ('CcnK');
prog->byteSize = 0; prog->byteSize = 0;
prog->fxMagic = swap ('FxCk');
prog->version = swap (fxbVersionNum);
prog->fxID = swap (getUID());
prog->fxVersion = swap (getVersionNumber());
prog->numParams = swap (numParams);
prog->fxMagic = vst_swap ('FxCk');
prog->version = vst_swap (fxbVersionNum);
prog->fxID = vst_swap (getUID());
prog->fxVersion = vst_swap (getVersionNumber());
prog->numParams = vst_swap (numParams);
getCurrentProgramName().copyToBuffer (prog->prgName, sizeof (prog->prgName) - 1); getCurrentProgramName().copyToBuffer (prog->prgName, sizeof (prog->prgName) - 1);
for (int i = 0; i < numParams; ++i) for (int i = 0; i < numParams; ++i)
prog->params[i] = swapFloat (getParameter (i));
prog->params[i] = vst_swapFloat (getParameter (i));
} }
bool VSTPluginInstance::saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB) bool VSTPluginInstance::saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB)
@@ -2104,14 +2104,14 @@ bool VSTPluginInstance::saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSiz
dest.setSize (totalLen, true); dest.setSize (totalLen, true);
fxChunkSet* const set = (fxChunkSet*) dest.getData(); fxChunkSet* const set = (fxChunkSet*) dest.getData();
set->chunkMagic = swap ('CcnK');
set->chunkMagic = vst_swap ('CcnK');
set->byteSize = 0; set->byteSize = 0;
set->fxMagic = swap ('FBCh');
set->version = swap (fxbVersionNum);
set->fxID = swap (getUID());
set->fxVersion = swap (getVersionNumber());
set->numPrograms = swap (numPrograms);
set->chunkSize = swap (chunk.getSize());
set->fxMagic = vst_swap ('FBCh');
set->version = vst_swap (fxbVersionNum);
set->fxID = vst_swap (getUID());
set->fxVersion = vst_swap (getVersionNumber());
set->numPrograms = vst_swap (numPrograms);
set->chunkSize = vst_swap (chunk.getSize());
chunk.copyTo (set->chunk, 0, chunk.getSize()); chunk.copyTo (set->chunk, 0, chunk.getSize());
} }
@@ -2124,14 +2124,14 @@ bool VSTPluginInstance::saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSiz
dest.setSize (totalLen, true); dest.setSize (totalLen, true);
fxProgramSet* const set = (fxProgramSet*) dest.getData(); fxProgramSet* const set = (fxProgramSet*) dest.getData();
set->chunkMagic = swap ('CcnK');
set->chunkMagic = vst_swap ('CcnK');
set->byteSize = 0; set->byteSize = 0;
set->fxMagic = swap ('FPCh');
set->version = swap (fxbVersionNum);
set->fxID = swap (getUID());
set->fxVersion = swap (getVersionNumber());
set->numPrograms = swap (numPrograms);
set->chunkSize = swap (chunk.getSize());
set->fxMagic = vst_swap ('FPCh');
set->version = vst_swap (fxbVersionNum);
set->fxID = vst_swap (getUID());
set->fxVersion = vst_swap (getVersionNumber());
set->numPrograms = vst_swap (numPrograms);
set->chunkSize = vst_swap (chunk.getSize());
getCurrentProgramName().copyToBuffer (set->name, sizeof (set->name) - 1); getCurrentProgramName().copyToBuffer (set->name, sizeof (set->name) - 1);
chunk.copyTo (set->chunk, 0, chunk.getSize()); chunk.copyTo (set->chunk, 0, chunk.getSize());
@@ -2146,13 +2146,13 @@ bool VSTPluginInstance::saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSiz
dest.setSize (len, true); dest.setSize (len, true);
fxSet* const set = (fxSet*) dest.getData(); fxSet* const set = (fxSet*) dest.getData();
set->chunkMagic = swap ('CcnK');
set->chunkMagic = vst_swap ('CcnK');
set->byteSize = 0; set->byteSize = 0;
set->fxMagic = swap ('FxBk');
set->version = swap (fxbVersionNum);
set->fxID = swap (getUID());
set->fxVersion = swap (getVersionNumber());
set->numPrograms = swap (numPrograms);
set->fxMagic = vst_swap ('FxBk');
set->version = vst_swap (fxbVersionNum);
set->fxID = vst_swap (getUID());
set->fxVersion = vst_swap (getVersionNumber());
set->numPrograms = vst_swap (numPrograms);
const int oldProgram = getCurrentProgram(); const int oldProgram = getCurrentProgram();
MemoryBlock oldSettings; MemoryBlock oldSettings;


+ 1366
- 1342
src/juce_appframework/audio/processors/juce_AudioProcessorGraph.cpp
File diff suppressed because it is too large
View File


+ 442
- 440
src/juce_appframework/audio/processors/juce_AudioProcessorGraph.h View File

@@ -1,440 +1,442 @@
/*
==============================================================================
This file is part of the JUCE library - "Jules' Utility Class Extensions"
Copyright 2004-7 by Raw Material Software ltd.
------------------------------------------------------------------------------
JUCE can be redistributed and/or modified under the terms of the
GNU General Public License, as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later version.
JUCE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with JUCE; if not, visit www.gnu.org/licenses or write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
------------------------------------------------------------------------------
If you'd like to release a closed-source product which uses JUCE, commercial
licenses are also available: visit www.rawmaterialsoftware.com/juce for
more information.
==============================================================================
*/
#ifndef __JUCE_AUDIOPROCESSORGRAPH_JUCEHEADER__
#define __JUCE_AUDIOPROCESSORGRAPH_JUCEHEADER__
#include "juce_AudioProcessor.h"
#include "../plugins/juce_AudioPluginFormatManager.h"
#include "../plugins/juce_KnownPluginList.h"
#include "../../../juce_core/containers/juce_ReferenceCountedArray.h"
//==============================================================================
/**
A type of AudioProcessor which plays back a graph of other AudioProcessors.
Use one of these objects if you want to wire-up a set of AudioProcessors
and play back the result.
Processors can be added to the graph as "nodes" using addNode(), and once
added, you can connect any of their input or output channels to other
nodes using addConnection().
To play back a graph through an audio device, you might want to use an
AudioProcessorPlayer object.
*/
class JUCE_API AudioProcessorGraph : public AudioProcessor,
public AsyncUpdater
{
public:
//==============================================================================
/** Creates an empty graph.
*/
AudioProcessorGraph();
/** Destructor.
Any processor objects that have been added to the graph will also be deleted.
*/
~AudioProcessorGraph();
//==============================================================================
/** Represents one of the nodes, or processors, in an AudioProcessorGraph.
To create a node, call AudioProcessorGraph::addNode().
*/
class Node : public ReferenceCountedObject
{
public:
/** Destructor.
*/
~Node();
//==============================================================================
/** The ID number assigned to this node.
This is assigned by the graph that owns it, and can't be changed.
*/
const uint32 id;
/** The actual processor object that this node represents.
*/
AudioProcessor* const processor;
/** A set of user-definable properties that are associated with this node.
This can be used to attach values to the node for whatever purpose seems
useful. For example, you might store an x and y position if your application
is displaying the nodes on-screen.
*/
PropertySet properties;
//==============================================================================
/** A convenient typedef for referring to a pointer to a node object.
*/
typedef ReferenceCountedObjectPtr <Node> Ptr;
//==============================================================================
juce_UseDebuggingNewOperator
private:
friend class AudioProcessorGraph;
bool isPrepared;
Node (const uint32 id, AudioProcessor* const processor) throw();
void prepare (const double sampleRate, const int blockSize, AudioProcessorGraph* const graph);
void unprepare();
Node (const Node&);
const Node& operator= (const Node&);
};
//==============================================================================
/** Represents a connection between two channels of two nodes in an AudioProcessorGraph.
To create a connection, use AudioProcessorGraph::addConnection().
*/
struct Connection
{
public:
//==============================================================================
/** The ID number of the node which is the input source for this connection.
@see AudioProcessorGraph::getNodeForId
*/
uint32 sourceNodeId;
/** The index of the output channel of the source node from which this
connection takes its data.
If this value is the special number AudioProcessorGraph::midiChannelIndex, then
it is referring to the source node's midi output. Otherwise, it is the zero-based
index of an audio output channel in the source node.
*/
int sourceChannelIndex;
/** The ID number of the node which is the destination for this connection.
@see AudioProcessorGraph::getNodeForId
*/
uint32 destNodeId;
/** The index of the input channel of the destination node to which this
connection delivers its data.
If this value is the special number AudioProcessorGraph::midiChannelIndex, then
it is referring to the destination node's midi input. Otherwise, it is the zero-based
index of an audio input channel in the destination node.
*/
int destChannelIndex;
//==============================================================================
juce_UseDebuggingNewOperator
private:
};
//==============================================================================
/** Deletes all nodes and connections from this graph.
Any processor objects in the graph will be deleted.
*/
void clear();
/** Returns the number of nodes in the graph. */
int getNumNodes() const throw() { return nodes.size(); }
/** Returns a pointer to one of the nodes in the graph.
This will return 0 if the index is out of range.
@see getNodeForId
*/
Node* getNode (const int index) const throw() { return nodes [index]; }
/** Searches the graph for a node with the given ID number and returns it.
If no such node was found, this returns 0.
@see getNode
*/
Node* getNodeForId (const uint32 nodeId) const throw();
/** Adds a node to the graph.
This creates a new node in the graph, for the specified processor. Once you have
added a processor to the graph, the graph owns it and will delete it later when
it is no longer needed.
The optional nodeId parameter lets you specify an ID to use for the node, but
if the value is already in use, this new node will overwrite the old one.
If this succeeds, it returns a pointer to the newly-created node.
*/
Node* addNode (AudioProcessor* const newProcessor,
uint32 nodeId = 0);
/** Deletes a node within the graph which has the specified ID.
This will also delete any connections that are attached to this node.
*/
bool removeNode (const uint32 nodeId);
//==============================================================================
/** Returns the number of connections in the graph. */
int getNumConnections() const throw() { return connections.size(); }
/** Returns a pointer to one of the connections in the graph. */
const Connection* getConnection (const int index) const throw() { return connections [index]; }
/** Searches for a connection between some specified channels.
If no such connection is found, this returns 0.
*/
const Connection* getConnectionBetween (const uint32 sourceNodeId,
const int sourceChannelIndex,
const uint32 destNodeId,
const int destChannelIndex) const throw();
/** Returns true if there is a connection between any of the channels of
two specified nodes.
*/
bool isConnected (const uint32 possibleSourceNodeId,
const uint32 possibleDestNodeId) const throw();
/** Returns true if it would be legal to connect the specified points.
*/
bool canConnect (const uint32 sourceNodeId, const int sourceChannelIndex,
const uint32 destNodeId, const int destChannelIndex) const throw();
/** Attempts to connect two specified channels of two nodes.
If this isn't allowed (e.g. because you're trying to connect a midi channel
to an audio one or other such nonsense), then it'll return 0.
*/
bool addConnection (const uint32 sourceNodeId, const int sourceChannelIndex,
const uint32 destNodeId, const int destChannelIndex);
/** Deletes the connection with the specified index.
Returns true if a connection was actually deleted.
*/
void removeConnection (const int index);
/** Deletes any connection between two specified points.
Returns true if a connection was actually deleted.
*/
bool removeConnection (const uint32 sourceNodeId, const int sourceChannelIndex,
const uint32 destNodeId, const int destChannelIndex);
/** Removes all connections from the specified node.
*/
bool disconnectNode (const uint32 nodeId);
/** Performs a sanity checks of all the connections.
This might be useful if some of the processors are doing things like changing
their channel counts, which could render some connections obsolete.
*/
bool removeIllegalConnections();
//==============================================================================
/** A special number that represents the midi channel of a node.
This is used as a channel index value if you want to refer to the midi input
or output instead of an audio channel.
*/
static const int midiChannelIndex;
//==============================================================================
/** A special type of AudioProcessor that can live inside an AudioProcessorGraph
in order to use the audio that comes into and out of the graph itself.
If you create an AudioGraphIOProcessor in "input" mode, it will act as a
node in the graph which delivers the audio that is coming into the parent
graph. This allows you to stream the data to other nodes and process the
incoming audio.
Likewise, one of these in "output" mode can be sent data which it will add to
the sum of data being sent to the graph's output.
@see AudioProcessorGraph
*/
class AudioGraphIOProcessor : public AudioPluginInstance
{
public:
/** Specifies the mode in which this processor will operate.
*/
enum IODeviceType
{
audioInputNode, /**< In this mode, the processor has output channels
representing all the audio input channels that are
coming into its parent audio graph. */
audioOutputNode, /**< In this mode, the processor has input channels
representing all the audio output channels that are
going out of its parent audio graph. */
midiInputNode, /**< In this mode, the processor has a midi output which
delivers the same midi data that is arriving at its
parent graph. */
midiOutputNode /**< In this mode, the processor has a midi input and
any data sent to it will be passed out of the parent
graph. */
};
//==============================================================================
/** Returns the mode of this processor. */
IODeviceType getType() const throw() { return type; }
/** Returns the parent graph to which this processor belongs, or 0 if it
hasn't yet been added to one. */
AudioProcessorGraph* getParentGraph() const throw() { return graph; }
/** True if this is an audio or midi input. */
bool isInput() const throw();
/** True if this is an audio or midi output. */
bool isOutput() const throw();
//==============================================================================
AudioGraphIOProcessor (const IODeviceType type);
~AudioGraphIOProcessor();
const String getName() const;
void fillInPluginDescription (PluginDescription& d) const;
void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
void releaseResources();
void processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages);
const String getInputChannelName (const int channelIndex) const;
const String getOutputChannelName (const int channelIndex) const;
bool isInputChannelStereoPair (int index) const;
bool isOutputChannelStereoPair (int index) const;
bool acceptsMidi() const;
bool producesMidi() const;
AudioProcessorEditor* createEditor();
int getNumParameters();
const String getParameterName (int);
float getParameter (int);
const String getParameterText (int);
void setParameter (int, float);
int getNumPrograms();
int getCurrentProgram();
void setCurrentProgram (int);
const String getProgramName (int);
void changeProgramName (int, const String&);
void getStateInformation (JUCE_NAMESPACE::MemoryBlock& destData);
void setStateInformation (const void* data, int sizeInBytes);
/** @internal */
void setParentGraph (AudioProcessorGraph* const graph) throw();
juce_UseDebuggingNewOperator
private:
const IODeviceType type;
AudioProcessorGraph* graph;
AudioGraphIOProcessor (const AudioGraphIOProcessor&);
const AudioGraphIOProcessor& operator= (const AudioGraphIOProcessor&);
};
//==============================================================================
// AudioProcessor methods:
const String getName() const;
void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
void releaseResources();
void processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages);
const String getInputChannelName (const int channelIndex) const;
const String getOutputChannelName (const int channelIndex) const;
bool isInputChannelStereoPair (int index) const;
bool isOutputChannelStereoPair (int index) const;
bool acceptsMidi() const;
bool producesMidi() const;
AudioProcessorEditor* createEditor() { return 0; }
int getNumParameters() { return 0; }
const String getParameterName (int) { return String::empty; }
float getParameter (int) { return 0; }
const String getParameterText (int) { return String::empty; }
void setParameter (int, float) { }
int getNumPrograms() { return 0; }
int getCurrentProgram() { return 0; }
void setCurrentProgram (int) { }
const String getProgramName (int) { return String::empty; }
void changeProgramName (int, const String&) { }
void getStateInformation (JUCE_NAMESPACE::MemoryBlock& destData);
void setStateInformation (const void* data, int sizeInBytes);
/** @internal */
void handleAsyncUpdate();
//==============================================================================
juce_UseDebuggingNewOperator
private:
ReferenceCountedArray <Node> nodes;
OwnedArray <Connection> connections;
int lastNodeId;
AudioSampleBuffer renderingBuffers;
OwnedArray <MidiBuffer> midiBuffers;
CriticalSection renderLock;
VoidArray renderingOps;
friend class AudioGraphIOProcessor;
AudioSampleBuffer* currentAudioIOBuffer;
MidiBuffer* currentMidiIOBuffer;
void clearRenderingSequence();
void buildRenderingSequence();
bool isAnInputTo (const uint32 possibleInputId,
const uint32 possibleDestinationId,
const int recursionCheck) const throw();
AudioProcessorGraph (const AudioProcessorGraph&);
const AudioProcessorGraph& operator= (const AudioProcessorGraph&);
};
#endif // __JUCE_AUDIOPROCESSORGRAPH_JUCEHEADER__
/*
==============================================================================

This file is part of the JUCE library - "Jules' Utility Class Extensions"
Copyright 2004-7 by Raw Material Software ltd.

------------------------------------------------------------------------------

JUCE can be redistributed and/or modified under the terms of the
GNU General Public License, as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later version.

JUCE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with JUCE; if not, visit www.gnu.org/licenses or write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA

------------------------------------------------------------------------------

If you'd like to release a closed-source product which uses JUCE, commercial
licenses are also available: visit www.rawmaterialsoftware.com/juce for
more information.

==============================================================================
*/

#ifndef __JUCE_AUDIOPROCESSORGRAPH_JUCEHEADER__
#define __JUCE_AUDIOPROCESSORGRAPH_JUCEHEADER__

#include "juce_AudioProcessor.h"
#include "../plugins/juce_AudioPluginFormatManager.h"
#include "../plugins/juce_KnownPluginList.h"
#include "../../../juce_core/containers/juce_ReferenceCountedArray.h"


//==============================================================================
/**
A type of AudioProcessor which plays back a graph of other AudioProcessors.

Use one of these objects if you want to wire-up a set of AudioProcessors
and play back the result.

Processors can be added to the graph as "nodes" using addNode(), and once
added, you can connect any of their input or output channels to other
nodes using addConnection().

To play back a graph through an audio device, you might want to use an
AudioProcessorPlayer object.
*/
class JUCE_API AudioProcessorGraph : public AudioProcessor,
public AsyncUpdater
{
public:
//==============================================================================
/** Creates an empty graph.
*/
AudioProcessorGraph();

/** Destructor.

Any processor objects that have been added to the graph will also be deleted.
*/
~AudioProcessorGraph();

//==============================================================================
/** Represents one of the nodes, or processors, in an AudioProcessorGraph.

To create a node, call AudioProcessorGraph::addNode().
*/
class Node : public ReferenceCountedObject
{
public:
/** Destructor.
*/
~Node();

//==============================================================================
/** The ID number assigned to this node.

This is assigned by the graph that owns it, and can't be changed.
*/
const uint32 id;

/** The actual processor object that this node represents.
*/
AudioProcessor* const processor;

/** A set of user-definable properties that are associated with this node.

This can be used to attach values to the node for whatever purpose seems
useful. For example, you might store an x and y position if your application
is displaying the nodes on-screen.
*/
PropertySet properties;

//==============================================================================
/** A convenient typedef for referring to a pointer to a node object.
*/
typedef ReferenceCountedObjectPtr <Node> Ptr;

//==============================================================================
juce_UseDebuggingNewOperator

private:
friend class AudioProcessorGraph;

bool isPrepared;

Node (const uint32 id, AudioProcessor* const processor) throw();

void prepare (const double sampleRate, const int blockSize, AudioProcessorGraph* const graph);
void unprepare();

Node (const Node&);
const Node& operator= (const Node&);
};

//==============================================================================
/** Represents a connection between two channels of two nodes in an AudioProcessorGraph.

To create a connection, use AudioProcessorGraph::addConnection().
*/
struct Connection
{
public:
//==============================================================================
/** The ID number of the node which is the input source for this connection.
@see AudioProcessorGraph::getNodeForId
*/
uint32 sourceNodeId;

/** The index of the output channel of the source node from which this
connection takes its data.

If this value is the special number AudioProcessorGraph::midiChannelIndex, then
it is referring to the source node's midi output. Otherwise, it is the zero-based
index of an audio output channel in the source node.
*/
int sourceChannelIndex;

/** The ID number of the node which is the destination for this connection.
@see AudioProcessorGraph::getNodeForId
*/
uint32 destNodeId;

/** The index of the input channel of the destination node to which this
connection delivers its data.

If this value is the special number AudioProcessorGraph::midiChannelIndex, then
it is referring to the destination node's midi input. Otherwise, it is the zero-based
index of an audio input channel in the destination node.
*/
int destChannelIndex;

//==============================================================================
juce_UseDebuggingNewOperator

private:
};

//==============================================================================
/** Deletes all nodes and connections from this graph.

Any processor objects in the graph will be deleted.
*/
void clear();

/** Returns the number of nodes in the graph. */
int getNumNodes() const throw() { return nodes.size(); }

/** Returns a pointer to one of the nodes in the graph.

This will return 0 if the index is out of range.
@see getNodeForId
*/
Node* getNode (const int index) const throw() { return nodes [index]; }

/** Searches the graph for a node with the given ID number and returns it.

If no such node was found, this returns 0.
@see getNode
*/
Node* getNodeForId (const uint32 nodeId) const throw();

/** Adds a node to the graph.

This creates a new node in the graph, for the specified processor. Once you have
added a processor to the graph, the graph owns it and will delete it later when
it is no longer needed.

The optional nodeId parameter lets you specify an ID to use for the node, but
if the value is already in use, this new node will overwrite the old one.

If this succeeds, it returns a pointer to the newly-created node.
*/
Node* addNode (AudioProcessor* const newProcessor,
uint32 nodeId = 0);

/** Deletes a node within the graph which has the specified ID.

This will also delete any connections that are attached to this node.
*/
bool removeNode (const uint32 nodeId);

//==============================================================================
/** Returns the number of connections in the graph. */
int getNumConnections() const throw() { return connections.size(); }

/** Returns a pointer to one of the connections in the graph. */
const Connection* getConnection (const int index) const throw() { return connections [index]; }

/** Searches for a connection between some specified channels.

If no such connection is found, this returns 0.
*/
const Connection* getConnectionBetween (const uint32 sourceNodeId,
const int sourceChannelIndex,
const uint32 destNodeId,
const int destChannelIndex) const throw();

/** Returns true if there is a connection between any of the channels of
two specified nodes.
*/
bool isConnected (const uint32 possibleSourceNodeId,
const uint32 possibleDestNodeId) const throw();

/** Returns true if it would be legal to connect the specified points.
*/
bool canConnect (const uint32 sourceNodeId, const int sourceChannelIndex,
const uint32 destNodeId, const int destChannelIndex) const throw();

/** Attempts to connect two specified channels of two nodes.

If this isn't allowed (e.g. because you're trying to connect a midi channel
to an audio one or other such nonsense), then it'll return false.
*/
bool addConnection (const uint32 sourceNodeId, const int sourceChannelIndex,
const uint32 destNodeId, const int destChannelIndex);

/** Deletes the connection with the specified index.

Returns true if a connection was actually deleted.
*/
void removeConnection (const int index);

/** Deletes any connection between two specified points.

Returns true if a connection was actually deleted.
*/
bool removeConnection (const uint32 sourceNodeId, const int sourceChannelIndex,
const uint32 destNodeId, const int destChannelIndex);

/** Removes all connections from the specified node.
*/
bool disconnectNode (const uint32 nodeId);

/** Performs a sanity checks of all the connections.

This might be useful if some of the processors are doing things like changing
their channel counts, which could render some connections obsolete.
*/
bool removeIllegalConnections();

//==============================================================================
/** A special number that represents the midi channel of a node.

This is used as a channel index value if you want to refer to the midi input
or output instead of an audio channel.
*/
static const int midiChannelIndex;


//==============================================================================
/** A special type of AudioProcessor that can live inside an AudioProcessorGraph
in order to use the audio that comes into and out of the graph itself.

If you create an AudioGraphIOProcessor in "input" mode, it will act as a
node in the graph which delivers the audio that is coming into the parent
graph. This allows you to stream the data to other nodes and process the
incoming audio.

Likewise, one of these in "output" mode can be sent data which it will add to
the sum of data being sent to the graph's output.

@see AudioProcessorGraph
*/
class AudioGraphIOProcessor : public AudioPluginInstance
{
public:
/** Specifies the mode in which this processor will operate.
*/
enum IODeviceType
{
audioInputNode, /**< In this mode, the processor has output channels
representing all the audio input channels that are
coming into its parent audio graph. */
audioOutputNode, /**< In this mode, the processor has input channels
representing all the audio output channels that are
going out of its parent audio graph. */
midiInputNode, /**< In this mode, the processor has a midi output which
delivers the same midi data that is arriving at its
parent graph. */
midiOutputNode /**< In this mode, the processor has a midi input and
any data sent to it will be passed out of the parent
graph. */
};

//==============================================================================
/** Returns the mode of this processor. */
IODeviceType getType() const throw() { return type; }

/** Returns the parent graph to which this processor belongs, or 0 if it
hasn't yet been added to one. */
AudioProcessorGraph* getParentGraph() const throw() { return graph; }

/** True if this is an audio or midi input. */
bool isInput() const throw();
/** True if this is an audio or midi output. */
bool isOutput() const throw();

//==============================================================================
AudioGraphIOProcessor (const IODeviceType type);
~AudioGraphIOProcessor();

const String getName() const;
void fillInPluginDescription (PluginDescription& d) const;

void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
void releaseResources();
void processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages);

const String getInputChannelName (const int channelIndex) const;
const String getOutputChannelName (const int channelIndex) const;
bool isInputChannelStereoPair (int index) const;
bool isOutputChannelStereoPair (int index) const;
bool acceptsMidi() const;
bool producesMidi() const;

AudioProcessorEditor* createEditor();

int getNumParameters();
const String getParameterName (int);
float getParameter (int);
const String getParameterText (int);
void setParameter (int, float);

int getNumPrograms();
int getCurrentProgram();
void setCurrentProgram (int);
const String getProgramName (int);
void changeProgramName (int, const String&);

void getStateInformation (JUCE_NAMESPACE::MemoryBlock& destData);
void setStateInformation (const void* data, int sizeInBytes);

/** @internal */
void setParentGraph (AudioProcessorGraph* const graph) throw();

juce_UseDebuggingNewOperator

private:
const IODeviceType type;
AudioProcessorGraph* graph;

AudioGraphIOProcessor (const AudioGraphIOProcessor&);
const AudioGraphIOProcessor& operator= (const AudioGraphIOProcessor&);
};

//==============================================================================
// AudioProcessor methods:

const String getName() const;

void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
void releaseResources();
void processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages);

const String getInputChannelName (const int channelIndex) const;
const String getOutputChannelName (const int channelIndex) const;
bool isInputChannelStereoPair (int index) const;
bool isOutputChannelStereoPair (int index) const;

bool acceptsMidi() const;
bool producesMidi() const;

AudioProcessorEditor* createEditor() { return 0; }

int getNumParameters() { return 0; }
const String getParameterName (int) { return String::empty; }
float getParameter (int) { return 0; }
const String getParameterText (int) { return String::empty; }
void setParameter (int, float) { }

int getNumPrograms() { return 0; }
int getCurrentProgram() { return 0; }
void setCurrentProgram (int) { }
const String getProgramName (int) { return String::empty; }
void changeProgramName (int, const String&) { }

void getStateInformation (JUCE_NAMESPACE::MemoryBlock& destData);
void setStateInformation (const void* data, int sizeInBytes);

/** @internal */
void handleAsyncUpdate();

//==============================================================================
juce_UseDebuggingNewOperator

private:
ReferenceCountedArray <Node> nodes;
OwnedArray <Connection> connections;
int lastNodeId;
AudioSampleBuffer renderingBuffers;
OwnedArray <MidiBuffer> midiBuffers;

CriticalSection renderLock;
VoidArray renderingOps;

friend class AudioGraphIOProcessor;
AudioSampleBuffer* currentAudioInputBuffer;
AudioSampleBuffer currentAudioOutputBuffer;
MidiBuffer* currentMidiInputBuffer;
MidiBuffer currentMidiOutputBuffer;

void clearRenderingSequence();
void buildRenderingSequence();

bool isAnInputTo (const uint32 possibleInputId,
const uint32 possibleDestinationId,
const int recursionCheck) const throw();

AudioProcessorGraph (const AudioProcessorGraph&);
const AudioProcessorGraph& operator= (const AudioProcessorGraph&);
};


#endif // __JUCE_AUDIOPROCESSORGRAPH_JUCEHEADER__

Loading…
Cancel
Save