annotate capnproto/VampnProto.h @ 66:6f160dee1192

Instead of using separate values and b64values entries in JSON serialisations, allow numeric arrays to be replaced by b64 variants wherever they appear (discriminating by type). Also rename values to featureValues in feature throughout, as values turns out to be a hazardous name in a JS context. Finally use Array instead of Text for array encoding (seems clearer).
author Chris Cannam <c.cannam@qmul.ac.uk>
date Tue, 27 Sep 2016 15:04:59 +0100 (2016-09-27)
parents 85ec33975434
children db17657ac875
rev   line source
c@5 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
c@5 2
c@18 3 /*
c@18 4 VamPipe
c@18 5
c@18 6 Centre for Digital Music, Queen Mary, University of London.
c@18 7 Copyright 2015-2016 QMUL.
c@18 8
c@18 9 Permission is hereby granted, free of charge, to any person
c@18 10 obtaining a copy of this software and associated documentation
c@18 11 files (the "Software"), to deal in the Software without
c@18 12 restriction, including without limitation the rights to use, copy,
c@18 13 modify, merge, publish, distribute, sublicense, and/or sell copies
c@18 14 of the Software, and to permit persons to whom the Software is
c@18 15 furnished to do so, subject to the following conditions:
c@18 16
c@18 17 The above copyright notice and this permission notice shall be
c@18 18 included in all copies or substantial portions of the Software.
c@18 19
c@18 20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
c@18 21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
c@18 22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
c@18 23 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
c@18 24 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
c@18 25 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
c@18 26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
c@18 27
c@18 28 Except as contained in this notice, the names of the Centre for
c@18 29 Digital Music; Queen Mary, University of London; and Chris Cannam
c@18 30 shall not be used in advertising or otherwise to promote the sale,
c@18 31 use or other dealings in this Software without prior written
c@18 32 authorization.
c@18 33 */
c@18 34
c@5 35 #include "vamp.capnp.h"
c@5 36
c@5 37 #include <capnp/message.h>
c@5 38 #include <capnp/serialize-packed.h>
c@5 39
c@5 40 #include <vamp-hostsdk/Plugin.h>
c@5 41 #include <vamp-hostsdk/PluginLoader.h>
c@5 42 #include <vamp-hostsdk/PluginStaticData.h>
c@5 43
c@10 44 #include "bits/PluginHandleMapper.h"
c@49 45 #include "bits/PluginOutputIdMapper.h"
c@26 46 #include "bits/RequestResponseType.h"
c@10 47
c@5 48 namespace vampipe
c@5 49 {
c@5 50
c@5 51 /**
c@5 52 * Convert the structures laid out in the Vamp SDK classes into Cap'n
c@6 53 * Proto structures (and back again).
c@5 54 *
c@6 55 * At least some of this will be necessary for any implementation
c@6 56 * using Cap'n Proto that uses the C++ Vamp SDK to provide its
c@6 57 * reference structures. An implementation could alternatively use the
c@6 58 * Cap'n Proto structures directly, and interact with Vamp plugins
c@6 59 * using the Vamp C API, without using the C++ Vamp SDK classes at
c@18 60 * all. That would avoid a lot of copying (in Cap'n Proto style).
c@5 61 */
c@6 62 class VampnProto
c@5 63 {
c@5 64 public:
c@5 65 typedef ::capnp::MallocMessageBuilder MsgBuilder;
c@5 66
c@5 67 template <typename T, typename B>
c@5 68 static void buildBasicDescriptor(B &basic, const T &t) {
c@5 69 basic.setIdentifier(t.identifier);
c@5 70 basic.setName(t.name);
c@5 71 basic.setDescription(t.description);
c@5 72 }
c@5 73
c@5 74 template <typename T, typename B>
c@5 75 static void readBasicDescriptor(T &t, const B &basic) {
c@5 76 t.identifier = basic.getIdentifier();
c@5 77 t.name = basic.getName();
c@5 78 t.description = basic.getDescription();
c@5 79 }
c@5 80
c@5 81 template <typename T, typename M>
c@5 82 static void buildValueExtents(M &m, const T &t) {
c@5 83 m.setMinValue(t.minValue);
c@5 84 m.setMaxValue(t.maxValue);
c@5 85 }
c@5 86
c@5 87 template <typename T, typename M>
c@5 88 static void readValueExtents(T &t, const M &m) {
c@5 89 t.minValue = m.getMinValue();
c@5 90 t.maxValue = m.getMaxValue();
c@5 91 }
c@5 92
c@5 93 static void buildRealTime(RealTime::Builder &b, const Vamp::RealTime &t) {
c@5 94 b.setSec(t.sec);
c@5 95 b.setNsec(t.nsec);
c@5 96 }
c@5 97
c@5 98 static void readRealTime(Vamp::RealTime &t, const RealTime::Reader &r) {
c@5 99 t.sec = r.getSec();
c@5 100 t.nsec = r.getNsec();
c@5 101 }
c@5 102
c@5 103 static SampleType
c@5 104 fromSampleType(Vamp::Plugin::OutputDescriptor::SampleType t) {
c@5 105 switch (t) {
c@5 106 case Vamp::Plugin::OutputDescriptor::OneSamplePerStep:
c@5 107 return SampleType::ONE_SAMPLE_PER_STEP;
c@5 108 case Vamp::Plugin::OutputDescriptor::FixedSampleRate:
c@5 109 return SampleType::FIXED_SAMPLE_RATE;
c@5 110 case Vamp::Plugin::OutputDescriptor::VariableSampleRate:
c@5 111 return SampleType::VARIABLE_SAMPLE_RATE;
c@5 112 }
c@5 113 throw std::logic_error("unexpected Vamp SampleType enum value");
c@5 114 }
c@5 115
c@5 116 static Vamp::Plugin::OutputDescriptor::SampleType
c@5 117 toSampleType(SampleType t) {
c@5 118 switch (t) {
c@5 119 case SampleType::ONE_SAMPLE_PER_STEP:
c@5 120 return Vamp::Plugin::OutputDescriptor::OneSamplePerStep;
c@5 121 case SampleType::FIXED_SAMPLE_RATE:
c@5 122 return Vamp::Plugin::OutputDescriptor::FixedSampleRate;
c@5 123 case SampleType::VARIABLE_SAMPLE_RATE:
c@5 124 return Vamp::Plugin::OutputDescriptor::VariableSampleRate;
c@5 125 }
c@5 126 throw std::logic_error("unexpected Capnp SampleType enum value");
c@5 127 }
c@5 128
c@5 129 static void
c@64 130 buildConfiguredOutputDescriptor(ConfiguredOutputDescriptor::Builder &b,
c@64 131 const Vamp::Plugin::OutputDescriptor &od) {
c@5 132
c@5 133 b.setUnit(od.unit);
c@5 134
c@5 135 b.setSampleType(fromSampleType(od.sampleType));
c@5 136 b.setSampleRate(od.sampleRate);
c@5 137 b.setHasDuration(od.hasDuration);
c@5 138
c@5 139 b.setHasFixedBinCount(od.hasFixedBinCount);
c@5 140 if (od.hasFixedBinCount) {
c@5 141 b.setBinCount(od.binCount);
c@5 142 if (od.binNames.size() > 0) {
c@5 143 auto binNames = b.initBinNames(od.binNames.size());
c@5 144 for (size_t i = 0; i < od.binNames.size(); ++i) {
c@5 145 binNames.set(i, od.binNames[i]);
c@5 146 }
c@5 147 }
c@5 148 }
c@5 149
c@5 150 b.setHasKnownExtents(od.hasKnownExtents);
c@5 151 if (od.hasKnownExtents) {
c@5 152 buildValueExtents(b, od);
c@5 153 }
c@5 154
c@5 155 b.setIsQuantized(od.isQuantized);
c@5 156 if (od.isQuantized) {
c@5 157 b.setQuantizeStep(od.quantizeStep);
c@5 158 }
c@5 159 }
c@5 160
c@5 161 static void
c@64 162 buildOutputDescriptor(OutputDescriptor::Builder &b,
c@64 163 const Vamp::Plugin::OutputDescriptor &od) {
c@5 164
c@64 165 auto basic = b.initBasic();
c@64 166 buildBasicDescriptor(basic, od);
c@64 167
c@64 168 auto configured = b.initConfigured();
c@64 169 buildConfiguredOutputDescriptor(configured, od);
c@64 170 }
c@64 171
c@64 172 static void
c@64 173 readConfiguredOutputDescriptor(Vamp::Plugin::OutputDescriptor &od,
c@64 174 const ConfiguredOutputDescriptor::Reader &r) {
c@5 175
c@5 176 od.unit = r.getUnit();
c@5 177
c@5 178 od.sampleType = toSampleType(r.getSampleType());
c@5 179 od.sampleRate = r.getSampleRate();
c@5 180 od.hasDuration = r.getHasDuration();
c@5 181
c@5 182 od.hasFixedBinCount = r.getHasFixedBinCount();
c@5 183 if (od.hasFixedBinCount) {
c@5 184 od.binCount = r.getBinCount();
c@13 185 od.binNames.clear();
c@28 186 auto nn = r.getBinNames();
c@28 187 for (const auto &n: nn) {
c@5 188 od.binNames.push_back(n);
c@5 189 }
c@5 190 }
c@5 191
c@5 192 od.hasKnownExtents = r.getHasKnownExtents();
c@5 193 if (od.hasKnownExtents) {
c@5 194 readValueExtents(od, r);
c@5 195 }
c@5 196
c@5 197 od.isQuantized = r.getIsQuantized();
c@5 198 if (od.isQuantized) {
c@5 199 od.quantizeStep = r.getQuantizeStep();
c@5 200 }
c@5 201 }
c@5 202
c@5 203 static void
c@64 204 readOutputDescriptor(Vamp::Plugin::OutputDescriptor &od,
c@64 205 const OutputDescriptor::Reader &r) {
c@64 206
c@64 207 readBasicDescriptor(od, r.getBasic());
c@64 208 readConfiguredOutputDescriptor(od, r.getConfigured());
c@64 209 }
c@64 210
c@64 211 static void
c@5 212 buildParameterDescriptor(ParameterDescriptor::Builder &b,
c@5 213 const Vamp::Plugin::ParameterDescriptor &pd) {
c@5 214
c@5 215 auto basic = b.initBasic();
c@5 216 buildBasicDescriptor(basic, pd);
c@5 217
c@5 218 b.setUnit(pd.unit);
c@5 219
c@5 220 buildValueExtents(b, pd);
c@5 221
c@5 222 b.setDefaultValue(pd.defaultValue);
c@5 223
c@5 224 b.setIsQuantized(pd.isQuantized);
c@5 225 if (pd.isQuantized) {
c@5 226 b.setQuantizeStep(pd.quantizeStep);
c@5 227 }
c@5 228
c@5 229 if (pd.valueNames.size() > 0) {
c@5 230 auto valueNames = b.initValueNames(pd.valueNames.size());
c@5 231 for (size_t i = 0; i < pd.valueNames.size(); ++i) {
c@5 232 valueNames.set(i, pd.valueNames[i]);
c@5 233 }
c@5 234 }
c@5 235 }
c@5 236
c@5 237 static void
c@5 238 readParameterDescriptor(Vamp::Plugin::ParameterDescriptor &pd,
c@5 239 const ParameterDescriptor::Reader &r) {
c@5 240
c@5 241 readBasicDescriptor(pd, r.getBasic());
c@5 242
c@5 243 pd.unit = r.getUnit();
c@5 244
c@5 245 readValueExtents(pd, r);
c@5 246
c@5 247 pd.defaultValue = r.getDefaultValue();
c@5 248
c@5 249 pd.isQuantized = r.getIsQuantized();
c@5 250 if (pd.isQuantized) {
c@5 251 pd.quantizeStep = r.getQuantizeStep();
c@5 252 }
c@5 253
c@13 254 pd.valueNames.clear();
c@28 255 auto nn = r.getValueNames();
c@28 256 for (const auto &n: nn) {
c@5 257 pd.valueNames.push_back(n);
c@5 258 }
c@5 259 }
c@5 260
c@5 261 static void
c@5 262 buildFeature(Feature::Builder &b,
c@5 263 const Vamp::Plugin::Feature &f) {
c@5 264
c@5 265 b.setHasTimestamp(f.hasTimestamp);
c@5 266 if (f.hasTimestamp) {
c@5 267 auto timestamp = b.initTimestamp();
c@5 268 buildRealTime(timestamp, f.timestamp);
c@5 269 }
c@5 270
c@5 271 b.setHasDuration(f.hasDuration);
c@5 272 if (f.hasDuration) {
c@5 273 auto duration = b.initDuration();
c@5 274 buildRealTime(duration, f.duration);
c@5 275 }
c@5 276
c@5 277 b.setLabel(f.label);
c@5 278
c@5 279 if (f.values.size() > 0) {
c@66 280 auto values = b.initFeatureValues(f.values.size());
c@5 281 for (size_t i = 0; i < f.values.size(); ++i) {
c@5 282 values.set(i, f.values[i]);
c@5 283 }
c@5 284 }
c@5 285 }
c@5 286
c@5 287 static void
c@5 288 readFeature(Vamp::Plugin::Feature &f,
c@5 289 const Feature::Reader &r) {
c@5 290
c@5 291 f.hasTimestamp = r.getHasTimestamp();
c@5 292 if (f.hasTimestamp) {
c@5 293 readRealTime(f.timestamp, r.getTimestamp());
c@5 294 }
c@5 295
c@5 296 f.hasDuration = r.getHasDuration();
c@5 297 if (f.hasDuration) {
c@5 298 readRealTime(f.duration, r.getDuration());
c@5 299 }
c@5 300
c@5 301 f.label = r.getLabel();
c@5 302
c@13 303 f.values.clear();
c@66 304 auto vv = r.getFeatureValues();
c@28 305 for (auto v: vv) {
c@5 306 f.values.push_back(v);
c@5 307 }
c@5 308 }
c@5 309
c@5 310 static void
c@5 311 buildFeatureSet(FeatureSet::Builder &b,
c@49 312 const Vamp::Plugin::FeatureSet &fs,
c@49 313 const PluginOutputIdMapper &omapper) {
c@5 314
c@5 315 auto featureset = b.initFeaturePairs(fs.size());
c@5 316 int ix = 0;
c@5 317 for (const auto &fsi : fs) {
c@5 318 auto fspair = featureset[ix];
c@49 319 fspair.setOutput(omapper.indexToId(fsi.first));
c@5 320 auto featurelist = fspair.initFeatures(fsi.second.size());
c@5 321 for (size_t j = 0; j < fsi.second.size(); ++j) {
c@5 322 auto feature = featurelist[j];
c@5 323 buildFeature(feature, fsi.second[j]);
c@5 324 }
c@5 325 ++ix;
c@5 326 }
c@5 327 }
c@5 328
c@5 329 static void
c@5 330 readFeatureSet(Vamp::Plugin::FeatureSet &fs,
c@49 331 const FeatureSet::Reader &r,
c@49 332 const PluginOutputIdMapper &omapper) {
c@5 333
c@13 334 fs.clear();
c@28 335 auto pp = r.getFeaturePairs();
c@28 336 for (const auto &p: pp) {
c@5 337 Vamp::Plugin::FeatureList vfl;
c@28 338 auto ff = p.getFeatures();
c@28 339 for (const auto &f: ff) {
c@5 340 Vamp::Plugin::Feature vf;
c@5 341 readFeature(vf, f);
c@5 342 vfl.push_back(vf);
c@5 343 }
c@49 344 fs[omapper.idToIndex(p.getOutput())] = vfl;
c@5 345 }
c@5 346 }
c@5 347
c@5 348 static InputDomain
c@5 349 fromInputDomain(Vamp::Plugin::InputDomain d) {
c@5 350 switch(d) {
c@5 351 case Vamp::Plugin::TimeDomain:
c@5 352 return InputDomain::TIME_DOMAIN;
c@5 353 case Vamp::Plugin::FrequencyDomain:
c@5 354 return InputDomain::FREQUENCY_DOMAIN;
c@5 355 default:
c@5 356 throw std::logic_error("unexpected Vamp InputDomain enum value");
c@5 357 }
c@5 358 }
c@5 359
c@5 360 static Vamp::Plugin::InputDomain
c@5 361 toInputDomain(InputDomain d) {
c@5 362 switch(d) {
c@5 363 case InputDomain::TIME_DOMAIN:
c@5 364 return Vamp::Plugin::TimeDomain;
c@5 365 case InputDomain::FREQUENCY_DOMAIN:
c@5 366 return Vamp::Plugin::FrequencyDomain;
c@5 367 default:
c@5 368 throw std::logic_error("unexpected Capnp InputDomain enum value");
c@5 369 }
c@5 370 }
c@5 371
c@5 372 static void
c@5 373 buildPluginStaticData(PluginStaticData::Builder &b,
c@5 374 const Vamp::HostExt::PluginStaticData &d) {
c@5 375
c@5 376 b.setPluginKey(d.pluginKey);
c@5 377
c@5 378 auto basic = b.initBasic();
c@5 379 buildBasicDescriptor(basic, d.basic);
c@5 380
c@5 381 b.setMaker(d.maker);
c@5 382 b.setCopyright(d.copyright);
c@5 383 b.setPluginVersion(d.pluginVersion);
c@5 384
c@5 385 auto clist = b.initCategory(d.category.size());
c@5 386 for (size_t i = 0; i < d.category.size(); ++i) {
c@5 387 clist.set(i, d.category[i]);
c@5 388 }
c@5 389
c@5 390 b.setMinChannelCount(d.minChannelCount);
c@5 391 b.setMaxChannelCount(d.maxChannelCount);
c@5 392
c@5 393 const auto &vparams = d.parameters;
c@5 394 auto plist = b.initParameters(vparams.size());
c@5 395 for (size_t i = 0; i < vparams.size(); ++i) {
c@5 396 auto pd = plist[i];
c@5 397 buildParameterDescriptor(pd, vparams[i]);
c@5 398 }
c@5 399
c@5 400 const auto &vprogs = d.programs;
c@5 401 auto pglist = b.initPrograms(vprogs.size());
c@5 402 for (size_t i = 0; i < vprogs.size(); ++i) {
c@5 403 pglist.set(i, vprogs[i]);
c@5 404 }
c@5 405
c@5 406 b.setInputDomain(fromInputDomain(d.inputDomain));
c@5 407
c@5 408 const auto &vouts = d.basicOutputInfo;
c@5 409 auto olist = b.initBasicOutputInfo(vouts.size());
c@5 410 for (size_t i = 0; i < vouts.size(); ++i) {
c@5 411 auto od = olist[i];
c@5 412 buildBasicDescriptor(od, vouts[i]);
c@5 413 }
c@5 414 }
c@5 415
c@5 416 static void
c@5 417 readPluginStaticData(Vamp::HostExt::PluginStaticData &d,
c@5 418 const PluginStaticData::Reader &r) {
c@5 419
c@5 420 d.pluginKey = r.getPluginKey();
c@5 421
c@5 422 readBasicDescriptor(d.basic, r.getBasic());
c@5 423
c@5 424 d.maker = r.getMaker();
c@5 425 d.copyright = r.getCopyright();
c@5 426 d.pluginVersion = r.getPluginVersion();
c@5 427
c@13 428 d.category.clear();
c@28 429 auto cc = r.getCategory();
c@28 430 for (auto c: cc) {
c@5 431 d.category.push_back(c);
c@5 432 }
c@5 433
c@5 434 d.minChannelCount = r.getMinChannelCount();
c@5 435 d.maxChannelCount = r.getMaxChannelCount();
c@5 436
c@13 437 d.parameters.clear();
c@28 438 auto pp = r.getParameters();
c@28 439 for (auto p: pp) {
c@5 440 Vamp::Plugin::ParameterDescriptor pd;
c@5 441 readParameterDescriptor(pd, p);
c@5 442 d.parameters.push_back(pd);
c@5 443 }
c@5 444
c@13 445 d.programs.clear();
c@28 446 auto prp = r.getPrograms();
c@28 447 for (auto p: prp) {
c@5 448 d.programs.push_back(p);
c@5 449 }
c@5 450
c@5 451 d.inputDomain = toInputDomain(r.getInputDomain());
c@5 452
c@13 453 d.basicOutputInfo.clear();
c@28 454 auto oo = r.getBasicOutputInfo();
c@28 455 for (auto o: oo) {
c@5 456 Vamp::HostExt::PluginStaticData::Basic b;
c@5 457 readBasicDescriptor(b, o);
c@5 458 d.basicOutputInfo.push_back(b);
c@5 459 }
c@5 460 }
c@5 461
c@5 462 static void
c@5 463 buildPluginConfiguration(PluginConfiguration::Builder &b,
c@5 464 const Vamp::HostExt::PluginConfiguration &c) {
c@5 465
c@5 466 const auto &vparams = c.parameterValues;
c@5 467 auto params = b.initParameterValues(vparams.size());
c@5 468 int i = 0;
c@5 469 for (const auto &pp : vparams) {
c@5 470 auto param = params[i++];
c@5 471 param.setParameter(pp.first);
c@5 472 param.setValue(pp.second);
c@5 473 }
c@5 474
c@5 475 b.setCurrentProgram(c.currentProgram);
c@5 476 b.setChannelCount(c.channelCount);
c@5 477 b.setStepSize(c.stepSize);
c@5 478 b.setBlockSize(c.blockSize);
c@5 479 }
c@5 480
c@5 481 static void
c@5 482 readPluginConfiguration(Vamp::HostExt::PluginConfiguration &c,
c@5 483 const PluginConfiguration::Reader &r) {
c@5 484
c@28 485 auto pp = r.getParameterValues();
c@28 486 for (const auto &p: pp) {
c@28 487 c.parameterValues[p.getParameter()] = p.getValue();
c@5 488 }
c@5 489
c@5 490 c.currentProgram = r.getCurrentProgram();
c@5 491 c.channelCount = r.getChannelCount();
c@5 492 c.stepSize = r.getStepSize();
c@5 493 c.blockSize = r.getBlockSize();
c@5 494 }
c@5 495
c@5 496 static void
c@5 497 buildLoadRequest(LoadRequest::Builder &r,
c@5 498 const Vamp::HostExt::LoadRequest &req) {
c@5 499
c@5 500 r.setPluginKey(req.pluginKey);
c@5 501 r.setInputSampleRate(req.inputSampleRate);
c@5 502
c@5 503 std::vector<AdapterFlag> flags;
c@5 504 if (req.adapterFlags & Vamp::HostExt::PluginLoader::ADAPT_INPUT_DOMAIN) {
c@5 505 flags.push_back(AdapterFlag::ADAPT_INPUT_DOMAIN);
c@5 506 }
c@5 507 if (req.adapterFlags & Vamp::HostExt::PluginLoader::ADAPT_CHANNEL_COUNT) {
c@5 508 flags.push_back(AdapterFlag::ADAPT_CHANNEL_COUNT);
c@5 509 }
c@5 510 if (req.adapterFlags & Vamp::HostExt::PluginLoader::ADAPT_BUFFER_SIZE) {
c@5 511 flags.push_back(AdapterFlag::ADAPT_BUFFER_SIZE);
c@5 512 }
c@5 513
c@5 514 auto f = r.initAdapterFlags(flags.size());
c@5 515 for (size_t i = 0; i < flags.size(); ++i) {
c@5 516 f.set(i, flags[i]);
c@5 517 }
c@5 518 }
c@5 519
c@5 520 static void
c@5 521 readLoadRequest(Vamp::HostExt::LoadRequest &req,
c@5 522 const LoadRequest::Reader &r) {
c@5 523
c@5 524 req.pluginKey = r.getPluginKey();
c@5 525 req.inputSampleRate = r.getInputSampleRate();
c@5 526
c@5 527 int flags = 0;
c@28 528 auto aa = r.getAdapterFlags();
c@28 529 for (auto a: aa) {
c@5 530 if (a == AdapterFlag::ADAPT_INPUT_DOMAIN) {
c@5 531 flags |= Vamp::HostExt::PluginLoader::ADAPT_INPUT_DOMAIN;
c@5 532 }
c@5 533 if (a == AdapterFlag::ADAPT_CHANNEL_COUNT) {
c@5 534 flags |= Vamp::HostExt::PluginLoader::ADAPT_CHANNEL_COUNT;
c@5 535 }
c@5 536 if (a == AdapterFlag::ADAPT_BUFFER_SIZE) {
c@5 537 flags |= Vamp::HostExt::PluginLoader::ADAPT_BUFFER_SIZE;
c@5 538 }
c@5 539 }
c@5 540 req.adapterFlags = flags;
c@5 541 }
c@10 542
c@10 543 static void
c@10 544 buildLoadResponse(LoadResponse::Builder &b,
c@10 545 const Vamp::HostExt::LoadResponse &resp,
c@51 546 const PluginHandleMapper &pmapper) {
c@10 547
c@49 548 b.setPluginHandle(pmapper.pluginToHandle(resp.plugin));
c@10 549 auto sd = b.initStaticData();
c@10 550 buildPluginStaticData(sd, resp.staticData);
c@10 551 auto conf = b.initDefaultConfiguration();
c@10 552 buildPluginConfiguration(conf, resp.defaultConfiguration);
c@10 553 }
c@10 554
c@10 555 static void
c@10 556 readLoadResponse(Vamp::HostExt::LoadResponse &resp,
c@10 557 const LoadResponse::Reader &r,
c@51 558 const PluginHandleMapper &pmapper) {
c@10 559
c@49 560 resp.plugin = pmapper.handleToPlugin(r.getPluginHandle());
c@10 561 readPluginStaticData(resp.staticData, r.getStaticData());
c@10 562 readPluginConfiguration(resp.defaultConfiguration,
c@10 563 r.getDefaultConfiguration());
c@10 564 }
c@13 565
c@13 566 static void
c@13 567 buildConfigurationRequest(ConfigurationRequest::Builder &b,
c@13 568 const Vamp::HostExt::ConfigurationRequest &cr,
c@51 569 const PluginHandleMapper &pmapper) {
c@13 570
c@49 571 b.setPluginHandle(pmapper.pluginToHandle(cr.plugin));
c@13 572 auto c = b.initConfiguration();
c@13 573 buildPluginConfiguration(c, cr.configuration);
c@13 574 }
c@13 575
c@13 576 static void
c@13 577 readConfigurationRequest(Vamp::HostExt::ConfigurationRequest &cr,
c@13 578 const ConfigurationRequest::Reader &r,
c@51 579 const PluginHandleMapper &pmapper) {
c@13 580
c@13 581 auto h = r.getPluginHandle();
c@49 582 cr.plugin = pmapper.handleToPlugin(h);
c@13 583 auto c = r.getConfiguration();
c@13 584 readPluginConfiguration(cr.configuration, c);
c@13 585 }
c@13 586
c@13 587 static void
c@13 588 buildConfigurationResponse(ConfigurationResponse::Builder &b,
c@55 589 const Vamp::HostExt::ConfigurationResponse &cr,
c@55 590 const PluginHandleMapper &pmapper) {
c@13 591
c@55 592 b.setPluginHandle(pmapper.pluginToHandle(cr.plugin));
c@13 593 auto olist = b.initOutputs(cr.outputs.size());
c@13 594 for (size_t i = 0; i < cr.outputs.size(); ++i) {
c@13 595 auto od = olist[i];
c@13 596 buildOutputDescriptor(od, cr.outputs[i]);
c@13 597 }
c@13 598 }
c@13 599
c@13 600 static void
c@13 601 readConfigurationResponse(Vamp::HostExt::ConfigurationResponse &cr,
c@55 602 const ConfigurationResponse::Reader &r,
c@55 603 const PluginHandleMapper &pmapper) {
c@13 604
c@55 605 cr.plugin = pmapper.handleToPlugin(r.getPluginHandle());
c@13 606 cr.outputs.clear();
c@28 607 auto oo = r.getOutputs();
c@28 608 for (const auto &o: oo) {
c@13 609 Vamp::Plugin::OutputDescriptor desc;
c@13 610 readOutputDescriptor(desc, o);
c@13 611 cr.outputs.push_back(desc);
c@13 612 }
c@13 613 }
c@14 614
c@14 615 static void
c@14 616 buildProcessInput(ProcessInput::Builder &b,
c@14 617 Vamp::RealTime timestamp,
c@14 618 const std::vector<std::vector<float> > &buffers) {
c@14 619
c@14 620 auto t = b.initTimestamp();
c@14 621 buildRealTime(t, timestamp);
c@14 622 auto vv = b.initInputBuffers(buffers.size());
c@14 623 for (size_t ch = 0; ch < buffers.size(); ++ch) {
c@14 624 const int n = int(buffers[ch].size());
c@14 625 vv.init(ch, n);
c@14 626 auto v = vv[ch];
c@14 627 for (int i = 0; i < n; ++i) {
c@14 628 v.set(i, buffers[ch][i]);
c@14 629 }
c@14 630 }
c@14 631 }
c@14 632
c@14 633 static void
c@14 634 readProcessInput(Vamp::RealTime &timestamp,
c@14 635 std::vector<std::vector<float> > &buffers,
c@14 636 const ProcessInput::Reader &b) {
c@14 637
c@14 638 readRealTime(timestamp, b.getTimestamp());
c@14 639 buffers.clear();
c@28 640 auto vv = b.getInputBuffers();
c@28 641 for (const auto &v: vv) {
c@14 642 std::vector<float> buf;
c@14 643 for (auto x: v) {
c@14 644 buf.push_back(x);
c@14 645 }
c@14 646 buffers.push_back(buf);
c@14 647 }
c@14 648 }
c@14 649
c@14 650 static void
c@14 651 buildProcessRequest(ProcessRequest::Builder &b,
c@14 652 const Vamp::HostExt::ProcessRequest &pr,
c@51 653 const PluginHandleMapper &pmapper) {
c@14 654
c@49 655 b.setPluginHandle(pmapper.pluginToHandle(pr.plugin));
c@61 656 auto input = b.initProcessInput();
c@14 657 buildProcessInput(input, pr.timestamp, pr.inputBuffers);
c@14 658 }
c@14 659
c@14 660 static void
c@14 661 readProcessRequest(Vamp::HostExt::ProcessRequest &pr,
c@14 662 const ProcessRequest::Reader &r,
c@51 663 const PluginHandleMapper &pmapper) {
c@14 664
c@14 665 auto h = r.getPluginHandle();
c@49 666 pr.plugin = pmapper.handleToPlugin(h);
c@61 667 readProcessInput(pr.timestamp, pr.inputBuffers, r.getProcessInput());
c@14 668 }
c@14 669
c@14 670 static void
c@15 671 buildProcessResponse(ProcessResponse::Builder &b,
c@49 672 const Vamp::HostExt::ProcessResponse &pr,
c@51 673 const PluginHandleMapper &pmapper) {
c@15 674
c@52 675 b.setPluginHandle(pmapper.pluginToHandle(pr.plugin));
c@15 676 auto f = b.initFeatures();
c@51 677 buildFeatureSet(f, pr.features,
c@57 678 *pmapper.pluginToOutputIdMapper(pr.plugin));
c@15 679 }
c@15 680
c@15 681 static void
c@15 682 readProcessResponse(Vamp::HostExt::ProcessResponse &pr,
c@49 683 const ProcessResponse::Reader &r,
c@51 684 const PluginHandleMapper &pmapper) {
c@15 685
c@52 686 auto h = r.getPluginHandle();
c@52 687 pr.plugin = pmapper.handleToPlugin(h);
c@51 688 readFeatureSet(pr.features, r.getFeatures(),
c@57 689 *pmapper.handleToOutputIdMapper(r.getPluginHandle()));
c@15 690 }
c@15 691
c@15 692 static void
c@15 693 buildVampRequest_List(VampRequest::Builder &b) {
c@14 694 b.getRequest().setList();
c@14 695 }
c@14 696
c@14 697 static void
c@15 698 buildVampResponse_List(VampResponse::Builder &b,
c@56 699 const Vamp::HostExt::ListResponse &resp) {
c@56 700 b.setSuccess(true);
c@24 701 auto r = b.getResponse().initList();
c@64 702 auto p = r.initPlugins(resp.plugins.size());
c@64 703 for (size_t i = 0; i < resp.plugins.size(); ++i) {
c@24 704 auto pd = p[i];
c@64 705 buildPluginStaticData(pd, resp.plugins[i]);
c@15 706 }
c@15 707 }
c@15 708
c@15 709 static void
c@15 710 buildVampRequest_Load(VampRequest::Builder &b,
c@15 711 const Vamp::HostExt::LoadRequest &req) {
c@14 712 auto u = b.getRequest().initLoad();
c@14 713 buildLoadRequest(u, req);
c@14 714 }
c@14 715
c@14 716 static void
c@15 717 buildVampResponse_Load(VampResponse::Builder &b,
c@15 718 const Vamp::HostExt::LoadResponse &resp,
c@51 719 const PluginHandleMapper &pmapper) {
c@17 720 b.setSuccess(resp.plugin != 0);
c@15 721 auto u = b.getResponse().initLoad();
c@49 722 buildLoadResponse(u, resp, pmapper);
c@15 723 }
c@15 724
c@15 725 static void
c@15 726 buildVampRequest_Configure(VampRequest::Builder &b,
c@15 727 const Vamp::HostExt::ConfigurationRequest &cr,
c@51 728 const PluginHandleMapper &pmapper) {
c@14 729 auto u = b.getRequest().initConfigure();
c@49 730 buildConfigurationRequest(u, cr, pmapper);
c@14 731 }
c@14 732
c@14 733 static void
c@15 734 buildVampResponse_Configure(VampResponse::Builder &b,
c@55 735 const Vamp::HostExt::ConfigurationResponse &cr,
c@55 736 const PluginHandleMapper &pmapper) {
c@17 737 b.setSuccess(!cr.outputs.empty());
c@15 738 auto u = b.getResponse().initConfigure();
c@55 739 buildConfigurationResponse(u, cr, pmapper);
c@15 740 }
c@15 741
c@15 742 static void
c@15 743 buildVampRequest_Process(VampRequest::Builder &b,
c@15 744 const Vamp::HostExt::ProcessRequest &pr,
c@51 745 const PluginHandleMapper &pmapper) {
c@14 746 auto u = b.getRequest().initProcess();
c@49 747 buildProcessRequest(u, pr, pmapper);
c@14 748 }
c@15 749
c@15 750 static void
c@15 751 buildVampResponse_Process(VampResponse::Builder &b,
c@49 752 const Vamp::HostExt::ProcessResponse &pr,
c@51 753 const PluginHandleMapper &pmapper) {
c@17 754 b.setSuccess(true);
c@15 755 auto u = b.getResponse().initProcess();
c@51 756 buildProcessResponse(u, pr, pmapper);
c@15 757 }
c@17 758
c@17 759 static void
c@23 760 buildVampRequest_Finish(VampRequest::Builder &b,
c@55 761 const Vamp::HostExt::FinishRequest &req,
c@51 762 const PluginHandleMapper &pmapper) {
c@17 763
c@23 764 auto u = b.getRequest().initFinish();
c@55 765 u.setPluginHandle(pmapper.pluginToHandle(req.plugin));
c@17 766 }
c@17 767
c@17 768 static void
c@17 769 buildVampResponse_Finish(VampResponse::Builder &b,
c@49 770 const Vamp::HostExt::ProcessResponse &pr,
c@51 771 const PluginHandleMapper &pmapper) {
c@17 772
c@51 773 buildVampResponse_Process(b, pr, pmapper);
c@17 774 }
c@26 775
c@52 776 static void
c@52 777 buildVampResponse_Error(VampResponse::Builder &b,
c@52 778 const std::string &errorText,
c@52 779 RRType responseType)
c@52 780 {
c@52 781 std::string type;
c@52 782
c@52 783 if (responseType == RRType::List) {
c@52 784 type = "list";
c@52 785 b.getResponse().initList();
c@52 786 } else if (responseType == RRType::Load) {
c@52 787 type = "load";
c@52 788 b.getResponse().initLoad();
c@52 789 } else if (responseType == RRType::Configure) {
c@52 790 type = "configure";
c@52 791 b.getResponse().initConfigure();
c@52 792 } else if (responseType == RRType::Process) {
c@52 793 type = "process";
c@52 794 b.getResponse().initProcess();
c@52 795 } else if (responseType == RRType::Finish) {
c@52 796 type = "finish";
c@52 797 b.getResponse().initFinish();
c@52 798 } else {
c@52 799 type = "invalid";
c@52 800 }
c@52 801
c@52 802 b.setSuccess(false);
c@52 803 b.setErrorText(std::string("error in ") + type + " request: " + errorText);
c@52 804 }
c@52 805
c@52 806 static void
c@52 807 buildVampResponse_Exception(VampResponse::Builder &b,
c@52 808 const std::exception &e,
c@52 809 RRType responseType)
c@52 810 {
c@52 811 return buildVampResponse_Error(b, e.what(), responseType);
c@52 812 }
c@52 813
c@26 814 static RRType
c@26 815 getRequestResponseType(const VampRequest::Reader &r) {
c@26 816 switch (r.getRequest().which()) {
c@26 817 case VampRequest::Request::Which::LIST:
c@26 818 return RRType::List;
c@26 819 case VampRequest::Request::Which::LOAD:
c@26 820 return RRType::Load;
c@26 821 case VampRequest::Request::Which::CONFIGURE:
c@26 822 return RRType::Configure;
c@26 823 case VampRequest::Request::Which::PROCESS:
c@26 824 return RRType::Process;
c@26 825 case VampRequest::Request::Which::FINISH:
c@26 826 return RRType::Finish;
c@26 827 }
c@27 828 return RRType::NotValid;
c@26 829 }
c@26 830
c@26 831 static RRType
c@26 832 getRequestResponseType(const VampResponse::Reader &r) {
c@26 833 switch (r.getResponse().which()) {
c@26 834 case VampResponse::Response::Which::LIST:
c@26 835 return RRType::List;
c@26 836 case VampResponse::Response::Which::LOAD:
c@26 837 return RRType::Load;
c@26 838 case VampResponse::Response::Which::CONFIGURE:
c@26 839 return RRType::Configure;
c@26 840 case VampResponse::Response::Which::PROCESS:
c@26 841 return RRType::Process;
c@26 842 case VampResponse::Response::Which::FINISH:
c@26 843 return RRType::Finish;
c@26 844 }
c@27 845 return RRType::NotValid;
c@26 846 }
c@26 847
c@26 848 static void
c@26 849 readVampRequest_List(const VampRequest::Reader &r) {
c@26 850 if (getRequestResponseType(r) != RRType::List) {
c@27 851 throw std::logic_error("not a list request");
c@26 852 }
c@26 853 }
c@26 854
c@26 855 static void
c@56 856 readVampResponse_List(Vamp::HostExt::ListResponse &resp,
c@26 857 const VampResponse::Reader &r) {
c@26 858 if (getRequestResponseType(r) != RRType::List) {
c@27 859 throw std::logic_error("not a list response");
c@26 860 }
c@64 861 resp.plugins.clear();
c@26 862 if (r.getSuccess()) {
c@28 863 auto pp = r.getResponse().getList().getPlugins();
c@28 864 for (const auto &p: pp) {
c@26 865 Vamp::HostExt::PluginStaticData psd;
c@26 866 readPluginStaticData(psd, p);
c@64 867 resp.plugins.push_back(psd);
c@26 868 }
c@26 869 }
c@26 870 }
c@26 871
c@27 872 static void
c@27 873 readVampRequest_Load(Vamp::HostExt::LoadRequest &req,
c@27 874 const VampRequest::Reader &r) {
c@27 875 if (getRequestResponseType(r) != RRType::Load) {
c@27 876 throw std::logic_error("not a load request");
c@27 877 }
c@27 878 readLoadRequest(req, r.getRequest().getLoad());
c@27 879 }
c@27 880
c@27 881 static void
c@27 882 readVampResponse_Load(Vamp::HostExt::LoadResponse &resp,
c@27 883 const VampResponse::Reader &r,
c@51 884 const PluginHandleMapper &pmapper) {
c@27 885 if (getRequestResponseType(r) != RRType::Load) {
c@27 886 throw std::logic_error("not a load response");
c@27 887 }
c@27 888 resp = {};
c@27 889 if (r.getSuccess()) {
c@49 890 readLoadResponse(resp, r.getResponse().getLoad(), pmapper);
c@27 891 }
c@27 892 }
c@27 893
c@27 894 static void
c@27 895 readVampRequest_Configure(Vamp::HostExt::ConfigurationRequest &req,
c@27 896 const VampRequest::Reader &r,
c@51 897 const PluginHandleMapper &pmapper) {
c@27 898 if (getRequestResponseType(r) != RRType::Configure) {
c@27 899 throw std::logic_error("not a configuration request");
c@27 900 }
c@49 901 readConfigurationRequest(req, r.getRequest().getConfigure(), pmapper);
c@27 902 }
c@27 903
c@27 904 static void
c@27 905 readVampResponse_Configure(Vamp::HostExt::ConfigurationResponse &resp,
c@55 906 const VampResponse::Reader &r,
c@55 907 const PluginHandleMapper &pmapper) {
c@27 908 if (getRequestResponseType(r) != RRType::Configure) {
c@27 909 throw std::logic_error("not a configuration response");
c@27 910 }
c@27 911 resp = {};
c@27 912 if (r.getSuccess()) {
c@55 913 readConfigurationResponse(resp,
c@55 914 r.getResponse().getConfigure(),
c@55 915 pmapper);
c@27 916 }
c@27 917 }
c@27 918
c@27 919 static void
c@27 920 readVampRequest_Process(Vamp::HostExt::ProcessRequest &req,
c@27 921 const VampRequest::Reader &r,
c@51 922 const PluginHandleMapper &pmapper) {
c@27 923 if (getRequestResponseType(r) != RRType::Process) {
c@27 924 throw std::logic_error("not a process request");
c@27 925 }
c@49 926 readProcessRequest(req, r.getRequest().getProcess(), pmapper);
c@27 927 }
c@27 928
c@27 929 static void
c@27 930 readVampResponse_Process(Vamp::HostExt::ProcessResponse &resp,
c@49 931 const VampResponse::Reader &r,
c@51 932 const PluginHandleMapper &pmapper) {
c@27 933 if (getRequestResponseType(r) != RRType::Process) {
c@27 934 throw std::logic_error("not a process response");
c@27 935 }
c@27 936 resp = {};
c@27 937 if (r.getSuccess()) {
c@51 938 readProcessResponse(resp, r.getResponse().getProcess(), pmapper);
c@27 939 }
c@27 940 }
c@27 941
c@27 942 static void
c@55 943 readVampRequest_Finish(Vamp::HostExt::FinishRequest &req,
c@27 944 const VampRequest::Reader &r,
c@51 945 const PluginHandleMapper &pmapper) {
c@27 946 if (getRequestResponseType(r) != RRType::Finish) {
c@27 947 throw std::logic_error("not a finish request");
c@27 948 }
c@55 949 req.plugin = pmapper.handleToPlugin
c@27 950 (r.getRequest().getFinish().getPluginHandle());
c@27 951 }
c@27 952
c@27 953 static void
c@27 954 readVampResponse_Finish(Vamp::HostExt::ProcessResponse &resp,
c@49 955 const VampResponse::Reader &r,
c@51 956 const PluginHandleMapper &pmapper) {
c@27 957 if (getRequestResponseType(r) != RRType::Finish) {
c@27 958 throw std::logic_error("not a finish response");
c@27 959 }
c@27 960 resp = {};
c@27 961 if (r.getSuccess()) {
c@51 962 readProcessResponse(resp, r.getResponse().getFinish(), pmapper);
c@27 963 }
c@27 964 }
c@5 965 };
c@5 966
c@5 967 }
c@5 968
c@5 969