/* ============================================================================== This file is part of the JUCE framework. Copyright (c) Raw Material Software Limited JUCE is an open source framework subject to commercial or open source licensing. By downloading, installing, or using the JUCE framework, or combining the JUCE framework with any other source code, object code, content or any other copyrightable work, you agree to the terms of the JUCE End User Licence Agreement, and all incorporated terms including the JUCE Privacy Policy and the JUCE Website Terms of Service, as applicable, which will bind you. If you do not agree to the terms of these agreements, we will not license the JUCE framework to you, and you must discontinue the installation or download process and cease use of the JUCE framework. JUCE End User Licence Agreement: https://juce.com/legal/juce-9-licence/ JUCE Privacy Policy: https://juce.com/juce-privacy-policy JUCE Website Terms of Service: https://juce.com/juce-website-terms-of-service/ Or: You may also use this code under the terms of the AGPLv3: https://www.gnu.org/licenses/agpl-3.0.en.html THE JUCE FRAMEWORK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER EXPRESSED OR IMPLIED, INCLUDING WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED. ============================================================================== */ /* Namespace containing metadata about MIDI-CI message types, such as replies corresponding to inquiries, and serialization functions. @tags{Audio} */ namespace juce::midi_ci::detail::MessageMeta { //============================================================================== /* The maximum CI version that can be parsed and generated by this implementation. */ static constexpr std::byte implementationVersion { 0x02 }; /* Wraps a pointer to a Span. Used to indicate to CI readers/writers that a particular field is of variable length, starting with a 16-bit or 32-bit byte count. */ template struct SpanWithSizeBytes { T& span; }; /* Creates a SpanWithSizeBytes with an appropriate template argument. */ template static constexpr auto makeSpanWithSizeBytes ( Span& span) { return SpanWithSizeBytes> { span }; } template static constexpr auto makeSpanWithSizeBytes (const Span& span) { return SpanWithSizeBytes> { span }; } template static constexpr auto makeJsonWithSizeBytes ( Span& span) { return SpanWithSizeBytes, true> { span }; } template static constexpr auto makeJsonWithSizeBytes (const Span& span) { return SpanWithSizeBytes, true> { span }; } template struct Metadata { static constexpr std::byte subID2 { SubID2 }; using Reply = R; }; template struct Meta; template <> struct Meta : Metadata<0x71> {}; template <> struct Meta : Metadata<0x70, Message::DiscoveryResponse> {}; template <> struct Meta : Metadata<0x73> {}; template <> struct Meta : Metadata<0x72, Message::EndpointInquiryResponse> {}; template <> struct Meta : Metadata<0x7e> {}; template <> struct Meta : Metadata<0x7d> {}; template <> struct Meta : Metadata<0x7f> {}; template <> struct Meta : Metadata<0x21> {}; template <> struct Meta : Metadata<0x20, Message::ProfileInquiryResponse> {}; template <> struct Meta : Metadata<0x26> {}; template <> struct Meta : Metadata<0x27> {}; template <> struct Meta : Metadata<0x29> {}; template <> struct Meta : Metadata<0x28, Message::ProfileDetailsResponse> {}; template <> struct Meta : Metadata<0x22> {}; template <> struct Meta : Metadata<0x23> {}; template <> struct Meta : Metadata<0x24> {}; template <> struct Meta : Metadata<0x25> {}; template <> struct Meta : Metadata<0x2f> {}; template <> struct Meta : Metadata<0x31> {}; template <> struct Meta : Metadata<0x30, Message::PropertyExchangeCapabilitiesResponse> {}; template <> struct Meta {}; template <> struct Meta {}; template <> struct Meta : Meta, Metadata<0x35> {}; template <> struct Meta : Meta, Metadata<0x34, Message::PropertyGetDataResponse> {}; template <> struct Meta : Meta, Metadata<0x37> {}; template <> struct Meta : Meta, Metadata<0x36, Message::PropertySetDataResponse> {}; template <> struct Meta : Meta, Metadata<0x39> {}; template <> struct Meta : Meta, Metadata<0x38, Message::PropertySubscribeResponse> {}; template <> struct Meta : Meta, Metadata<0x3f> {}; template <> struct Meta : Metadata<0x41> {}; template <> struct Meta : Metadata<0x40, Message::ProcessInquiryResponse> {}; template <> struct Meta : Metadata<0x43> {}; template <> struct Meta : Metadata<0x42, Message::ProcessMidiMessageReportResponse> {}; template <> struct Meta : Metadata<0x44> {}; } // namespace juce::midi_ci::detail::MessageMeta /** @cond */ namespace juce { struct VersionBase { static constexpr auto marshallingVersion = (int) juce::midi_ci::detail::MessageMeta::implementationVersion; }; template struct SerialisationTraits> { static constexpr auto marshallingVersion = std::nullopt; template static auto getSize (This& t) { if constexpr (NumBytes == 1) return (uint8_t) t.size(); else if constexpr (NumBytes == 2) return (uint16_t) t.size(); else if constexpr (NumBytes == 4) return (uint32_t) t.size(); else if constexpr (NumBytes == 8) return (uint64_t) t.size(); else static_assert (detail::delayStaticAssert, "NumBytes is not a power of two"); } template static auto load (Archive&, This&) { } template static auto save (Archive& archive, const This& t) { auto size = getSize (t.span); archive (serialisationSize (size)); for (const auto& element : t.span) archive (element); } }; template <> struct SerialisationTraits : VersionBase { template static auto load (Archive& archive, ci::MUID& t) { uint32_t muid{}; auto result = archive (muid); t = ci::MUID::makeUnchecked (muid); return result; } template static auto save (Archive& archive, const ci::MUID& t) { return archive (t.get()); } }; template <> struct SerialisationTraits : VersionBase { template static auto serialise (Archive& archive, This& t) { const std::byte universalSystemExclusive { 0x7e }, subID { 0x0d }; return archive (universalSystemExclusive, t.deviceID, subID, t.category, t.version, t.source, t.destination); } }; template <> struct SerialisationTraits : VersionBase { template static auto serialise (Archive& archive, This& t) { return archive (t.header, t.data); } }; template <> struct SerialisationTraits : VersionBase { template static auto serialise (Archive& archive, This& t) { archive (named ("device", t.device), named ("capabilities", t.capabilities), named ("maximumSysexSize", t.maximumSysexSize)); if (0x02 <= archive.getVersion()) archive (named ("outputPathID", t.outputPathID), named ("functionBlock", t.functionBlock)); } }; template <> struct SerialisationTraits : VersionBase { template static auto serialise (Archive& archive, This& t) { archive (named ("device", t.device), named ("capabilities", t.capabilities), named ("maximumSysexSize", t.maximumSysexSize)); if (0x02 <= archive.getVersion()) archive (named ("outputPathID", t.outputPathID)); } }; template <> struct SerialisationTraits : VersionBase { template static auto serialise (Archive& archive, This& t) { archive (named ("status", t.status), named ("data", midi_ci::detail::MessageMeta::makeSpanWithSizeBytes<2> (t.data))); } }; template <> struct SerialisationTraits : VersionBase { template static auto serialise (Archive& archive, This& t) { archive (named ("status", t.status)); } }; template <> struct SerialisationTraits : VersionBase { template static auto serialise (Archive& archive, This& t) { archive (named ("target", t.target)); } }; template <> struct SerialisationTraits : VersionBase { template static auto serialise (Archive& archive, This& t) { archive (named ("originalCategory", t.originalCategory), named ("statusCode", t.statusCode), named ("statusData", t.statusData), named ("details", t.details), named ("messageText", midi_ci::detail::MessageMeta::makeSpanWithSizeBytes<2> (t.messageText))); } }; template <> struct SerialisationTraits : VersionBase { template static auto serialise (Archive& archive, This& t) { if (0x02 <= archive.getVersion()) { archive (named ("originalCategory", t.originalCategory), named ("statusCode", t.statusCode), named ("statusData", t.statusData), named ("details", t.details), named ("messageText", midi_ci::detail::MessageMeta::makeSpanWithSizeBytes<2> (t.messageText))); } } }; template <> struct SerialisationTraits : VersionBase { template static auto serialise (Archive& archive, This& t) { archive (named ("enabledProfiles", midi_ci::detail::MessageMeta::makeSpanWithSizeBytes<2> (t.enabledProfiles)), named ("disabledProfiles", midi_ci::detail::MessageMeta::makeSpanWithSizeBytes<2> (t.disabledProfiles))); } }; template <> struct SerialisationTraits : VersionBase { template static auto serialise (Archive&, This&) { } }; template <> struct SerialisationTraits : VersionBase { template static auto serialise (Archive& archive, This& t) { archive (named ("profile", t.profile)); } }; template <> struct SerialisationTraits : VersionBase { template static auto serialise (Archive& archive, This& t) { archive (named ("profile", t.profile)); } }; template <> struct SerialisationTraits : VersionBase { template static auto serialise (Archive& archive, This& t) { archive (named ("profile", t.profile), named ("target", t.target), named ("data", midi_ci::detail::MessageMeta::makeSpanWithSizeBytes<2> (t.data))); } }; template <> struct SerialisationTraits : VersionBase { template static auto serialise (Archive& archive, This& t) { archive (named ("profile", t.profile), named ("target", t.target)); } }; template <> struct SerialisationTraits : VersionBase { template static auto serialise (Archive& archive, This& t) { archive (named ("profile", t.profile)); if (0x02 <= archive.getVersion()) archive (named ("numChannels", t.numChannels)); } }; template <> struct SerialisationTraits : VersionBase { template static auto serialise (Archive& archive, This& t) { archive (named ("profile", t.profile)); if (0x02 <= archive.getVersion()) { uint16_t reserved{}; archive (named ("reserved", reserved)); } } }; template <> struct SerialisationTraits : VersionBase { template static auto serialise (Archive& archive, This& t) { archive (named ("profile", t.profile)); if (0x02 <= archive.getVersion()) archive (named ("numChannels", t.numChannels)); } }; template <> struct SerialisationTraits : VersionBase { template static auto serialise (Archive& archive, This& t) { archive (named ("profile", t.profile)); if (0x02 <= archive.getVersion()) archive (named ("numChannels", t.numChannels)); } }; template <> struct SerialisationTraits : VersionBase { template static auto serialise (Archive& archive, This& t) { archive (named ("profile", t.profile), named ("data", midi_ci::detail::MessageMeta::makeSpanWithSizeBytes<4> (t.data))); } }; template <> struct SerialisationTraits : VersionBase { template static auto serialise (Archive& archive, This& t) { archive (named ("numRequests", t.numSimultaneousRequestsSupported)); if (0x02 <= archive.getVersion()) archive (named ("major", t.majorVersion), named ("minor", t.minorVersion)); } }; template <> struct SerialisationTraits : VersionBase { template static auto serialise (Archive& archive, This& t) { archive (named ("numRequests", t.numSimultaneousRequestsSupported)); if (0x02 <= archive.getVersion()) archive (named ("major", t.majorVersion), named ("minor", t.minorVersion)); } }; template <> struct SerialisationTraits : VersionBase { template static auto serialise (Archive& archive, This& t) { const uint16_t chunkNum = 1, dataLength = 0; archive (named ("requestID", t.requestID), named ("header", midi_ci::detail::MessageMeta::makeJsonWithSizeBytes<2> (t.header)), named ("numChunks", chunkNum), named ("thisChunk", chunkNum), named ("length", dataLength)); } }; template <> struct SerialisationTraits : VersionBase { template static auto serialise (Archive& archive, This& t) { archive (named ("requestID", t.requestID), named ("header", midi_ci::detail::MessageMeta::makeJsonWithSizeBytes<2> (t.header)), named ("numChunks", t.totalNumChunks), named ("thisChunk", t.thisChunkNum), named ("data", midi_ci::detail::MessageMeta::makeSpanWithSizeBytes<2> (t.data))); } }; template <> struct SerialisationTraits : SerialisationTraits {}; template <> struct SerialisationTraits : SerialisationTraits {}; template <> struct SerialisationTraits : SerialisationTraits {}; template <> struct SerialisationTraits : SerialisationTraits {}; template <> struct SerialisationTraits : SerialisationTraits {}; template <> struct SerialisationTraits : SerialisationTraits {}; template <> struct SerialisationTraits : SerialisationTraits {}; template <> struct SerialisationTraits : VersionBase { template static auto serialise (Archive& archive, This& t) { archive (t.supportedFeatures); } }; template <> struct SerialisationTraits : VersionBase { template static auto serialise (Archive&, This&) { } }; template <> struct SerialisationTraits : VersionBase { template static auto serialise (Archive& archive, This& t) { std::byte reserved{}; archive (named ("messageDataControl", t.messageDataControl), named ("requestedMessages", t.requestedMessages), named ("reserved", reserved), named ("channelControllerMessages", t.channelControllerMessages), named ("noteDataMessages", t.noteDataMessages)); } }; template <> struct SerialisationTraits : VersionBase { template static auto serialise (Archive& archive, This& t) { std::byte reserved{}; archive (named ("messageDataControl", t.messageDataControl), named ("requestedMessages", t.requestedMessages), named ("reserved", reserved), named ("channelControllerMessages", t.channelControllerMessages), named ("noteDataMessages", t.noteDataMessages)); } }; template <> struct SerialisationTraits : VersionBase { template static auto serialise (Archive&, This&) { } }; } // namespace juce /** @endcond */