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.

139 lines
4.2KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. // Note: for the Bluetooth Midi selector overlay, we need the class
  18. // UIViewComponent from the juce_gui_extra module. If this module is not
  19. // included in your app, BluetoothMidiDevicePairingDialogue::open() will fail
  20. // and return false.
  21. // It is also not available in the iPhone/iPad simulator.
  22. #if JUCE_MODULE_AVAILABLE_juce_gui_extra && ! TARGET_IPHONE_SIMULATOR
  23. } // (juce namespace)
  24. #include <CoreAudioKit/CoreAudioKit.h>
  25. //==============================================================================
  26. @interface BluetoothSelectorView : NSObject
  27. @property CABTMIDICentralViewController *central;
  28. - (UIView*) getView;
  29. @end
  30. //==============================================================================
  31. @implementation BluetoothSelectorView
  32. - (instancetype) init
  33. {
  34. self = [super init];
  35. self.central = [[CABTMIDICentralViewController alloc] init];
  36. return self;
  37. }
  38. - (UIView*) getView
  39. {
  40. return self.central.view;
  41. }
  42. @end
  43. namespace juce
  44. {
  45. //==============================================================================
  46. class BluetoothMidiSelectorOverlay : public Component
  47. {
  48. public:
  49. BluetoothMidiSelectorOverlay()
  50. {
  51. setAlwaysOnTop (true);
  52. setVisible (true);
  53. addToDesktop (ComponentPeer::windowHasDropShadow);
  54. setBounds (0, 0, getParentWidth(), getParentHeight());
  55. toFront (true);
  56. nativeSelectorComponent.setView ([[[BluetoothSelectorView alloc] init] getView]);
  57. addAndMakeVisible (nativeSelectorComponent);
  58. enterModalState (true, nullptr, true);
  59. }
  60. void paint (Graphics& g) override
  61. {
  62. g.fillAll (Colours::black.withAlpha (0.5f));
  63. }
  64. void inputAttemptWhenModal() override { close(); }
  65. void mouseDrag (const MouseEvent&) override {}
  66. void mouseDown (const MouseEvent&) override { close(); }
  67. void resized () override { update(); }
  68. void parentSizeChanged() override { update(); }
  69. private:
  70. void update()
  71. {
  72. const int pw = getParentWidth();
  73. const int ph = getParentHeight();
  74. nativeSelectorComponent.setBounds (Rectangle<int> (pw, ph)
  75. .withSizeKeepingCentre (jmin (400, pw - 14),
  76. jmin (500, ph - 40)));
  77. }
  78. void close()
  79. {
  80. exitModalState (0);
  81. setVisible (false);
  82. }
  83. UIViewComponent nativeSelectorComponent;
  84. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BluetoothMidiSelectorOverlay)
  85. };
  86. #endif // JUCE_MODULE_AVAILABLE_juce_gui_extra && ! TARGET_IPHONE_SIMULATOR
  87. //==============================================================================
  88. bool BluetoothMidiDevicePairingDialogue::open()
  89. {
  90. #if JUCE_MODULE_AVAILABLE_juce_gui_extra && ! TARGET_IPHONE_SIMULATOR
  91. if (isAvailable())
  92. {
  93. new BluetoothMidiSelectorOverlay();
  94. return true;
  95. }
  96. #endif
  97. return false;
  98. }
  99. bool BluetoothMidiDevicePairingDialogue::isAvailable()
  100. {
  101. #if JUCE_MODULE_AVAILABLE_juce_gui_extra && ! TARGET_IPHONE_SIMULATOR
  102. return NSClassFromString ([NSString stringWithUTF8String: "CABTMIDICentralViewController"]) != nil;
  103. #else
  104. return false;
  105. #endif
  106. }