TripleOscillator.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. /*
  2. * TripleOscillator.cpp - powerful instrument with three oscillators
  3. *
  4. * Copyright (c) 2004-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 <QDomDocument>
  25. #include <QBitmap>
  26. #include <QPainter>
  27. #include "TripleOscillator.h"
  28. #include "AutomatableButton.h"
  29. #include "debug.h"
  30. #include "Engine.h"
  31. #include "InstrumentTrack.h"
  32. #include "Knob.h"
  33. #include "Mixer.h"
  34. #include "NotePlayHandle.h"
  35. #include "PixmapButton.h"
  36. #include "SampleBuffer.h"
  37. #include "ToolTip.h"
  38. #include "embed.h"
  39. #include "plugin_export.h"
  40. extern "C"
  41. {
  42. Plugin::Descriptor PLUGIN_EXPORT tripleoscillator_plugin_descriptor =
  43. {
  44. STRINGIFY( PLUGIN_NAME ),
  45. "TripleOscillator",
  46. QT_TRANSLATE_NOOP( "PluginBrowser",
  47. "Three powerful oscillators you can modulate "
  48. "in several ways" ),
  49. "Tobias Doerffel <tobydox/at/users.sf.net>",
  50. 0x0110,
  51. Plugin::Instrument,
  52. new PluginPixmapLoader( "logo" ),
  53. NULL,
  54. NULL
  55. } ;
  56. }
  57. OscillatorObject::OscillatorObject( Model * _parent, int _idx ) :
  58. Model( _parent ),
  59. m_volumeModel( DefaultVolume / NUM_OF_OSCILLATORS, MinVolume,
  60. MaxVolume, 1.0f, this, tr( "Osc %1 volume" ).arg( _idx+1 ) ),
  61. m_panModel( DefaultPanning, PanningLeft, PanningRight, 1.0f, this,
  62. tr( "Osc %1 panning" ).arg( _idx+1 ) ),
  63. m_coarseModel( -_idx*KeysPerOctave,
  64. -2 * KeysPerOctave, 2 * KeysPerOctave, 1.0f, this,
  65. tr( "Osc %1 coarse detuning" ).arg( _idx+1 ) ),
  66. m_fineLeftModel( 0.0f, -100.0f, 100.0f, 1.0f, this,
  67. tr( "Osc %1 fine detuning left" ).arg( _idx+1 ) ),
  68. m_fineRightModel( 0.0f, -100.0f, 100.0f, 1.0f, this,
  69. tr( "Osc %1 fine detuning right" ).arg( _idx + 1 ) ),
  70. m_phaseOffsetModel( 0.0f, 0.0f, 360.0f, 1.0f, this,
  71. tr( "Osc %1 phase-offset" ).arg( _idx+1 ) ),
  72. m_stereoPhaseDetuningModel( 0.0f, 0.0f, 360.0f, 1.0f, this,
  73. tr( "Osc %1 stereo phase-detuning" ).arg( _idx+1 ) ),
  74. m_waveShapeModel( Oscillator::SineWave, 0,
  75. Oscillator::NumWaveShapes-1, this,
  76. tr( "Osc %1 wave shape" ).arg( _idx+1 ) ),
  77. m_modulationAlgoModel( Oscillator::SignalMix, 0,
  78. Oscillator::NumModulationAlgos-1, this,
  79. tr( "Modulation type %1" ).arg( _idx+1 ) ),
  80. m_sampleBuffer( new SampleBuffer ),
  81. m_volumeLeft( 0.0f ),
  82. m_volumeRight( 0.0f ),
  83. m_detuningLeft( 0.0f ),
  84. m_detuningRight( 0.0f ),
  85. m_phaseOffsetLeft( 0.0f ),
  86. m_phaseOffsetRight( 0.0f )
  87. {
  88. // Connect knobs with Oscillators' inputs
  89. connect( &m_volumeModel, SIGNAL( dataChanged() ),
  90. this, SLOT( updateVolume() ), Qt::DirectConnection );
  91. connect( &m_panModel, SIGNAL( dataChanged() ),
  92. this, SLOT( updateVolume() ), Qt::DirectConnection );
  93. updateVolume();
  94. connect( &m_coarseModel, SIGNAL( dataChanged() ),
  95. this, SLOT( updateDetuningLeft() ), Qt::DirectConnection );
  96. connect( &m_coarseModel, SIGNAL( dataChanged() ),
  97. this, SLOT( updateDetuningRight() ), Qt::DirectConnection );
  98. connect( &m_fineLeftModel, SIGNAL( dataChanged() ),
  99. this, SLOT( updateDetuningLeft() ), Qt::DirectConnection );
  100. connect( &m_fineRightModel, SIGNAL( dataChanged() ),
  101. this, SLOT( updateDetuningRight() ), Qt::DirectConnection );
  102. updateDetuningLeft();
  103. updateDetuningRight();
  104. connect( &m_phaseOffsetModel, SIGNAL( dataChanged() ),
  105. this, SLOT( updatePhaseOffsetLeft() ), Qt::DirectConnection );
  106. connect( &m_phaseOffsetModel, SIGNAL( dataChanged() ),
  107. this, SLOT( updatePhaseOffsetRight() ), Qt::DirectConnection );
  108. connect( &m_stereoPhaseDetuningModel, SIGNAL( dataChanged() ),
  109. this, SLOT( updatePhaseOffsetLeft() ), Qt::DirectConnection );
  110. updatePhaseOffsetLeft();
  111. updatePhaseOffsetRight();
  112. }
  113. OscillatorObject::~OscillatorObject()
  114. {
  115. sharedObject::unref( m_sampleBuffer );
  116. }
  117. void OscillatorObject::oscUserDefWaveDblClick()
  118. {
  119. QString af = m_sampleBuffer->openAndSetWaveformFile();
  120. if( af != "" )
  121. {
  122. // TODO:
  123. //ToolTip::add( m_usrWaveBtn, m_sampleBuffer->audioFile() );
  124. }
  125. }
  126. void OscillatorObject::updateVolume()
  127. {
  128. if( m_panModel.value() >= 0.0f )
  129. {
  130. const float panningFactorLeft = 1.0f - m_panModel.value()
  131. / (float)PanningRight;
  132. m_volumeLeft = panningFactorLeft * m_volumeModel.value() /
  133. 100.0f;
  134. m_volumeRight = m_volumeModel.value() / 100.0f;
  135. }
  136. else
  137. {
  138. m_volumeLeft = m_volumeModel.value() / 100.0f;
  139. const float panningFactorRight = 1.0f + m_panModel.value()
  140. / (float)PanningRight;
  141. m_volumeRight = panningFactorRight * m_volumeModel.value() /
  142. 100.0f;
  143. }
  144. }
  145. void OscillatorObject::updateDetuningLeft()
  146. {
  147. m_detuningLeft = powf( 2.0f, ( (float)m_coarseModel.value() * 100.0f
  148. + (float)m_fineLeftModel.value() ) / 1200.0f )
  149. / Engine::mixer()->processingSampleRate();
  150. }
  151. void OscillatorObject::updateDetuningRight()
  152. {
  153. m_detuningRight = powf( 2.0f, ( (float)m_coarseModel.value() * 100.0f
  154. + (float)m_fineRightModel.value() ) / 1200.0f )
  155. / Engine::mixer()->processingSampleRate();
  156. }
  157. void OscillatorObject::updatePhaseOffsetLeft()
  158. {
  159. m_phaseOffsetLeft = ( m_phaseOffsetModel.value() +
  160. m_stereoPhaseDetuningModel.value() ) / 360.0f;
  161. }
  162. void OscillatorObject::updatePhaseOffsetRight()
  163. {
  164. m_phaseOffsetRight = m_phaseOffsetModel.value() / 360.0f;
  165. }
  166. TripleOscillator::TripleOscillator( InstrumentTrack * _instrument_track ) :
  167. Instrument( _instrument_track, &tripleoscillator_plugin_descriptor )
  168. {
  169. for( int i = 0; i < NUM_OF_OSCILLATORS; ++i )
  170. {
  171. m_osc[i] = new OscillatorObject( this, i );
  172. }
  173. connect( Engine::mixer(), SIGNAL( sampleRateChanged() ),
  174. this, SLOT( updateAllDetuning() ) );
  175. }
  176. TripleOscillator::~TripleOscillator()
  177. {
  178. }
  179. void TripleOscillator::saveSettings( QDomDocument & _doc, QDomElement & _this )
  180. {
  181. for( int i = 0; i < NUM_OF_OSCILLATORS; ++i )
  182. {
  183. QString is = QString::number( i );
  184. m_osc[i]->m_volumeModel.saveSettings( _doc, _this, "vol" + is );
  185. m_osc[i]->m_panModel.saveSettings( _doc, _this, "pan" + is );
  186. m_osc[i]->m_coarseModel.saveSettings( _doc, _this, "coarse"
  187. + is );
  188. m_osc[i]->m_fineLeftModel.saveSettings( _doc, _this, "finel" +
  189. is );
  190. m_osc[i]->m_fineRightModel.saveSettings( _doc, _this, "finer" +
  191. is );
  192. m_osc[i]->m_phaseOffsetModel.saveSettings( _doc, _this,
  193. "phoffset" + is );
  194. m_osc[i]->m_stereoPhaseDetuningModel.saveSettings( _doc, _this,
  195. "stphdetun" + is );
  196. m_osc[i]->m_waveShapeModel.saveSettings( _doc, _this,
  197. "wavetype" + is );
  198. m_osc[i]->m_modulationAlgoModel.saveSettings( _doc, _this,
  199. "modalgo" + QString::number( i+1 ) );
  200. _this.setAttribute( "userwavefile" + is,
  201. m_osc[i]->m_sampleBuffer->audioFile() );
  202. }
  203. }
  204. void TripleOscillator::loadSettings( const QDomElement & _this )
  205. {
  206. for( int i = 0; i < NUM_OF_OSCILLATORS; ++i )
  207. {
  208. const QString is = QString::number( i );
  209. m_osc[i]->m_volumeModel.loadSettings( _this, "vol" + is );
  210. m_osc[i]->m_panModel.loadSettings( _this, "pan" + is );
  211. m_osc[i]->m_coarseModel.loadSettings( _this, "coarse" + is );
  212. m_osc[i]->m_fineLeftModel.loadSettings( _this, "finel" + is );
  213. m_osc[i]->m_fineRightModel.loadSettings( _this, "finer" + is );
  214. m_osc[i]->m_phaseOffsetModel.loadSettings( _this,
  215. "phoffset" + is );
  216. m_osc[i]->m_stereoPhaseDetuningModel.loadSettings( _this,
  217. "stphdetun" + is );
  218. m_osc[i]->m_waveShapeModel.loadSettings( _this, "wavetype" +
  219. is );
  220. m_osc[i]->m_modulationAlgoModel.loadSettings( _this,
  221. "modalgo" + QString::number( i+1 ) );
  222. m_osc[i]->m_sampleBuffer->setAudioFile( _this.attribute(
  223. "userwavefile" + is ) );
  224. }
  225. }
  226. QString TripleOscillator::nodeName() const
  227. {
  228. return( tripleoscillator_plugin_descriptor.name );
  229. }
  230. void TripleOscillator::playNote( NotePlayHandle * _n,
  231. sampleFrame * _working_buffer )
  232. {
  233. if( _n->totalFramesPlayed() == 0 || _n->m_pluginData == NULL )
  234. {
  235. Oscillator * oscs_l[NUM_OF_OSCILLATORS];
  236. Oscillator * oscs_r[NUM_OF_OSCILLATORS];
  237. for( int i = NUM_OF_OSCILLATORS - 1; i >= 0; --i )
  238. {
  239. // the last oscs needs no sub-oscs...
  240. if( i == NUM_OF_OSCILLATORS - 1 )
  241. {
  242. oscs_l[i] = new Oscillator(
  243. &m_osc[i]->m_waveShapeModel,
  244. &m_osc[i]->m_modulationAlgoModel,
  245. _n->frequency(),
  246. m_osc[i]->m_detuningLeft,
  247. m_osc[i]->m_phaseOffsetLeft,
  248. m_osc[i]->m_volumeLeft );
  249. oscs_r[i] = new Oscillator(
  250. &m_osc[i]->m_waveShapeModel,
  251. &m_osc[i]->m_modulationAlgoModel,
  252. _n->frequency(),
  253. m_osc[i]->m_detuningRight,
  254. m_osc[i]->m_phaseOffsetRight,
  255. m_osc[i]->m_volumeRight );
  256. }
  257. else
  258. {
  259. oscs_l[i] = new Oscillator(
  260. &m_osc[i]->m_waveShapeModel,
  261. &m_osc[i]->m_modulationAlgoModel,
  262. _n->frequency(),
  263. m_osc[i]->m_detuningLeft,
  264. m_osc[i]->m_phaseOffsetLeft,
  265. m_osc[i]->m_volumeLeft,
  266. oscs_l[i + 1] );
  267. oscs_r[i] = new Oscillator(
  268. &m_osc[i]->m_waveShapeModel,
  269. &m_osc[i]->m_modulationAlgoModel,
  270. _n->frequency(),
  271. m_osc[i]->m_detuningRight,
  272. m_osc[i]->m_phaseOffsetRight,
  273. m_osc[i]->m_volumeRight,
  274. oscs_r[i + 1] );
  275. }
  276. oscs_l[i]->setUserWave( m_osc[i]->m_sampleBuffer );
  277. oscs_r[i]->setUserWave( m_osc[i]->m_sampleBuffer );
  278. }
  279. _n->m_pluginData = new oscPtr;
  280. static_cast<oscPtr *>( _n->m_pluginData )->oscLeft = oscs_l[0];
  281. static_cast< oscPtr *>( _n->m_pluginData )->oscRight =
  282. oscs_r[0];
  283. }
  284. Oscillator * osc_l = static_cast<oscPtr *>( _n->m_pluginData )->oscLeft;
  285. Oscillator * osc_r = static_cast<oscPtr *>( _n->m_pluginData )->oscRight;
  286. const fpp_t frames = _n->framesLeftForCurrentPeriod();
  287. const f_cnt_t offset = _n->noteOffset();
  288. osc_l->update( _working_buffer + offset, frames, 0 );
  289. osc_r->update( _working_buffer + offset, frames, 1 );
  290. applyFadeIn(_working_buffer, _n);
  291. applyRelease( _working_buffer, _n );
  292. instrumentTrack()->processAudioBuffer( _working_buffer, frames + offset, _n );
  293. }
  294. void TripleOscillator::deleteNotePluginData( NotePlayHandle * _n )
  295. {
  296. delete static_cast<Oscillator *>( static_cast<oscPtr *>(
  297. _n->m_pluginData )->oscLeft );
  298. delete static_cast<Oscillator *>( static_cast<oscPtr *>(
  299. _n->m_pluginData )->oscRight );
  300. delete static_cast<oscPtr *>( _n->m_pluginData );
  301. }
  302. PluginView * TripleOscillator::instantiateView( QWidget * _parent )
  303. {
  304. return new TripleOscillatorView( this, _parent );
  305. }
  306. void TripleOscillator::updateAllDetuning()
  307. {
  308. for( int i = 0; i < NUM_OF_OSCILLATORS; ++i )
  309. {
  310. m_osc[i]->updateDetuningLeft();
  311. m_osc[i]->updateDetuningRight();
  312. }
  313. }
  314. class TripleOscKnob : public Knob
  315. {
  316. public:
  317. TripleOscKnob( QWidget * _parent ) :
  318. Knob( knobStyled, _parent )
  319. {
  320. setFixedSize( 28, 35 );
  321. }
  322. };
  323. // 82, 109
  324. TripleOscillatorView::TripleOscillatorView( Instrument * _instrument,
  325. QWidget * _parent ) :
  326. InstrumentViewFixedSize( _instrument, _parent )
  327. {
  328. setAutoFillBackground( true );
  329. QPalette pal;
  330. pal.setBrush( backgroundRole(),
  331. PLUGIN_NAME::getIconPixmap( "artwork" ) );
  332. setPalette( pal );
  333. const int mod_x = 66;
  334. const int mod1_y = 58;
  335. const int mod2_y = 75;
  336. const int osc_y = 109;
  337. const int osc_h = 52;
  338. // TODO: clean rewrite using layouts and all that...
  339. PixmapButton * pm_osc1_btn = new PixmapButton( this, NULL );
  340. pm_osc1_btn->move( mod_x, mod1_y );
  341. pm_osc1_btn->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
  342. "pm_active" ) );
  343. pm_osc1_btn->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
  344. "pm_inactive" ) );
  345. ToolTip::add( pm_osc1_btn, tr( "Modulate phase of oscillator 1 by oscillator 2" ) );
  346. PixmapButton * am_osc1_btn = new PixmapButton( this, NULL );
  347. am_osc1_btn->move( mod_x + 35, mod1_y );
  348. am_osc1_btn->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
  349. "am_active" ) );
  350. am_osc1_btn->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
  351. "am_inactive" ) );
  352. ToolTip::add( am_osc1_btn, tr( "Modulate amplitude of oscillator 1 by oscillator 2" ) );
  353. PixmapButton * mix_osc1_btn = new PixmapButton( this, NULL );
  354. mix_osc1_btn->move( mod_x + 70, mod1_y );
  355. mix_osc1_btn->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
  356. "mix_active" ) );
  357. mix_osc1_btn->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
  358. "mix_inactive" ) );
  359. ToolTip::add( mix_osc1_btn, tr( "Mix output of oscillators 1 & 2" ) );
  360. PixmapButton * sync_osc1_btn = new PixmapButton( this, NULL );
  361. sync_osc1_btn->move( mod_x + 105, mod1_y );
  362. sync_osc1_btn->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
  363. "sync_active" ) );
  364. sync_osc1_btn->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
  365. "sync_inactive" ) );
  366. ToolTip::add( sync_osc1_btn, tr( "Synchronize oscillator 1 with "
  367. "oscillator 2" ) );
  368. PixmapButton * fm_osc1_btn = new PixmapButton( this, NULL );
  369. fm_osc1_btn->move( mod_x + 140, mod1_y );
  370. fm_osc1_btn->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
  371. "fm_active" ) );
  372. fm_osc1_btn->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
  373. "fm_inactive" ) );
  374. ToolTip::add( fm_osc1_btn, tr( "Modulate frequency of oscillator 1 by oscillator 2" ) );
  375. m_mod1BtnGrp = new automatableButtonGroup( this );
  376. m_mod1BtnGrp->addButton( pm_osc1_btn );
  377. m_mod1BtnGrp->addButton( am_osc1_btn );
  378. m_mod1BtnGrp->addButton( mix_osc1_btn );
  379. m_mod1BtnGrp->addButton( sync_osc1_btn );
  380. m_mod1BtnGrp->addButton( fm_osc1_btn );
  381. PixmapButton * pm_osc2_btn = new PixmapButton( this, NULL );
  382. pm_osc2_btn->move( mod_x, mod2_y );
  383. pm_osc2_btn->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
  384. "pm_active" ) );
  385. pm_osc2_btn->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
  386. "pm_inactive" ) );
  387. ToolTip::add( pm_osc2_btn, tr( "Modulate phase of oscillator 2 by oscillator 3" ) );
  388. PixmapButton * am_osc2_btn = new PixmapButton( this, NULL );
  389. am_osc2_btn->move( mod_x + 35, mod2_y );
  390. am_osc2_btn->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
  391. "am_active" ) );
  392. am_osc2_btn->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
  393. "am_inactive" ) );
  394. ToolTip::add( am_osc2_btn, tr( "Modulate amplitude of oscillator 2 by oscillator 3" ) );
  395. PixmapButton * mix_osc2_btn = new PixmapButton( this, NULL );
  396. mix_osc2_btn->move( mod_x + 70, mod2_y );
  397. mix_osc2_btn->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
  398. "mix_active" ) );
  399. mix_osc2_btn->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
  400. "mix_inactive" ) );
  401. ToolTip::add( mix_osc2_btn, tr("Mix output of oscillators 2 & 3" ) );
  402. PixmapButton * sync_osc2_btn = new PixmapButton( this, NULL );
  403. sync_osc2_btn->move( mod_x + 105, mod2_y );
  404. sync_osc2_btn->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
  405. "sync_active" ) );
  406. sync_osc2_btn->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
  407. "sync_inactive" ) );
  408. ToolTip::add( sync_osc2_btn, tr( "Synchronize oscillator 2 with oscillator 3" ) );
  409. PixmapButton * fm_osc2_btn = new PixmapButton( this, NULL );
  410. fm_osc2_btn->move( mod_x + 140, mod2_y );
  411. fm_osc2_btn->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
  412. "fm_active" ) );
  413. fm_osc2_btn->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
  414. "fm_inactive" ) );
  415. ToolTip::add( fm_osc2_btn, tr( "Modulate frequency of oscillator 2 by oscillator 3" ) );
  416. m_mod2BtnGrp = new automatableButtonGroup( this );
  417. m_mod2BtnGrp->addButton( pm_osc2_btn );
  418. m_mod2BtnGrp->addButton( am_osc2_btn );
  419. m_mod2BtnGrp->addButton( mix_osc2_btn );
  420. m_mod2BtnGrp->addButton( sync_osc2_btn );
  421. m_mod2BtnGrp->addButton( fm_osc2_btn );
  422. for( int i = 0; i < NUM_OF_OSCILLATORS; ++i )
  423. {
  424. int knob_y = osc_y + i * osc_h;
  425. // setup volume-knob
  426. Knob * vk = new Knob( knobStyled, this );
  427. vk->setVolumeKnob( true );
  428. vk->setFixedSize( 28, 35 );
  429. vk->move( 6, knob_y );
  430. vk->setHintText( tr( "Osc %1 volume:" ).arg(
  431. i+1 ), "%" );
  432. // setup panning-knob
  433. Knob * pk = new TripleOscKnob( this );
  434. pk->move( 35, knob_y );
  435. pk->setHintText( tr("Osc %1 panning:").arg( i + 1 ), "" );
  436. // setup coarse-knob
  437. Knob * ck = new TripleOscKnob( this );
  438. ck->move( 82, knob_y );
  439. ck->setHintText( tr( "Osc %1 coarse detuning:" ).arg( i + 1 )
  440. , " " + tr( "semitones" ) );
  441. // setup knob for left fine-detuning
  442. Knob * flk = new TripleOscKnob( this );
  443. flk->move( 111, knob_y );
  444. flk->setHintText( tr( "Osc %1 fine detuning left:" ).
  445. arg( i + 1 ),
  446. " " + tr( "cents" ) );
  447. // setup knob for right fine-detuning
  448. Knob * frk = new TripleOscKnob( this );
  449. frk->move( 140, knob_y );
  450. frk->setHintText( tr( "Osc %1 fine detuning right:" ).
  451. arg( i + 1 ),
  452. " " + tr( "cents" ) );
  453. // setup phase-offset-knob
  454. Knob * pok = new TripleOscKnob( this );
  455. pok->move( 188, knob_y );
  456. pok->setHintText( tr( "Osc %1 phase-offset:" ).
  457. arg( i + 1 ),
  458. " " + tr( "degrees" ) );
  459. // setup stereo-phase-detuning-knob
  460. Knob * spdk = new TripleOscKnob( this );
  461. spdk->move( 217, knob_y );
  462. spdk->setHintText( tr("Osc %1 stereo phase-detuning:" ).
  463. arg( i + 1 ),
  464. " " + tr( "degrees" ) );
  465. int btn_y = 96 + i * osc_h;
  466. PixmapButton * sin_wave_btn = new PixmapButton( this, NULL );
  467. sin_wave_btn->move( 128, btn_y );
  468. sin_wave_btn->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
  469. "sin_shape_active" ) );
  470. sin_wave_btn->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
  471. "sin_shape_inactive" ) );
  472. ToolTip::add( sin_wave_btn,
  473. tr( "Sine wave" ) );
  474. PixmapButton * triangle_wave_btn =
  475. new PixmapButton( this, NULL );
  476. triangle_wave_btn->move( 143, btn_y );
  477. triangle_wave_btn->setActiveGraphic(
  478. PLUGIN_NAME::getIconPixmap( "triangle_shape_active" ) );
  479. triangle_wave_btn->setInactiveGraphic(
  480. PLUGIN_NAME::getIconPixmap( "triangle_shape_inactive" ) );
  481. ToolTip::add( triangle_wave_btn,
  482. tr( "Triangle wave") );
  483. PixmapButton * saw_wave_btn = new PixmapButton( this, NULL );
  484. saw_wave_btn->move( 158, btn_y );
  485. saw_wave_btn->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
  486. "saw_shape_active" ) );
  487. saw_wave_btn->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
  488. "saw_shape_inactive" ) );
  489. ToolTip::add( saw_wave_btn,
  490. tr( "Saw wave" ) );
  491. PixmapButton * sqr_wave_btn = new PixmapButton( this, NULL );
  492. sqr_wave_btn->move( 173, btn_y );
  493. sqr_wave_btn->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
  494. "square_shape_active" ) );
  495. sqr_wave_btn->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
  496. "square_shape_inactive" ) );
  497. ToolTip::add( sqr_wave_btn,
  498. tr( "Square wave" ) );
  499. PixmapButton * moog_saw_wave_btn =
  500. new PixmapButton( this, NULL );
  501. moog_saw_wave_btn->move( 188, btn_y );
  502. moog_saw_wave_btn->setActiveGraphic(
  503. PLUGIN_NAME::getIconPixmap( "moog_saw_shape_active" ) );
  504. moog_saw_wave_btn->setInactiveGraphic(
  505. PLUGIN_NAME::getIconPixmap( "moog_saw_shape_inactive" ) );
  506. ToolTip::add( moog_saw_wave_btn,
  507. tr( "Moog-like saw wave" ) );
  508. PixmapButton * exp_wave_btn = new PixmapButton( this, NULL );
  509. exp_wave_btn->move( 203, btn_y );
  510. exp_wave_btn->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
  511. "exp_shape_active" ) );
  512. exp_wave_btn->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
  513. "exp_shape_inactive" ) );
  514. ToolTip::add( exp_wave_btn,
  515. tr( "Exponential wave" ) );
  516. PixmapButton * white_noise_btn = new PixmapButton( this, NULL );
  517. white_noise_btn->move( 218, btn_y );
  518. white_noise_btn->setActiveGraphic(
  519. PLUGIN_NAME::getIconPixmap( "white_noise_shape_active" ) );
  520. white_noise_btn->setInactiveGraphic(
  521. PLUGIN_NAME::getIconPixmap( "white_noise_shape_inactive" ) );
  522. ToolTip::add( white_noise_btn,
  523. tr( "White noise" ) );
  524. PixmapButton * uwb = new PixmapButton( this, NULL );
  525. uwb->move( 233, btn_y );
  526. uwb->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
  527. "usr_shape_active" ) );
  528. uwb->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
  529. "usr_shape_inactive" ) );
  530. ToolTip::add( uwb, tr( "User-defined wave" ) );
  531. automatableButtonGroup * wsbg =
  532. new automatableButtonGroup( this );
  533. wsbg->addButton( sin_wave_btn );
  534. wsbg->addButton( triangle_wave_btn );
  535. wsbg->addButton( saw_wave_btn );
  536. wsbg->addButton( sqr_wave_btn );
  537. wsbg->addButton( moog_saw_wave_btn );
  538. wsbg->addButton( exp_wave_btn );
  539. wsbg->addButton( white_noise_btn );
  540. wsbg->addButton( uwb );
  541. m_oscKnobs[i] = OscillatorKnobs( vk, pk, ck, flk, frk, pok,
  542. spdk, uwb, wsbg );
  543. }
  544. }
  545. TripleOscillatorView::~TripleOscillatorView()
  546. {
  547. }
  548. void TripleOscillatorView::modelChanged()
  549. {
  550. TripleOscillator * t = castModel<TripleOscillator>();
  551. m_mod1BtnGrp->setModel( &t->m_osc[0]->m_modulationAlgoModel );
  552. m_mod2BtnGrp->setModel( &t->m_osc[1]->m_modulationAlgoModel );
  553. for( int i = 0; i < NUM_OF_OSCILLATORS; ++i )
  554. {
  555. m_oscKnobs[i].m_volKnob->setModel(
  556. &t->m_osc[i]->m_volumeModel );
  557. m_oscKnobs[i].m_panKnob->setModel(
  558. &t->m_osc[i]->m_panModel );
  559. m_oscKnobs[i].m_coarseKnob->setModel(
  560. &t->m_osc[i]->m_coarseModel );
  561. m_oscKnobs[i].m_fineLeftKnob->setModel(
  562. &t->m_osc[i]->m_fineLeftModel );
  563. m_oscKnobs[i].m_fineRightKnob->setModel(
  564. &t->m_osc[i]->m_fineRightModel );
  565. m_oscKnobs[i].m_phaseOffsetKnob->setModel(
  566. &t->m_osc[i]->m_phaseOffsetModel );
  567. m_oscKnobs[i].m_stereoPhaseDetuningKnob->setModel(
  568. &t->m_osc[i]->m_stereoPhaseDetuningModel );
  569. m_oscKnobs[i].m_waveShapeBtnGrp->setModel(
  570. &t->m_osc[i]->m_waveShapeModel );
  571. connect( m_oscKnobs[i].m_userWaveButton,
  572. SIGNAL( doubleClicked() ),
  573. t->m_osc[i], SLOT( oscUserDefWaveDblClick() ) );
  574. }
  575. }
  576. extern "C"
  577. {
  578. // necessary for getting instance out of shared lib
  579. PLUGIN_EXPORT Plugin * lmms_plugin_main( Model* model, void * )
  580. {
  581. return new TripleOscillator( static_cast<InstrumentTrack *>( model ) );
  582. }
  583. }