comparison capnproto/VampnProto.h @ 51:f4244a2d55ac

Introduce and use output id mappers
author Chris Cannam <c.cannam@qmul.ac.uk>
date Fri, 16 Sep 2016 15:10:57 +0100
parents f3f7561233d6
children e90fd30990eb
comparison
equal deleted inserted replaced
50:12e3b396544c 51:f4244a2d55ac
527 } 527 }
528 528
529 static void 529 static void
530 buildLoadResponse(LoadResponse::Builder &b, 530 buildLoadResponse(LoadResponse::Builder &b,
531 const Vamp::HostExt::LoadResponse &resp, 531 const Vamp::HostExt::LoadResponse &resp,
532 PluginHandleMapper &pmapper) { 532 const PluginHandleMapper &pmapper) {
533 533
534 b.setPluginHandle(pmapper.pluginToHandle(resp.plugin)); 534 b.setPluginHandle(pmapper.pluginToHandle(resp.plugin));
535 auto sd = b.initStaticData(); 535 auto sd = b.initStaticData();
536 buildPluginStaticData(sd, resp.staticData); 536 buildPluginStaticData(sd, resp.staticData);
537 auto conf = b.initDefaultConfiguration(); 537 auto conf = b.initDefaultConfiguration();
539 } 539 }
540 540
541 static void 541 static void
542 readLoadResponse(Vamp::HostExt::LoadResponse &resp, 542 readLoadResponse(Vamp::HostExt::LoadResponse &resp,
543 const LoadResponse::Reader &r, 543 const LoadResponse::Reader &r,
544 PluginHandleMapper &pmapper) { 544 const PluginHandleMapper &pmapper) {
545 545
546 resp.plugin = pmapper.handleToPlugin(r.getPluginHandle()); 546 resp.plugin = pmapper.handleToPlugin(r.getPluginHandle());
547 readPluginStaticData(resp.staticData, r.getStaticData()); 547 readPluginStaticData(resp.staticData, r.getStaticData());
548 readPluginConfiguration(resp.defaultConfiguration, 548 readPluginConfiguration(resp.defaultConfiguration,
549 r.getDefaultConfiguration()); 549 r.getDefaultConfiguration());
550 } 550 }
551 551
552 static void 552 static void
553 buildConfigurationRequest(ConfigurationRequest::Builder &b, 553 buildConfigurationRequest(ConfigurationRequest::Builder &b,
554 const Vamp::HostExt::ConfigurationRequest &cr, 554 const Vamp::HostExt::ConfigurationRequest &cr,
555 PluginHandleMapper &pmapper) { 555 const PluginHandleMapper &pmapper) {
556 556
557 b.setPluginHandle(pmapper.pluginToHandle(cr.plugin)); 557 b.setPluginHandle(pmapper.pluginToHandle(cr.plugin));
558 auto c = b.initConfiguration(); 558 auto c = b.initConfiguration();
559 buildPluginConfiguration(c, cr.configuration); 559 buildPluginConfiguration(c, cr.configuration);
560 } 560 }
561 561
562 static void 562 static void
563 readConfigurationRequest(Vamp::HostExt::ConfigurationRequest &cr, 563 readConfigurationRequest(Vamp::HostExt::ConfigurationRequest &cr,
564 const ConfigurationRequest::Reader &r, 564 const ConfigurationRequest::Reader &r,
565 PluginHandleMapper &pmapper) { 565 const PluginHandleMapper &pmapper) {
566 566
567 auto h = r.getPluginHandle(); 567 auto h = r.getPluginHandle();
568 cr.plugin = pmapper.handleToPlugin(h); 568 cr.plugin = pmapper.handleToPlugin(h);
569 auto c = r.getConfiguration(); 569 auto c = r.getConfiguration();
570 readPluginConfiguration(cr.configuration, c); 570 readPluginConfiguration(cr.configuration, c);
630 } 630 }
631 631
632 static void 632 static void
633 buildProcessRequest(ProcessRequest::Builder &b, 633 buildProcessRequest(ProcessRequest::Builder &b,
634 const Vamp::HostExt::ProcessRequest &pr, 634 const Vamp::HostExt::ProcessRequest &pr,
635 PluginHandleMapper &pmapper) { 635 const PluginHandleMapper &pmapper) {
636 636
637 b.setPluginHandle(pmapper.pluginToHandle(pr.plugin)); 637 b.setPluginHandle(pmapper.pluginToHandle(pr.plugin));
638 auto input = b.initInput(); 638 auto input = b.initInput();
639 buildProcessInput(input, pr.timestamp, pr.inputBuffers); 639 buildProcessInput(input, pr.timestamp, pr.inputBuffers);
640 } 640 }
641 641
642 static void 642 static void
643 readProcessRequest(Vamp::HostExt::ProcessRequest &pr, 643 readProcessRequest(Vamp::HostExt::ProcessRequest &pr,
644 const ProcessRequest::Reader &r, 644 const ProcessRequest::Reader &r,
645 PluginHandleMapper &pmapper) { 645 const PluginHandleMapper &pmapper) {
646 646
647 auto h = r.getPluginHandle(); 647 auto h = r.getPluginHandle();
648 pr.plugin = pmapper.handleToPlugin(h); 648 pr.plugin = pmapper.handleToPlugin(h);
649 readProcessInput(pr.timestamp, pr.inputBuffers, r.getInput()); 649 readProcessInput(pr.timestamp, pr.inputBuffers, r.getInput());
650 } 650 }
651 651
652 static void 652 static void
653 buildProcessResponse(ProcessResponse::Builder &b, 653 buildProcessResponse(ProcessResponse::Builder &b,
654 const Vamp::HostExt::ProcessResponse &pr, 654 const Vamp::HostExt::ProcessResponse &pr,
655 const PluginOutputIdMapper &omapper) { 655 const PluginHandleMapper &pmapper) {
656 656
657 auto f = b.initFeatures(); 657 auto f = b.initFeatures();
658 buildFeatureSet(f, pr.features, omapper); 658 buildFeatureSet(f, pr.features,
659 pmapper.pluginToOutputIdMapper(pr.plugin));
659 } 660 }
660 661
661 static void 662 static void
662 readProcessResponse(Vamp::HostExt::ProcessResponse &pr, 663 readProcessResponse(Vamp::HostExt::ProcessResponse &pr,
663 const ProcessResponse::Reader &r, 664 const ProcessResponse::Reader &r,
664 const PluginOutputIdMapper &omapper) { 665 const PluginHandleMapper &pmapper) {
665 666
666 readFeatureSet(pr.features, r.getFeatures(), omapper); 667 readFeatureSet(pr.features, r.getFeatures(),
668 pmapper.handleToOutputIdMapper(r.getPluginHandle()));
667 } 669 }
668 670
669 static void 671 static void
670 buildVampRequest_List(VampRequest::Builder &b) { 672 buildVampRequest_List(VampRequest::Builder &b) {
671 b.getRequest().setList(); 673 b.getRequest().setList();
693 } 695 }
694 696
695 static void 697 static void
696 buildVampResponse_Load(VampResponse::Builder &b, 698 buildVampResponse_Load(VampResponse::Builder &b,
697 const Vamp::HostExt::LoadResponse &resp, 699 const Vamp::HostExt::LoadResponse &resp,
698 PluginHandleMapper &pmapper) { 700 const PluginHandleMapper &pmapper) {
699 b.setSuccess(resp.plugin != 0); 701 b.setSuccess(resp.plugin != 0);
700 b.setErrorText(""); 702 b.setErrorText("");
701 auto u = b.getResponse().initLoad(); 703 auto u = b.getResponse().initLoad();
702 buildLoadResponse(u, resp, pmapper); 704 buildLoadResponse(u, resp, pmapper);
703 } 705 }
704 706
705 static void 707 static void
706 buildVampRequest_Configure(VampRequest::Builder &b, 708 buildVampRequest_Configure(VampRequest::Builder &b,
707 const Vamp::HostExt::ConfigurationRequest &cr, 709 const Vamp::HostExt::ConfigurationRequest &cr,
708 PluginHandleMapper &pmapper) { 710 const PluginHandleMapper &pmapper) {
709 auto u = b.getRequest().initConfigure(); 711 auto u = b.getRequest().initConfigure();
710 buildConfigurationRequest(u, cr, pmapper); 712 buildConfigurationRequest(u, cr, pmapper);
711 } 713 }
712 714
713 static void 715 static void
720 } 722 }
721 723
722 static void 724 static void
723 buildVampRequest_Process(VampRequest::Builder &b, 725 buildVampRequest_Process(VampRequest::Builder &b,
724 const Vamp::HostExt::ProcessRequest &pr, 726 const Vamp::HostExt::ProcessRequest &pr,
725 PluginHandleMapper &pmapper) { 727 const PluginHandleMapper &pmapper) {
726 auto u = b.getRequest().initProcess(); 728 auto u = b.getRequest().initProcess();
727 buildProcessRequest(u, pr, pmapper); 729 buildProcessRequest(u, pr, pmapper);
728 } 730 }
729 731
730 static void 732 static void
731 buildVampResponse_Process(VampResponse::Builder &b, 733 buildVampResponse_Process(VampResponse::Builder &b,
732 const Vamp::HostExt::ProcessResponse &pr, 734 const Vamp::HostExt::ProcessResponse &pr,
733 const PluginOutputIdMapper &omapper) { 735 const PluginHandleMapper &pmapper) {
734 b.setSuccess(true); 736 b.setSuccess(true);
735 b.setErrorText(""); 737 b.setErrorText("");
736 auto u = b.getResponse().initProcess(); 738 auto u = b.getResponse().initProcess();
737 buildProcessResponse(u, pr, omapper); 739 buildProcessResponse(u, pr, pmapper);
738 } 740 }
739 741
740 static void 742 static void
741 buildVampRequest_Finish(VampRequest::Builder &b, 743 buildVampRequest_Finish(VampRequest::Builder &b,
742 Vamp::Plugin *p, 744 Vamp::Plugin *p,
743 PluginHandleMapper &pmapper) { 745 const PluginHandleMapper &pmapper) {
744 746
745 auto u = b.getRequest().initFinish(); 747 auto u = b.getRequest().initFinish();
746 u.setPluginHandle(pmapper.pluginToHandle(p)); 748 u.setPluginHandle(pmapper.pluginToHandle(p));
747 } 749 }
748 750
749 static void 751 static void
750 buildVampResponse_Finish(VampResponse::Builder &b, 752 buildVampResponse_Finish(VampResponse::Builder &b,
751 const Vamp::HostExt::ProcessResponse &pr, 753 const Vamp::HostExt::ProcessResponse &pr,
752 const PluginOutputIdMapper &omapper) { 754 const PluginHandleMapper &pmapper) {
753 755
754 buildVampResponse_Process(b, pr, omapper); 756 buildVampResponse_Process(b, pr, pmapper);
755 } 757 }
756 758
757 static RRType 759 static RRType
758 getRequestResponseType(const VampRequest::Reader &r) { 760 getRequestResponseType(const VampRequest::Reader &r) {
759 switch (r.getRequest().which()) { 761 switch (r.getRequest().which()) {
822 } 824 }
823 825
824 static void 826 static void
825 readVampResponse_Load(Vamp::HostExt::LoadResponse &resp, 827 readVampResponse_Load(Vamp::HostExt::LoadResponse &resp,
826 const VampResponse::Reader &r, 828 const VampResponse::Reader &r,
827 PluginHandleMapper &pmapper) { 829 const PluginHandleMapper &pmapper) {
828 if (getRequestResponseType(r) != RRType::Load) { 830 if (getRequestResponseType(r) != RRType::Load) {
829 throw std::logic_error("not a load response"); 831 throw std::logic_error("not a load response");
830 } 832 }
831 resp = {}; 833 resp = {};
832 if (r.getSuccess()) { 834 if (r.getSuccess()) {
835 } 837 }
836 838
837 static void 839 static void
838 readVampRequest_Configure(Vamp::HostExt::ConfigurationRequest &req, 840 readVampRequest_Configure(Vamp::HostExt::ConfigurationRequest &req,
839 const VampRequest::Reader &r, 841 const VampRequest::Reader &r,
840 PluginHandleMapper &pmapper) { 842 const PluginHandleMapper &pmapper) {
841 if (getRequestResponseType(r) != RRType::Configure) { 843 if (getRequestResponseType(r) != RRType::Configure) {
842 throw std::logic_error("not a configuration request"); 844 throw std::logic_error("not a configuration request");
843 } 845 }
844 readConfigurationRequest(req, r.getRequest().getConfigure(), pmapper); 846 readConfigurationRequest(req, r.getRequest().getConfigure(), pmapper);
845 } 847 }
857 } 859 }
858 860
859 static void 861 static void
860 readVampRequest_Process(Vamp::HostExt::ProcessRequest &req, 862 readVampRequest_Process(Vamp::HostExt::ProcessRequest &req,
861 const VampRequest::Reader &r, 863 const VampRequest::Reader &r,
862 PluginHandleMapper &pmapper) { 864 const PluginHandleMapper &pmapper) {
863 if (getRequestResponseType(r) != RRType::Process) { 865 if (getRequestResponseType(r) != RRType::Process) {
864 throw std::logic_error("not a process request"); 866 throw std::logic_error("not a process request");
865 } 867 }
866 readProcessRequest(req, r.getRequest().getProcess(), pmapper); 868 readProcessRequest(req, r.getRequest().getProcess(), pmapper);
867 } 869 }
868 870
869 static void 871 static void
870 readVampResponse_Process(Vamp::HostExt::ProcessResponse &resp, 872 readVampResponse_Process(Vamp::HostExt::ProcessResponse &resp,
871 const VampResponse::Reader &r, 873 const VampResponse::Reader &r,
872 const PluginOutputIdMapper &omapper) { 874 const PluginHandleMapper &pmapper) {
873 if (getRequestResponseType(r) != RRType::Process) { 875 if (getRequestResponseType(r) != RRType::Process) {
874 throw std::logic_error("not a process response"); 876 throw std::logic_error("not a process response");
875 } 877 }
876 resp = {}; 878 resp = {};
877 if (r.getSuccess()) { 879 if (r.getSuccess()) {
878 readProcessResponse(resp, r.getResponse().getProcess(), omapper); 880 readProcessResponse(resp, r.getResponse().getProcess(), pmapper);
879 } 881 }
880 } 882 }
881 883
882 static void 884 static void
883 readVampRequest_Finish(Vamp::Plugin *&finishPlugin, 885 readVampRequest_Finish(Vamp::Plugin *&finishPlugin,
884 const VampRequest::Reader &r, 886 const VampRequest::Reader &r,
885 PluginHandleMapper &pmapper) { 887 const PluginHandleMapper &pmapper) {
886 if (getRequestResponseType(r) != RRType::Finish) { 888 if (getRequestResponseType(r) != RRType::Finish) {
887 throw std::logic_error("not a finish request"); 889 throw std::logic_error("not a finish request");
888 } 890 }
889 finishPlugin = pmapper.handleToPlugin 891 finishPlugin = pmapper.handleToPlugin
890 (r.getRequest().getFinish().getPluginHandle()); 892 (r.getRequest().getFinish().getPluginHandle());
891 } 893 }
892 894
893 static void 895 static void
894 readVampResponse_Finish(Vamp::HostExt::ProcessResponse &resp, 896 readVampResponse_Finish(Vamp::HostExt::ProcessResponse &resp,
895 const VampResponse::Reader &r, 897 const VampResponse::Reader &r,
896 const PluginOutputIdMapper &omapper) { 898 const PluginHandleMapper &pmapper) {
897 if (getRequestResponseType(r) != RRType::Finish) { 899 if (getRequestResponseType(r) != RRType::Finish) {
898 throw std::logic_error("not a finish response"); 900 throw std::logic_error("not a finish response");
899 } 901 }
900 resp = {}; 902 resp = {};
901 if (r.getSuccess()) { 903 if (r.getSuccess()) {
902 readProcessResponse(resp, r.getResponse().getFinish(), omapper); 904 readProcessResponse(resp, r.getResponse().getFinish(), pmapper);
903 } 905 }
904 } 906 }
905 }; 907 };
906 908
907 } 909 }