c@97: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
c@97: 
c@97: /*
c@97:     Piper C++
c@97: 
c@97:     An API for audio analysis and feature extraction plugins.
c@97: 
c@97:     Centre for Digital Music, Queen Mary, University of London.
c@97:     Copyright 2006-2016 Chris Cannam and QMUL.
c@97:   
c@97:     Permission is hereby granted, free of charge, to any person
c@97:     obtaining a copy of this software and associated documentation
c@97:     files (the "Software"), to deal in the Software without
c@97:     restriction, including without limitation the rights to use, copy,
c@97:     modify, merge, publish, distribute, sublicense, and/or sell copies
c@97:     of the Software, and to permit persons to whom the Software is
c@97:     furnished to do so, subject to the following conditions:
c@97: 
c@97:     The above copyright notice and this permission notice shall be
c@97:     included in all copies or substantial portions of the Software.
c@97: 
c@97:     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
c@97:     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
c@97:     MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
c@97:     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
c@97:     ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
c@97:     CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
c@97:     WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
c@97: 
c@97:     Except as contained in this notice, the names of the Centre for
c@97:     Digital Music; Queen Mary, University of London; and Chris Cannam
c@97:     shall not be used in advertising or otherwise to promote the sale,
c@97:     use or other dealings in this Software without prior written
c@97:     authorization.
c@97: */
c@97: 
c@97: #ifndef PIPER_PLUGIN_CONFIGURATION_H
c@97: #define PIPER_PLUGIN_CONFIGURATION_H
c@97: 
c@97: #include <vamp-hostsdk/Plugin.h>
c@97: 
c@97: #include <map>
c@97: #include <string>
c@97: 
c@97: namespace piper_vamp {
c@97: 
c@97: /**
cannam@185:  * \struct Framing
cannam@185:  * 
cannam@185:  * A structure bundling the processing step and block size.
cannam@185:  */
cannam@185: struct Framing
cannam@185: {
cannam@185:     Framing() : // invalid by default 
cannam@185:         stepSize(0), blockSize(0) { }
cannam@185:     
cannam@185:     int stepSize;
cannam@185:     int blockSize;
cannam@185: };
cannam@185: 
cannam@185: /**
c@97:  * \class PluginConfiguration
c@97:  * 
c@97:  * PluginConfiguration is a structure bundling together data that
c@97:  * affect the configuration of a plugin: parameter values, programs,
c@97:  * and initialisation settings. Although an interactive Vamp plugin
c@97:  * host may configure a plugin in stages, for example to take into
c@97:  * account that a plugin's preferred step and block size may change
c@97:  * when its parameters are changed, a batch host or a host supporting
c@97:  * store and recall of configurations may wish to keep all
c@97:  * configuration settings together.
c@97:  */
c@97: struct PluginConfiguration
c@97: {
c@97:     PluginConfiguration() : // invalid configuration by default
cannam@185: 	channelCount(0) { }
c@97: 	
c@97:     int channelCount;
cannam@185:     Framing framing;
c@97:     typedef std::map<std::string, float> ParameterMap;
c@97:     ParameterMap parameterValues;
c@97:     std::string currentProgram;
c@97: 
c@97:     static PluginConfiguration
c@97:     fromPlugin(Vamp::Plugin *p,
c@97: 	       int channelCount,
c@97: 	       int stepSize,
c@97: 	       int blockSize) {
c@97: 	
c@97: 	PluginConfiguration c;
c@97: 	
c@97: 	c.channelCount = channelCount;
cannam@185: 	c.framing.stepSize = stepSize;
cannam@185: 	c.framing.blockSize = blockSize;
c@97: 
c@97: 	Vamp::PluginBase::ParameterList params = p->getParameterDescriptors();
c@97: 	for (Vamp::PluginBase::ParameterList::const_iterator i = params.begin();
c@97: 	     i != params.end(); ++i) {
c@97: 	    std::string pid = i->identifier;
c@97: 	    c.parameterValues[pid] = p->getParameter(pid);
c@97: 	}
c@97: 	
c@97: 	if (!p->getPrograms().empty()) {
c@97: 	    c.currentProgram = p->getCurrentProgram();
c@97: 	}
c@97: 
c@97: 	return c;
c@97:     }
c@97: };
c@97: 
c@97: }
c@97: 
c@97: #endif