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.

170 lines
5.4KB

  1. /*!
  2. @file AudioUnitSDK/AUMIDIBase.h
  3. @copyright © 2000-2021 Apple Inc. All rights reserved.
  4. */
  5. #ifndef AudioUnitSDK_AUMIDIBase_h
  6. #define AudioUnitSDK_AUMIDIBase_h
  7. #include <AudioUnitSDK/AUBase.h>
  8. #ifndef AUSDK_HAVE_XML_NAMES
  9. #define AUSDK_HAVE_XML_NAMES TARGET_OS_OSX // NOLINT(cppcoreguidelines-macro-usage)
  10. #endif
  11. #ifndef AUSDK_HAVE_MIDI_MAPPING
  12. #define AUSDK_HAVE_MIDI_MAPPING TARGET_OS_OSX // NOLINT(cppcoreguidelines-macro-usage)
  13. #endif
  14. namespace ausdk {
  15. #if AUSDK_HAVE_MIDI_MAPPING
  16. /// Abstract interface for parameter MIDI mapping
  17. class AUMIDIMapper {
  18. public:
  19. AUMIDIMapper() = default;
  20. virtual ~AUMIDIMapper() = default;
  21. AUMIDIMapper(const AUMIDIMapper&) = delete;
  22. AUMIDIMapper(AUMIDIMapper&&) = delete;
  23. AUMIDIMapper& operator=(const AUMIDIMapper&) = delete;
  24. AUMIDIMapper& operator=(AUMIDIMapper&&) = delete;
  25. [[nodiscard]] virtual UInt32 GetNumberMaps() const = 0;
  26. virtual void GetMaps(AUParameterMIDIMapping* outMapping) = 0;
  27. virtual void GetHotParameterMap(AUParameterMIDIMapping& outMapping) = 0;
  28. virtual void AddParameterMapping(
  29. const AUParameterMIDIMapping* maps, UInt32 count, AUBase& auBase) = 0;
  30. virtual void RemoveParameterMapping(
  31. const AUParameterMIDIMapping* maps, UInt32 count, bool& outDidChange) = 0;
  32. virtual void SetHotMapping(const AUParameterMIDIMapping& mapping) = 0;
  33. virtual void ReplaceAllMaps(
  34. const AUParameterMIDIMapping* maps, UInt32 count, AUBase& auBase) = 0;
  35. virtual bool HandleHotMapping(UInt8 status, UInt8 channel, UInt8 data1, AUBase& auBase) = 0;
  36. virtual bool FindParameterMapEventMatch(UInt8 status, UInt8 channel, UInt8 data1, UInt8 data2,
  37. UInt32 inStartFrame, AUBase& auBase) = 0;
  38. };
  39. #endif
  40. // ________________________________________________________________________
  41. // AUMIDIBase
  42. //
  43. /*!
  44. @class AUMIDIBase
  45. @brief Auxiliary class supporting MIDI events.
  46. */
  47. class AUMIDIBase {
  48. public:
  49. explicit AUMIDIBase(AUBase& inBase) : mAUBaseInstance(inBase) {}
  50. virtual ~AUMIDIBase() = default;
  51. AUMIDIBase(const AUMIDIBase&) = delete;
  52. AUMIDIBase(AUMIDIBase&&) = delete;
  53. AUMIDIBase& operator=(const AUMIDIBase&) = delete;
  54. AUMIDIBase& operator=(AUMIDIBase&&) = delete;
  55. virtual OSStatus MIDIEvent(
  56. UInt32 inStatus, UInt32 inData1, UInt32 inData2, UInt32 inOffsetSampleFrame)
  57. {
  58. const UInt32 strippedStatus = inStatus & 0xf0U; // NOLINT
  59. const UInt32 channel = inStatus & 0x0fU; // NOLINT
  60. return HandleMIDIEvent(strippedStatus, channel, inData1, inData2, inOffsetSampleFrame);
  61. }
  62. #if AUSDK_MIDI2_AVAILABLE
  63. virtual OSStatus MIDIEventList(
  64. UInt32 /*inOffsetSampleFrame*/, const MIDIEventList* /*eventList*/)
  65. {
  66. return kAudio_UnimplementedError;
  67. }
  68. #endif
  69. virtual OSStatus SysEx(const UInt8* inData, UInt32 inLength);
  70. virtual OSStatus DelegateGetPropertyInfo(AudioUnitPropertyID inID, AudioUnitScope inScope,
  71. AudioUnitElement inElement, UInt32& outDataSize, bool& outWritable);
  72. virtual OSStatus DelegateGetProperty(AudioUnitPropertyID inID, AudioUnitScope inScope,
  73. AudioUnitElement inElement, void* outData);
  74. virtual OSStatus DelegateSetProperty(AudioUnitPropertyID inID, AudioUnitScope inScope,
  75. AudioUnitElement inElement, const void* inData, UInt32 inDataSize);
  76. protected:
  77. // MIDI dispatch
  78. virtual OSStatus HandleMIDIEvent(
  79. UInt8 inStatus, UInt8 inChannel, UInt8 inData1, UInt8 inData2, UInt32 inStartFrame);
  80. virtual OSStatus HandleNonNoteEvent(
  81. UInt8 status, UInt8 channel, UInt8 data1, UInt8 data2, UInt32 inStartFrame);
  82. // Old name
  83. AUSDK_DEPRECATED("HandleMIDIEvent")
  84. OSStatus HandleMidiEvent(
  85. UInt8 inStatus, UInt8 inChannel, UInt8 inData1, UInt8 inData2, UInt32 inStartFrame)
  86. {
  87. return HandleMIDIEvent(inStatus, inChannel, inData1, inData2, inStartFrame);
  88. }
  89. #if AUSDK_HAVE_XML_NAMES
  90. virtual OSStatus GetXMLNames(CFURLRef* /*outNameDocument*/)
  91. {
  92. return kAudioUnitErr_InvalidProperty;
  93. } // if not overridden, it's unsupported
  94. #endif
  95. // channel messages
  96. virtual OSStatus HandleNoteOn(
  97. UInt8 /*inChannel*/, UInt8 /*inNoteNumber*/, UInt8 /*inVelocity*/, UInt32 /*inStartFrame*/)
  98. {
  99. return noErr;
  100. }
  101. virtual OSStatus HandleNoteOff(
  102. UInt8 /*inChannel*/, UInt8 /*inNoteNumber*/, UInt8 /*inVelocity*/, UInt32 /*inStartFrame*/)
  103. {
  104. return noErr;
  105. }
  106. virtual OSStatus HandleControlChange(
  107. UInt8 /*inChannel*/, UInt8 /*inController*/, UInt8 /*inValue*/, UInt32 /*inStartFrame*/)
  108. {
  109. return noErr;
  110. }
  111. virtual OSStatus HandlePitchWheel(
  112. UInt8 /*inChannel*/, UInt8 /*inPitch1*/, UInt8 /*inPitch2*/, UInt32 /*inStartFrame*/)
  113. {
  114. return noErr;
  115. }
  116. virtual OSStatus HandleChannelPressure(
  117. UInt8 /*inChannel*/, UInt8 /*inValue*/, UInt32 /*inStartFrame*/)
  118. {
  119. return noErr;
  120. }
  121. virtual OSStatus HandleProgramChange(UInt8 /*inChannel*/, UInt8 /*inValue*/) { return noErr; }
  122. virtual OSStatus HandlePolyPressure(
  123. UInt8 /*inChannel*/, UInt8 /*inKey*/, UInt8 /*inValue*/, UInt32 /*inStartFrame*/)
  124. {
  125. return noErr;
  126. }
  127. virtual OSStatus HandleResetAllControllers(UInt8 /*inChannel*/) { return noErr; }
  128. virtual OSStatus HandleAllNotesOff(UInt8 /*inChannel*/) { return noErr; }
  129. virtual OSStatus HandleAllSoundOff(UInt8 /*inChannel*/) { return noErr; }
  130. // System messages
  131. virtual OSStatus HandleSysEx(const UInt8* /*inData*/, UInt32 /*inLength*/) { return noErr; }
  132. #if AUSDK_HAVE_MIDI_MAPPING
  133. void SetMIDIMapper(const std::shared_ptr<AUMIDIMapper>& mapper) { mMIDIMapper = mapper; }
  134. #endif
  135. private:
  136. AUBase& mAUBaseInstance;
  137. #if AUSDK_HAVE_MIDI_MAPPING
  138. std::shared_ptr<AUMIDIMapper> mMIDIMapper;
  139. #endif
  140. };
  141. } // namespace ausdk
  142. #endif // AudioUnitSDK_AUMIDIBase_h