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.

122 lines
3.8KB

  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()
  32. {
  33. setAlwaysOnTop (true);
  34. setVisible (true);
  35. addToDesktop (ComponentPeer::windowHasDropShadow);
  36. setBounds (0, 0, getParentWidth(), getParentHeight());
  37. toFront (true);
  38. controller = [[CABTMIDICentralViewController alloc] init];
  39. nativeSelectorComponent.setView ([controller view]);
  40. addAndMakeVisible (nativeSelectorComponent);
  41. enterModalState (true, nullptr, true);
  42. }
  43. ~BluetoothMidiSelectorOverlay()
  44. {
  45. nativeSelectorComponent.setView (nullptr);
  46. [controller release];
  47. }
  48. void paint (Graphics& g) override
  49. {
  50. g.fillAll (Colours::black.withAlpha (0.5f));
  51. }
  52. void inputAttemptWhenModal() override { close(); }
  53. void mouseDrag (const MouseEvent&) override {}
  54. void mouseDown (const MouseEvent&) override { close(); }
  55. void resized() override { update(); }
  56. void parentSizeChanged() override { update(); }
  57. private:
  58. void update()
  59. {
  60. const int pw = getParentWidth();
  61. const int ph = getParentHeight();
  62. nativeSelectorComponent.setBounds (Rectangle<int> (pw, ph)
  63. .withSizeKeepingCentre (jmin (400, pw),
  64. jmin (450, ph - 40)));
  65. }
  66. void close()
  67. {
  68. exitModalState (0);
  69. setVisible (false);
  70. }
  71. CABTMIDICentralViewController* controller;
  72. UIViewComponent nativeSelectorComponent;
  73. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BluetoothMidiSelectorOverlay)
  74. };
  75. bool BluetoothMidiDevicePairingDialogue::open()
  76. {
  77. if (isAvailable())
  78. {
  79. new BluetoothMidiSelectorOverlay();
  80. return true;
  81. }
  82. return false;
  83. }
  84. bool BluetoothMidiDevicePairingDialogue::isAvailable()
  85. {
  86. return NSClassFromString ([NSString stringWithUTF8String: "CABTMIDICentralViewController"]) != nil;
  87. }
  88. //==============================================================================
  89. #else
  90. bool BluetoothMidiDevicePairingDialogue::open() { return false; }
  91. bool BluetoothMidiDevicePairingDialogue::isAvailable() { return false; }
  92. #endif