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@182
|
33 windowType(HanningWindow),
|
Chris@182
|
34 startFrame(0),
|
Chris@182
|
35 duration(0),
|
Chris@182
|
36 sampleRate(0)
|
Chris@27
|
37 {
|
Chris@27
|
38 }
|
Chris@27
|
39
|
Chris@27
|
40 PluginTransform::ExecutionContext::ExecutionContext(int _c, size_t _ss,
|
Chris@27
|
41 size_t _bs, WindowType _wt) :
|
Chris@27
|
42 channel(_c),
|
Chris@27
|
43 domain(Vamp::Plugin::FrequencyDomain),
|
Chris@27
|
44 stepSize(_ss ? _ss : (_bs ? _bs / 2 : 512)),
|
Chris@27
|
45 blockSize(_bs ? _bs : 1024),
|
Chris@182
|
46 windowType(_wt),
|
Chris@182
|
47 startFrame(0),
|
Chris@182
|
48 duration(0),
|
Chris@182
|
49 sampleRate(0)
|
Chris@27
|
50 {
|
Chris@27
|
51 }
|
Chris@27
|
52
|
Chris@27
|
53 PluginTransform::ExecutionContext::ExecutionContext(int _c,
|
Chris@27
|
54 const Vamp::PluginBase *_plugin) :
|
Chris@27
|
55 channel(_c),
|
Chris@27
|
56 domain(Vamp::Plugin::TimeDomain),
|
Chris@27
|
57 stepSize(0),
|
Chris@27
|
58 blockSize(0),
|
Chris@182
|
59 windowType(HanningWindow),
|
Chris@182
|
60 startFrame(0),
|
Chris@182
|
61 duration(0),
|
Chris@182
|
62 sampleRate(0)
|
Chris@27
|
63 {
|
Chris@27
|
64 makeConsistentWithPlugin(_plugin);
|
Chris@27
|
65 }
|
Chris@27
|
66
|
Chris@27
|
67 bool
|
Chris@27
|
68 PluginTransform::ExecutionContext::operator==(const ExecutionContext &c)
|
Chris@27
|
69 {
|
Chris@27
|
70 return (c.channel == channel &&
|
Chris@27
|
71 c.domain == domain &&
|
Chris@27
|
72 c.stepSize == stepSize &&
|
Chris@27
|
73 c.blockSize == blockSize &&
|
Chris@182
|
74 c.windowType == windowType &&
|
Chris@182
|
75 c.startFrame == startFrame &&
|
Chris@182
|
76 c.duration == duration &&
|
Chris@182
|
77 c.sampleRate == sampleRate);
|
Chris@27
|
78 }
|
Chris@27
|
79
|
Chris@27
|
80 void
|
Chris@27
|
81 PluginTransform::ExecutionContext::makeConsistentWithPlugin(const Vamp::PluginBase *_plugin)
|
Chris@27
|
82 {
|
Chris@27
|
83 const Vamp::Plugin *vp = dynamic_cast<const Vamp::Plugin *>(_plugin);
|
Chris@28
|
84 if (!vp) {
|
Chris@181
|
85 // std::cerr << "makeConsistentWithPlugin: not a Vamp::Plugin" << std::endl;
|
Chris@28
|
86 vp = dynamic_cast<const Vamp::PluginHostAdapter *>(_plugin); //!!! why?
|
Chris@181
|
87 }
|
Chris@181
|
88 if (!vp) {
|
Chris@181
|
89 // std::cerr << "makeConsistentWithPlugin: not a Vamp::PluginHostAdapter" << std::endl;
|
Chris@181
|
90 vp = dynamic_cast<const Vamp::HostExt::PluginWrapper *>(_plugin); //!!! no, I mean really why?
|
Chris@181
|
91 }
|
Chris@181
|
92 if (!vp) {
|
Chris@181
|
93 // std::cerr << "makeConsistentWithPlugin: not a Vamp::HostExt::PluginWrapper" << std::endl;
|
Chris@28
|
94 }
|
Chris@27
|
95
|
Chris@27
|
96 if (!vp) {
|
Chris@27
|
97 domain = Vamp::Plugin::TimeDomain;
|
Chris@27
|
98 if (!stepSize) {
|
Chris@27
|
99 if (!blockSize) blockSize = 1024;
|
Chris@27
|
100 stepSize = blockSize;
|
Chris@27
|
101 } else {
|
Chris@27
|
102 if (!blockSize) blockSize = stepSize;
|
Chris@27
|
103 }
|
Chris@27
|
104 } else {
|
Chris@27
|
105 domain = vp->getInputDomain();
|
Chris@27
|
106 if (!stepSize) stepSize = vp->getPreferredStepSize();
|
Chris@27
|
107 if (!blockSize) blockSize = vp->getPreferredBlockSize();
|
Chris@27
|
108 if (!blockSize) blockSize = 1024;
|
Chris@27
|
109 if (!stepSize) {
|
Chris@27
|
110 if (domain == Vamp::Plugin::FrequencyDomain) {
|
Chris@191
|
111 // std::cerr << "frequency domain, step = " << blockSize/2 << std::endl;
|
Chris@27
|
112 stepSize = blockSize/2;
|
Chris@27
|
113 } else {
|
Chris@191
|
114 // std::cerr << "time domain, step = " << blockSize/2 << std::endl;
|
Chris@27
|
115 stepSize = blockSize;
|
Chris@27
|
116 }
|
Chris@27
|
117 }
|
Chris@27
|
118 }
|
Chris@27
|
119 }
|
Chris@27
|
120
|
Chris@27
|
121
|