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.

JucePluginWindow.hpp 24KB

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