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.

147 lines
4.5KB

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