VstEffectControlDialog.cpp 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. /*
  2. * VstEffectControlDialog.cpp - dialog for displaying VST-effect GUI
  3. *
  4. * Copyright (c) 2006-2011 Tobias Doerffel <tobydox/at/users.sourceforge.net>
  5. *
  6. * This file is part of LMMS - https://lmms.io
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with this program (see COPYING); if not, write to the
  20. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. * Boston, MA 02110-1301 USA.
  22. *
  23. */
  24. #include <QLayout>
  25. #include <QMdiArea>
  26. #include <QMenu>
  27. #include <QPushButton>
  28. #include "VstEffectControlDialog.h"
  29. #include "VstEffect.h"
  30. #include "ConfigManager.h"
  31. #include "PixmapButton.h"
  32. #include "embed.h"
  33. #include "ToolTip.h"
  34. #include <QObject>
  35. #include <QPainter>
  36. #include "gui_templates.h"
  37. #include <QToolBar>
  38. #include <QLabel>
  39. VstEffectControlDialog::VstEffectControlDialog( VstEffectControls * _ctl ) :
  40. EffectControlDialog( _ctl ),
  41. m_pluginWidget( NULL ),
  42. m_plugin( NULL ),
  43. tbLabel( NULL )
  44. {
  45. QGridLayout * l = new QGridLayout( this );
  46. l->setContentsMargins( 10, 10, 10, 10 );
  47. l->setVerticalSpacing( 2 );
  48. l->setHorizontalSpacing( 2 );
  49. bool embed_vst = false;
  50. if( _ctl != NULL && _ctl->m_effect != NULL &&
  51. _ctl->m_effect->m_plugin != NULL )
  52. {
  53. m_plugin = _ctl->m_effect->m_plugin;
  54. embed_vst = m_plugin->embedMethod() != "none";
  55. if (embed_vst) {
  56. if (m_plugin->hasEditor() && ! m_plugin->pluginWidget()) {
  57. m_plugin->createUI(this);
  58. }
  59. m_pluginWidget = m_plugin->pluginWidget();
  60. }
  61. }
  62. if (m_plugin)
  63. {
  64. setWindowTitle( m_plugin->name() );
  65. QPushButton * btn = new QPushButton( tr( "Show/hide" ));
  66. if (embed_vst) {
  67. btn->setCheckable( true );
  68. btn->setChecked( true );
  69. connect( btn, SIGNAL( toggled( bool ) ),
  70. SLOT( togglePluginUI( bool ) ) );
  71. } else {
  72. connect( btn, SIGNAL( clicked() ),
  73. m_plugin.data(), SLOT( toggleUI() ) );
  74. }
  75. btn->setMinimumWidth( 78 );
  76. btn->setMaximumWidth( 78 );
  77. btn->setMinimumHeight( 24 );
  78. btn->setMaximumHeight( 24 );
  79. m_togglePluginButton = btn;
  80. m_managePluginButton = new PixmapButton( this, "" );
  81. m_managePluginButton->setCheckable( false );
  82. m_managePluginButton->setCursor( Qt::PointingHandCursor );
  83. m_managePluginButton->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
  84. "controls_active" ) );
  85. m_managePluginButton->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
  86. "controls" ) );
  87. connect( m_managePluginButton, SIGNAL( clicked() ), _ctl,
  88. SLOT( managePlugin() ) );
  89. ToolTip::add( m_managePluginButton, tr( "Control VST-plugin from LMMS host" ) );
  90. m_managePluginButton->setWhatsThis(
  91. tr( "Click here, if you want to control VST-plugin from host." ) );
  92. m_managePluginButton->setMinimumWidth( 26 );
  93. m_managePluginButton->setMaximumWidth( 26 );
  94. m_managePluginButton->setMinimumHeight( 21 );
  95. m_managePluginButton->setMaximumHeight( 21 );
  96. m_openPresetButton = new PixmapButton( this, "" );
  97. m_openPresetButton->setCheckable( false );
  98. m_openPresetButton->setCursor( Qt::PointingHandCursor );
  99. m_openPresetButton->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
  100. "stepper-up-press" ) );
  101. m_openPresetButton->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
  102. "stepper-up" ) );
  103. connect( m_openPresetButton, SIGNAL( clicked() ), _ctl,
  104. SLOT( openPreset() ) );
  105. ToolTip::add( m_openPresetButton, tr( "Open VST-plugin preset" ) );
  106. m_openPresetButton->setWhatsThis(
  107. tr( "Click here, if you want to open another *.fxp, *.fxb VST-plugin preset." ) );
  108. m_openPresetButton->setMinimumWidth( 16 );
  109. m_openPresetButton->setMaximumWidth( 16 );
  110. m_openPresetButton->setMinimumHeight( 16 );
  111. m_openPresetButton->setMaximumHeight( 16 );
  112. m_rolLPresetButton = new PixmapButton( this, "" );
  113. m_rolLPresetButton->setCheckable( false );
  114. m_rolLPresetButton->setCursor( Qt::PointingHandCursor );
  115. m_rolLPresetButton->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
  116. "stepper-left-press" ) );
  117. m_rolLPresetButton->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
  118. "stepper-left" ) );
  119. connect( m_rolLPresetButton, SIGNAL( clicked() ), _ctl,
  120. SLOT( rolrPreset() ) );
  121. connect( m_rolLPresetButton, SIGNAL( clicked() ), this,
  122. SLOT( update() ) );
  123. ToolTip::add( m_rolLPresetButton, tr( "Previous (-)" ) );
  124. m_rolLPresetButton->setShortcut( Qt::Key_Minus );
  125. m_rolLPresetButton->setWhatsThis(
  126. tr( "Click here, if you want to switch to another VST-plugin preset program." ) );
  127. m_rolLPresetButton->setMinimumWidth( 16 );
  128. m_rolLPresetButton->setMaximumWidth( 16 );
  129. m_rolLPresetButton->setMinimumHeight( 16 );
  130. m_rolLPresetButton->setMaximumHeight( 16 );
  131. m_rolRPresetButton = new PixmapButton( this, "" );
  132. m_rolRPresetButton->setCheckable( false );
  133. m_rolRPresetButton->setCursor( Qt::PointingHandCursor );
  134. m_rolRPresetButton->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
  135. "stepper-right-press" ) );
  136. m_rolRPresetButton->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
  137. "stepper-right" ) );
  138. connect( m_rolRPresetButton, SIGNAL( clicked() ), _ctl,
  139. SLOT( rollPreset() ) );
  140. connect( m_rolRPresetButton, SIGNAL( clicked() ), this,
  141. SLOT( update() ) );
  142. ToolTip::add( m_rolRPresetButton, tr( "Next (+)" ) );
  143. m_rolRPresetButton->setShortcut( Qt::Key_Plus );
  144. m_rolRPresetButton->setWhatsThis(
  145. tr( "Click here, if you want to switch to another VST-plugin preset program." ) );
  146. m_rolRPresetButton->setMinimumWidth( 16 );
  147. m_rolRPresetButton->setMaximumWidth( 16 );
  148. m_rolRPresetButton->setMinimumHeight( 16 );
  149. m_rolRPresetButton->setMaximumHeight( 16 );
  150. _ctl->m_selPresetButton = new QPushButton( tr( "" ), this );
  151. _ctl->m_selPresetButton->setCheckable( false );
  152. _ctl->m_selPresetButton->setCursor( Qt::PointingHandCursor );
  153. _ctl->m_selPresetButton->setIcon( PLUGIN_NAME::getIconPixmap( "stepper-down" ) );
  154. _ctl->m_selPresetButton->setWhatsThis(
  155. tr( "Click here to select presets that are currently loaded in VST." ) );
  156. QMenu * menu = new QMenu;
  157. connect( menu, SIGNAL( aboutToShow() ), _ctl, SLOT( updateMenu() ) );
  158. _ctl->m_selPresetButton->setMenu(menu);
  159. _ctl->m_selPresetButton->setMinimumWidth( 16 );
  160. _ctl->m_selPresetButton->setMaximumWidth( 16 );
  161. _ctl->m_selPresetButton->setMinimumHeight( 16 );
  162. _ctl->m_selPresetButton->setMaximumHeight( 16 );
  163. m_savePresetButton = new PixmapButton( this, "" );
  164. m_savePresetButton->setCheckable( false );
  165. m_savePresetButton->setCursor( Qt::PointingHandCursor );
  166. m_savePresetButton->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
  167. "project_save", 21, 21 ) );
  168. m_savePresetButton->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
  169. "project_save", 21, 21 ) );
  170. connect( m_savePresetButton, SIGNAL( clicked() ), _ctl,
  171. SLOT( savePreset() ) );
  172. ToolTip::add( m_savePresetButton, tr( "Save preset" ) );
  173. m_savePresetButton->setWhatsThis(
  174. tr( "Click here, if you want to save current VST-plugin preset program." ) );
  175. m_savePresetButton->setMinimumWidth( 21 );
  176. m_savePresetButton->setMaximumWidth( 21 );
  177. m_savePresetButton->setMinimumHeight( 21 );
  178. m_savePresetButton->setMaximumHeight( 21 );
  179. int newSize = 0;
  180. if (m_pluginWidget) {
  181. newSize = m_pluginWidget->width() + 20;
  182. }
  183. newSize = std::max(newSize, 250);
  184. QWidget* resize = new QWidget(this);
  185. resize->resize( newSize, 10 );
  186. QWidget* space0 = new QWidget(this);
  187. space0->resize(8, 10);
  188. QWidget* space1 = new QWidget(this);
  189. space1->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
  190. QFont f( "Arial", 10 );
  191. l->addItem( new QSpacerItem( newSize - 20, 30, QSizePolicy::Fixed,
  192. QSizePolicy::Fixed ), 1, 0 );
  193. l->addWidget( resize, 2, 0, 1, 1, Qt::AlignCenter );
  194. if (m_pluginWidget) {
  195. l->addWidget( m_pluginWidget, 3, 0, 1, 1, Qt::AlignCenter );
  196. }
  197. l->setRowStretch( 5, 1 );
  198. l->setColumnStretch( 1, 1 );
  199. QToolBar * tb = new QToolBar( this );
  200. tb->resize( newSize , 32 );
  201. tb->addWidget(space0);
  202. tb->addWidget( m_rolLPresetButton );
  203. tb->addWidget( m_rolRPresetButton );
  204. tb->addWidget( _ctl->m_selPresetButton );
  205. tb->addWidget( m_openPresetButton );
  206. tb->addWidget( m_savePresetButton );
  207. tb->addWidget( m_managePluginButton );
  208. tb->addWidget( btn );
  209. tb->addWidget(space1);
  210. tbLabel = new QLabel( tr( "Effect by: " ), this );
  211. tbLabel->setFont( pointSize<7>( f ) );
  212. tbLabel->setTextFormat(Qt::RichText);
  213. tbLabel->setAlignment( Qt::AlignTop | Qt::AlignLeft );
  214. tb->addWidget( tbLabel );
  215. }
  216. }
  217. void VstEffectControlDialog::paintEvent( QPaintEvent * )
  218. {
  219. if( m_plugin != NULL && tbLabel != NULL )
  220. {
  221. tbLabel->setText( tr( "Effect by: " ) + m_plugin->vendorString() +
  222. tr( "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />" ) +
  223. m_plugin->currentProgramName() );
  224. }
  225. }
  226. void VstEffectControlDialog::showEvent(QShowEvent *_se)
  227. {
  228. EffectControlDialog::showEvent( _se );
  229. // Workaround for a (unexplained) bug where on project-load the effect
  230. // control window has size 0 and would only restore to the proper size upon
  231. // moving the window or interacting with it.
  232. if (parentWidget()) {
  233. parentWidget()->adjustSize();
  234. }
  235. }
  236. VstEffectControlDialog::~VstEffectControlDialog()
  237. {
  238. #if !(QT_VERSION < 0x050000 && defined(LMMS_BUILD_LINUX))
  239. if (m_pluginWidget && layout()) {
  240. layout()->removeWidget(m_pluginWidget);
  241. m_pluginWidget->setParent(nullptr);
  242. }
  243. #endif
  244. }
  245. void VstEffectControlDialog::togglePluginUI( bool checked )
  246. {
  247. if( !m_plugin ) {
  248. return;
  249. }
  250. if ( m_togglePluginButton->isChecked() != checked ) {
  251. m_togglePluginButton->setChecked( checked );
  252. }
  253. if ( checked ) {
  254. m_plugin->showUI();
  255. } else {
  256. m_plugin->hideUI();
  257. }
  258. }