Chris@320: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@320: Chris@320: /* Chris@320: Sonic Visualiser Chris@320: An audio file viewer and annotation editor. Chris@320: Centre for Digital Music, Queen Mary, University of London. Chris@320: This file copyright 2006 QMUL. Chris@320: Chris@320: This program is free software; you can redistribute it and/or Chris@320: modify it under the terms of the GNU General Public License as Chris@320: published by the Free Software Foundation; either version 2 of the Chris@320: License, or (at your option) any later version. See the file Chris@320: COPYING included with this distribution for more information. Chris@320: */ Chris@320: Chris@320: #include "PluginTransform.h" Chris@320: Chris@320: #include "vamp-sdk/PluginHostAdapter.h" Chris@320: #include "vamp-sdk/hostext/PluginWrapper.h" Chris@320: Chris@320: PluginTransform::PluginTransform(Model *inputModel, Chris@320: const ExecutionContext &context) : Chris@320: Transform(inputModel), Chris@320: m_context(context) Chris@320: { Chris@320: } Chris@320: Chris@320: PluginTransform::ExecutionContext::ExecutionContext(int _c, size_t _bs) : Chris@320: channel(_c), Chris@320: domain(Vamp::Plugin::TimeDomain), Chris@320: stepSize(_bs ? _bs : 1024), Chris@320: blockSize(_bs ? _bs : 1024), Chris@320: windowType(HanningWindow), Chris@320: startFrame(0), Chris@320: duration(0), Chris@320: sampleRate(0) Chris@320: { Chris@320: } Chris@320: Chris@320: PluginTransform::ExecutionContext::ExecutionContext(int _c, size_t _ss, Chris@320: size_t _bs, WindowType _wt) : Chris@320: channel(_c), Chris@320: domain(Vamp::Plugin::FrequencyDomain), Chris@320: stepSize(_ss ? _ss : (_bs ? _bs / 2 : 512)), Chris@320: blockSize(_bs ? _bs : 1024), Chris@320: windowType(_wt), Chris@320: startFrame(0), Chris@320: duration(0), Chris@320: sampleRate(0) Chris@320: { Chris@320: } Chris@320: Chris@320: PluginTransform::ExecutionContext::ExecutionContext(int _c, Chris@320: const Vamp::PluginBase *_plugin) : Chris@320: channel(_c), Chris@320: domain(Vamp::Plugin::TimeDomain), Chris@320: stepSize(0), Chris@320: blockSize(0), Chris@320: windowType(HanningWindow), Chris@320: startFrame(0), Chris@320: duration(0), Chris@320: sampleRate(0) Chris@320: { Chris@320: makeConsistentWithPlugin(_plugin); Chris@320: } Chris@320: Chris@320: bool Chris@320: PluginTransform::ExecutionContext::operator==(const ExecutionContext &c) Chris@320: { Chris@320: return (c.channel == channel && Chris@320: c.domain == domain && Chris@320: c.stepSize == stepSize && Chris@320: c.blockSize == blockSize && Chris@320: c.windowType == windowType && Chris@320: c.startFrame == startFrame && Chris@320: c.duration == duration && Chris@320: c.sampleRate == sampleRate); Chris@320: } Chris@320: Chris@320: void Chris@320: PluginTransform::ExecutionContext::makeConsistentWithPlugin(const Vamp::PluginBase *_plugin) Chris@320: { Chris@320: const Vamp::Plugin *vp = dynamic_cast(_plugin); Chris@320: if (!vp) { Chris@320: // std::cerr << "makeConsistentWithPlugin: not a Vamp::Plugin" << std::endl; Chris@320: vp = dynamic_cast(_plugin); //!!! why? Chris@320: } Chris@320: if (!vp) { Chris@320: // std::cerr << "makeConsistentWithPlugin: not a Vamp::PluginHostAdapter" << std::endl; Chris@320: vp = dynamic_cast(_plugin); //!!! no, I mean really why? Chris@320: } Chris@320: if (!vp) { Chris@320: // std::cerr << "makeConsistentWithPlugin: not a Vamp::HostExt::PluginWrapper" << std::endl; Chris@320: } Chris@320: Chris@320: if (!vp) { Chris@320: domain = Vamp::Plugin::TimeDomain; Chris@320: if (!stepSize) { Chris@320: if (!blockSize) blockSize = 1024; Chris@320: stepSize = blockSize; Chris@320: } else { Chris@320: if (!blockSize) blockSize = stepSize; Chris@320: } Chris@320: } else { Chris@320: domain = vp->getInputDomain(); Chris@320: if (!stepSize) stepSize = vp->getPreferredStepSize(); Chris@320: if (!blockSize) blockSize = vp->getPreferredBlockSize(); Chris@320: if (!blockSize) blockSize = 1024; Chris@320: if (!stepSize) { Chris@320: if (domain == Vamp::Plugin::FrequencyDomain) { Chris@320: // std::cerr << "frequency domain, step = " << blockSize/2 << std::endl; Chris@320: stepSize = blockSize/2; Chris@320: } else { Chris@320: // std::cerr << "time domain, step = " << blockSize/2 << std::endl; Chris@320: stepSize = blockSize; Chris@320: } Chris@320: } Chris@320: } Chris@320: } Chris@320: Chris@320: