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.

149 lines
4.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - 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 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-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. #if ! TARGET_IPHONE_SIMULATOR
  19. #include <CoreAudioKit/CoreAudioKit.h>
  20. namespace juce
  21. {
  22. //==============================================================================
  23. class BluetoothMidiSelectorOverlay : public Component
  24. {
  25. public:
  26. BluetoothMidiSelectorOverlay (ModalComponentManager::Callback* exitCallbackToUse,
  27. const Rectangle<int>& boundsToUse)
  28. : bounds (boundsToUse)
  29. {
  30. std::unique_ptr<ModalComponentManager::Callback> exitCallback (exitCallbackToUse);
  31. setAlwaysOnTop (true);
  32. setVisible (true);
  33. addToDesktop (ComponentPeer::windowHasDropShadow);
  34. if (bounds.isEmpty())
  35. setBounds (0, 0, getParentWidth(), getParentHeight());
  36. else
  37. setBounds (bounds);
  38. toFront (true);
  39. setOpaque (true);
  40. controller = [[CABTMIDICentralViewController alloc] init];
  41. nativeSelectorComponent.setView ([controller view]);
  42. addAndMakeVisible (nativeSelectorComponent);
  43. enterModalState (true, exitCallback.release(), true);
  44. }
  45. ~BluetoothMidiSelectorOverlay() override
  46. {
  47. nativeSelectorComponent.setView (nullptr);
  48. [controller release];
  49. }
  50. void paint (Graphics& g) override
  51. {
  52. g.fillAll (bounds.isEmpty() ? Colours::black.withAlpha (0.5f) : Colours::black);
  53. }
  54. void inputAttemptWhenModal() override { close(); }
  55. void mouseDrag (const MouseEvent&) override {}
  56. void mouseDown (const MouseEvent&) override { close(); }
  57. void resized() override { update(); }
  58. void parentSizeChanged() override { update(); }
  59. private:
  60. void update()
  61. {
  62. if (bounds.isEmpty())
  63. {
  64. const int pw = getParentWidth();
  65. const int ph = getParentHeight();
  66. nativeSelectorComponent.setBounds (Rectangle<int> (pw, ph)
  67. .withSizeKeepingCentre (jmin (400, pw),
  68. jmin (450, ph - 40)));
  69. }
  70. else
  71. {
  72. nativeSelectorComponent.setBounds (bounds.withZeroOrigin());
  73. }
  74. }
  75. void close()
  76. {
  77. exitModalState (0);
  78. setVisible (false);
  79. }
  80. CABTMIDICentralViewController* controller;
  81. UIViewComponent nativeSelectorComponent;
  82. Rectangle<int> bounds;
  83. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BluetoothMidiSelectorOverlay)
  84. };
  85. bool BluetoothMidiDevicePairingDialogue::open (ModalComponentManager::Callback* exitCallback,
  86. Rectangle<int>* btBounds)
  87. {
  88. std::unique_ptr<ModalComponentManager::Callback> cb (exitCallback);
  89. auto boundsToUse = (btBounds != nullptr ? *btBounds : Rectangle<int> {});
  90. if (isAvailable())
  91. {
  92. new BluetoothMidiSelectorOverlay (cb.release(), boundsToUse);
  93. return true;
  94. }
  95. return false;
  96. }
  97. bool BluetoothMidiDevicePairingDialogue::isAvailable()
  98. {
  99. return NSClassFromString (@"CABTMIDICentralViewController") != nil;
  100. }
  101. } // namespace juce
  102. //==============================================================================
  103. #else
  104. namespace juce
  105. {
  106. bool BluetoothMidiDevicePairingDialogue::open (ModalComponentManager::Callback* exitCallback,
  107. Rectangle<int>*)
  108. {
  109. std::unique_ptr<ModalComponentManager::Callback> cb (exitCallback);
  110. return false;
  111. }
  112. bool BluetoothMidiDevicePairingDialogue::isAvailable() { return false; }
  113. }
  114. #endif