comparison capnproto/VampnProto.h @ 49:f3f7561233d6

Begin plugin output id / index mapping for use in feature sets
author Chris Cannam <c.cannam@qmul.ac.uk>
date Fri, 16 Sep 2016 14:13:21 +0100
parents b5005ebc5116
children f4244a2d55ac
comparison
equal deleted inserted replaced
48:ce6cb3308bd7 49:f3f7561233d6
40 #include <vamp-hostsdk/Plugin.h> 40 #include <vamp-hostsdk/Plugin.h>
41 #include <vamp-hostsdk/PluginLoader.h> 41 #include <vamp-hostsdk/PluginLoader.h>
42 #include <vamp-hostsdk/PluginStaticData.h> 42 #include <vamp-hostsdk/PluginStaticData.h>
43 43
44 #include "bits/PluginHandleMapper.h" 44 #include "bits/PluginHandleMapper.h"
45 #include "bits/PluginOutputIdMapper.h"
45 #include "bits/RequestResponseType.h" 46 #include "bits/RequestResponseType.h"
46 47
47 namespace vampipe 48 namespace vampipe
48 { 49 {
49 50
292 } 293 }
293 } 294 }
294 295
295 static void 296 static void
296 buildFeatureSet(FeatureSet::Builder &b, 297 buildFeatureSet(FeatureSet::Builder &b,
297 const Vamp::Plugin::FeatureSet &fs) { 298 const Vamp::Plugin::FeatureSet &fs,
299 const PluginOutputIdMapper &omapper) {
298 300
299 auto featureset = b.initFeaturePairs(fs.size()); 301 auto featureset = b.initFeaturePairs(fs.size());
300 int ix = 0; 302 int ix = 0;
301 for (const auto &fsi : fs) { 303 for (const auto &fsi : fs) {
302 auto fspair = featureset[ix]; 304 auto fspair = featureset[ix];
303 fspair.setOutput(fsi.first); 305 fspair.setOutput(omapper.indexToId(fsi.first));
304 auto featurelist = fspair.initFeatures(fsi.second.size()); 306 auto featurelist = fspair.initFeatures(fsi.second.size());
305 for (size_t j = 0; j < fsi.second.size(); ++j) { 307 for (size_t j = 0; j < fsi.second.size(); ++j) {
306 auto feature = featurelist[j]; 308 auto feature = featurelist[j];
307 buildFeature(feature, fsi.second[j]); 309 buildFeature(feature, fsi.second[j]);
308 } 310 }
310 } 312 }
311 } 313 }
312 314
313 static void 315 static void
314 readFeatureSet(Vamp::Plugin::FeatureSet &fs, 316 readFeatureSet(Vamp::Plugin::FeatureSet &fs,
315 const FeatureSet::Reader &r) { 317 const FeatureSet::Reader &r,
318 const PluginOutputIdMapper &omapper) {
316 319
317 fs.clear(); 320 fs.clear();
318 auto pp = r.getFeaturePairs(); 321 auto pp = r.getFeaturePairs();
319 for (const auto &p: pp) { 322 for (const auto &p: pp) {
320 Vamp::Plugin::FeatureList vfl; 323 Vamp::Plugin::FeatureList vfl;
322 for (const auto &f: ff) { 325 for (const auto &f: ff) {
323 Vamp::Plugin::Feature vf; 326 Vamp::Plugin::Feature vf;
324 readFeature(vf, f); 327 readFeature(vf, f);
325 vfl.push_back(vf); 328 vfl.push_back(vf);
326 } 329 }
327 fs[p.getOutput()] = vfl; 330 fs[omapper.idToIndex(p.getOutput())] = vfl;
328 } 331 }
329 } 332 }
330 333
331 static InputDomain 334 static InputDomain
332 fromInputDomain(Vamp::Plugin::InputDomain d) { 335 fromInputDomain(Vamp::Plugin::InputDomain d) {
524 } 527 }
525 528
526 static void 529 static void
527 buildLoadResponse(LoadResponse::Builder &b, 530 buildLoadResponse(LoadResponse::Builder &b,
528 const Vamp::HostExt::LoadResponse &resp, 531 const Vamp::HostExt::LoadResponse &resp,
529 PluginHandleMapper &mapper) { 532 PluginHandleMapper &pmapper) {
530 533
531 b.setPluginHandle(mapper.pluginToHandle(resp.plugin)); 534 b.setPluginHandle(pmapper.pluginToHandle(resp.plugin));
532 auto sd = b.initStaticData(); 535 auto sd = b.initStaticData();
533 buildPluginStaticData(sd, resp.staticData); 536 buildPluginStaticData(sd, resp.staticData);
534 auto conf = b.initDefaultConfiguration(); 537 auto conf = b.initDefaultConfiguration();
535 buildPluginConfiguration(conf, resp.defaultConfiguration); 538 buildPluginConfiguration(conf, resp.defaultConfiguration);
536 } 539 }
537 540
538 static void 541 static void
539 readLoadResponse(Vamp::HostExt::LoadResponse &resp, 542 readLoadResponse(Vamp::HostExt::LoadResponse &resp,
540 const LoadResponse::Reader &r, 543 const LoadResponse::Reader &r,
541 PluginHandleMapper &mapper) { 544 PluginHandleMapper &pmapper) {
542 545
543 resp.plugin = mapper.handleToPlugin(r.getPluginHandle()); 546 resp.plugin = pmapper.handleToPlugin(r.getPluginHandle());
544 readPluginStaticData(resp.staticData, r.getStaticData()); 547 readPluginStaticData(resp.staticData, r.getStaticData());
545 readPluginConfiguration(resp.defaultConfiguration, 548 readPluginConfiguration(resp.defaultConfiguration,
546 r.getDefaultConfiguration()); 549 r.getDefaultConfiguration());
547 } 550 }
548 551
549 static void 552 static void
550 buildConfigurationRequest(ConfigurationRequest::Builder &b, 553 buildConfigurationRequest(ConfigurationRequest::Builder &b,
551 const Vamp::HostExt::ConfigurationRequest &cr, 554 const Vamp::HostExt::ConfigurationRequest &cr,
552 PluginHandleMapper &mapper) { 555 PluginHandleMapper &pmapper) {
553 556
554 b.setPluginHandle(mapper.pluginToHandle(cr.plugin)); 557 b.setPluginHandle(pmapper.pluginToHandle(cr.plugin));
555 auto c = b.initConfiguration(); 558 auto c = b.initConfiguration();
556 buildPluginConfiguration(c, cr.configuration); 559 buildPluginConfiguration(c, cr.configuration);
557 } 560 }
558 561
559 static void 562 static void
560 readConfigurationRequest(Vamp::HostExt::ConfigurationRequest &cr, 563 readConfigurationRequest(Vamp::HostExt::ConfigurationRequest &cr,
561 const ConfigurationRequest::Reader &r, 564 const ConfigurationRequest::Reader &r,
562 PluginHandleMapper &mapper) { 565 PluginHandleMapper &pmapper) {
563 566
564 auto h = r.getPluginHandle(); 567 auto h = r.getPluginHandle();
565 cr.plugin = mapper.handleToPlugin(h); 568 cr.plugin = pmapper.handleToPlugin(h);
566 auto c = r.getConfiguration(); 569 auto c = r.getConfiguration();
567 readPluginConfiguration(cr.configuration, c); 570 readPluginConfiguration(cr.configuration, c);
568 } 571 }
569 572
570 static void 573 static void
627 } 630 }
628 631
629 static void 632 static void
630 buildProcessRequest(ProcessRequest::Builder &b, 633 buildProcessRequest(ProcessRequest::Builder &b,
631 const Vamp::HostExt::ProcessRequest &pr, 634 const Vamp::HostExt::ProcessRequest &pr,
632 PluginHandleMapper &mapper) { 635 PluginHandleMapper &pmapper) {
633 636
634 b.setPluginHandle(mapper.pluginToHandle(pr.plugin)); 637 b.setPluginHandle(pmapper.pluginToHandle(pr.plugin));
635 auto input = b.initInput(); 638 auto input = b.initInput();
636 buildProcessInput(input, pr.timestamp, pr.inputBuffers); 639 buildProcessInput(input, pr.timestamp, pr.inputBuffers);
637 } 640 }
638 641
639 static void 642 static void
640 readProcessRequest(Vamp::HostExt::ProcessRequest &pr, 643 readProcessRequest(Vamp::HostExt::ProcessRequest &pr,
641 const ProcessRequest::Reader &r, 644 const ProcessRequest::Reader &r,
642 PluginHandleMapper &mapper) { 645 PluginHandleMapper &pmapper) {
643 646
644 auto h = r.getPluginHandle(); 647 auto h = r.getPluginHandle();
645 pr.plugin = mapper.handleToPlugin(h); 648 pr.plugin = pmapper.handleToPlugin(h);
646 readProcessInput(pr.timestamp, pr.inputBuffers, r.getInput()); 649 readProcessInput(pr.timestamp, pr.inputBuffers, r.getInput());
647 } 650 }
648 651
649 static void 652 static void
650 buildProcessResponse(ProcessResponse::Builder &b, 653 buildProcessResponse(ProcessResponse::Builder &b,
651 const Vamp::HostExt::ProcessResponse &pr) { 654 const Vamp::HostExt::ProcessResponse &pr,
655 const PluginOutputIdMapper &omapper) {
652 656
653 auto f = b.initFeatures(); 657 auto f = b.initFeatures();
654 buildFeatureSet(f, pr.features); 658 buildFeatureSet(f, pr.features, omapper);
655 } 659 }
656 660
657 static void 661 static void
658 readProcessResponse(Vamp::HostExt::ProcessResponse &pr, 662 readProcessResponse(Vamp::HostExt::ProcessResponse &pr,
659 const ProcessResponse::Reader &r) { 663 const ProcessResponse::Reader &r,
660 664 const PluginOutputIdMapper &omapper) {
661 readFeatureSet(pr.features, r.getFeatures()); 665
666 readFeatureSet(pr.features, r.getFeatures(), omapper);
662 } 667 }
663 668
664 static void 669 static void
665 buildVampRequest_List(VampRequest::Builder &b) { 670 buildVampRequest_List(VampRequest::Builder &b) {
666 b.getRequest().setList(); 671 b.getRequest().setList();
688 } 693 }
689 694
690 static void 695 static void
691 buildVampResponse_Load(VampResponse::Builder &b, 696 buildVampResponse_Load(VampResponse::Builder &b,
692 const Vamp::HostExt::LoadResponse &resp, 697 const Vamp::HostExt::LoadResponse &resp,
693 PluginHandleMapper &mapper) { 698 PluginHandleMapper &pmapper) {
694 b.setSuccess(resp.plugin != 0); 699 b.setSuccess(resp.plugin != 0);
695 b.setErrorText(""); 700 b.setErrorText("");
696 auto u = b.getResponse().initLoad(); 701 auto u = b.getResponse().initLoad();
697 buildLoadResponse(u, resp, mapper); 702 buildLoadResponse(u, resp, pmapper);
698 } 703 }
699 704
700 static void 705 static void
701 buildVampRequest_Configure(VampRequest::Builder &b, 706 buildVampRequest_Configure(VampRequest::Builder &b,
702 const Vamp::HostExt::ConfigurationRequest &cr, 707 const Vamp::HostExt::ConfigurationRequest &cr,
703 PluginHandleMapper &mapper) { 708 PluginHandleMapper &pmapper) {
704 auto u = b.getRequest().initConfigure(); 709 auto u = b.getRequest().initConfigure();
705 buildConfigurationRequest(u, cr, mapper); 710 buildConfigurationRequest(u, cr, pmapper);
706 } 711 }
707 712
708 static void 713 static void
709 buildVampResponse_Configure(VampResponse::Builder &b, 714 buildVampResponse_Configure(VampResponse::Builder &b,
710 const Vamp::HostExt::ConfigurationResponse &cr) { 715 const Vamp::HostExt::ConfigurationResponse &cr) {
715 } 720 }
716 721
717 static void 722 static void
718 buildVampRequest_Process(VampRequest::Builder &b, 723 buildVampRequest_Process(VampRequest::Builder &b,
719 const Vamp::HostExt::ProcessRequest &pr, 724 const Vamp::HostExt::ProcessRequest &pr,
720 PluginHandleMapper &mapper) { 725 PluginHandleMapper &pmapper) {
721 auto u = b.getRequest().initProcess(); 726 auto u = b.getRequest().initProcess();
722 buildProcessRequest(u, pr, mapper); 727 buildProcessRequest(u, pr, pmapper);
723 } 728 }
724 729
725 static void 730 static void
726 buildVampResponse_Process(VampResponse::Builder &b, 731 buildVampResponse_Process(VampResponse::Builder &b,
727 const Vamp::HostExt::ProcessResponse &pr) { 732 const Vamp::HostExt::ProcessResponse &pr,
733 const PluginOutputIdMapper &omapper) {
728 b.setSuccess(true); 734 b.setSuccess(true);
729 b.setErrorText(""); 735 b.setErrorText("");
730 auto u = b.getResponse().initProcess(); 736 auto u = b.getResponse().initProcess();
731 buildProcessResponse(u, pr); 737 buildProcessResponse(u, pr, omapper);
732 } 738 }
733 739
734 static void 740 static void
735 buildVampRequest_Finish(VampRequest::Builder &b, 741 buildVampRequest_Finish(VampRequest::Builder &b,
736 Vamp::Plugin *p, 742 Vamp::Plugin *p,
737 PluginHandleMapper &mapper) { 743 PluginHandleMapper &pmapper) {
738 744
739 auto u = b.getRequest().initFinish(); 745 auto u = b.getRequest().initFinish();
740 u.setPluginHandle(mapper.pluginToHandle(p)); 746 u.setPluginHandle(pmapper.pluginToHandle(p));
741 } 747 }
742 748
743 static void 749 static void
744 buildVampResponse_Finish(VampResponse::Builder &b, 750 buildVampResponse_Finish(VampResponse::Builder &b,
745 const Vamp::HostExt::ProcessResponse &pr) { 751 const Vamp::HostExt::ProcessResponse &pr,
746 752 const PluginOutputIdMapper &omapper) {
747 buildVampResponse_Process(b, pr); 753
754 buildVampResponse_Process(b, pr, omapper);
748 } 755 }
749 756
750 static RRType 757 static RRType
751 getRequestResponseType(const VampRequest::Reader &r) { 758 getRequestResponseType(const VampRequest::Reader &r) {
752 switch (r.getRequest().which()) { 759 switch (r.getRequest().which()) {
815 } 822 }
816 823
817 static void 824 static void
818 readVampResponse_Load(Vamp::HostExt::LoadResponse &resp, 825 readVampResponse_Load(Vamp::HostExt::LoadResponse &resp,
819 const VampResponse::Reader &r, 826 const VampResponse::Reader &r,
820 PluginHandleMapper &mapper) { 827 PluginHandleMapper &pmapper) {
821 if (getRequestResponseType(r) != RRType::Load) { 828 if (getRequestResponseType(r) != RRType::Load) {
822 throw std::logic_error("not a load response"); 829 throw std::logic_error("not a load response");
823 } 830 }
824 resp = {}; 831 resp = {};
825 if (r.getSuccess()) { 832 if (r.getSuccess()) {
826 readLoadResponse(resp, r.getResponse().getLoad(), mapper); 833 readLoadResponse(resp, r.getResponse().getLoad(), pmapper);
827 } 834 }
828 } 835 }
829 836
830 static void 837 static void
831 readVampRequest_Configure(Vamp::HostExt::ConfigurationRequest &req, 838 readVampRequest_Configure(Vamp::HostExt::ConfigurationRequest &req,
832 const VampRequest::Reader &r, 839 const VampRequest::Reader &r,
833 PluginHandleMapper &mapper) { 840 PluginHandleMapper &pmapper) {
834 if (getRequestResponseType(r) != RRType::Configure) { 841 if (getRequestResponseType(r) != RRType::Configure) {
835 throw std::logic_error("not a configuration request"); 842 throw std::logic_error("not a configuration request");
836 } 843 }
837 readConfigurationRequest(req, r.getRequest().getConfigure(), mapper); 844 readConfigurationRequest(req, r.getRequest().getConfigure(), pmapper);
838 } 845 }
839 846
840 static void 847 static void
841 readVampResponse_Configure(Vamp::HostExt::ConfigurationResponse &resp, 848 readVampResponse_Configure(Vamp::HostExt::ConfigurationResponse &resp,
842 const VampResponse::Reader &r) { 849 const VampResponse::Reader &r) {
850 } 857 }
851 858
852 static void 859 static void
853 readVampRequest_Process(Vamp::HostExt::ProcessRequest &req, 860 readVampRequest_Process(Vamp::HostExt::ProcessRequest &req,
854 const VampRequest::Reader &r, 861 const VampRequest::Reader &r,
855 PluginHandleMapper &mapper) { 862 PluginHandleMapper &pmapper) {
856 if (getRequestResponseType(r) != RRType::Process) { 863 if (getRequestResponseType(r) != RRType::Process) {
857 throw std::logic_error("not a process request"); 864 throw std::logic_error("not a process request");
858 } 865 }
859 readProcessRequest(req, r.getRequest().getProcess(), mapper); 866 readProcessRequest(req, r.getRequest().getProcess(), pmapper);
860 } 867 }
861 868
862 static void 869 static void
863 readVampResponse_Process(Vamp::HostExt::ProcessResponse &resp, 870 readVampResponse_Process(Vamp::HostExt::ProcessResponse &resp,
864 const VampResponse::Reader &r) { 871 const VampResponse::Reader &r,
872 const PluginOutputIdMapper &omapper) {
865 if (getRequestResponseType(r) != RRType::Process) { 873 if (getRequestResponseType(r) != RRType::Process) {
866 throw std::logic_error("not a process response"); 874 throw std::logic_error("not a process response");
867 } 875 }
868 resp = {}; 876 resp = {};
869 if (r.getSuccess()) { 877 if (r.getSuccess()) {
870 readProcessResponse(resp, r.getResponse().getProcess()); 878 readProcessResponse(resp, r.getResponse().getProcess(), omapper);
871 } 879 }
872 } 880 }
873 881
874 static void 882 static void
875 readVampRequest_Finish(Vamp::Plugin *&finishPlugin, 883 readVampRequest_Finish(Vamp::Plugin *&finishPlugin,
876 const VampRequest::Reader &r, 884 const VampRequest::Reader &r,
877 PluginHandleMapper &mapper) { 885 PluginHandleMapper &pmapper) {
878 if (getRequestResponseType(r) != RRType::Finish) { 886 if (getRequestResponseType(r) != RRType::Finish) {
879 throw std::logic_error("not a finish request"); 887 throw std::logic_error("not a finish request");
880 } 888 }
881 finishPlugin = mapper.handleToPlugin 889 finishPlugin = pmapper.handleToPlugin
882 (r.getRequest().getFinish().getPluginHandle()); 890 (r.getRequest().getFinish().getPluginHandle());
883 } 891 }
884 892
885 static void 893 static void
886 readVampResponse_Finish(Vamp::HostExt::ProcessResponse &resp, 894 readVampResponse_Finish(Vamp::HostExt::ProcessResponse &resp,
887 const VampResponse::Reader &r) { 895 const VampResponse::Reader &r,
896 const PluginOutputIdMapper &omapper) {
888 if (getRequestResponseType(r) != RRType::Finish) { 897 if (getRequestResponseType(r) != RRType::Finish) {
889 throw std::logic_error("not a finish response"); 898 throw std::logic_error("not a finish response");
890 } 899 }
891 resp = {}; 900 resp = {};
892 if (r.getSuccess()) { 901 if (r.getSuccess()) {
893 readProcessResponse(resp, r.getResponse().getFinish()); 902 readProcessResponse(resp, r.getResponse().getFinish(), omapper);
894 } 903 }
895 } 904 }
896 }; 905 };
897 906
898 } 907 }