Audio plugin host https://kx.studio/carla
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.

584 lines
24KB

  1. /*
  2. * Juce Plugin Window Helper
  3. * Copyright (C) 2013-2021 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #ifndef JUCE_PLUGIN_WINDOW_HPP_INCLUDED
  18. #define JUCE_PLUGIN_WINDOW_HPP_INCLUDED
  19. #include "CarlaJuceUtils.hpp"
  20. #include "CarlaVst2Utils.hpp"
  21. #include "CarlaVst3Utils.hpp"
  22. #include "AppConfig.h"
  23. #include "juce_gui_basics/juce_gui_basics.h"
  24. #if defined(CARLA_OS_LINUX) && defined(HAVE_X11)
  25. # include <X11/Xlib.h>
  26. #elif defined(CARLA_OS_MAC)
  27. # ifdef __MAC_10_12
  28. # define Component CocoaComponent
  29. # define MemoryBlock CocoaMemoryBlock
  30. # define Point CocoaPoint
  31. # endif
  32. # import <Cocoa/Cocoa.h>
  33. # undef Component
  34. # undef MemoryBlock
  35. # undef Point
  36. #endif
  37. // -----------------------------------------------------------------------
  38. namespace juce {
  39. class JucePluginWindow : public DialogWindow
  40. {
  41. public:
  42. JucePluginWindow(const uintptr_t parentId, const bool isStandalone,
  43. AEffect* const vst2effect, v3_plugin_view** const vst3view)
  44. : DialogWindow("JucePluginWindow", Colour(50, 50, 200), true, false),
  45. fIsStandalone(isStandalone),
  46. fClosed(false),
  47. fShown(false),
  48. fTransientId(parentId),
  49. fLastKeys(),
  50. fVst2Effect(vst2effect),
  51. fVst3View(vst3view)
  52. {
  53. carla_zeroStruct(fLastKeys);
  54. setVisible(false);
  55. setOpaque(true);
  56. setResizable(false, false);
  57. setUsingNativeTitleBar(true);
  58. }
  59. void show(Component* const comp)
  60. {
  61. fClosed = false;
  62. fShown = true;
  63. centreWithSize(comp->getWidth(), comp->getHeight());
  64. setContentNonOwned(comp, true);
  65. if (! isOnDesktop())
  66. addToDesktop();
  67. #ifndef CARLA_OS_LINUX
  68. setAlwaysOnTop(true);
  69. #endif
  70. setTransient();
  71. setVisible(true);
  72. toFront(true);
  73. #ifndef CARLA_OS_LINUX
  74. postCommandMessage(0);
  75. #endif
  76. }
  77. bool keyPressed (const KeyPress& key) override
  78. {
  79. if (DialogWindow::keyPressed (key))
  80. return true;
  81. if (fVst2Effect != nullptr)
  82. {
  83. const int juceKeyCode = key.getKeyCode();
  84. int vstKeyIndex = 0;
  85. int vstKeyValue = 0;
  86. do {
  87. /**/ if (juceKeyCode == KeyPress::spaceKey) vstKeyValue = 7;
  88. else if (juceKeyCode == KeyPress::escapeKey) vstKeyValue = 6;
  89. else if (juceKeyCode == KeyPress::returnKey) vstKeyValue = 19; // NOTE: 4 is '\r' while 19 is '\n'
  90. else if (juceKeyCode == KeyPress::tabKey) vstKeyValue = 2;
  91. else if (juceKeyCode == KeyPress::deleteKey) vstKeyValue = 22;
  92. else if (juceKeyCode == KeyPress::backspaceKey) vstKeyValue = 1;
  93. else if (juceKeyCode == KeyPress::insertKey) vstKeyValue = 21;
  94. else if (juceKeyCode == KeyPress::upKey) vstKeyValue = 12;
  95. else if (juceKeyCode == KeyPress::downKey) vstKeyValue = 14;
  96. else if (juceKeyCode == KeyPress::leftKey) vstKeyValue = 11;
  97. else if (juceKeyCode == KeyPress::rightKey) vstKeyValue = 13;
  98. else if (juceKeyCode == KeyPress::pageUpKey) vstKeyValue = 15;
  99. else if (juceKeyCode == KeyPress::pageDownKey) vstKeyValue = 16;
  100. else if (juceKeyCode == KeyPress::homeKey) vstKeyValue = 10;
  101. else if (juceKeyCode == KeyPress::endKey) vstKeyValue = 9;
  102. else if (juceKeyCode == KeyPress::F1Key) vstKeyValue = 40;
  103. else if (juceKeyCode == KeyPress::F2Key) vstKeyValue = 41;
  104. else if (juceKeyCode == KeyPress::F3Key) vstKeyValue = 42;
  105. else if (juceKeyCode == KeyPress::F4Key) vstKeyValue = 43;
  106. else if (juceKeyCode == KeyPress::F5Key) vstKeyValue = 44;
  107. else if (juceKeyCode == KeyPress::F6Key) vstKeyValue = 45;
  108. else if (juceKeyCode == KeyPress::F7Key) vstKeyValue = 46;
  109. else if (juceKeyCode == KeyPress::F8Key) vstKeyValue = 47;
  110. else if (juceKeyCode == KeyPress::F9Key) vstKeyValue = 48;
  111. else if (juceKeyCode == KeyPress::F10Key) vstKeyValue = 49;
  112. else if (juceKeyCode == KeyPress::F11Key) vstKeyValue = 50;
  113. else if (juceKeyCode == KeyPress::F12Key) vstKeyValue = 51;
  114. else if (juceKeyCode == KeyPress::F13Key) break;
  115. else if (juceKeyCode == KeyPress::F14Key) break;
  116. else if (juceKeyCode == KeyPress::F15Key) break;
  117. else if (juceKeyCode == KeyPress::F16Key) break;
  118. else if (juceKeyCode == KeyPress::F17Key) break;
  119. else if (juceKeyCode == KeyPress::F18Key) break;
  120. else if (juceKeyCode == KeyPress::F19Key) break;
  121. else if (juceKeyCode == KeyPress::F20Key) break;
  122. else if (juceKeyCode == KeyPress::F21Key) break;
  123. else if (juceKeyCode == KeyPress::F22Key) break;
  124. else if (juceKeyCode == KeyPress::F23Key) break;
  125. else if (juceKeyCode == KeyPress::F24Key) break;
  126. else if (juceKeyCode == KeyPress::F25Key) break;
  127. else if (juceKeyCode == KeyPress::F26Key) break;
  128. else if (juceKeyCode == KeyPress::F27Key) break;
  129. else if (juceKeyCode == KeyPress::F28Key) break;
  130. else if (juceKeyCode == KeyPress::F29Key) break;
  131. else if (juceKeyCode == KeyPress::F30Key) break;
  132. else if (juceKeyCode == KeyPress::F31Key) break;
  133. else if (juceKeyCode == KeyPress::F32Key) break;
  134. else if (juceKeyCode == KeyPress::F33Key) break;
  135. else if (juceKeyCode == KeyPress::F34Key) break;
  136. else if (juceKeyCode == KeyPress::F35Key) break;
  137. else if (juceKeyCode == KeyPress::numberPad0) vstKeyValue = 24;
  138. else if (juceKeyCode == KeyPress::numberPad1) vstKeyValue = 25;
  139. else if (juceKeyCode == KeyPress::numberPad2) vstKeyValue = 26;
  140. else if (juceKeyCode == KeyPress::numberPad3) vstKeyValue = 27;
  141. else if (juceKeyCode == KeyPress::numberPad4) vstKeyValue = 28;
  142. else if (juceKeyCode == KeyPress::numberPad5) vstKeyValue = 29;
  143. else if (juceKeyCode == KeyPress::numberPad6) vstKeyValue = 30;
  144. else if (juceKeyCode == KeyPress::numberPad7) vstKeyValue = 31;
  145. else if (juceKeyCode == KeyPress::numberPad8) vstKeyValue = 32;
  146. else if (juceKeyCode == KeyPress::numberPad9) vstKeyValue = 33;
  147. else if (juceKeyCode == KeyPress::numberPadAdd) vstKeyValue = 35;
  148. else if (juceKeyCode == KeyPress::numberPadSubtract) vstKeyValue = 37;
  149. else if (juceKeyCode == KeyPress::numberPadMultiply) vstKeyValue = 34;
  150. else if (juceKeyCode == KeyPress::numberPadDivide) vstKeyValue = 39;
  151. else if (juceKeyCode == KeyPress::numberPadSeparator) vstKeyValue = 36;
  152. else if (juceKeyCode == KeyPress::numberPadDecimalPoint) vstKeyValue = 38;
  153. else if (juceKeyCode == KeyPress::numberPadEquals) vstKeyValue = 57;
  154. else if (juceKeyCode == KeyPress::numberPadDelete) break;
  155. else if (juceKeyCode == KeyPress::playKey) break;
  156. else if (juceKeyCode == KeyPress::stopKey) break;
  157. else if (juceKeyCode == KeyPress::fastForwardKey) break;
  158. else if (juceKeyCode == KeyPress::rewindKey) break;
  159. else vstKeyIndex = juceKeyCode;
  160. } while (false);
  161. fLastKeys.vst2.index = vstKeyIndex;
  162. fLastKeys.vst2.value = vstKeyValue;
  163. return fVst2Effect->dispatcher (fVst2Effect, effEditKeyDown, vstKeyIndex, vstKeyValue, nullptr, 0.0f) != 0;
  164. }
  165. if (fVst3View != nullptr)
  166. {
  167. const int juceKeyCode = key.getKeyCode();
  168. const int juceKeyMods = key.getModifiers().getRawFlags();
  169. int16_t vst3KeyChar = 0;
  170. int16_t vst3KeyCode = 0;
  171. int16_t vst3KeyMods = 0;
  172. // KEY_NEXT 8
  173. // KEY_SELECT 17
  174. // KEY_SELECT 18
  175. // KEY_SNAPSHOT 20
  176. // KEY_HELP 23
  177. // KEY_NUMLOCK 52
  178. // KEY_SCROLL 53
  179. // KEY_VOLUME_UP 63
  180. // KEY_VOLUME_DOWN 64
  181. do {
  182. /**/ if (juceKeyCode == KeyPress::spaceKey)
  183. {
  184. vst3KeyChar = ' ';
  185. vst3KeyCode = 7;
  186. }
  187. else if (juceKeyCode == KeyPress::escapeKey)
  188. {
  189. vst3KeyCode = 6;
  190. }
  191. else if (juceKeyCode == KeyPress::returnKey)
  192. {
  193. vst3KeyChar = '\n';
  194. vst3KeyCode = 19; // NOTE: 4 is '\r' while 19 is '\n'
  195. }
  196. else if (juceKeyCode == KeyPress::tabKey)
  197. {
  198. vst3KeyChar = '\t';
  199. vst3KeyCode = 2;
  200. }
  201. else if (juceKeyCode == KeyPress::deleteKey) vst3KeyCode = 22;
  202. else if (juceKeyCode == KeyPress::backspaceKey) vst3KeyCode = 1;
  203. else if (juceKeyCode == KeyPress::insertKey) vst3KeyCode = 21;
  204. else if (juceKeyCode == KeyPress::upKey) vst3KeyCode = 12;
  205. else if (juceKeyCode == KeyPress::downKey) vst3KeyCode = 14;
  206. else if (juceKeyCode == KeyPress::leftKey) vst3KeyCode = 11;
  207. else if (juceKeyCode == KeyPress::rightKey) vst3KeyCode = 13;
  208. else if (juceKeyCode == KeyPress::pageUpKey) vst3KeyCode = 15;
  209. else if (juceKeyCode == KeyPress::pageDownKey) vst3KeyCode = 16;
  210. else if (juceKeyCode == KeyPress::homeKey) vst3KeyCode = 10;
  211. else if (juceKeyCode == KeyPress::endKey) vst3KeyCode = 9;
  212. else if (juceKeyCode == KeyPress::F1Key) vst3KeyCode = 40;
  213. else if (juceKeyCode == KeyPress::F2Key) vst3KeyCode = 41;
  214. else if (juceKeyCode == KeyPress::F3Key) vst3KeyCode = 42;
  215. else if (juceKeyCode == KeyPress::F4Key) vst3KeyCode = 43;
  216. else if (juceKeyCode == KeyPress::F5Key) vst3KeyCode = 44;
  217. else if (juceKeyCode == KeyPress::F6Key) vst3KeyCode = 45;
  218. else if (juceKeyCode == KeyPress::F7Key) vst3KeyCode = 46;
  219. else if (juceKeyCode == KeyPress::F8Key) vst3KeyCode = 47;
  220. else if (juceKeyCode == KeyPress::F9Key) vst3KeyCode = 48;
  221. else if (juceKeyCode == KeyPress::F10Key) vst3KeyCode = 49;
  222. else if (juceKeyCode == KeyPress::F11Key) vst3KeyCode = 50;
  223. else if (juceKeyCode == KeyPress::F12Key) vst3KeyCode = 51;
  224. else if (juceKeyCode == KeyPress::F13Key) vst3KeyCode = 65;
  225. else if (juceKeyCode == KeyPress::F14Key) vst3KeyCode = 66;
  226. else if (juceKeyCode == KeyPress::F15Key) vst3KeyCode = 67;
  227. else if (juceKeyCode == KeyPress::F16Key) vst3KeyCode = 68;
  228. else if (juceKeyCode == KeyPress::F17Key) vst3KeyCode = 69;
  229. else if (juceKeyCode == KeyPress::F18Key) vst3KeyCode = 70;
  230. else if (juceKeyCode == KeyPress::F19Key) vst3KeyCode = 71;
  231. else if (juceKeyCode == KeyPress::F20Key) break;
  232. else if (juceKeyCode == KeyPress::F21Key) break;
  233. else if (juceKeyCode == KeyPress::F22Key) break;
  234. else if (juceKeyCode == KeyPress::F23Key) break;
  235. else if (juceKeyCode == KeyPress::F24Key) break;
  236. else if (juceKeyCode == KeyPress::F25Key) break;
  237. else if (juceKeyCode == KeyPress::F26Key) break;
  238. else if (juceKeyCode == KeyPress::F27Key) break;
  239. else if (juceKeyCode == KeyPress::F28Key) break;
  240. else if (juceKeyCode == KeyPress::F29Key) break;
  241. else if (juceKeyCode == KeyPress::F30Key) break;
  242. else if (juceKeyCode == KeyPress::F31Key) break;
  243. else if (juceKeyCode == KeyPress::F32Key) break;
  244. else if (juceKeyCode == KeyPress::F33Key) break;
  245. else if (juceKeyCode == KeyPress::F34Key) break;
  246. else if (juceKeyCode == KeyPress::F35Key) break;
  247. else if (juceKeyCode == KeyPress::numberPad0) vst3KeyCode = 24;
  248. else if (juceKeyCode == KeyPress::numberPad1) vst3KeyCode = 25;
  249. else if (juceKeyCode == KeyPress::numberPad2) vst3KeyCode = 26;
  250. else if (juceKeyCode == KeyPress::numberPad3) vst3KeyCode = 27;
  251. else if (juceKeyCode == KeyPress::numberPad4) vst3KeyCode = 28;
  252. else if (juceKeyCode == KeyPress::numberPad5) vst3KeyCode = 29;
  253. else if (juceKeyCode == KeyPress::numberPad6) vst3KeyCode = 30;
  254. else if (juceKeyCode == KeyPress::numberPad7) vst3KeyCode = 31;
  255. else if (juceKeyCode == KeyPress::numberPad8) vst3KeyCode = 32;
  256. else if (juceKeyCode == KeyPress::numberPad9) vst3KeyCode = 33;
  257. else if (juceKeyCode == KeyPress::numberPadAdd) vst3KeyCode = 35;
  258. else if (juceKeyCode == KeyPress::numberPadSubtract) vst3KeyCode = 37;
  259. else if (juceKeyCode == KeyPress::numberPadMultiply) vst3KeyCode = 34;
  260. else if (juceKeyCode == KeyPress::numberPadDivide) vst3KeyCode = 39;
  261. else if (juceKeyCode == KeyPress::numberPadSeparator) vst3KeyCode = 36;
  262. else if (juceKeyCode == KeyPress::numberPadDecimalPoint) vst3KeyCode = 38;
  263. else if (juceKeyCode == KeyPress::numberPadEquals) vst3KeyCode = 57;
  264. else if (juceKeyCode == KeyPress::numberPadDelete) break;
  265. else if (juceKeyCode == KeyPress::playKey) vst3KeyCode = 59;
  266. else if (juceKeyCode == KeyPress::stopKey) vst3KeyCode = 60;
  267. else if (juceKeyCode == KeyPress::fastForwardKey) vst3KeyCode = 62;
  268. else if (juceKeyCode == KeyPress::rewindKey) vst3KeyCode = 61;
  269. else
  270. {
  271. vst3KeyChar = static_cast<int16_t>(juceKeyCode);
  272. if ((juceKeyCode >= 0x30 && juceKeyCode <= 0x39) || (juceKeyCode >= 0x41 && juceKeyCode <= 0x5A))
  273. vst3KeyCode = static_cast<int16_t>(juceKeyCode - 0x30 + 128);
  274. }
  275. } while (false);
  276. if (juceKeyMods & ModifierKeys::shiftModifier)
  277. vst3KeyMods |= 1 << 0;
  278. if (juceKeyMods & ModifierKeys::altModifier)
  279. vst3KeyMods |= 1 << 1;
  280. if (juceKeyMods & ModifierKeys::commandModifier)
  281. vst3KeyMods |= 1 << 2;
  282. #if JUCE_MAC || JUCE_IOS
  283. if (juceKeyMods & ModifierKeys::ctrlModifier)
  284. vst3KeyMods |= 1 << 3;
  285. #endif
  286. fLastKeys.vst3.keychar = vst3KeyChar;
  287. fLastKeys.vst3.keycode = vst3KeyCode;
  288. fLastKeys.vst3.keymods = vst3KeyMods;
  289. return v3_cpp_obj(fVst3View)->on_key_down (fVst3View, vst3KeyChar, vst3KeyCode, vst3KeyMods) == V3_TRUE;
  290. }
  291. if (Component* const comp = getContentComponent())
  292. return comp->keyPressed (key);
  293. return false;
  294. }
  295. bool keyStateChanged (bool isKeyDown) override
  296. {
  297. if (DialogWindow::keyStateChanged (isKeyDown))
  298. return true;
  299. if (fVst2Effect != nullptr && (fLastKeys.vst2.index != 0 || fLastKeys.vst2.value != 0) && ! isKeyDown)
  300. {
  301. const int vstKeyIndex = fLastKeys.vst2.index;
  302. const int vstKeyValue = fLastKeys.vst2.value;
  303. fLastKeys.vst2.index = fLastKeys.vst2.value = 0;
  304. return fVst2Effect->dispatcher (fVst2Effect, effEditKeyUp, vstKeyIndex, vstKeyValue, nullptr, 0.0f) != 0;
  305. }
  306. if (fVst3View != nullptr && (fLastKeys.vst3.keychar != 0 || fLastKeys.vst3.keycode != 0) && ! isKeyDown)
  307. {
  308. const int16_t vst3KeyChar = fLastKeys.vst3.keychar;
  309. const int16_t vst3KeyCode = fLastKeys.vst3.keycode;
  310. const int16_t vst3KeyMods = fLastKeys.vst3.keymods;
  311. fLastKeys.vst3.keychar = fLastKeys.vst3.keycode = fLastKeys.vst3.keymods = 0;
  312. return v3_cpp_obj(fVst3View)->on_key_up (fVst3View, vst3KeyChar, vst3KeyCode, vst3KeyMods) == V3_TRUE;
  313. }
  314. if (Component* const comp = getContentComponent())
  315. return comp->keyStateChanged (isKeyDown);
  316. return false;
  317. }
  318. void modifierKeysChanged (const ModifierKeys& modifiers) override
  319. {
  320. DialogWindow::modifierKeysChanged (modifiers);
  321. if (fVst2Effect != nullptr)
  322. {
  323. const int oldRawFlags = fLastKeys.vst2.rmods;
  324. const int newRawFlags = modifiers.getRawFlags();
  325. if ((oldRawFlags & ModifierKeys::shiftModifier) != (newRawFlags & ModifierKeys::shiftModifier))
  326. {
  327. fVst2Effect->dispatcher (fVst2Effect,
  328. (newRawFlags & ModifierKeys::shiftModifier) ? effEditKeyDown : effEditKeyUp,
  329. 0, 54, nullptr, 0.0f);
  330. }
  331. if ((oldRawFlags & ModifierKeys::ctrlModifier) != (newRawFlags & ModifierKeys::ctrlModifier))
  332. {
  333. fVst2Effect->dispatcher (fVst2Effect,
  334. (newRawFlags & ModifierKeys::ctrlModifier) ? effEditKeyDown : effEditKeyUp,
  335. 0, 55, nullptr, 0.0f);
  336. }
  337. if ((oldRawFlags & ModifierKeys::altModifier) != (newRawFlags & ModifierKeys::altModifier))
  338. {
  339. fVst2Effect->dispatcher (fVst2Effect,
  340. (newRawFlags & ModifierKeys::altModifier) ? effEditKeyDown : effEditKeyUp,
  341. 0, 56, nullptr, 0.0f);
  342. }
  343. if ((oldRawFlags & ModifierKeys::popupMenuClickModifier) != (newRawFlags & ModifierKeys::popupMenuClickModifier))
  344. {
  345. fVst2Effect->dispatcher (fVst2Effect,
  346. (newRawFlags & ModifierKeys::popupMenuClickModifier) ? effEditKeyDown : effEditKeyUp,
  347. 0, 58, nullptr, 0.0f);
  348. }
  349. fLastKeys.vst2.rmods = newRawFlags;
  350. }
  351. if (fVst3View != nullptr)
  352. {
  353. const int oldRawFlags = fLastKeys.vst3.rmods;
  354. const int newRawFlags = modifiers.getRawFlags();
  355. if ((oldRawFlags & ModifierKeys::shiftModifier) != (newRawFlags & ModifierKeys::shiftModifier))
  356. {
  357. if (newRawFlags & ModifierKeys::shiftModifier)
  358. v3_cpp_obj(fVst3View)->on_key_down (fVst3View, 0, 54, fLastKeys.vst3.keymods);
  359. else
  360. v3_cpp_obj(fVst3View)->on_key_up (fVst3View, 0, 54, fLastKeys.vst3.keymods);
  361. }
  362. if ((oldRawFlags & ModifierKeys::ctrlModifier) != (newRawFlags & ModifierKeys::ctrlModifier))
  363. {
  364. if (newRawFlags & ModifierKeys::ctrlModifier)
  365. v3_cpp_obj(fVst3View)->on_key_down (fVst3View, 0, 55, fLastKeys.vst3.keymods);
  366. else
  367. v3_cpp_obj(fVst3View)->on_key_up (fVst3View, 0, 55, fLastKeys.vst3.keymods);
  368. }
  369. if ((oldRawFlags & ModifierKeys::altModifier) != (newRawFlags & ModifierKeys::altModifier))
  370. {
  371. if (newRawFlags & ModifierKeys::altModifier)
  372. v3_cpp_obj(fVst3View)->on_key_down (fVst3View, 0, 56, fLastKeys.vst3.keymods);
  373. else
  374. v3_cpp_obj(fVst3View)->on_key_up (fVst3View, 0, 56, fLastKeys.vst3.keymods);
  375. }
  376. if ((oldRawFlags & ModifierKeys::popupMenuClickModifier) != (newRawFlags & ModifierKeys::popupMenuClickModifier))
  377. {
  378. if (newRawFlags & ModifierKeys::popupMenuClickModifier)
  379. v3_cpp_obj(fVst3View)->on_key_down (fVst3View, 0, 58, fLastKeys.vst3.keymods);
  380. else
  381. v3_cpp_obj(fVst3View)->on_key_up (fVst3View, 0, 58, fLastKeys.vst3.keymods);
  382. }
  383. fLastKeys.vst3.rmods = newRawFlags;
  384. }
  385. }
  386. void focusGained (const FocusChangeType cause) override
  387. {
  388. DialogWindow::focusGained (cause);
  389. if (fVst3View != nullptr)
  390. v3_cpp_obj(fVst3View)->on_focus (fVst3View, true);
  391. }
  392. void focusLost (const FocusChangeType cause) override
  393. {
  394. if (fVst3View != nullptr)
  395. v3_cpp_obj(fVst3View)->on_focus (fVst3View, false);
  396. DialogWindow::focusLost (cause);
  397. }
  398. void hide()
  399. {
  400. setVisible(false);
  401. if (isOnDesktop())
  402. removeFromDesktop();
  403. clearContentComponent();
  404. }
  405. bool wasClosedByUser() const noexcept
  406. {
  407. return fClosed;
  408. }
  409. protected:
  410. void closeButtonPressed() override
  411. {
  412. fClosed = true;
  413. }
  414. bool escapeKeyPressed() override
  415. {
  416. fClosed = true;
  417. return true;
  418. }
  419. int getDesktopWindowStyleFlags() const override
  420. {
  421. int wflags = 0;
  422. wflags |= ComponentPeer::windowHasCloseButton;
  423. wflags |= ComponentPeer::windowHasDropShadow;
  424. wflags |= ComponentPeer::windowHasTitleBar;
  425. if (fIsStandalone)
  426. wflags |= ComponentPeer::windowAppearsOnTaskbar;
  427. return wflags;
  428. }
  429. #ifndef CARLA_OS_LINUX
  430. void handleCommandMessage(const int comamndId) override
  431. {
  432. CARLA_SAFE_ASSERT_RETURN(comamndId == 0,);
  433. if (fShown)
  434. {
  435. fShown = false;
  436. setAlwaysOnTop(false);
  437. }
  438. }
  439. #endif
  440. private:
  441. const bool fIsStandalone;
  442. volatile bool fClosed;
  443. bool fShown;
  444. const uintptr_t fTransientId;
  445. union {
  446. struct {
  447. int index;
  448. int value;
  449. int rmods;
  450. } vst2;
  451. struct {
  452. int16_t keychar;
  453. int16_t keycode;
  454. int16_t keymods;
  455. int rmods;
  456. } vst3;
  457. } fLastKeys;
  458. AEffect* const fVst2Effect;
  459. v3_plugin_view** const fVst3View;
  460. void setTransient()
  461. {
  462. if (fTransientId == 0)
  463. return;
  464. #if defined(CARLA_OS_LINUX) && defined(HAVE_X11)
  465. Display* const display = XWindowSystem::getInstance()->getDisplay();
  466. CARLA_SAFE_ASSERT_RETURN(display != nullptr,);
  467. ::Window window = (::Window)getWindowHandle();
  468. CARLA_SAFE_ASSERT_RETURN(window != 0,);
  469. XSetTransientForHint(display, window, static_cast<::Window>(fTransientId));
  470. #endif
  471. #ifdef CARLA_OS_MAC
  472. NSView* const view = (NSView*)getWindowHandle();
  473. CARLA_SAFE_ASSERT_RETURN(view != nullptr,);
  474. NSWindow* const window = [view window];
  475. CARLA_SAFE_ASSERT_RETURN(window != nullptr,);
  476. NSWindow* const parentWindow = [NSApp windowWithWindowNumber:fTransientId];
  477. CARLA_SAFE_ASSERT_RETURN(parentWindow != nullptr,);
  478. [parentWindow addChildWindow:window
  479. ordered:NSWindowAbove];
  480. #endif
  481. #ifdef CARLA_OS_WIN
  482. const HWND window = (HWND)getWindowHandle();
  483. CARLA_SAFE_ASSERT_RETURN(window != nullptr,);
  484. SetWindowLongPtr(window, GWLP_HWNDPARENT, static_cast<LONG_PTR>(fTransientId));
  485. #endif
  486. }
  487. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(JucePluginWindow)
  488. };
  489. } // namespace juce
  490. using juce::JucePluginWindow;
  491. // -----------------------------------------------------------------------
  492. #endif // JUCE_PLUGIN_WINDOW_HPP_INCLUDED