annotate capnproto/VampnProto.h @ 14:c35d0909a74e

Process requests
author Chris Cannam <c.cannam@qmul.ac.uk>
date Wed, 18 May 2016 12:21:23 +0100
parents 1d13354ddc44
children d907576aa299
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@5 3 #include "vamp.capnp.h"
c@5 4
c@5 5 #include <capnp/message.h>
c@5 6 #include <capnp/serialize-packed.h>
c@5 7
c@5 8 #include <vamp-hostsdk/Plugin.h>
c@5 9 #include <vamp-hostsdk/PluginLoader.h>
c@5 10 #include <vamp-hostsdk/PluginStaticData.h>
c@5 11
c@10 12 #include "bits/PluginHandleMapper.h"
c@10 13
c@5 14 namespace vampipe
c@5 15 {
c@5 16
c@5 17 /**
c@5 18 * Convert the structures laid out in the Vamp SDK classes into Cap'n
c@6 19 * Proto structures (and back again).
c@5 20 *
c@6 21 * At least some of this will be necessary for any implementation
c@6 22 * using Cap'n Proto that uses the C++ Vamp SDK to provide its
c@6 23 * reference structures. An implementation could alternatively use the
c@6 24 * Cap'n Proto structures directly, and interact with Vamp plugins
c@6 25 * using the Vamp C API, without using the C++ Vamp SDK classes at
c@6 26 * all.
c@5 27 */
c@6 28 class VampnProto
c@5 29 {
c@5 30 public:
c@5 31 typedef ::capnp::MallocMessageBuilder MsgBuilder;
c@5 32
c@5 33 template <typename T, typename B>
c@5 34 static void buildBasicDescriptor(B &basic, const T &t) {
c@5 35 basic.setIdentifier(t.identifier);
c@5 36 basic.setName(t.name);
c@5 37 basic.setDescription(t.description);
c@5 38 }
c@5 39
c@5 40 template <typename T, typename B>
c@5 41 static void readBasicDescriptor(T &t, const B &basic) {
c@5 42 t.identifier = basic.getIdentifier();
c@5 43 t.name = basic.getName();
c@5 44 t.description = basic.getDescription();
c@5 45 }
c@5 46
c@5 47 template <typename T, typename M>
c@5 48 static void buildValueExtents(M &m, const T &t) {
c@5 49 m.setMinValue(t.minValue);
c@5 50 m.setMaxValue(t.maxValue);
c@5 51 }
c@5 52
c@5 53 template <typename T, typename M>
c@5 54 static void readValueExtents(T &t, const M &m) {
c@5 55 t.minValue = m.getMinValue();
c@5 56 t.maxValue = m.getMaxValue();
c@5 57 }
c@5 58
c@5 59 static void buildRealTime(RealTime::Builder &b, const Vamp::RealTime &t) {
c@5 60 b.setSec(t.sec);
c@5 61 b.setNsec(t.nsec);
c@5 62 }
c@5 63
c@5 64 static void readRealTime(Vamp::RealTime &t, const RealTime::Reader &r) {
c@5 65 t.sec = r.getSec();
c@5 66 t.nsec = r.getNsec();
c@5 67 }
c@5 68
c@5 69 static SampleType
c@5 70 fromSampleType(Vamp::Plugin::OutputDescriptor::SampleType t) {
c@5 71 switch (t) {
c@5 72 case Vamp::Plugin::OutputDescriptor::OneSamplePerStep:
c@5 73 return SampleType::ONE_SAMPLE_PER_STEP;
c@5 74 case Vamp::Plugin::OutputDescriptor::FixedSampleRate:
c@5 75 return SampleType::FIXED_SAMPLE_RATE;
c@5 76 case Vamp::Plugin::OutputDescriptor::VariableSampleRate:
c@5 77 return SampleType::VARIABLE_SAMPLE_RATE;
c@5 78 }
c@5 79 throw std::logic_error("unexpected Vamp SampleType enum value");
c@5 80 }
c@5 81
c@5 82 static Vamp::Plugin::OutputDescriptor::SampleType
c@5 83 toSampleType(SampleType t) {
c@5 84 switch (t) {
c@5 85 case SampleType::ONE_SAMPLE_PER_STEP:
c@5 86 return Vamp::Plugin::OutputDescriptor::OneSamplePerStep;
c@5 87 case SampleType::FIXED_SAMPLE_RATE:
c@5 88 return Vamp::Plugin::OutputDescriptor::FixedSampleRate;
c@5 89 case SampleType::VARIABLE_SAMPLE_RATE:
c@5 90 return Vamp::Plugin::OutputDescriptor::VariableSampleRate;
c@5 91 }
c@5 92 throw std::logic_error("unexpected Capnp SampleType enum value");
c@5 93 }
c@5 94
c@5 95 static void
c@5 96 buildOutputDescriptor(OutputDescriptor::Builder &b,
c@5 97 const Vamp::Plugin::OutputDescriptor &od) {
c@5 98
c@5 99 auto basic = b.initBasic();
c@5 100 buildBasicDescriptor(basic, od);
c@5 101
c@5 102 b.setUnit(od.unit);
c@5 103
c@5 104 b.setSampleType(fromSampleType(od.sampleType));
c@5 105 b.setSampleRate(od.sampleRate);
c@5 106 b.setHasDuration(od.hasDuration);
c@5 107
c@5 108 b.setHasFixedBinCount(od.hasFixedBinCount);
c@5 109 if (od.hasFixedBinCount) {
c@5 110 b.setBinCount(od.binCount);
c@5 111 if (od.binNames.size() > 0) {
c@5 112 auto binNames = b.initBinNames(od.binNames.size());
c@5 113 for (size_t i = 0; i < od.binNames.size(); ++i) {
c@5 114 binNames.set(i, od.binNames[i]);
c@5 115 }
c@5 116 }
c@5 117 }
c@5 118
c@5 119 b.setHasKnownExtents(od.hasKnownExtents);
c@5 120 if (od.hasKnownExtents) {
c@5 121 buildValueExtents(b, od);
c@5 122 }
c@5 123
c@5 124 b.setIsQuantized(od.isQuantized);
c@5 125 if (od.isQuantized) {
c@5 126 b.setQuantizeStep(od.quantizeStep);
c@5 127 }
c@5 128 }
c@5 129
c@5 130 static void
c@5 131 readOutputDescriptor(Vamp::Plugin::OutputDescriptor &od,
c@5 132 const OutputDescriptor::Reader &r) {
c@5 133
c@5 134 readBasicDescriptor(od, r.getBasic());
c@5 135
c@5 136 od.unit = r.getUnit();
c@5 137
c@5 138 od.sampleType = toSampleType(r.getSampleType());
c@5 139 od.sampleRate = r.getSampleRate();
c@5 140 od.hasDuration = r.getHasDuration();
c@5 141
c@5 142 od.hasFixedBinCount = r.getHasFixedBinCount();
c@5 143 if (od.hasFixedBinCount) {
c@5 144 od.binCount = r.getBinCount();
c@13 145 od.binNames.clear();
c@5 146 for (const auto &n: r.getBinNames()) {
c@5 147 od.binNames.push_back(n);
c@5 148 }
c@5 149 }
c@5 150
c@5 151 od.hasKnownExtents = r.getHasKnownExtents();
c@5 152 if (od.hasKnownExtents) {
c@5 153 readValueExtents(od, r);
c@5 154 }
c@5 155
c@5 156 od.isQuantized = r.getIsQuantized();
c@5 157 if (od.isQuantized) {
c@5 158 od.quantizeStep = r.getQuantizeStep();
c@5 159 }
c@5 160 }
c@5 161
c@5 162 static void
c@5 163 buildParameterDescriptor(ParameterDescriptor::Builder &b,
c@5 164 const Vamp::Plugin::ParameterDescriptor &pd) {
c@5 165
c@5 166 auto basic = b.initBasic();
c@5 167 buildBasicDescriptor(basic, pd);
c@5 168
c@5 169 b.setUnit(pd.unit);
c@5 170
c@5 171 buildValueExtents(b, pd);
c@5 172
c@5 173 b.setDefaultValue(pd.defaultValue);
c@5 174
c@5 175 b.setIsQuantized(pd.isQuantized);
c@5 176 if (pd.isQuantized) {
c@5 177 b.setQuantizeStep(pd.quantizeStep);
c@5 178 }
c@5 179
c@5 180 if (pd.valueNames.size() > 0) {
c@5 181 auto valueNames = b.initValueNames(pd.valueNames.size());
c@5 182 for (size_t i = 0; i < pd.valueNames.size(); ++i) {
c@5 183 valueNames.set(i, pd.valueNames[i]);
c@5 184 }
c@5 185 }
c@5 186 }
c@5 187
c@5 188 static void
c@5 189 readParameterDescriptor(Vamp::Plugin::ParameterDescriptor &pd,
c@5 190 const ParameterDescriptor::Reader &r) {
c@5 191
c@5 192 readBasicDescriptor(pd, r.getBasic());
c@5 193
c@5 194 pd.unit = r.getUnit();
c@5 195
c@5 196 readValueExtents(pd, r);
c@5 197
c@5 198 pd.defaultValue = r.getDefaultValue();
c@5 199
c@5 200 pd.isQuantized = r.getIsQuantized();
c@5 201 if (pd.isQuantized) {
c@5 202 pd.quantizeStep = r.getQuantizeStep();
c@5 203 }
c@5 204
c@13 205 pd.valueNames.clear();
c@5 206 for (const auto &n: r.getValueNames()) {
c@5 207 pd.valueNames.push_back(n);
c@5 208 }
c@5 209 }
c@5 210
c@5 211 static void
c@5 212 buildFeature(Feature::Builder &b,
c@5 213 const Vamp::Plugin::Feature &f) {
c@5 214
c@5 215 b.setHasTimestamp(f.hasTimestamp);
c@5 216 if (f.hasTimestamp) {
c@5 217 auto timestamp = b.initTimestamp();
c@5 218 buildRealTime(timestamp, f.timestamp);
c@5 219 }
c@5 220
c@5 221 b.setHasDuration(f.hasDuration);
c@5 222 if (f.hasDuration) {
c@5 223 auto duration = b.initDuration();
c@5 224 buildRealTime(duration, f.duration);
c@5 225 }
c@5 226
c@5 227 b.setLabel(f.label);
c@5 228
c@5 229 if (f.values.size() > 0) {
c@5 230 auto values = b.initValues(f.values.size());
c@5 231 for (size_t i = 0; i < f.values.size(); ++i) {
c@5 232 values.set(i, f.values[i]);
c@5 233 }
c@5 234 }
c@5 235 }
c@5 236
c@5 237 static void
c@5 238 readFeature(Vamp::Plugin::Feature &f,
c@5 239 const Feature::Reader &r) {
c@5 240
c@5 241 f.hasTimestamp = r.getHasTimestamp();
c@5 242 if (f.hasTimestamp) {
c@5 243 readRealTime(f.timestamp, r.getTimestamp());
c@5 244 }
c@5 245
c@5 246 f.hasDuration = r.getHasDuration();
c@5 247 if (f.hasDuration) {
c@5 248 readRealTime(f.duration, r.getDuration());
c@5 249 }
c@5 250
c@5 251 f.label = r.getLabel();
c@5 252
c@13 253 f.values.clear();
c@5 254 for (auto v: r.getValues()) {
c@5 255 f.values.push_back(v);
c@5 256 }
c@5 257 }
c@5 258
c@5 259 static void
c@5 260 buildFeatureSet(FeatureSet::Builder &b,
c@5 261 const Vamp::Plugin::FeatureSet &fs) {
c@5 262
c@5 263 auto featureset = b.initFeaturePairs(fs.size());
c@5 264 int ix = 0;
c@5 265 for (const auto &fsi : fs) {
c@5 266 auto fspair = featureset[ix];
c@5 267 fspair.setOutput(fsi.first);
c@5 268 auto featurelist = fspair.initFeatures(fsi.second.size());
c@5 269 for (size_t j = 0; j < fsi.second.size(); ++j) {
c@5 270 auto feature = featurelist[j];
c@5 271 buildFeature(feature, fsi.second[j]);
c@5 272 }
c@5 273 ++ix;
c@5 274 }
c@5 275 }
c@5 276
c@5 277 static void
c@5 278 readFeatureSet(Vamp::Plugin::FeatureSet &fs,
c@5 279 const FeatureSet::Reader &r) {
c@5 280
c@13 281 fs.clear();
c@5 282 for (const auto &p: r.getFeaturePairs()) {
c@5 283 Vamp::Plugin::FeatureList vfl;
c@5 284 for (const auto &f: p.getFeatures()) {
c@5 285 Vamp::Plugin::Feature vf;
c@5 286 readFeature(vf, f);
c@5 287 vfl.push_back(vf);
c@5 288 }
c@5 289 fs[p.getOutput()] = vfl;
c@5 290 }
c@5 291 }
c@5 292
c@5 293 static InputDomain
c@5 294 fromInputDomain(Vamp::Plugin::InputDomain d) {
c@5 295 switch(d) {
c@5 296 case Vamp::Plugin::TimeDomain:
c@5 297 return InputDomain::TIME_DOMAIN;
c@5 298 case Vamp::Plugin::FrequencyDomain:
c@5 299 return InputDomain::FREQUENCY_DOMAIN;
c@5 300 default:
c@5 301 throw std::logic_error("unexpected Vamp InputDomain enum value");
c@5 302 }
c@5 303 }
c@5 304
c@5 305 static Vamp::Plugin::InputDomain
c@5 306 toInputDomain(InputDomain d) {
c@5 307 switch(d) {
c@5 308 case InputDomain::TIME_DOMAIN:
c@5 309 return Vamp::Plugin::TimeDomain;
c@5 310 case InputDomain::FREQUENCY_DOMAIN:
c@5 311 return Vamp::Plugin::FrequencyDomain;
c@5 312 default:
c@5 313 throw std::logic_error("unexpected Capnp InputDomain enum value");
c@5 314 }
c@5 315 }
c@5 316
c@5 317 static void
c@5 318 buildPluginStaticData(PluginStaticData::Builder &b,
c@5 319 const Vamp::HostExt::PluginStaticData &d) {
c@5 320
c@5 321 b.setPluginKey(d.pluginKey);
c@5 322
c@5 323 auto basic = b.initBasic();
c@5 324 buildBasicDescriptor(basic, d.basic);
c@5 325
c@5 326 b.setMaker(d.maker);
c@5 327 b.setCopyright(d.copyright);
c@5 328 b.setPluginVersion(d.pluginVersion);
c@5 329
c@5 330 auto clist = b.initCategory(d.category.size());
c@5 331 for (size_t i = 0; i < d.category.size(); ++i) {
c@5 332 clist.set(i, d.category[i]);
c@5 333 }
c@5 334
c@5 335 b.setMinChannelCount(d.minChannelCount);
c@5 336 b.setMaxChannelCount(d.maxChannelCount);
c@5 337
c@5 338 const auto &vparams = d.parameters;
c@5 339 auto plist = b.initParameters(vparams.size());
c@5 340 for (size_t i = 0; i < vparams.size(); ++i) {
c@5 341 auto pd = plist[i];
c@5 342 buildParameterDescriptor(pd, vparams[i]);
c@5 343 }
c@5 344
c@5 345 const auto &vprogs = d.programs;
c@5 346 auto pglist = b.initPrograms(vprogs.size());
c@5 347 for (size_t i = 0; i < vprogs.size(); ++i) {
c@5 348 pglist.set(i, vprogs[i]);
c@5 349 }
c@5 350
c@5 351 b.setInputDomain(fromInputDomain(d.inputDomain));
c@5 352
c@5 353 const auto &vouts = d.basicOutputInfo;
c@5 354 auto olist = b.initBasicOutputInfo(vouts.size());
c@5 355 for (size_t i = 0; i < vouts.size(); ++i) {
c@5 356 auto od = olist[i];
c@5 357 buildBasicDescriptor(od, vouts[i]);
c@5 358 }
c@5 359 }
c@5 360
c@5 361 static void
c@5 362 readPluginStaticData(Vamp::HostExt::PluginStaticData &d,
c@5 363 const PluginStaticData::Reader &r) {
c@5 364
c@5 365 d.pluginKey = r.getPluginKey();
c@5 366
c@5 367 readBasicDescriptor(d.basic, r.getBasic());
c@5 368
c@5 369 d.maker = r.getMaker();
c@5 370 d.copyright = r.getCopyright();
c@5 371 d.pluginVersion = r.getPluginVersion();
c@5 372
c@13 373 d.category.clear();
c@5 374 for (auto c: r.getCategory()) {
c@5 375 d.category.push_back(c);
c@5 376 }
c@5 377
c@5 378 d.minChannelCount = r.getMinChannelCount();
c@5 379 d.maxChannelCount = r.getMaxChannelCount();
c@5 380
c@13 381 d.parameters.clear();
c@5 382 for (auto p: r.getParameters()) {
c@5 383 Vamp::Plugin::ParameterDescriptor pd;
c@5 384 readParameterDescriptor(pd, p);
c@5 385 d.parameters.push_back(pd);
c@5 386 }
c@5 387
c@13 388 d.programs.clear();
c@5 389 for (auto p: r.getPrograms()) {
c@5 390 d.programs.push_back(p);
c@5 391 }
c@5 392
c@5 393 d.inputDomain = toInputDomain(r.getInputDomain());
c@5 394
c@13 395 d.basicOutputInfo.clear();
c@5 396 for (auto o: r.getBasicOutputInfo()) {
c@5 397 Vamp::HostExt::PluginStaticData::Basic b;
c@5 398 readBasicDescriptor(b, o);
c@5 399 d.basicOutputInfo.push_back(b);
c@5 400 }
c@5 401 }
c@5 402
c@5 403 static void
c@5 404 buildPluginConfiguration(PluginConfiguration::Builder &b,
c@5 405 const Vamp::HostExt::PluginConfiguration &c) {
c@5 406
c@5 407 const auto &vparams = c.parameterValues;
c@5 408 auto params = b.initParameterValues(vparams.size());
c@5 409 int i = 0;
c@5 410 for (const auto &pp : vparams) {
c@5 411 auto param = params[i++];
c@5 412 param.setParameter(pp.first);
c@5 413 param.setValue(pp.second);
c@5 414 }
c@5 415
c@5 416 b.setCurrentProgram(c.currentProgram);
c@5 417 b.setChannelCount(c.channelCount);
c@5 418 b.setStepSize(c.stepSize);
c@5 419 b.setBlockSize(c.blockSize);
c@5 420 }
c@5 421
c@5 422 static void
c@5 423 readPluginConfiguration(Vamp::HostExt::PluginConfiguration &c,
c@5 424 const PluginConfiguration::Reader &r) {
c@5 425
c@5 426 for (const auto &pp: r.getParameterValues()) {
c@5 427 c.parameterValues[pp.getParameter()] = pp.getValue();
c@5 428 }
c@5 429
c@5 430 c.currentProgram = r.getCurrentProgram();
c@5 431 c.channelCount = r.getChannelCount();
c@5 432 c.stepSize = r.getStepSize();
c@5 433 c.blockSize = r.getBlockSize();
c@5 434 }
c@5 435
c@5 436 static void
c@5 437 buildLoadRequest(LoadRequest::Builder &r,
c@5 438 const Vamp::HostExt::LoadRequest &req) {
c@5 439
c@5 440 r.setPluginKey(req.pluginKey);
c@5 441 r.setInputSampleRate(req.inputSampleRate);
c@5 442
c@5 443 std::vector<AdapterFlag> flags;
c@5 444 if (req.adapterFlags & Vamp::HostExt::PluginLoader::ADAPT_INPUT_DOMAIN) {
c@5 445 flags.push_back(AdapterFlag::ADAPT_INPUT_DOMAIN);
c@5 446 }
c@5 447 if (req.adapterFlags & Vamp::HostExt::PluginLoader::ADAPT_CHANNEL_COUNT) {
c@5 448 flags.push_back(AdapterFlag::ADAPT_CHANNEL_COUNT);
c@5 449 }
c@5 450 if (req.adapterFlags & Vamp::HostExt::PluginLoader::ADAPT_BUFFER_SIZE) {
c@5 451 flags.push_back(AdapterFlag::ADAPT_BUFFER_SIZE);
c@5 452 }
c@5 453
c@5 454 auto f = r.initAdapterFlags(flags.size());
c@5 455 for (size_t i = 0; i < flags.size(); ++i) {
c@5 456 f.set(i, flags[i]);
c@5 457 }
c@5 458 }
c@5 459
c@5 460 static void
c@5 461 readLoadRequest(Vamp::HostExt::LoadRequest &req,
c@5 462 const LoadRequest::Reader &r) {
c@5 463
c@5 464 req.pluginKey = r.getPluginKey();
c@5 465 req.inputSampleRate = r.getInputSampleRate();
c@5 466
c@5 467 int flags = 0;
c@5 468 for (const auto &a: r.getAdapterFlags()) {
c@5 469 if (a == AdapterFlag::ADAPT_INPUT_DOMAIN) {
c@5 470 flags |= Vamp::HostExt::PluginLoader::ADAPT_INPUT_DOMAIN;
c@5 471 }
c@5 472 if (a == AdapterFlag::ADAPT_CHANNEL_COUNT) {
c@5 473 flags |= Vamp::HostExt::PluginLoader::ADAPT_CHANNEL_COUNT;
c@5 474 }
c@5 475 if (a == AdapterFlag::ADAPT_BUFFER_SIZE) {
c@5 476 flags |= Vamp::HostExt::PluginLoader::ADAPT_BUFFER_SIZE;
c@5 477 }
c@5 478 }
c@5 479 req.adapterFlags = flags;
c@5 480 }
c@10 481
c@10 482 static void
c@10 483 buildLoadResponse(LoadResponse::Builder &b,
c@10 484 const Vamp::HostExt::LoadResponse &resp,
c@10 485 PluginHandleMapper &mapper) {
c@10 486
c@10 487 b.setPluginHandle(mapper.pluginToHandle(resp.plugin));
c@10 488 auto sd = b.initStaticData();
c@10 489 buildPluginStaticData(sd, resp.staticData);
c@10 490 auto conf = b.initDefaultConfiguration();
c@10 491 buildPluginConfiguration(conf, resp.defaultConfiguration);
c@10 492 }
c@10 493
c@10 494 static void
c@10 495 readLoadResponse(Vamp::HostExt::LoadResponse &resp,
c@10 496 const LoadResponse::Reader &r,
c@10 497 PluginHandleMapper &mapper) {
c@10 498
c@10 499 resp.plugin = mapper.handleToPlugin(r.getPluginHandle());
c@10 500 readPluginStaticData(resp.staticData, r.getStaticData());
c@10 501 readPluginConfiguration(resp.defaultConfiguration,
c@10 502 r.getDefaultConfiguration());
c@10 503 }
c@13 504
c@13 505 static void
c@13 506 buildConfigurationRequest(ConfigurationRequest::Builder &b,
c@13 507 const Vamp::HostExt::ConfigurationRequest &cr,
c@13 508 PluginHandleMapper &mapper) {
c@13 509
c@13 510 b.setPluginHandle(mapper.pluginToHandle(cr.plugin));
c@13 511 auto c = b.initConfiguration();
c@13 512 buildPluginConfiguration(c, cr.configuration);
c@13 513 }
c@13 514
c@13 515 static void
c@13 516 readConfigurationRequest(Vamp::HostExt::ConfigurationRequest &cr,
c@13 517 const ConfigurationRequest::Reader &r,
c@13 518 PluginHandleMapper &mapper) {
c@13 519
c@13 520 auto h = r.getPluginHandle();
c@13 521 cr.plugin = mapper.handleToPlugin(h);
c@13 522 auto c = r.getConfiguration();
c@13 523 readPluginConfiguration(cr.configuration, c);
c@13 524 }
c@13 525
c@13 526 static void
c@13 527 buildConfigurationResponse(ConfigurationResponse::Builder &b,
c@13 528 const Vamp::HostExt::ConfigurationResponse &cr) {
c@13 529
c@13 530 auto olist = b.initOutputs(cr.outputs.size());
c@13 531 for (size_t i = 0; i < cr.outputs.size(); ++i) {
c@13 532 auto od = olist[i];
c@13 533 buildOutputDescriptor(od, cr.outputs[i]);
c@13 534 }
c@13 535 }
c@13 536
c@13 537 static void
c@13 538 readConfigurationResponse(Vamp::HostExt::ConfigurationResponse &cr,
c@13 539 const ConfigurationResponse::Reader &r) {
c@13 540
c@13 541 cr.outputs.clear();
c@13 542 for (const auto &o: r.getOutputs()) {
c@13 543 Vamp::Plugin::OutputDescriptor desc;
c@13 544 readOutputDescriptor(desc, o);
c@13 545 cr.outputs.push_back(desc);
c@13 546 }
c@13 547 }
c@14 548
c@14 549 static void
c@14 550 buildProcessInput(ProcessInput::Builder &b,
c@14 551 Vamp::RealTime timestamp,
c@14 552 const std::vector<std::vector<float> > &buffers) {
c@14 553
c@14 554 auto t = b.initTimestamp();
c@14 555 buildRealTime(t, timestamp);
c@14 556 auto vv = b.initInputBuffers(buffers.size());
c@14 557 for (size_t ch = 0; ch < buffers.size(); ++ch) {
c@14 558 const int n = int(buffers[ch].size());
c@14 559 vv.init(ch, n);
c@14 560 auto v = vv[ch];
c@14 561 for (int i = 0; i < n; ++i) {
c@14 562 v.set(i, buffers[ch][i]);
c@14 563 }
c@14 564 }
c@14 565 }
c@14 566
c@14 567 static void
c@14 568 readProcessInput(Vamp::RealTime &timestamp,
c@14 569 std::vector<std::vector<float> > &buffers,
c@14 570 const ProcessInput::Reader &b) {
c@14 571
c@14 572 readRealTime(timestamp, b.getTimestamp());
c@14 573 buffers.clear();
c@14 574 for (const auto &v: b.getInputBuffers()) {
c@14 575 std::vector<float> buf;
c@14 576 for (auto x: v) {
c@14 577 buf.push_back(x);
c@14 578 }
c@14 579 buffers.push_back(buf);
c@14 580 }
c@14 581 }
c@14 582
c@14 583 static void
c@14 584 buildProcessRequest(ProcessRequest::Builder &b,
c@14 585 const Vamp::HostExt::ProcessRequest &pr,
c@14 586 PluginHandleMapper &mapper) {
c@14 587
c@14 588 b.setPluginHandle(mapper.pluginToHandle(pr.plugin));
c@14 589 auto input = b.initInput();
c@14 590 buildProcessInput(input, pr.timestamp, pr.inputBuffers);
c@14 591 }
c@14 592
c@14 593 static void
c@14 594 readProcessRequest(Vamp::HostExt::ProcessRequest &pr,
c@14 595 const ProcessRequest::Reader &r,
c@14 596 PluginHandleMapper &mapper) {
c@14 597
c@14 598 auto h = r.getPluginHandle();
c@14 599 pr.plugin = mapper.handleToPlugin(h);
c@14 600 readProcessInput(pr.timestamp, pr.inputBuffers, r.getInput());
c@14 601 }
c@14 602
c@14 603 static void
c@14 604 buildVampListRequest(VampRequest::Builder &b) {
c@14 605 b.getRequest().setList();
c@14 606 }
c@14 607
c@14 608 static void
c@14 609 buildVampLoadRequest(VampRequest::Builder &b,
c@14 610 const Vamp::HostExt::LoadRequest &req) {
c@14 611 auto u = b.getRequest().initLoad();
c@14 612 buildLoadRequest(u, req);
c@14 613 }
c@14 614
c@14 615 static void
c@14 616 buildVampConfigureRequest(VampRequest::Builder &b,
c@14 617 const Vamp::HostExt::ConfigurationRequest &cr,
c@14 618 PluginHandleMapper &mapper) {
c@14 619 auto u = b.getRequest().initConfigure();
c@14 620 buildConfigurationRequest(u, cr, mapper);
c@14 621 }
c@14 622
c@14 623 static void
c@14 624 buildVampProcessRequest(VampRequest::Builder &b,
c@14 625 const Vamp::HostExt::ProcessRequest &pr,
c@14 626 PluginHandleMapper &mapper) {
c@14 627 auto u = b.getRequest().initProcess();
c@14 628 buildProcessRequest(u, pr, mapper);
c@14 629 }
c@14 630
c@14 631
c@14 632 //...!!! and responses
c@5 633 };
c@5 634
c@5 635 }
c@5 636
c@5 637