The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
2.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce::midi_ci
  19. {
  20. #define JUCE_ENCODINGS X(ascii, "ASCII") X(mcoded7, "Mcoded7") X(zlibAndMcoded7, "zlib+Mcoded7")
  21. /**
  22. Identifies different encodings that may be used by property exchange messages.
  23. @tags{Audio}
  24. */
  25. enum class Encoding
  26. {
  27. #define X(name, unused) name,
  28. JUCE_ENCODINGS
  29. #undef X
  30. };
  31. /**
  32. Utility functions for working with the Encoding enum.
  33. @tags{Audio}
  34. */
  35. struct EncodingUtils
  36. {
  37. EncodingUtils() = delete;
  38. /** Converts an Encoding to a human-readable string. */
  39. static const char* toString (Encoding e)
  40. {
  41. switch (e)
  42. {
  43. #define X(name, string) case Encoding::name: return string;
  44. JUCE_ENCODINGS
  45. #undef X
  46. }
  47. return nullptr;
  48. }
  49. /** Converts an encoding string from a property exchange JSON header to
  50. an Encoding.
  51. */
  52. static std::optional<Encoding> toEncoding (const char* str)
  53. {
  54. #define X(name, string) if (std::string_view (str) == std::string_view (string)) return Encoding::name;
  55. JUCE_ENCODINGS
  56. #undef X
  57. return {};
  58. }
  59. };
  60. #undef JUCE_ENCODINGS
  61. } // namespace juce::midi_ci
  62. #ifndef DOXYGEN
  63. namespace juce
  64. {
  65. template <>
  66. struct SerialisationTraits<midi_ci::Encoding>
  67. {
  68. static constexpr auto marshallingVersion = std::nullopt;
  69. template <typename Archive>
  70. void load (Archive& archive, midi_ci::Encoding& t)
  71. {
  72. String encoding;
  73. archive (encoding);
  74. t = midi_ci::EncodingUtils::toEncoding (encoding.toRawUTF8()).value_or (midi_ci::Encoding{});
  75. }
  76. template <typename Archive>
  77. void save (Archive& archive, const midi_ci::Encoding& t)
  78. {
  79. archive (midi_ci::EncodingUtils::toString (t));
  80. }
  81. };
  82. } // namespace juce
  83. #endif // ifndef DOXYGEN