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.

132 lines
4.2KB

  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. // Note: for the Bluetooth Midi selector overlay, we need the class
  20. // UIViewComponent from the juce_gui_extra module. If this module is not
  21. // included in your app, BluetoothMidiDevicePairingDialogue::open() will fail
  22. // and return false.
  23. // It is also not available in the iPhone/iPad simulator.
  24. #if JUCE_MODULE_AVAILABLE_juce_gui_extra && ! TARGET_IPHONE_SIMULATOR
  25. } // (juce namespace)
  26. #include <CoreAudioKit/CoreAudioKit.h>
  27. namespace juce
  28. {
  29. //==============================================================================
  30. class BluetoothMidiSelectorOverlay : public Component
  31. {
  32. public:
  33. BluetoothMidiSelectorOverlay (ModalComponentManager::Callback* exitCallbackToUse)
  34. {
  35. ScopedPointer<ModalComponentManager::Callback> exitCallback (exitCallbackToUse);
  36. setAlwaysOnTop (true);
  37. setVisible (true);
  38. addToDesktop (ComponentPeer::windowHasDropShadow);
  39. setBounds (0, 0, getParentWidth(), getParentHeight());
  40. toFront (true);
  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 (Colours::black.withAlpha (0.5f));
  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. const int pw = getParentWidth();
  64. const int ph = getParentHeight();
  65. nativeSelectorComponent.setBounds (Rectangle<int> (pw, ph)
  66. .withSizeKeepingCentre (jmin (400, pw),
  67. jmin (450, ph - 40)));
  68. }
  69. void close()
  70. {
  71. exitModalState (0);
  72. setVisible (false);
  73. }
  74. CABTMIDICentralViewController* controller;
  75. UIViewComponent nativeSelectorComponent;
  76. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BluetoothMidiSelectorOverlay)
  77. };
  78. bool BluetoothMidiDevicePairingDialogue::open (ModalComponentManager::Callback* exitCallback)
  79. {
  80. ScopedPointer<ModalComponentManager::Callback> cb (exitCallback);
  81. if (isAvailable())
  82. {
  83. new BluetoothMidiSelectorOverlay (cb.release());
  84. return true;
  85. }
  86. return false;
  87. }
  88. bool BluetoothMidiDevicePairingDialogue::isAvailable()
  89. {
  90. return NSClassFromString ([NSString stringWithUTF8String: "CABTMIDICentralViewController"]) != nil;
  91. }
  92. //==============================================================================
  93. #else
  94. bool BluetoothMidiDevicePairingDialogue::open (ModalComponentManager::Callback* exitCallback)
  95. {
  96. ScopedPointer<ModalComponentManager::Callback> cb (exitCallback);
  97. return false;
  98. }
  99. bool BluetoothMidiDevicePairingDialogue::isAvailable() { return false; }
  100. #endif