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.

150 lines
4.6KB

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