/* * Copyright (C) 2002 - David W. Durham * * This file is part of ReZound, an audio editing application. * * ReZound is free software; you can redistribute it and/or modify * it 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. * * ReZound 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #include "CPluginMapping.h" CPluginMapping::CPluginMapping() : outputAppendCount(0), outputRemoveCount(0) { } CPluginMapping::CPluginMapping(const CPluginMapping &src) : outputAppendCount(src.outputAppendCount), inputMappings(src.inputMappings), outputMappings(src.outputMappings), passThrus(src.passThrus), //outputSwapChannels(src.outputSwapChannels), outputRemoveCount(src.outputRemoveCount) { } CPluginMapping &CPluginMapping::operator=(const CPluginMapping &rhs) { outputAppendCount=rhs.outputAppendCount; inputMappings=rhs.inputMappings; outputMappings=rhs.outputMappings; passThrus=rhs.passThrus; //outputSwapChannels=rhs.outputSwapChannels; outputRemoveCount=rhs.outputRemoveCount; return *this; } CPluginMapping::~CPluginMapping() { } #include void CPluginMapping::writeToFile(CNestedDataFile *f,const string key) const { f->setValue(key DOT "outputAppendCount",outputAppendCount); // write inputMappings f->setValue(key DOT "n_inputMappings0",inputMappings.size()); for(size_t a=0;asetValue(key_a DOT "n_inputMappings1",inputMappings[a].size()); for(size_t b=0;bsetValue(key_b DOT "n_inputMappings2",inputMappings[a][b].size()); for(size_t c=0;csetValue(key DOT "n_outputMappings0",outputMappings.size()); for(size_t a=0;asetValue(key_a DOT "n_outputMappings1",outputMappings[a].size()); for(size_t b=0;bsetValue(key_b DOT "n_outputMappings2",outputMappings[a][b].size()); for(size_t c=0;csetValue(key DOT "n_passThrus0",passThrus.size()); for(size_t a=0;asetValue(key_a DOT "n_passThrus1",passThrus[a].size()); for(size_t b=0;bsetValue(key DOT "outputRemoveCount",outputRemoveCount); } void CPluginMapping::readFromFile(const CNestedDataFile *f,const string key) { outputAppendCount=f->getValue(key DOT "outputAppendCount"); // write inputMappings inputMappings.clear(); size_t inputMappingsSize_a=f->getValue(key DOT "n_inputMappings0"); for(size_t a=0;a > inputMapping_a; const string key_a=key DOT "sub"+istring(a); size_t inputMappingsSize_b=f->getValue(key_a DOT "n_inputMappings1"); for(size_t b=0;b inputMapping_b; const string key_b=key_a DOT "sub"+istring(b); size_t inputMappingsSize_c=f->getValue(key_b DOT "n_inputMappings2"); for(size_t c=0;cgetValue(key DOT "n_outputMappings0"); for(size_t a=0;a > outputMapping_a; const string key_a=key DOT "sub"+istring(a); size_t outputMappingsSize_b=f->getValue(key_a DOT "n_outputMappings1"); for(size_t b=0;b outputMapping_b; const string key_b=key_a DOT "sub"+istring(b); size_t outputMappingsSize_c=f->getValue(key_b DOT "n_outputMappings2"); for(size_t c=0;cgetValue(key DOT "n_passThrus0"); for(size_t a=0;a passThru_a; const string key_a=key DOT "sub"+istring(a); size_t passThrusSize_b=f->getValue(key_a DOT "n_passThrus1"); for(size_t b=0;bgetValue(key DOT "outputRemoveCount"); } #include "CSound.h" const CPluginMapping CPluginMapping::getDefaultMapping(const string pluginName,unsigned pluginInputPorts,unsigned pluginOutputPorts,const CSound *sound) { #warning the case (but generalize it) that there is one input, one channel, and two outputs, append a channel and map both outputs CPluginMapping m; // locate which index to default things to by looking at what index is sound at size_t soundFileManagerIndex=0; /* don't have it to look for.. so just leave as zero for now for(size_t t=0;tgetOpenedCount();t++) { if(soundFileManager->getSound(t)->sound==sound) { soundFileManagerindex=t; break; } } */ if(pluginInputPorts>pluginOutputPorts) { throw runtime_error(string(__func__)+" -- unimplemented that input ports is greater than output ports"); } else if(pluginInputPorts==pluginOutputPorts) { if(pluginInputPorts==0) throw runtime_error("Both input and output ports for this plugin are 0"); if((sound->getChannelCount()%pluginInputPorts)==0) { unsigned srcChannel=0; unsigned destChannel=0; for(unsigned t=0;tgetChannelCount()/pluginInputPorts;t++) { // create a new iteration of the plugin (for instance if the plugin has 1 input port (and same # outputs) and the sound has 2 channels, then we would iterate the plugin twice) m.inputMappings.push_back(vector > >::value_type()); m.outputMappings.push_back(vector > >::value_type()); vector > &inputMapping=m.inputMappings[t]; vector > &outputMapping=m.outputMappings[t]; // make the input ports (for this iteration) point to the next N src channels (where N is the number of input ports on the plugin) for(unsigned i=0;i v; v.push_back(CPluginMapping::RInputDesc(soundFileManagerIndex,srcChannel++,CPluginMapping::RInputDesc::wdroSilence,CPluginMapping::RInputDesc::hmSelection,1)); inputMapping.push_back(v); } // make the sound's next N channels map to the output ports (where N is the numbetr of output ports on the plugin (same # as inputs in this case)) for(unsigned i=0;igetChannelCount();i++) outputMapping.push_back(vector >::value_type()); for(unsigned i=0;ipluginOutputPorts) { if(pluginInputPorts==0) { // sound generation plugin (no audio inputs, only outputs) // add more channels if needed if(pluginOutputPorts>sound->getChannelCount()) m.outputAppendCount=sound->getChannelCount()-pluginOutputPorts; // ??? possibly remove channels if there are more channels in the action sound that the plugin's output? // create one iteration of the plugin // and even tho there is no input, there needs to be a single empty mapping (moreover, the inputMappings and outputMappings vectors are supposed to be parallel) m.inputMappings.push_back(vector > >::value_type()); m.outputMappings.push_back(vector > >::value_type()); // this is the output mapping of the single iteration vector > &outputMapping=m.outputMappings[0]; // for each output port on the plugin, map it to the same indexed channel on the action sound (and there should be enough channels in the action sound) for(unsigned i=0;i >::value_type()); outputMapping[i].push_back(CPluginMapping::ROutputDesc(i,1)); } } else { throw runtime_error(string(__func__)+" -- unimplemented that input ports is greater than output ports"); } } return m; } bool CPluginMapping::somethingMappedToAnOutput() const { for(size_t t=0;t0) return true; } } for(size_t t=0;t0) return true; } return false; } #include void CPluginMapping::print() const { printf("outputAppendCount: %d\n",outputAppendCount); printf("inputMappings:\n"); for(size_t t=0;tsetValue(key DOT "soundFileManagerIndex",soundFileManagerIndex); f->setValue(key DOT "channel",channel); f->setValue(key DOT "wdro",(unsigned)wdro); f->setValue(key DOT "howMuch",(unsigned)howMuch); f->setValue(key DOT "gain",gain); } void CPluginMapping::RInputDesc::readFromFile(const CNestedDataFile *f,const string key) { soundFileManagerIndex=f->getValue(key DOT "soundFileManagerIndex"); channel=f->getValue(key DOT "channel"); wdro=(WhenDataRunsOut)f->getValue(key DOT "wdro"); howMuch=(HowMuch)f->getValue(key DOT "howMuch"); gain=f->getValue(key DOT "gain"); } void CPluginMapping::ROutputDesc::writeToFile(CNestedDataFile *f,const string key) const { f->setValue(key DOT "channel",channel); f->setValue(key DOT "gain",gain); } void CPluginMapping::ROutputDesc::readFromFile(const CNestedDataFile *f,const string key) { channel=f->getValue(key DOT "channel"); gain=f->getValue(key DOT "gain"); }