VstEffectControlDialog.cpp 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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->setMinimumWidth( 26 );
  91. m_managePluginButton->setMaximumWidth( 26 );
  92. m_managePluginButton->setMinimumHeight( 21 );
  93. m_managePluginButton->setMaximumHeight( 21 );
  94. m_openPresetButton = new PixmapButton( this, "" );
  95. m_openPresetButton->setCheckable( false );
  96. m_openPresetButton->setCursor( Qt::PointingHandCursor );
  97. m_openPresetButton->setActiveGraphic( embed::getIconPixmap(
  98. "project_open" ) );
  99. m_openPresetButton->setInactiveGraphic( embed::getIconPixmap(
  100. "project_open" ) );
  101. connect( m_openPresetButton, SIGNAL( clicked() ), _ctl,
  102. SLOT( openPreset() ) );
  103. ToolTip::add( m_openPresetButton, tr( "Open VST plugin preset" ) );
  104. m_openPresetButton->setMinimumWidth( 16 );
  105. m_openPresetButton->setMaximumWidth( 16 );
  106. m_openPresetButton->setMinimumHeight( 16 );
  107. m_openPresetButton->setMaximumHeight( 16 );
  108. m_rolLPresetButton = new PixmapButton( this, "" );
  109. m_rolLPresetButton->setCheckable( false );
  110. m_rolLPresetButton->setCursor( Qt::PointingHandCursor );
  111. m_rolLPresetButton->setActiveGraphic( embed::getIconPixmap(
  112. "stepper-left-press" ) );
  113. m_rolLPresetButton->setInactiveGraphic( embed::getIconPixmap(
  114. "stepper-left" ) );
  115. connect( m_rolLPresetButton, SIGNAL( clicked() ), _ctl,
  116. SLOT( rolrPreset() ) );
  117. connect( m_rolLPresetButton, SIGNAL( clicked() ), this,
  118. SLOT( update() ) );
  119. ToolTip::add( m_rolLPresetButton, tr( "Previous (-)" ) );
  120. m_rolLPresetButton->setShortcut( Qt::Key_Minus );
  121. m_rolLPresetButton->setMinimumWidth( 16 );
  122. m_rolLPresetButton->setMaximumWidth( 16 );
  123. m_rolLPresetButton->setMinimumHeight( 16 );
  124. m_rolLPresetButton->setMaximumHeight( 16 );
  125. m_rolRPresetButton = new PixmapButton( this, "" );
  126. m_rolRPresetButton->setCheckable( false );
  127. m_rolRPresetButton->setCursor( Qt::PointingHandCursor );
  128. m_rolRPresetButton->setActiveGraphic( embed::getIconPixmap(
  129. "stepper-right-press" ) );
  130. m_rolRPresetButton->setInactiveGraphic( embed::getIconPixmap(
  131. "stepper-right" ) );
  132. connect( m_rolRPresetButton, SIGNAL( clicked() ), _ctl,
  133. SLOT( rollPreset() ) );
  134. connect( m_rolRPresetButton, SIGNAL( clicked() ), this,
  135. SLOT( update() ) );
  136. ToolTip::add( m_rolRPresetButton, tr( "Next (+)" ) );
  137. m_rolRPresetButton->setShortcut( Qt::Key_Plus );
  138. m_rolRPresetButton->setMinimumWidth( 16 );
  139. m_rolRPresetButton->setMaximumWidth( 16 );
  140. m_rolRPresetButton->setMinimumHeight( 16 );
  141. m_rolRPresetButton->setMaximumHeight( 16 );
  142. _ctl->m_selPresetButton = new QPushButton( tr( "" ), this );
  143. _ctl->m_selPresetButton->setCheckable( false );
  144. _ctl->m_selPresetButton->setCursor( Qt::PointingHandCursor );
  145. _ctl->m_selPresetButton->setIcon( embed::getIconPixmap( "stepper-down" ) );
  146. QMenu * menu = new QMenu;
  147. connect( menu, SIGNAL( aboutToShow() ), _ctl, SLOT( updateMenu() ) );
  148. _ctl->m_selPresetButton->setMenu(menu);
  149. _ctl->m_selPresetButton->setMinimumWidth( 16 );
  150. _ctl->m_selPresetButton->setMaximumWidth( 16 );
  151. _ctl->m_selPresetButton->setMinimumHeight( 16 );
  152. _ctl->m_selPresetButton->setMaximumHeight( 16 );
  153. m_savePresetButton = new PixmapButton( this, "" );
  154. m_savePresetButton->setCheckable( false );
  155. m_savePresetButton->setCursor( Qt::PointingHandCursor );
  156. m_savePresetButton->setActiveGraphic( embed::getIconPixmap(
  157. "project_save", 21, 21 ) );
  158. m_savePresetButton->setInactiveGraphic( embed::getIconPixmap(
  159. "project_save", 21, 21 ) );
  160. connect( m_savePresetButton, SIGNAL( clicked() ), _ctl,
  161. SLOT( savePreset() ) );
  162. ToolTip::add( m_savePresetButton, tr( "Save preset" ) );
  163. m_savePresetButton->setMinimumWidth( 21 );
  164. m_savePresetButton->setMaximumWidth( 21 );
  165. m_savePresetButton->setMinimumHeight( 21 );
  166. m_savePresetButton->setMaximumHeight( 21 );
  167. int newSize = 0;
  168. if (m_pluginWidget) {
  169. newSize = m_pluginWidget->width() + 20;
  170. }
  171. newSize = std::max(newSize, 250);
  172. QWidget* resize = new QWidget(this);
  173. resize->resize( newSize, 10 );
  174. QWidget* space0 = new QWidget(this);
  175. space0->resize(8, 10);
  176. QWidget* space1 = new QWidget(this);
  177. space1->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
  178. QFont f( "Arial", 10 );
  179. l->addItem( new QSpacerItem( newSize - 20, 30, QSizePolicy::Fixed,
  180. QSizePolicy::Fixed ), 1, 0 );
  181. l->addWidget( resize, 2, 0, 1, 1, Qt::AlignCenter );
  182. if (m_pluginWidget) {
  183. l->addWidget( m_pluginWidget, 3, 0, 1, 1, Qt::AlignCenter );
  184. }
  185. l->setRowStretch( 5, 1 );
  186. l->setColumnStretch( 1, 1 );
  187. QToolBar * tb = new QToolBar( this );
  188. tb->resize( newSize , 32 );
  189. tb->addWidget(space0);
  190. tb->addWidget( m_rolLPresetButton );
  191. tb->addWidget( m_rolRPresetButton );
  192. tb->addWidget( _ctl->m_selPresetButton );
  193. tb->addWidget( m_openPresetButton );
  194. tb->addWidget( m_savePresetButton );
  195. tb->addWidget( m_managePluginButton );
  196. tb->addWidget( btn );
  197. tb->addWidget(space1);
  198. tbLabel = new QLabel( tr( "Effect by: " ), this );
  199. tbLabel->setFont( pointSize<7>( f ) );
  200. tbLabel->setTextFormat(Qt::RichText);
  201. tbLabel->setAlignment( Qt::AlignTop | Qt::AlignLeft );
  202. tb->addWidget( tbLabel );
  203. }
  204. }
  205. void VstEffectControlDialog::paintEvent( QPaintEvent * )
  206. {
  207. if( m_plugin != NULL && tbLabel != NULL )
  208. {
  209. tbLabel->setText( tr( "Effect by: " ) + m_plugin->vendorString() +
  210. tr( "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />" ) +
  211. m_plugin->currentProgramName() );
  212. }
  213. }
  214. void VstEffectControlDialog::showEvent(QShowEvent *_se)
  215. {
  216. EffectControlDialog::showEvent( _se );
  217. // Workaround for a (unexplained) bug where on project-load the effect
  218. // control window has size 0 and would only restore to the proper size upon
  219. // moving the window or interacting with it.
  220. if (parentWidget()) {
  221. parentWidget()->adjustSize();
  222. }
  223. }
  224. VstEffectControlDialog::~VstEffectControlDialog()
  225. {
  226. if (m_pluginWidget && layout()) {
  227. layout()->removeWidget(m_pluginWidget);
  228. m_pluginWidget->setParent(nullptr);
  229. }
  230. }
  231. void VstEffectControlDialog::togglePluginUI( bool checked )
  232. {
  233. if( !m_plugin ) {
  234. return;
  235. }
  236. if ( m_togglePluginButton->isChecked() != checked ) {
  237. m_togglePluginButton->setChecked( checked );
  238. }
  239. if ( checked ) {
  240. m_plugin->showUI();
  241. } else {
  242. m_plugin->hideUI();
  243. }
  244. }