![]() |
pl-nk v0.4.5
Plonk|Plink|Plank are a set of cross-platform C/C++ frameworks for audio software development
|
00001 /* 00002 ------------------------------------------------------------------------------- 00003 This file is part of the Plink, Plonk, Plank libraries 00004 by Martin Robinson 00005 00006 http://code.google.com/p/pl-nk/ 00007 00008 Copyright University of the West of England, Bristol 2011-14 00009 All rights reserved. 00010 00011 Redistribution and use in source and binary forms, with or without 00012 modification, are permitted provided that the following conditions are met: 00013 00014 * Redistributions of source code must retain the above copyright 00015 notice, this list of conditions and the following disclaimer. 00016 * Redistributions in binary form must reproduce the above copyright 00017 notice, this list of conditions and the following disclaimer in the 00018 documentation and/or other materials provided with the distribution. 00019 * Neither the name of University of the West of England, Bristol nor 00020 the names of its contributors may be used to endorse or promote products 00021 derived from this software without specific prior written permission. 00022 00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00024 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00025 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00026 DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF THE WEST OF ENGLAND, BRISTOL BE 00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 00034 This software makes use of third party libraries. For more information see: 00035 doc/license.txt included in the distribution. 00036 ------------------------------------------------------------------------------- 00037 */ 00038 00039 #ifndef PLONK_PROXYOWNERCHANNELINTERNAL_H 00040 #define PLONK_PROXYOWNERCHANNELINTERNAL_H 00041 00042 #include "../plonk_GraphForwardDeclarations.h" 00043 #include "../utility/plonk_ProcessInfo.h" 00044 00058 template<class SampleType, class DataType> 00059 class ProxyOwnerChannelInternal : public ChannelInternal<SampleType, DataType> 00060 { 00061 public: 00062 typedef ChannelBase<SampleType> ChannelType; 00063 typedef ObjectArray<ChannelType> ChannelArrayType; 00064 typedef WeakPointerContainer<ChannelType> WeakChannelType; 00065 typedef SimpleArray<WeakChannelType> WeakChannelArrayType; 00066 typedef ChannelInternalBase<SampleType> InternalBase; 00067 typedef ChannelInternal<SampleType,DataType> Internal; 00068 typedef ProxyChannelInternal<SampleType> ProxyInternal; 00069 typedef UnitBase<SampleType> UnitType; 00070 typedef InputDictionary Inputs; 00071 typedef NumericalArray<SampleType> Buffer; 00072 typedef ObjectArray<Buffer> BufferArray; 00073 typedef typename ProxyInternal::Data ProxyData; 00074 00075 ProxyOwnerChannelInternal (const int numOutputs, 00076 Inputs const& inputs, 00077 DataType const& data, 00078 BlockSize const& blockSize, 00079 SampleRate const& sampleRate, 00080 ChannelArrayType& proxyChannels) throw() 00081 : Internal (inputs, data, blockSize, sampleRate)//, ready (false), fullyInitialised (false) 00082 { 00083 plonk_assert (numOutputs >= 1); 00084 00085 proxyChannels.setSize (numOutputs, false); 00086 channelBuffers.setSize (numOutputs, false); 00087 proxies.getInternal()->setSize (numOutputs, false); 00088 00089 WeakChannelType* proxiesArray = proxies.getInternal()->getArray(); 00090 00091 InternalBase* const ownerInternal = this; 00092 ChannelType ownerChannel = ChannelType (ownerInternal); 00093 proxyChannels.put (0, ownerChannel); 00094 proxiesArray[0] = WeakChannelType (ownerChannel); 00095 channelBuffers[0] = InternalBase::getOutputBuffer(); 00096 00097 const ProxyData& proxyData (reinterpret_cast<ProxyData const&> (data)); 00098 00099 for (int i = 1; i < numOutputs; ++i) 00100 { 00101 InternalBase* proxyInternal 00102 = new ProxyInternal (ownerChannel, 00103 proxyData, 00104 blockSize, 00105 sampleRate, 00106 i); 00107 00108 ChannelType channel = ChannelType (proxyInternal); 00109 proxyChannels.put (i, channel); 00110 proxiesArray[i] = WeakChannelType (channel); 00111 channelBuffers[i] = proxyInternal->getOutputBuffer(); 00112 } 00113 } 00114 00115 bool isProxyOwner() const throw() 00116 { 00117 return true; 00118 } 00119 00120 InternalBase* getChannel (const int /*index*/) throw() 00121 { 00122 return this; 00123 } 00124 00125 inline const SampleType* getOutputSamples (const int index) const throw() 00126 { 00127 return channelBuffers.atUnchecked (index).getArray(); 00128 } 00129 00130 inline SampleType* getOutputSamples (const int index) throw() 00131 { 00132 return channelBuffers.atUnchecked (index).getArray(); 00133 } 00134 00135 inline const Buffer& getOutputBuffer (const int index) const throw() 00136 { 00137 return channelBuffers.atUnchecked (index); 00138 } 00139 00140 inline Buffer& getOutputBuffer (const int index) throw() 00141 { 00142 return channelBuffers.atUnchecked (index); 00143 } 00144 00145 int getNumChannels() const throw() 00146 { 00147 return proxies.getInternal()->length(); 00148 } 00149 00150 void initProxyValue (const int index, SampleType const& value) 00151 { 00152 plonk_assert (index >= 0); 00153 plonk_assert (index < proxies.getInternal()->length()); 00154 WeakChannelType* proxiesArray = proxies.getInternal()->getArray(); 00155 00156 if (proxiesArray[index].isAlive()) 00157 proxiesArray[index].fromWeak().initValue (value); 00158 } 00159 00160 ChannelType getProxy (const int index) throw() 00161 { 00162 plonk_assert (index >= 0); 00163 plonk_assert (index < proxies.getInternal()->length()); 00164 WeakChannelType* proxiesArray = proxies.getInternal()->getArray(); 00165 00166 plonk_assert (proxiesArray[index].isAlive()); 00167 00168 return proxiesArray[index].fromWeak(); 00169 } 00170 00171 void setBlockSize (BlockSize const& newBlockSize) throw() 00172 { 00173 InternalBase::setBlockSize (newBlockSize); 00174 00175 const int numProxies = proxies.getInternal()->length(); 00176 WeakChannelType* proxiesArray = proxies.getInternal()->getArray(); 00177 00178 for (int i = 1; i < numProxies; ++i) 00179 { 00180 if (proxiesArray[i].isAlive()) 00181 proxiesArray[i].fromWeak().setBlockSize (newBlockSize); 00182 } 00183 } 00184 00185 void setSampleRate (SampleRate const& newSampleRate) throw() 00186 { 00187 Internal::setSampleRate (newSampleRate); 00188 00189 const int numProxies = proxies.getInternal()->length(); 00190 WeakChannelType* proxiesArray = proxies.getInternal()->getArray(); 00191 00192 for (int i = 1; i < numProxies; ++i) 00193 { 00194 if (proxiesArray[i].isAlive()) 00195 proxiesArray[i].fromWeak().setSampleRate (newSampleRate); 00196 } 00197 } 00198 00199 void setOverlap (DoubleVariable const& newOverlap) throw() 00200 { 00201 Internal::setOverlap (newOverlap); 00202 00203 const int numProxies = proxies.getInternal()->length(); 00204 WeakChannelType* proxiesArray = proxies.getInternal()->getArray(); 00205 00206 for (int i = 1; i < numProxies; ++i) 00207 { 00208 if (proxiesArray[i].isAlive()) 00209 proxiesArray[i].fromWeak().setOverlap (newOverlap); 00210 } 00211 } 00212 00213 private: 00214 WeakChannelArrayType proxies; 00215 BufferArray channelBuffers; 00216 }; 00217 00218 00219 00220 00221 #endif // PLONK_PROXYOWNERCHANNELINTERNAL_H 00222