Chris@27
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@27
|
2
|
Chris@27
|
3 /*
|
Chris@27
|
4 Sonic Visualiser
|
Chris@27
|
5 An audio file viewer and annotation editor.
|
Chris@27
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@77
|
7 This file copyright 2006 QMUL.
|
Chris@27
|
8
|
Chris@27
|
9 This program is free software; you can redistribute it and/or
|
Chris@27
|
10 modify it under the terms of the GNU General Public License as
|
Chris@27
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@27
|
12 License, or (at your option) any later version. See the file
|
Chris@27
|
13 COPYING included with this distribution for more information.
|
Chris@27
|
14 */
|
Chris@27
|
15
|
Chris@27
|
16 #include "PluginTransform.h"
|
Chris@27
|
17
|
Chris@28
|
18 #include "vamp-sdk/PluginHostAdapter.h"
|
Chris@181
|
19 #include "vamp-sdk/hostext/PluginWrapper.h"
|
Chris@28
|
20
|
Chris@27
|
21 PluginTransform::PluginTransform(Model *inputModel,
|
Chris@27
|
22 const ExecutionContext &context) :
|
Chris@27
|
23 Transform(inputModel),
|
Chris@27
|
24 m_context(context)
|
Chris@27
|
25 {
|
Chris@27
|
26 }
|
Chris@27
|
27
|
Chris@27
|
28 PluginTransform::ExecutionContext::ExecutionContext(int _c, size_t _bs) :
|
Chris@27
|
29 channel(_c),
|
Chris@27
|
30 domain(Vamp::Plugin::TimeDomain),
|
Chris@27
|
31 stepSize(_bs ? _bs : 1024),
|
Chris@27
|
32 blockSize(_bs ? _bs : 1024),
|
Chris@27
|
33 windowType(HanningWindow)
|
Chris@27
|
34 {
|
Chris@27
|
35 }
|
Chris@27
|
36
|
Chris@27
|
37 PluginTransform::ExecutionContext::ExecutionContext(int _c, size_t _ss,
|
Chris@27
|
38 size_t _bs, WindowType _wt) :
|
Chris@27
|
39 channel(_c),
|
Chris@27
|
40 domain(Vamp::Plugin::FrequencyDomain),
|
Chris@27
|
41 stepSize(_ss ? _ss : (_bs ? _bs / 2 : 512)),
|
Chris@27
|
42 blockSize(_bs ? _bs : 1024),
|
Chris@27
|
43 windowType(_wt)
|
Chris@27
|
44 {
|
Chris@27
|
45 }
|
Chris@27
|
46
|
Chris@27
|
47 PluginTransform::ExecutionContext::ExecutionContext(int _c,
|
Chris@27
|
48 const Vamp::PluginBase *_plugin) :
|
Chris@27
|
49 channel(_c),
|
Chris@27
|
50 domain(Vamp::Plugin::TimeDomain),
|
Chris@27
|
51 stepSize(0),
|
Chris@27
|
52 blockSize(0),
|
Chris@27
|
53 windowType(HanningWindow)
|
Chris@27
|
54 {
|
Chris@27
|
55 makeConsistentWithPlugin(_plugin);
|
Chris@27
|
56 }
|
Chris@27
|
57
|
Chris@27
|
58 bool
|
Chris@27
|
59 PluginTransform::ExecutionContext::operator==(const ExecutionContext &c)
|
Chris@27
|
60 {
|
Chris@27
|
61 return (c.channel == channel &&
|
Chris@27
|
62 c.domain == domain &&
|
Chris@27
|
63 c.stepSize == stepSize &&
|
Chris@27
|
64 c.blockSize == blockSize &&
|
Chris@27
|
65 c.windowType == windowType);
|
Chris@27
|
66 }
|
Chris@27
|
67
|
Chris@27
|
68 void
|
Chris@27
|
69 PluginTransform::ExecutionContext::makeConsistentWithPlugin(const Vamp::PluginBase *_plugin)
|
Chris@27
|
70 {
|
Chris@27
|
71 const Vamp::Plugin *vp = dynamic_cast<const Vamp::Plugin *>(_plugin);
|
Chris@28
|
72 if (!vp) {
|
Chris@181
|
73 // std::cerr << "makeConsistentWithPlugin: not a Vamp::Plugin" << std::endl;
|
Chris@28
|
74 vp = dynamic_cast<const Vamp::PluginHostAdapter *>(_plugin); //!!! why?
|
Chris@181
|
75 }
|
Chris@181
|
76 if (!vp) {
|
Chris@181
|
77 // std::cerr << "makeConsistentWithPlugin: not a Vamp::PluginHostAdapter" << std::endl;
|
Chris@181
|
78 vp = dynamic_cast<const Vamp::HostExt::PluginWrapper *>(_plugin); //!!! no, I mean really why?
|
Chris@181
|
79 }
|
Chris@181
|
80 if (!vp) {
|
Chris@181
|
81 // std::cerr << "makeConsistentWithPlugin: not a Vamp::HostExt::PluginWrapper" << std::endl;
|
Chris@28
|
82 }
|
Chris@27
|
83
|
Chris@27
|
84 if (!vp) {
|
Chris@27
|
85 domain = Vamp::Plugin::TimeDomain;
|
Chris@27
|
86 if (!stepSize) {
|
Chris@27
|
87 if (!blockSize) blockSize = 1024;
|
Chris@27
|
88 stepSize = blockSize;
|
Chris@27
|
89 } else {
|
Chris@27
|
90 if (!blockSize) blockSize = stepSize;
|
Chris@27
|
91 }
|
Chris@27
|
92 } else {
|
Chris@27
|
93 domain = vp->getInputDomain();
|
Chris@27
|
94 if (!stepSize) stepSize = vp->getPreferredStepSize();
|
Chris@27
|
95 if (!blockSize) blockSize = vp->getPreferredBlockSize();
|
Chris@27
|
96 if (!blockSize) blockSize = 1024;
|
Chris@27
|
97 if (!stepSize) {
|
Chris@27
|
98 if (domain == Vamp::Plugin::FrequencyDomain) {
|
Chris@27
|
99 stepSize = blockSize/2;
|
Chris@27
|
100 } else {
|
Chris@27
|
101 stepSize = blockSize;
|
Chris@27
|
102 }
|
Chris@27
|
103 }
|
Chris@27
|
104 }
|
Chris@27
|
105 }
|
Chris@27
|
106
|
Chris@27
|
107
|