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.

130 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. namespace juce
  26. {
  27. //==============================================================================
  28. class BluetoothMidiSelectorOverlay : public Component
  29. {
  30. public:
  31. BluetoothMidiSelectorOverlay (ModalComponentManager::Callback* exitCallbackToUse)
  32. {
  33. ScopedPointer<ModalComponentManager::Callback> exitCallback (exitCallbackToUse);
  34. setAlwaysOnTop (true);
  35. setVisible (true);
  36. addToDesktop (ComponentPeer::windowHasDropShadow);
  37. setBounds (0, 0, getParentWidth(), getParentHeight());
  38. toFront (true);
  39. controller = [[CABTMIDICentralViewController alloc] init];
  40. nativeSelectorComponent.setView ([controller view]);
  41. addAndMakeVisible (nativeSelectorComponent);
  42. enterModalState (true, exitCallback.release(), true);
  43. }
  44. ~BluetoothMidiSelectorOverlay()
  45. {
  46. nativeSelectorComponent.setView (nullptr);
  47. [controller release];
  48. }
  49. void paint (Graphics& g) override
  50. {
  51. g.fillAll (Colours::black.withAlpha (0.5f));
  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. const int pw = getParentWidth();
  62. const int ph = getParentHeight();
  63. nativeSelectorComponent.setBounds (Rectangle<int> (pw, ph)
  64. .withSizeKeepingCentre (jmin (400, pw),
  65. jmin (450, ph - 40)));
  66. }
  67. void close()
  68. {
  69. exitModalState (0);
  70. setVisible (false);
  71. }
  72. CABTMIDICentralViewController* controller;
  73. UIViewComponent nativeSelectorComponent;
  74. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BluetoothMidiSelectorOverlay)
  75. };
  76. bool BluetoothMidiDevicePairingDialogue::open (ModalComponentManager::Callback* exitCallback)
  77. {
  78. ScopedPointer<ModalComponentManager::Callback> cb (exitCallback);
  79. if (isAvailable())
  80. {
  81. new BluetoothMidiSelectorOverlay (cb.release());
  82. return true;
  83. }
  84. return false;
  85. }
  86. bool BluetoothMidiDevicePairingDialogue::isAvailable()
  87. {
  88. return NSClassFromString ([NSString stringWithUTF8String: "CABTMIDICentralViewController"]) != nil;
  89. }
  90. //==============================================================================
  91. #else
  92. bool BluetoothMidiDevicePairingDialogue::open (ModalComponentManager::Callback* exitCallback)
  93. {
  94. ScopedPointer<ModalComponentManager::Callback> cb (exitCallback);
  95. return false;
  96. }
  97. bool BluetoothMidiDevicePairingDialogue::isAvailable() { return false; }
  98. #endif