ZynAddSubFx.cpp 17 KB

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