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.

142 lines
4.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. #if ! TARGET_IPHONE_SIMULATOR
  14. #include <CoreAudioKit/CoreAudioKit.h>
  15. namespace juce
  16. {
  17. //==============================================================================
  18. class BluetoothMidiSelectorOverlay : public Component
  19. {
  20. public:
  21. BluetoothMidiSelectorOverlay (ModalComponentManager::Callback* exitCallbackToUse,
  22. const Rectangle<int>& boundsToUse)
  23. : bounds (boundsToUse)
  24. {
  25. std::unique_ptr<ModalComponentManager::Callback> exitCallback (exitCallbackToUse);
  26. setAlwaysOnTop (true);
  27. setVisible (true);
  28. addToDesktop (ComponentPeer::windowHasDropShadow);
  29. if (bounds.isEmpty())
  30. setBounds (0, 0, getParentWidth(), getParentHeight());
  31. else
  32. setBounds (bounds);
  33. toFront (true);
  34. setOpaque (true);
  35. controller = [[CABTMIDICentralViewController alloc] init];
  36. nativeSelectorComponent.setView ([controller view]);
  37. addAndMakeVisible (nativeSelectorComponent);
  38. enterModalState (true, exitCallback.release(), true);
  39. }
  40. ~BluetoothMidiSelectorOverlay() override
  41. {
  42. nativeSelectorComponent.setView (nullptr);
  43. [controller release];
  44. }
  45. void paint (Graphics& g) override
  46. {
  47. g.fillAll (bounds.isEmpty() ? Colours::black.withAlpha (0.5f) : Colours::black);
  48. }
  49. void inputAttemptWhenModal() override { close(); }
  50. void mouseDrag (const MouseEvent&) override {}
  51. void mouseDown (const MouseEvent&) override { close(); }
  52. void resized() override { update(); }
  53. void parentSizeChanged() override { update(); }
  54. private:
  55. void update()
  56. {
  57. if (bounds.isEmpty())
  58. {
  59. const int pw = getParentWidth();
  60. const int ph = getParentHeight();
  61. nativeSelectorComponent.setBounds (Rectangle<int> (pw, ph)
  62. .withSizeKeepingCentre (jmin (400, pw),
  63. jmin (450, ph - 40)));
  64. }
  65. else
  66. {
  67. nativeSelectorComponent.setBounds (bounds.withZeroOrigin());
  68. }
  69. }
  70. void close()
  71. {
  72. exitModalState (0);
  73. setVisible (false);
  74. }
  75. CABTMIDICentralViewController* controller;
  76. UIViewComponent nativeSelectorComponent;
  77. Rectangle<int> bounds;
  78. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BluetoothMidiSelectorOverlay)
  79. };
  80. bool BluetoothMidiDevicePairingDialogue::open (ModalComponentManager::Callback* exitCallback,
  81. Rectangle<int>* btBounds)
  82. {
  83. std::unique_ptr<ModalComponentManager::Callback> cb (exitCallback);
  84. auto boundsToUse = (btBounds != nullptr ? *btBounds : Rectangle<int> {});
  85. if (isAvailable())
  86. {
  87. new BluetoothMidiSelectorOverlay (cb.release(), boundsToUse);
  88. return true;
  89. }
  90. return false;
  91. }
  92. bool BluetoothMidiDevicePairingDialogue::isAvailable()
  93. {
  94. return NSClassFromString (@"CABTMIDICentralViewController") != nil;
  95. }
  96. } // namespace juce
  97. //==============================================================================
  98. #else
  99. namespace juce
  100. {
  101. bool BluetoothMidiDevicePairingDialogue::open (ModalComponentManager::Callback* exitCallback,
  102. Rectangle<int>*)
  103. {
  104. std::unique_ptr<ModalComponentManager::Callback> cb (exitCallback);
  105. return false;
  106. }
  107. bool BluetoothMidiDevicePairingDialogue::isAvailable() { return false; }
  108. }
  109. #endif