Mercurial > hg > svcore
comparison plugin/transform/PluginTransformer.cpp @ 328:21bd032ae791
* Introduce new Transform class which contains data necessary to describe the
context for a plugin -- the plugin's name and output, the step/block size
etc (formerly spread across ExecutionContext and TransformFactory). Other
code hasn't been updated to use this yet.
* Rename existing Transform stuff to Transformers (because they run Transforms)
I'm still not 100% sure about this change, don't rely on it.
author | Chris Cannam |
---|---|
date | Mon, 05 Nov 2007 15:31:06 +0000 |
parents | plugin/transform/PluginTransform.cpp@32e50b620a6c |
children | f620ce48c950 |
comparison
equal
deleted
inserted
replaced
327:1d656dcda8ef | 328:21bd032ae791 |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Sonic Visualiser | |
5 An audio file viewer and annotation editor. | |
6 Centre for Digital Music, Queen Mary, University of London. | |
7 This file copyright 2006 QMUL. | |
8 | |
9 This program is free software; you can redistribute it and/or | |
10 modify it under the terms of the GNU General Public License as | |
11 published by the Free Software Foundation; either version 2 of the | |
12 License, or (at your option) any later version. See the file | |
13 COPYING included with this distribution for more information. | |
14 */ | |
15 | |
16 #include "PluginTransformer.h" | |
17 | |
18 #include "vamp-sdk/PluginHostAdapter.h" | |
19 #include "vamp-sdk/hostext/PluginWrapper.h" | |
20 | |
21 PluginTransformer::PluginTransformer(Model *inputModel, | |
22 const ExecutionContext &context) : | |
23 Transformer(inputModel), | |
24 m_context(context) | |
25 { | |
26 } | |
27 | |
28 PluginTransformer::ExecutionContext::ExecutionContext(int _c, size_t _bs) : | |
29 channel(_c), | |
30 domain(Vamp::Plugin::TimeDomain), | |
31 stepSize(_bs ? _bs : 1024), | |
32 blockSize(_bs ? _bs : 1024), | |
33 windowType(HanningWindow), | |
34 startFrame(0), | |
35 duration(0), | |
36 sampleRate(0) | |
37 { | |
38 } | |
39 | |
40 PluginTransformer::ExecutionContext::ExecutionContext(int _c, size_t _ss, | |
41 size_t _bs, WindowType _wt) : | |
42 channel(_c), | |
43 domain(Vamp::Plugin::FrequencyDomain), | |
44 stepSize(_ss ? _ss : (_bs ? _bs / 2 : 512)), | |
45 blockSize(_bs ? _bs : 1024), | |
46 windowType(_wt), | |
47 startFrame(0), | |
48 duration(0), | |
49 sampleRate(0) | |
50 { | |
51 } | |
52 | |
53 PluginTransformer::ExecutionContext::ExecutionContext(int _c, | |
54 const Vamp::PluginBase *_plugin) : | |
55 channel(_c), | |
56 domain(Vamp::Plugin::TimeDomain), | |
57 stepSize(0), | |
58 blockSize(0), | |
59 windowType(HanningWindow), | |
60 startFrame(0), | |
61 duration(0), | |
62 sampleRate(0) | |
63 { | |
64 makeConsistentWithPlugin(_plugin); | |
65 } | |
66 | |
67 bool | |
68 PluginTransformer::ExecutionContext::operator==(const ExecutionContext &c) | |
69 { | |
70 return (c.channel == channel && | |
71 c.domain == domain && | |
72 c.stepSize == stepSize && | |
73 c.blockSize == blockSize && | |
74 c.windowType == windowType && | |
75 c.startFrame == startFrame && | |
76 c.duration == duration && | |
77 c.sampleRate == sampleRate); | |
78 } | |
79 | |
80 void | |
81 PluginTransformer::ExecutionContext::makeConsistentWithPlugin(const Vamp::PluginBase *_plugin) | |
82 { | |
83 const Vamp::Plugin *vp = dynamic_cast<const Vamp::Plugin *>(_plugin); | |
84 if (!vp) { | |
85 // std::cerr << "makeConsistentWithPlugin: not a Vamp::Plugin" << std::endl; | |
86 vp = dynamic_cast<const Vamp::PluginHostAdapter *>(_plugin); //!!! why? | |
87 } | |
88 if (!vp) { | |
89 // std::cerr << "makeConsistentWithPlugin: not a Vamp::PluginHostAdapter" << std::endl; | |
90 vp = dynamic_cast<const Vamp::HostExt::PluginWrapper *>(_plugin); //!!! no, I mean really why? | |
91 } | |
92 if (!vp) { | |
93 // std::cerr << "makeConsistentWithPlugin: not a Vamp::HostExt::PluginWrapper" << std::endl; | |
94 } | |
95 | |
96 if (!vp) { | |
97 domain = Vamp::Plugin::TimeDomain; | |
98 if (!stepSize) { | |
99 if (!blockSize) blockSize = 1024; | |
100 stepSize = blockSize; | |
101 } else { | |
102 if (!blockSize) blockSize = stepSize; | |
103 } | |
104 } else { | |
105 domain = vp->getInputDomain(); | |
106 if (!stepSize) stepSize = vp->getPreferredStepSize(); | |
107 if (!blockSize) blockSize = vp->getPreferredBlockSize(); | |
108 if (!blockSize) blockSize = 1024; | |
109 if (!stepSize) { | |
110 if (domain == Vamp::Plugin::FrequencyDomain) { | |
111 // std::cerr << "frequency domain, step = " << blockSize/2 << std::endl; | |
112 stepSize = blockSize/2; | |
113 } else { | |
114 // std::cerr << "time domain, step = " << blockSize/2 << std::endl; | |
115 stepSize = blockSize; | |
116 } | |
117 } | |
118 } | |
119 } | |
120 | |
121 |