ZynAddSubFx.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. /*
  2. * ZynAddSubFx.cpp - ZynAddSubxFX-embedding plugin
  3. *
  4. * Copyright (c) 2008-2014 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 "lmmsconfig.h"
  25. #include <QDir>
  26. #include <QDomDocument>
  27. #include <QTemporaryFile>
  28. #include <QtGlobal>
  29. #include <QDropEvent>
  30. #include <QGridLayout>
  31. #include <QPushButton>
  32. #include "ZynAddSubFx.h"
  33. #include "ConfigManager.h"
  34. #include "Engine.h"
  35. #include "Knob.h"
  36. #include "LedCheckbox.h"
  37. #include "DataFile.h"
  38. #include "InstrumentPlayHandle.h"
  39. #include "InstrumentTrack.h"
  40. #include "gui_templates.h"
  41. #include "Song.h"
  42. #include "StringPairDrag.h"
  43. #include "RemoteZynAddSubFx.h"
  44. #include "LocalZynAddSubFx.h"
  45. #include "Mixer.h"
  46. #include "ControllerConnection.h"
  47. #include "embed.h"
  48. #include "plugin_export.h"
  49. extern "C"
  50. {
  51. Plugin::Descriptor PLUGIN_EXPORT zynaddsubfx_plugin_descriptor =
  52. {
  53. STRINGIFY( PLUGIN_NAME ),
  54. "ZynAddSubFX",
  55. QT_TRANSLATE_NOOP( "pluginBrowser",
  56. "Embedded ZynAddSubFX" ),
  57. "Tobias Doerffel <tobydox/at/users.sf.net>",
  58. 0x0100,
  59. Plugin::Instrument,
  60. new PluginPixmapLoader( "logo" ),
  61. "xiz",
  62. NULL,
  63. } ;
  64. }
  65. ZynAddSubFxRemotePlugin::ZynAddSubFxRemotePlugin() :
  66. RemotePlugin()
  67. {
  68. init( "RemoteZynAddSubFx", false );
  69. }
  70. ZynAddSubFxRemotePlugin::~ZynAddSubFxRemotePlugin()
  71. {
  72. }
  73. bool ZynAddSubFxRemotePlugin::processMessage( const message & _m )
  74. {
  75. switch( _m.id )
  76. {
  77. case IdHideUI:
  78. emit clickedCloseButton();
  79. return true;
  80. default:
  81. break;
  82. }
  83. return RemotePlugin::processMessage( _m );
  84. }
  85. ZynAddSubFxInstrument::ZynAddSubFxInstrument(
  86. InstrumentTrack * _instrumentTrack ) :
  87. Instrument( _instrumentTrack, &zynaddsubfx_plugin_descriptor ),
  88. m_hasGUI( false ),
  89. m_plugin( NULL ),
  90. m_remotePlugin( NULL ),
  91. m_portamentoModel( 0, 0, 127, 1, this, tr( "Portamento" ) ),
  92. m_filterFreqModel( 64, 0, 127, 1, this, tr( "Filter frequency" ) ),
  93. m_filterQModel( 64, 0, 127, 1, this, tr( "Filter resonance" ) ),
  94. m_bandwidthModel( 64, 0, 127, 1, this, tr( "Bandwidth" ) ),
  95. m_fmGainModel( 127, 0, 127, 1, this, tr( "FM gain" ) ),
  96. m_resCenterFreqModel( 64, 0, 127, 1, this, tr( "Resonance center frequency" ) ),
  97. m_resBandwidthModel( 64, 0, 127, 1, this, tr( "Resonance bandwidth" ) ),
  98. m_forwardMidiCcModel( true, this, tr( "Forward MIDI control change events" ) )
  99. {
  100. initPlugin();
  101. connect( &m_portamentoModel, SIGNAL( dataChanged() ),
  102. this, SLOT( updatePortamento() ), Qt::DirectConnection );
  103. connect( &m_filterFreqModel, SIGNAL( dataChanged() ),
  104. this, SLOT( updateFilterFreq() ), Qt::DirectConnection );
  105. connect( &m_filterQModel, SIGNAL( dataChanged() ),
  106. this, SLOT( updateFilterQ() ), Qt::DirectConnection );
  107. connect( &m_bandwidthModel, SIGNAL( dataChanged() ),
  108. this, SLOT( updateBandwidth() ), Qt::DirectConnection );
  109. connect( &m_fmGainModel, SIGNAL( dataChanged() ),
  110. this, SLOT( updateFmGain() ), Qt::DirectConnection );
  111. connect( &m_resCenterFreqModel, SIGNAL( dataChanged() ),
  112. this, SLOT( updateResCenterFreq() ), Qt::DirectConnection );
  113. connect( &m_resBandwidthModel, SIGNAL( dataChanged() ),
  114. this, SLOT( updateResBandwidth() ), Qt::DirectConnection );
  115. // now we need a play-handle which cares for calling play()
  116. InstrumentPlayHandle * iph = new InstrumentPlayHandle( this, _instrumentTrack );
  117. Engine::mixer()->addPlayHandle( iph );
  118. connect( Engine::mixer(), SIGNAL( sampleRateChanged() ),
  119. this, SLOT( reloadPlugin() ) );
  120. connect( instrumentTrack()->pitchRangeModel(), SIGNAL( dataChanged() ),
  121. this, SLOT( updatePitchRange() ), Qt::DirectConnection );
  122. }
  123. ZynAddSubFxInstrument::~ZynAddSubFxInstrument()
  124. {
  125. Engine::mixer()->removePlayHandlesOfTypes( instrumentTrack(),
  126. PlayHandle::TypeNotePlayHandle
  127. | PlayHandle::TypeInstrumentPlayHandle );
  128. m_pluginMutex.lock();
  129. delete m_plugin;
  130. delete m_remotePlugin;
  131. m_plugin = NULL;
  132. m_remotePlugin = NULL;
  133. m_pluginMutex.unlock();
  134. }
  135. void ZynAddSubFxInstrument::saveSettings( QDomDocument & _doc,
  136. QDomElement & _this )
  137. {
  138. m_portamentoModel.saveSettings( _doc, _this, "portamento" );
  139. m_filterFreqModel.saveSettings( _doc, _this, "filterfreq" );
  140. m_filterQModel.saveSettings( _doc, _this, "filterq" );
  141. m_bandwidthModel.saveSettings( _doc, _this, "bandwidth" );
  142. m_fmGainModel.saveSettings( _doc, _this, "fmgain" );
  143. m_resCenterFreqModel.saveSettings( _doc, _this, "rescenterfreq" );
  144. m_resBandwidthModel.saveSettings( _doc, _this, "resbandwidth" );
  145. QString modifiedControllers;
  146. for( QMap<int, bool>::ConstIterator it = m_modifiedControllers.begin();
  147. it != m_modifiedControllers.end(); ++it )
  148. {
  149. if( it.value() )
  150. {
  151. modifiedControllers += QString( "%1," ).arg( it.key() );
  152. }
  153. }
  154. _this.setAttribute( "modifiedcontrollers", modifiedControllers );
  155. m_forwardMidiCcModel.saveSettings( _doc, _this, "forwardmidicc" );
  156. QTemporaryFile tf;
  157. if( tf.open() )
  158. {
  159. const std::string fn = QSTR_TO_STDSTR(
  160. QDir::toNativeSeparators( tf.fileName() ) );
  161. m_pluginMutex.lock();
  162. if( m_remotePlugin )
  163. {
  164. m_remotePlugin->lock();
  165. m_remotePlugin->sendMessage( RemotePlugin::message( IdSaveSettingsToFile ).addString( fn ) );
  166. m_remotePlugin->waitForMessage( IdSaveSettingsToFile );
  167. m_remotePlugin->unlock();
  168. }
  169. else
  170. {
  171. m_plugin->saveXML( fn );
  172. }
  173. m_pluginMutex.unlock();
  174. QByteArray a = tf.readAll();
  175. QDomDocument doc( "mydoc" );
  176. if( doc.setContent( a ) )
  177. {
  178. QDomNode n = _doc.importNode( doc.documentElement(), true );
  179. _this.appendChild( n );
  180. }
  181. }
  182. }
  183. void ZynAddSubFxInstrument::loadSettings( const QDomElement & _this )
  184. {
  185. if( !_this.hasChildNodes() )
  186. {
  187. return;
  188. }
  189. m_portamentoModel.loadSettings( _this, "portamento" );
  190. m_filterFreqModel.loadSettings( _this, "filterfreq" );
  191. m_filterQModel.loadSettings( _this, "filterq" );
  192. m_bandwidthModel.loadSettings( _this, "bandwidth" );
  193. m_fmGainModel.loadSettings( _this, "fmgain" );
  194. m_resCenterFreqModel.loadSettings( _this, "rescenterfreq" );
  195. m_resBandwidthModel.loadSettings( _this, "resbandwidth" );
  196. m_forwardMidiCcModel.loadSettings( _this, "forwardmidicc" );
  197. QDomDocument doc;
  198. QDomElement data = _this.firstChildElement( "ZynAddSubFX-data" );
  199. if( data.isNull() )
  200. {
  201. data = _this.firstChildElement();
  202. }
  203. doc.appendChild( doc.importNode( data, true ) );
  204. QTemporaryFile tf;
  205. if( tf.open() )
  206. {
  207. QByteArray a = doc.toString( 0 ).toUtf8();
  208. tf.write( a );
  209. tf.flush();
  210. const std::string fn = QSTR_TO_STDSTR( QDir::toNativeSeparators( tf.fileName() ) );
  211. m_pluginMutex.lock();
  212. if( m_remotePlugin )
  213. {
  214. m_remotePlugin->lock();
  215. m_remotePlugin->sendMessage( RemotePlugin::message( IdLoadSettingsFromFile ).addString( fn ) );
  216. m_remotePlugin->waitForMessage( IdLoadSettingsFromFile );
  217. m_remotePlugin->unlock();
  218. }
  219. else
  220. {
  221. m_plugin->loadXML( fn );
  222. }
  223. m_pluginMutex.unlock();
  224. m_modifiedControllers.clear();
  225. for( const QString & c : _this.attribute( "modifiedcontrollers" ).split( ',' ) )
  226. {
  227. if( !c.isEmpty() )
  228. {
  229. switch( c.toInt() )
  230. {
  231. case C_portamento: updatePortamento(); break;
  232. case C_filtercutoff: updateFilterFreq(); break;
  233. case C_filterq: updateFilterQ(); break;
  234. case C_bandwidth: updateBandwidth(); break;
  235. case C_fmamp: updateFmGain(); break;
  236. case C_resonance_center: updateResCenterFreq(); break;
  237. case C_resonance_bandwidth: updateResBandwidth(); break;
  238. default:
  239. break;
  240. }
  241. }
  242. }
  243. emit settingsChanged();
  244. }
  245. emit instrumentTrack()->pitchModel()->dataChanged();
  246. }
  247. void ZynAddSubFxInstrument::loadFile( const QString & _file )
  248. {
  249. const std::string fn = QSTR_TO_STDSTR( _file );
  250. if( m_remotePlugin )
  251. {
  252. m_remotePlugin->lock();
  253. m_remotePlugin->sendMessage( RemotePlugin::message( IdLoadPresetFile ).addString( fn ) );
  254. m_remotePlugin->waitForMessage( IdLoadPresetFile );
  255. m_remotePlugin->unlock();
  256. }
  257. else
  258. {
  259. m_pluginMutex.lock();
  260. m_plugin->loadPreset( fn );
  261. m_pluginMutex.unlock();
  262. }
  263. instrumentTrack()->setName( QFileInfo( _file ).baseName().replace( QRegExp( "^[0-9]{4}-" ), QString() ) );
  264. m_modifiedControllers.clear();
  265. emit settingsChanged();
  266. }
  267. QString ZynAddSubFxInstrument::nodeName() const
  268. {
  269. return zynaddsubfx_plugin_descriptor.name;
  270. }
  271. void ZynAddSubFxInstrument::play( sampleFrame * _buf )
  272. {
  273. if (!m_pluginMutex.tryLock(Engine::getSong()->isExporting() ? -1 : 0)) {return;}
  274. if( m_remotePlugin )
  275. {
  276. m_remotePlugin->process( NULL, _buf );
  277. }
  278. else
  279. {
  280. m_plugin->processAudio( _buf );
  281. }
  282. m_pluginMutex.unlock();
  283. instrumentTrack()->processAudioBuffer( _buf, Engine::mixer()->framesPerPeriod(), NULL );
  284. }
  285. bool ZynAddSubFxInstrument::handleMidiEvent( const MidiEvent& event, const MidiTime& time, f_cnt_t offset )
  286. {
  287. // do not forward external MIDI Control Change events if the according
  288. // LED is not checked
  289. if( event.type() == MidiControlChange &&
  290. event.sourcePort() != this &&
  291. m_forwardMidiCcModel.value() == false )
  292. {
  293. return true;
  294. }
  295. MidiEvent localEvent = event;
  296. localEvent.setChannel( 0 );
  297. m_pluginMutex.lock();
  298. if( m_remotePlugin )
  299. {
  300. m_remotePlugin->processMidiEvent( localEvent, 0 );
  301. }
  302. else
  303. {
  304. m_plugin->processMidiEvent( localEvent );
  305. }
  306. m_pluginMutex.unlock();
  307. return true;
  308. }
  309. void ZynAddSubFxInstrument::reloadPlugin()
  310. {
  311. // save state of current plugin instance
  312. DataFile m( DataFile::InstrumentTrackSettings );
  313. saveSettings( m, m.content() );
  314. // init plugin (will delete current one and create a new instance)
  315. initPlugin();
  316. // and load the settings again
  317. loadSettings( m.content() );
  318. }
  319. void ZynAddSubFxInstrument::updatePitchRange()
  320. {
  321. m_pluginMutex.lock();
  322. if( m_remotePlugin )
  323. {
  324. m_remotePlugin->sendMessage( RemotePlugin::message( IdZasfSetPitchWheelBendRange ).
  325. addInt( instrumentTrack()->midiPitchRange() ) );
  326. }
  327. else
  328. {
  329. m_plugin->setPitchWheelBendRange( instrumentTrack()->midiPitchRange() );
  330. }
  331. m_pluginMutex.unlock();
  332. }
  333. #define GEN_CC_SLOT(slotname,midictl,modelname) \
  334. void ZynAddSubFxInstrument::slotname() \
  335. { \
  336. sendControlChange( midictl, modelname.value() ); \
  337. m_modifiedControllers[midictl] = true; \
  338. }
  339. GEN_CC_SLOT(updatePortamento,C_portamento,m_portamentoModel);
  340. GEN_CC_SLOT(updateFilterFreq,C_filtercutoff,m_filterFreqModel);
  341. GEN_CC_SLOT(updateFilterQ,C_filterq,m_filterQModel);
  342. GEN_CC_SLOT(updateBandwidth,C_bandwidth,m_bandwidthModel);
  343. GEN_CC_SLOT(updateFmGain,C_fmamp,m_fmGainModel);
  344. GEN_CC_SLOT(updateResCenterFreq,C_resonance_center,m_resCenterFreqModel);
  345. GEN_CC_SLOT(updateResBandwidth,C_resonance_bandwidth,m_resBandwidthModel);
  346. void ZynAddSubFxInstrument::initPlugin()
  347. {
  348. m_pluginMutex.lock();
  349. delete m_plugin;
  350. delete m_remotePlugin;
  351. m_plugin = NULL;
  352. m_remotePlugin = NULL;
  353. if( m_hasGUI )
  354. {
  355. m_remotePlugin = new ZynAddSubFxRemotePlugin();
  356. m_remotePlugin->lock();
  357. m_remotePlugin->waitForInitDone( false );
  358. m_remotePlugin->sendMessage(
  359. RemotePlugin::message( IdZasfLmmsWorkingDirectory ).
  360. addString(
  361. QSTR_TO_STDSTR(
  362. QString( ConfigManager::inst()->workingDir() ) ) ) );
  363. m_remotePlugin->sendMessage(
  364. RemotePlugin::message( IdZasfPresetDirectory ).
  365. addString(
  366. QSTR_TO_STDSTR(
  367. QDir( ConfigManager::inst()->factoryPresetsDir() +
  368. "/ZynAddSubFX" ).absolutePath() ) ) );
  369. m_remotePlugin->updateSampleRate( Engine::mixer()->processingSampleRate() );
  370. // temporary workaround until the VST synchronization feature gets stripped out of the RemotePluginClient class
  371. // causing not to send buffer size information requests
  372. m_remotePlugin->sendMessage( RemotePlugin::message( IdBufferSizeInformation ).addInt( Engine::mixer()->framesPerPeriod() ) );
  373. m_remotePlugin->showUI();
  374. m_remotePlugin->unlock();
  375. }
  376. else
  377. {
  378. m_plugin = new LocalZynAddSubFx;
  379. m_plugin->setSampleRate( Engine::mixer()->processingSampleRate() );
  380. m_plugin->setBufferSize( Engine::mixer()->framesPerPeriod() );
  381. }
  382. m_pluginMutex.unlock();
  383. }
  384. void ZynAddSubFxInstrument::sendControlChange( MidiControllers midiCtl, float value )
  385. {
  386. handleMidiEvent( MidiEvent( MidiControlChange, instrumentTrack()->midiPort()->realOutputChannel(), midiCtl, (int) value, this ) );
  387. }
  388. PluginView * ZynAddSubFxInstrument::instantiateView( QWidget * _parent )
  389. {
  390. return new ZynAddSubFxView( this, _parent );
  391. }
  392. ZynAddSubFxView::ZynAddSubFxView( Instrument * _instrument, QWidget * _parent ) :
  393. InstrumentViewFixedSize( _instrument, _parent )
  394. {
  395. setAutoFillBackground( true );
  396. QPalette pal;
  397. pal.setBrush( backgroundRole(), PLUGIN_NAME::getIconPixmap(
  398. "artwork" ) );
  399. setPalette( pal );
  400. QGridLayout * l = new QGridLayout( this );
  401. l->setContentsMargins( 20, 80, 10, 10 );
  402. l->setVerticalSpacing( 16 );
  403. l->setHorizontalSpacing( 10 );
  404. m_portamento = new Knob( knobBright_26, this );
  405. m_portamento->setHintText( tr( "Portamento:" ), "" );
  406. m_portamento->setLabel( tr( "PORT" ) );
  407. m_filterFreq = new Knob( knobBright_26, this );
  408. m_filterFreq->setHintText( tr( "Filter frequency:" ), "" );
  409. m_filterFreq->setLabel( tr( "FREQ" ) );
  410. m_filterQ = new Knob( knobBright_26, this );
  411. m_filterQ->setHintText( tr( "Filter resonance:" ), "" );
  412. m_filterQ->setLabel( tr( "RES" ) );
  413. m_bandwidth = new Knob( knobBright_26, this );
  414. m_bandwidth->setHintText( tr( "Bandwidth:" ), "" );
  415. m_bandwidth->setLabel( tr( "BW" ) );
  416. m_fmGain = new Knob( knobBright_26, this );
  417. m_fmGain->setHintText( tr( "FM gain:" ), "" );
  418. m_fmGain->setLabel( tr( "FM GAIN" ) );
  419. m_resCenterFreq = new Knob( knobBright_26, this );
  420. m_resCenterFreq->setHintText( tr( "Resonance center frequency:" ), "" );
  421. m_resCenterFreq->setLabel( tr( "RES CF" ) );
  422. m_resBandwidth = new Knob( knobBright_26, this );
  423. m_resBandwidth->setHintText( tr( "Resonance bandwidth:" ), "" );
  424. m_resBandwidth->setLabel( tr( "RES BW" ) );
  425. m_forwardMidiCC = new LedCheckBox( tr( "Forward MIDI control changes" ), this );
  426. m_toggleUIButton = new QPushButton( tr( "Show GUI" ), this );
  427. m_toggleUIButton->setCheckable( true );
  428. m_toggleUIButton->setChecked( false );
  429. m_toggleUIButton->setIcon( embed::getIconPixmap( "zoom" ) );
  430. m_toggleUIButton->setFont( pointSize<8>( m_toggleUIButton->font() ) );
  431. connect( m_toggleUIButton, SIGNAL( toggled( bool ) ), this,
  432. SLOT( toggleUI() ) );
  433. l->addWidget( m_toggleUIButton, 0, 0, 1, 4 );
  434. l->setRowStretch( 1, 5 );
  435. l->addWidget( m_portamento, 2, 0 );
  436. l->addWidget( m_filterFreq, 2, 1 );
  437. l->addWidget( m_filterQ, 2, 2 );
  438. l->addWidget( m_bandwidth, 2, 3 );
  439. l->addWidget( m_fmGain, 3, 0 );
  440. l->addWidget( m_resCenterFreq, 3, 1 );
  441. l->addWidget( m_resBandwidth, 3, 2 );
  442. l->addWidget( m_forwardMidiCC, 4, 0, 1, 4 );
  443. l->setRowStretch( 5, 10 );
  444. l->setColumnStretch( 4, 10 );
  445. setAcceptDrops( true );
  446. }
  447. ZynAddSubFxView::~ZynAddSubFxView()
  448. {
  449. }
  450. void ZynAddSubFxView::dragEnterEvent( QDragEnterEvent * _dee )
  451. {
  452. if( _dee->mimeData()->hasFormat( StringPairDrag::mimeType() ) )
  453. {
  454. QString txt = _dee->mimeData()->data(
  455. StringPairDrag::mimeType() );
  456. if( txt.section( ':', 0, 0 ) == "pluginpresetfile" )
  457. {
  458. _dee->acceptProposedAction();
  459. }
  460. else
  461. {
  462. _dee->ignore();
  463. }
  464. }
  465. else
  466. {
  467. _dee->ignore();
  468. }
  469. }
  470. void ZynAddSubFxView::dropEvent( QDropEvent * _de )
  471. {
  472. const QString type = StringPairDrag::decodeKey( _de );
  473. const QString value = StringPairDrag::decodeValue( _de );
  474. if( type == "pluginpresetfile" )
  475. {
  476. castModel<ZynAddSubFxInstrument>()->loadFile( value );
  477. _de->accept();
  478. return;
  479. }
  480. _de->ignore();
  481. }
  482. void ZynAddSubFxView::modelChanged()
  483. {
  484. ZynAddSubFxInstrument * m = castModel<ZynAddSubFxInstrument>();
  485. // set models for controller knobs
  486. m_portamento->setModel( &m->m_portamentoModel );
  487. m_filterFreq->setModel( &m->m_filterFreqModel );
  488. m_filterQ->setModel( &m->m_filterQModel );
  489. m_bandwidth->setModel( &m->m_bandwidthModel );
  490. m_fmGain->setModel( &m->m_fmGainModel );
  491. m_resCenterFreq->setModel( &m->m_resCenterFreqModel );
  492. m_resBandwidth->setModel( &m->m_resBandwidthModel );
  493. m_forwardMidiCC->setModel( &m->m_forwardMidiCcModel );
  494. m_toggleUIButton->setChecked( m->m_hasGUI );
  495. }
  496. void ZynAddSubFxView::toggleUI()
  497. {
  498. ZynAddSubFxInstrument * model = castModel<ZynAddSubFxInstrument>();
  499. if( model->m_hasGUI != m_toggleUIButton->isChecked() )
  500. {
  501. model->m_hasGUI = m_toggleUIButton->isChecked();
  502. model->reloadPlugin();
  503. if( model->m_remotePlugin )
  504. {
  505. connect( model->m_remotePlugin, SIGNAL( clickedCloseButton() ),
  506. m_toggleUIButton, SLOT( toggle() ) );
  507. }
  508. }
  509. }
  510. extern "C"
  511. {
  512. // necessary for getting instance out of shared lib
  513. PLUGIN_EXPORT Plugin * lmms_plugin_main(Model * m, void *)
  514. {
  515. return new ZynAddSubFxInstrument(static_cast<InstrumentTrack *>(m));
  516. }
  517. }