From aab8d414cabbbeff46c90ebd291aff1d68f04c5f Mon Sep 17 00:00:00 2001 From: falkTX Date: Tue, 31 Oct 2017 14:07:35 +0100 Subject: [PATCH] The minified juce graph class is done --- .../juce_audio_graph/juce_audio_graph.cpp | 2 +- .../juce_audio_graph/juce_audio_graph.h | 5 +- .../processors/juce_AudioProcessorGraph.cpp | 120 +++--------------- .../processors/juce_AudioProcessorGraph.h | 13 +- 4 files changed, 30 insertions(+), 110 deletions(-) diff --git a/source/modules/juce_audio_graph/juce_audio_graph.cpp b/source/modules/juce_audio_graph/juce_audio_graph.cpp index ddd1252a5..0c2e7ce24 100644 --- a/source/modules/juce_audio_graph/juce_audio_graph.cpp +++ b/source/modules/juce_audio_graph/juce_audio_graph.cpp @@ -33,7 +33,7 @@ // #include //============================================================================== -namespace juce +namespace juce2 { #include "memory/juce_MemoryBlock.cpp" diff --git a/source/modules/juce_audio_graph/juce_audio_graph.h b/source/modules/juce_audio_graph/juce_audio_graph.h index 1e1db136f..a8b3cffe3 100644 --- a/source/modules/juce_audio_graph/juce_audio_graph.h +++ b/source/modules/juce_audio_graph/juce_audio_graph.h @@ -106,7 +106,7 @@ #define NEEDS_TRANS(x) (x) //============================================================================== -namespace juce +namespace juce2 { class File; @@ -127,12 +127,15 @@ class StringRef; #include "memory/juce_HeapBlock.h" #include "memory/juce_MemoryBlock.h" +#include "memory/juce_ReferenceCountedObject.h" #include "text/juce_NewLine.h" #include "containers/juce_ElementComparator.h" #include "containers/juce_ArrayAllocationBase.h" #include "containers/juce_Array.h" #include "containers/juce_OwnedArray.h" +#include "containers/juce_ReferenceCountedArray.h" +#include "containers/juce_SortedSet.h" // #include "containers/juce_Variant.h" // #include "containers/juce_NamedValueSet.h" diff --git a/source/modules/juce_audio_graph/processors/juce_AudioProcessorGraph.cpp b/source/modules/juce_audio_graph/processors/juce_AudioProcessorGraph.cpp index 636aefeb2..c645e3845 100644 --- a/source/modules/juce_audio_graph/processors/juce_AudioProcessorGraph.cpp +++ b/source/modules/juce_audio_graph/processors/juce_AudioProcessorGraph.cpp @@ -26,38 +26,6 @@ const int AudioProcessorGraph::midiChannelIndex = 0x1000; -#if 0 -//============================================================================== -template struct FloatDoubleUtil {}; -template struct FloatDoubleType {}; - -template -struct FloatAndDoubleComposition -{ - typedef typename FloatDoubleType::Type FloatType; - typedef typename FloatDoubleType::Type DoubleType; - - template - inline typename FloatDoubleType::Type& get() noexcept - { - return FloatDoubleUtil >::get (*this); - } - - FloatType floatVersion; - DoubleType doubleVersion; -}; - -template struct FloatDoubleUtil { static inline typename Impl::FloatType& get (Impl& i) noexcept { return i.floatVersion; } }; -template struct FloatDoubleUtil { static inline typename Impl::DoubleType& get (Impl& i) noexcept { return i.doubleVersion; } }; - -struct FloatPlaceholder; - -template struct FloatDoubleType, FloatingType> { typedef HeapBlock Type; }; -template struct FloatDoubleType, FloatingType> { typedef HeapBlock Type; }; -template struct FloatDoubleType, FloatingType> { typedef AudioBuffer Type; }; -template struct FloatDoubleType*, FloatingType> { typedef AudioBuffer* Type; }; -#endif - //============================================================================== namespace GraphRenderingOps { @@ -219,7 +187,6 @@ private: JUCE_DECLARE_NON_COPYABLE (DelayChannelOp) }; -#if 0 //============================================================================== struct ProcessBufferOp : public AudioGraphRenderingOp { @@ -241,7 +208,7 @@ struct ProcessBufferOp : public AudioGraphRenderingOp void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray& sharedMidiBuffers, const int numSamples) { - HeapBlock& channels = audioChannels(); + HeapBlock& channels = audioChannels; for (int i = totalChans; --i >= 0;) channels[i] = sharedBufferChans.getWritePointer (audioChannelsToUse.getUnchecked (i), 0); @@ -270,14 +237,13 @@ struct ProcessBufferOp : public AudioGraphRenderingOp private: Array audioChannelsToUse; - FloatAndDoubleComposition > audioChannels; + HeapBlock audioChannels; AudioSampleBuffer tempBuffer; const int totalChans; const int midiBufferToUse; JUCE_DECLARE_NON_COPYABLE (ProcessBufferOp) }; -#endif //============================================================================== /** Used to calculate the correct sequence of rendering ops needed, based on @@ -303,9 +269,7 @@ struct RenderingOpSequenceCalculator markAnyUnusedBuffersAsFree (i); } -#if 0 graph.setLatencySamples (totalLatency); -#endif } int getNumBuffersNeeded() const noexcept { return nodeIds.size(); } @@ -363,15 +327,10 @@ private: Array& renderingOps, const int ourRenderingIndex) { -#if 0 AudioProcessor& processor = *node.getProcessor(); const int numIns = processor.getTotalNumInputChannels(); const int numOuts = processor.getTotalNumOutputChannels(); const int totalChans = jmax (numIns, numOuts); -#else - const int numIns = 0; - const int numOuts = 0; -#endif Array audioChannelsToUse; int midiBufferToUse = -1; @@ -566,10 +525,8 @@ private: // No midi inputs.. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi -#if 0 if (processor.acceptsMidi() || processor.producesMidi()) renderingOps.add (new ClearMidiBufferOp (midiBufferToUse)); -#endif } else if (midiSourceNodes.size() == 1) { @@ -648,7 +605,6 @@ private: } } -#if 0 if (processor.producesMidi()) markBufferAsContaining (midiBufferToUse, node.nodeId, AudioProcessorGraph::midiChannelIndex); @@ -660,7 +616,6 @@ private: renderingOps.add (new ProcessBufferOp (&node, audioChannelsToUse, totalChans, midiBufferToUse)); -#endif } //============================================================================== @@ -754,13 +709,11 @@ private: } else { -#if 0 for (int i = 0; i < node->getProcessor()->getTotalNumInputChannels(); ++i) if (i != inputChannelOfIndexToIgnore && graph.getConnectionBetween (nodeId, outputChanIndex, node->nodeId, i) != nullptr) return true; -#endif } inputChannelOfIndexToIgnore = -1; @@ -810,9 +763,7 @@ public: entries.insert (index, entry); } -#if 0 entry->srcNodes.add (c->sourceNodeId); -#endif } } @@ -829,9 +780,7 @@ private: explicit Entry (const uint32 destNodeId_) noexcept : destNodeId (destNodeId_) {} const uint32 destNodeId; -#if 0 SortedSet srcNodes; -#endif JUCE_DECLARE_NON_COPYABLE (Entry) }; @@ -846,7 +795,6 @@ private: if (const Entry* const entry = findEntry (possibleDestinationId, index)) { -#if 0 const SortedSet& srcNodes = entry->srcNodes; if (srcNodes.contains (possibleInputId)) @@ -858,10 +806,6 @@ private: if (isAnInputToRecursive (possibleInputId, srcNodes.getUnchecked(i), recursionCheck)) return true; } -#else - (void)possibleInputId; - (void)recursionCheck; -#endif } return false; @@ -1010,7 +954,7 @@ struct AudioProcessorGraph::AudioProcessorGraphBufferHelpers //============================================================================== AudioProcessorGraph::AudioProcessorGraph() : lastNodeId (0), audioBuffers (new AudioProcessorGraphBufferHelpers), - currentMidiInputBuffer (nullptr), isPrepared (false) + currentMidiInputBuffer (nullptr), isPrepared (false), needsReorder (false) { } @@ -1028,16 +972,11 @@ const String AudioProcessorGraph::getName() const //============================================================================== void AudioProcessorGraph::clear() { -#if 0 nodes.clear(); -#endif connections.clear(); -#if 0 - triggerAsyncUpdate(); -#endif + needsReorder = true; } -#if 0 AudioProcessorGraph::Node* AudioProcessorGraph::getNodeForId (const uint32 nodeId) const { for (int i = nodes.size(); --i >= 0;) @@ -1084,7 +1023,7 @@ AudioProcessorGraph::Node* AudioProcessorGraph::addNode (AudioProcessor* const n nodes.add (n); if (isPrepared) - triggerAsyncUpdate(); + needsReorder = true; n->setParentGraph (this); return n; @@ -1101,7 +1040,7 @@ bool AudioProcessorGraph::removeNode (const uint32 nodeId) nodes.remove (i); if (isPrepared) - triggerAsyncUpdate(); + needsReorder = true; return true; } @@ -1118,7 +1057,6 @@ bool AudioProcessorGraph::removeNode (Node* node) jassertfalse; return false; } -#endif //============================================================================== const AudioProcessorGraph::Connection* AudioProcessorGraph::getConnectionBetween (const uint32 sourceNodeId, @@ -1148,7 +1086,6 @@ bool AudioProcessorGraph::isConnected (const uint32 possibleSourceNodeId, return false; } -#if 0 bool AudioProcessorGraph::canConnect (const uint32 sourceNodeId, const int sourceChannelIndex, const uint32 destNodeId, @@ -1177,7 +1114,6 @@ bool AudioProcessorGraph::canConnect (const uint32 sourceNodeId, return getConnectionBetween (sourceNodeId, sourceChannelIndex, destNodeId, destChannelIndex) == nullptr; } -#endif bool AudioProcessorGraph::addConnection (const uint32 sourceNodeId, const int sourceChannelIndex, @@ -1191,10 +1127,8 @@ bool AudioProcessorGraph::addConnection (const uint32 sourceNodeId, connections.addSorted (sorter, new Connection (sourceNodeId, sourceChannelIndex, destNodeId, destChannelIndex)); -#if 0 if (isPrepared) - triggerAsyncUpdate(); -#endif + needsReorder = true; return true; } @@ -1203,10 +1137,8 @@ void AudioProcessorGraph::removeConnection (const int index) { connections.remove (index); -#if 0 if (isPrepared) - triggerAsyncUpdate(); -#endif + needsReorder = true; } bool AudioProcessorGraph::removeConnection (const uint32 sourceNodeId, const int sourceChannelIndex, @@ -1249,7 +1181,6 @@ bool AudioProcessorGraph::disconnectNode (const uint32 nodeId) return doneAnything; } -#if 0 bool AudioProcessorGraph::isConnectionLegal (const Connection* const c) const { jassert (c != nullptr); @@ -1264,7 +1195,6 @@ bool AudioProcessorGraph::isConnectionLegal (const Connection* const c) const && (c->destChannelIndex != midiChannelIndex ? isPositiveAndBelow (c->destChannelIndex, dest->processor->getTotalNumInputChannels()) : dest->processor->acceptsMidi()); } -#endif bool AudioProcessorGraph::removeIllegalConnections() { @@ -1301,7 +1231,6 @@ void AudioProcessorGraph::clearRenderingSequence() deleteRenderOpArray (oldOps); } -#if 0 bool AudioProcessorGraph::isAnInputTo (const uint32 possibleInputId, const uint32 possibleDestinationId, const int recursionCheck) const @@ -1321,7 +1250,6 @@ bool AudioProcessorGraph::isAnInputTo (const uint32 possibleInputId, return false; } -#endif void AudioProcessorGraph::buildRenderingSequence() { @@ -1330,21 +1258,18 @@ void AudioProcessorGraph::buildRenderingSequence() int numMidiBuffersNeeded = 1; { -#if 0 - MessageManagerLock mml; -#endif + const CarlaRecursiveMutexLocker cml (reorderMutex); Array orderedNodes; { const GraphRenderingOps::ConnectionLookupTable table (connections); -#if 0 for (int i = 0; i < nodes.size(); ++i) { Node* const node = nodes.getUnchecked(i); - node->prepare (getSampleRate(), getBlockSize(), this, getProcessingPrecision()); + node->prepare (getSampleRate(), getBlockSize(), this); int j = 0; for (; j < orderedNodes.size(); ++j) @@ -1353,7 +1278,6 @@ void AudioProcessorGraph::buildRenderingSequence() orderedNodes.insert (j, node); } -#endif } GraphRenderingOps::RenderingOpSequenceCalculator calculator (*this, orderedNodes, newRenderingOps); @@ -1381,13 +1305,6 @@ void AudioProcessorGraph::buildRenderingSequence() deleteRenderOpArray (newRenderingOps); } -#if 0 -void AudioProcessorGraph::handleAsyncUpdate() -{ - buildRenderingSequence(); -} -#endif - //============================================================================== void AudioProcessorGraph::prepareToPlay (double /*sampleRate*/, int estimatedSamplesPerBlock) { @@ -1406,10 +1323,8 @@ void AudioProcessorGraph::releaseResources() { isPrepared = false; -#if 0 for (int i = 0; i < nodes.size(); ++i) nodes.getUnchecked(i)->unprepare(); -#endif audioBuffers->release(); midiBuffers.clear(); @@ -1422,10 +1337,8 @@ void AudioProcessorGraph::reset() { const CarlaRecursiveMutexLocker cml (getCallbackLock()); -#if 0 for (int i = 0; i < nodes.size(); ++i) nodes.getUnchecked(i)->getProcessor()->reset(); -#endif } void AudioProcessorGraph::setNonRealtime (bool isProcessingNonRealtime) noexcept @@ -1434,10 +1347,8 @@ void AudioProcessorGraph::setNonRealtime (bool isProcessingNonRealtime) noexcept AudioProcessor::setNonRealtime (isProcessingNonRealtime); -#if 0 for (int i = 0; i < nodes.size(); ++i) nodes.getUnchecked(i)->getProcessor()->setNonRealtime (isProcessingNonRealtime); -#endif } void AudioProcessorGraph::setPlayHead (AudioPlayHead* audioPlayHead) @@ -1446,10 +1357,8 @@ void AudioProcessorGraph::setPlayHead (AudioPlayHead* audioPlayHead) AudioProcessor::setPlayHead (audioPlayHead); -#if 0 for (int i = 0; i < nodes.size(); ++i) nodes.getUnchecked(i)->getProcessor()->setPlayHead (audioPlayHead); -#endif } void AudioProcessorGraph::processAudio (AudioSampleBuffer& buffer, MidiBuffer& midiMessages) @@ -1490,6 +1399,15 @@ void AudioProcessorGraph::processBlock (AudioSampleBuffer& buffer, MidiBuffer& m processAudio (buffer, midiMessages); } +void AudioProcessorGraph::reorderNowIfNeeded() +{ + if (needsReorder) + { + needsReorder = false; + buildRenderingSequence(); + } +} + //============================================================================== AudioProcessorGraph::AudioGraphIOProcessor::AudioGraphIOProcessor (const IODeviceType deviceType) : type (deviceType), graph (nullptr) diff --git a/source/modules/juce_audio_graph/processors/juce_AudioProcessorGraph.h b/source/modules/juce_audio_graph/processors/juce_AudioProcessorGraph.h index faca741c0..5db476658 100644 --- a/source/modules/juce_audio_graph/processors/juce_AudioProcessorGraph.h +++ b/source/modules/juce_audio_graph/processors/juce_AudioProcessorGraph.h @@ -59,7 +59,7 @@ public: To create a node, call AudioProcessorGraph::addNode(). */ - class JUCE_API Node /*: public ReferenceCountedObject*/ + class JUCE_API Node : public ReferenceCountedObject { public: //============================================================================== @@ -79,11 +79,11 @@ public: is displaying the nodes on-screen. */ NamedValueSet properties; +#endif //============================================================================== /** A convenient typedef for referring to a pointer to a node object. */ typedef ReferenceCountedObjectPtr Ptr; -#endif private: //============================================================================== @@ -153,7 +153,6 @@ public: */ void clear(); -#if 0 /** Returns the number of nodes in the graph. */ int getNumNodes() const noexcept { return nodes.size(); } @@ -193,7 +192,6 @@ public: This will also delete any connections that are attached to this node. */ bool removeNode (Node* node); -#endif //============================================================================== /** Returns the number of connections in the graph. */ @@ -354,14 +352,14 @@ public: bool acceptsMidi() const override; bool producesMidi() const override; + void reorderNowIfNeeded(); + private: //============================================================================== void processAudio (AudioSampleBuffer& buffer, MidiBuffer& midiMessages); //============================================================================== -#if 0 ReferenceCountedArray nodes; -#endif OwnedArray connections; uint32 lastNodeId; OwnedArray midiBuffers; @@ -374,7 +372,8 @@ private: MidiBuffer* currentMidiInputBuffer; MidiBuffer currentMidiOutputBuffer; - bool isPrepared; + bool isPrepared, needsReorder; + CarlaRecursiveMutex reorderMutex; void clearRenderingSequence(); void buildRenderingSequence();