TripleOscillator.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  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() ) );
  91. connect( &m_panModel, SIGNAL( dataChanged() ),
  92. this, SLOT( updateVolume() ) );
  93. updateVolume();
  94. connect( &m_coarseModel, SIGNAL( dataChanged() ),
  95. this, SLOT( updateDetuningLeft() ) );
  96. connect( &m_coarseModel, SIGNAL( dataChanged() ),
  97. this, SLOT( updateDetuningRight() ) );
  98. connect( &m_fineLeftModel, SIGNAL( dataChanged() ),
  99. this, SLOT( updateDetuningLeft() ) );
  100. connect( &m_fineRightModel, SIGNAL( dataChanged() ),
  101. this, SLOT( updateDetuningRight() ) );
  102. updateDetuningLeft();
  103. updateDetuningRight();
  104. connect( &m_phaseOffsetModel, SIGNAL( dataChanged() ),
  105. this, SLOT( updatePhaseOffsetLeft() ) );
  106. connect( &m_phaseOffsetModel, SIGNAL( dataChanged() ),
  107. this, SLOT( updatePhaseOffsetRight() ) );
  108. connect( &m_stereoPhaseDetuningModel, SIGNAL( dataChanged() ),
  109. this, SLOT( updatePhaseOffsetLeft() ) );
  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. applyRelease( _working_buffer, _n );
  291. instrumentTrack()->processAudioBuffer( _working_buffer, frames + offset, _n );
  292. }
  293. void TripleOscillator::deleteNotePluginData( NotePlayHandle * _n )
  294. {
  295. delete static_cast<Oscillator *>( static_cast<oscPtr *>(
  296. _n->m_pluginData )->oscLeft );
  297. delete static_cast<Oscillator *>( static_cast<oscPtr *>(
  298. _n->m_pluginData )->oscRight );
  299. delete static_cast<oscPtr *>( _n->m_pluginData );
  300. }
  301. PluginView * TripleOscillator::instantiateView( QWidget * _parent )
  302. {
  303. return new TripleOscillatorView( this, _parent );
  304. }
  305. void TripleOscillator::updateAllDetuning()
  306. {
  307. for( int i = 0; i < NUM_OF_OSCILLATORS; ++i )
  308. {
  309. m_osc[i]->updateDetuningLeft();
  310. m_osc[i]->updateDetuningRight();
  311. }
  312. }
  313. class TripleOscKnob : public Knob
  314. {
  315. public:
  316. TripleOscKnob( QWidget * _parent ) :
  317. Knob( knobStyled, _parent )
  318. {
  319. setFixedSize( 28, 35 );
  320. }
  321. };
  322. // 82, 109
  323. TripleOscillatorView::TripleOscillatorView( Instrument * _instrument,
  324. QWidget * _parent ) :
  325. InstrumentViewFixedSize( _instrument, _parent )
  326. {
  327. setAutoFillBackground( true );
  328. QPalette pal;
  329. pal.setBrush( backgroundRole(),
  330. PLUGIN_NAME::getIconPixmap( "artwork" ) );
  331. setPalette( pal );
  332. const int mod_x = 66;
  333. const int mod1_y = 58;
  334. const int mod2_y = 75;
  335. const int osc_y = 109;
  336. const int osc_h = 52;
  337. // TODO: clean rewrite using layouts and all that...
  338. PixmapButton * pm_osc1_btn = new PixmapButton( this, NULL );
  339. pm_osc1_btn->move( mod_x, mod1_y );
  340. pm_osc1_btn->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
  341. "pm_active" ) );
  342. pm_osc1_btn->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
  343. "pm_inactive" ) );
  344. ToolTip::add( pm_osc1_btn, tr( "Modulate phase of oscillator 1 by oscillator 2" ) );
  345. PixmapButton * am_osc1_btn = new PixmapButton( this, NULL );
  346. am_osc1_btn->move( mod_x + 35, mod1_y );
  347. am_osc1_btn->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
  348. "am_active" ) );
  349. am_osc1_btn->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
  350. "am_inactive" ) );
  351. ToolTip::add( am_osc1_btn, tr( "Modulate amplitude of oscillator 1 by oscillator 2" ) );
  352. PixmapButton * mix_osc1_btn = new PixmapButton( this, NULL );
  353. mix_osc1_btn->move( mod_x + 70, mod1_y );
  354. mix_osc1_btn->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
  355. "mix_active" ) );
  356. mix_osc1_btn->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
  357. "mix_inactive" ) );
  358. ToolTip::add( mix_osc1_btn, tr( "Mix output of oscillators 1 & 2" ) );
  359. PixmapButton * sync_osc1_btn = new PixmapButton( this, NULL );
  360. sync_osc1_btn->move( mod_x + 105, mod1_y );
  361. sync_osc1_btn->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
  362. "sync_active" ) );
  363. sync_osc1_btn->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
  364. "sync_inactive" ) );
  365. ToolTip::add( sync_osc1_btn, tr( "Synchronize oscillator 1 with "
  366. "oscillator 2" ) );
  367. PixmapButton * fm_osc1_btn = new PixmapButton( this, NULL );
  368. fm_osc1_btn->move( mod_x + 140, mod1_y );
  369. fm_osc1_btn->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
  370. "fm_active" ) );
  371. fm_osc1_btn->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
  372. "fm_inactive" ) );
  373. ToolTip::add( fm_osc1_btn, tr( "Modulate frequency of oscillator 1 by oscillator 2" ) );
  374. m_mod1BtnGrp = new automatableButtonGroup( this );
  375. m_mod1BtnGrp->addButton( pm_osc1_btn );
  376. m_mod1BtnGrp->addButton( am_osc1_btn );
  377. m_mod1BtnGrp->addButton( mix_osc1_btn );
  378. m_mod1BtnGrp->addButton( sync_osc1_btn );
  379. m_mod1BtnGrp->addButton( fm_osc1_btn );
  380. PixmapButton * pm_osc2_btn = new PixmapButton( this, NULL );
  381. pm_osc2_btn->move( mod_x, mod2_y );
  382. pm_osc2_btn->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
  383. "pm_active" ) );
  384. pm_osc2_btn->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
  385. "pm_inactive" ) );
  386. ToolTip::add( pm_osc2_btn, tr( "Modulate phase of oscillator 2 by oscillator 3" ) );
  387. PixmapButton * am_osc2_btn = new PixmapButton( this, NULL );
  388. am_osc2_btn->move( mod_x + 35, mod2_y );
  389. am_osc2_btn->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
  390. "am_active" ) );
  391. am_osc2_btn->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
  392. "am_inactive" ) );
  393. ToolTip::add( am_osc2_btn, tr( "Modulate amplitude of oscillator 2 by oscillator 3" ) );
  394. PixmapButton * mix_osc2_btn = new PixmapButton( this, NULL );
  395. mix_osc2_btn->move( mod_x + 70, mod2_y );
  396. mix_osc2_btn->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
  397. "mix_active" ) );
  398. mix_osc2_btn->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
  399. "mix_inactive" ) );
  400. ToolTip::add( mix_osc2_btn, tr("Mix output of oscillators 2 & 3" ) );
  401. PixmapButton * sync_osc2_btn = new PixmapButton( this, NULL );
  402. sync_osc2_btn->move( mod_x + 105, mod2_y );
  403. sync_osc2_btn->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
  404. "sync_active" ) );
  405. sync_osc2_btn->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
  406. "sync_inactive" ) );
  407. ToolTip::add( sync_osc2_btn, tr( "Synchronize oscillator 2 with oscillator 3" ) );
  408. PixmapButton * fm_osc2_btn = new PixmapButton( this, NULL );
  409. fm_osc2_btn->move( mod_x + 140, mod2_y );
  410. fm_osc2_btn->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
  411. "fm_active" ) );
  412. fm_osc2_btn->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
  413. "fm_inactive" ) );
  414. ToolTip::add( fm_osc2_btn, tr( "Modulate frequency of oscillator 2 by oscillator 3" ) );
  415. m_mod2BtnGrp = new automatableButtonGroup( this );
  416. m_mod2BtnGrp->addButton( pm_osc2_btn );
  417. m_mod2BtnGrp->addButton( am_osc2_btn );
  418. m_mod2BtnGrp->addButton( mix_osc2_btn );
  419. m_mod2BtnGrp->addButton( sync_osc2_btn );
  420. m_mod2BtnGrp->addButton( fm_osc2_btn );
  421. for( int i = 0; i < NUM_OF_OSCILLATORS; ++i )
  422. {
  423. int knob_y = osc_y + i * osc_h;
  424. // setup volume-knob
  425. Knob * vk = new Knob( knobStyled, this );
  426. vk->setVolumeKnob( true );
  427. vk->setFixedSize( 28, 35 );
  428. vk->move( 6, knob_y );
  429. vk->setHintText( tr( "Osc %1 volume:" ).arg(
  430. i+1 ), "%" );
  431. // setup panning-knob
  432. Knob * pk = new TripleOscKnob( this );
  433. pk->move( 35, knob_y );
  434. pk->setHintText( tr("Osc %1 panning:").arg( i + 1 ), "" );
  435. // setup coarse-knob
  436. Knob * ck = new TripleOscKnob( this );
  437. ck->move( 82, knob_y );
  438. ck->setHintText( tr( "Osc %1 coarse detuning:" ).arg( i + 1 )
  439. , " " + tr( "semitones" ) );
  440. // setup knob for left fine-detuning
  441. Knob * flk = new TripleOscKnob( this );
  442. flk->move( 111, knob_y );
  443. flk->setHintText( tr( "Osc %1 fine detuning left:" ).
  444. arg( i + 1 ),
  445. " " + tr( "cents" ) );
  446. // setup knob for right fine-detuning
  447. Knob * frk = new TripleOscKnob( this );
  448. frk->move( 140, knob_y );
  449. frk->setHintText( tr( "Osc %1 fine detuning right:" ).
  450. arg( i + 1 ),
  451. " " + tr( "cents" ) );
  452. // setup phase-offset-knob
  453. Knob * pok = new TripleOscKnob( this );
  454. pok->move( 188, knob_y );
  455. pok->setHintText( tr( "Osc %1 phase-offset:" ).
  456. arg( i + 1 ),
  457. " " + tr( "degrees" ) );
  458. // setup stereo-phase-detuning-knob
  459. Knob * spdk = new TripleOscKnob( this );
  460. spdk->move( 217, knob_y );
  461. spdk->setHintText( tr("Osc %1 stereo phase-detuning:" ).
  462. arg( i + 1 ),
  463. " " + tr( "degrees" ) );
  464. int btn_y = 96 + i * osc_h;
  465. PixmapButton * sin_wave_btn = new PixmapButton( this, NULL );
  466. sin_wave_btn->move( 128, btn_y );
  467. sin_wave_btn->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
  468. "sin_shape_active" ) );
  469. sin_wave_btn->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
  470. "sin_shape_inactive" ) );
  471. ToolTip::add( sin_wave_btn,
  472. tr( "Sine wave" ) );
  473. PixmapButton * triangle_wave_btn =
  474. new PixmapButton( this, NULL );
  475. triangle_wave_btn->move( 143, btn_y );
  476. triangle_wave_btn->setActiveGraphic(
  477. PLUGIN_NAME::getIconPixmap( "triangle_shape_active" ) );
  478. triangle_wave_btn->setInactiveGraphic(
  479. PLUGIN_NAME::getIconPixmap( "triangle_shape_inactive" ) );
  480. ToolTip::add( triangle_wave_btn,
  481. tr( "Triangle wave") );
  482. PixmapButton * saw_wave_btn = new PixmapButton( this, NULL );
  483. saw_wave_btn->move( 158, btn_y );
  484. saw_wave_btn->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
  485. "saw_shape_active" ) );
  486. saw_wave_btn->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
  487. "saw_shape_inactive" ) );
  488. ToolTip::add( saw_wave_btn,
  489. tr( "Saw wave" ) );
  490. PixmapButton * sqr_wave_btn = new PixmapButton( this, NULL );
  491. sqr_wave_btn->move( 173, btn_y );
  492. sqr_wave_btn->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
  493. "square_shape_active" ) );
  494. sqr_wave_btn->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
  495. "square_shape_inactive" ) );
  496. ToolTip::add( sqr_wave_btn,
  497. tr( "Square wave" ) );
  498. PixmapButton * moog_saw_wave_btn =
  499. new PixmapButton( this, NULL );
  500. moog_saw_wave_btn->move( 188, btn_y );
  501. moog_saw_wave_btn->setActiveGraphic(
  502. PLUGIN_NAME::getIconPixmap( "moog_saw_shape_active" ) );
  503. moog_saw_wave_btn->setInactiveGraphic(
  504. PLUGIN_NAME::getIconPixmap( "moog_saw_shape_inactive" ) );
  505. ToolTip::add( moog_saw_wave_btn,
  506. tr( "Moog-like saw wave" ) );
  507. PixmapButton * exp_wave_btn = new PixmapButton( this, NULL );
  508. exp_wave_btn->move( 203, btn_y );
  509. exp_wave_btn->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
  510. "exp_shape_active" ) );
  511. exp_wave_btn->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
  512. "exp_shape_inactive" ) );
  513. ToolTip::add( exp_wave_btn,
  514. tr( "Exponential wave" ) );
  515. PixmapButton * white_noise_btn = new PixmapButton( this, NULL );
  516. white_noise_btn->move( 218, btn_y );
  517. white_noise_btn->setActiveGraphic(
  518. PLUGIN_NAME::getIconPixmap( "white_noise_shape_active" ) );
  519. white_noise_btn->setInactiveGraphic(
  520. PLUGIN_NAME::getIconPixmap( "white_noise_shape_inactive" ) );
  521. ToolTip::add( white_noise_btn,
  522. tr( "White noise" ) );
  523. PixmapButton * uwb = new PixmapButton( this, NULL );
  524. uwb->move( 233, btn_y );
  525. uwb->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
  526. "usr_shape_active" ) );
  527. uwb->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
  528. "usr_shape_inactive" ) );
  529. ToolTip::add( uwb, tr( "User-defined wave" ) );
  530. automatableButtonGroup * wsbg =
  531. new automatableButtonGroup( this );
  532. wsbg->addButton( sin_wave_btn );
  533. wsbg->addButton( triangle_wave_btn );
  534. wsbg->addButton( saw_wave_btn );
  535. wsbg->addButton( sqr_wave_btn );
  536. wsbg->addButton( moog_saw_wave_btn );
  537. wsbg->addButton( exp_wave_btn );
  538. wsbg->addButton( white_noise_btn );
  539. wsbg->addButton( uwb );
  540. m_oscKnobs[i] = OscillatorKnobs( vk, pk, ck, flk, frk, pok,
  541. spdk, uwb, wsbg );
  542. }
  543. }
  544. TripleOscillatorView::~TripleOscillatorView()
  545. {
  546. }
  547. void TripleOscillatorView::modelChanged()
  548. {
  549. TripleOscillator * t = castModel<TripleOscillator>();
  550. m_mod1BtnGrp->setModel( &t->m_osc[0]->m_modulationAlgoModel );
  551. m_mod2BtnGrp->setModel( &t->m_osc[1]->m_modulationAlgoModel );
  552. for( int i = 0; i < NUM_OF_OSCILLATORS; ++i )
  553. {
  554. m_oscKnobs[i].m_volKnob->setModel(
  555. &t->m_osc[i]->m_volumeModel );
  556. m_oscKnobs[i].m_panKnob->setModel(
  557. &t->m_osc[i]->m_panModel );
  558. m_oscKnobs[i].m_coarseKnob->setModel(
  559. &t->m_osc[i]->m_coarseModel );
  560. m_oscKnobs[i].m_fineLeftKnob->setModel(
  561. &t->m_osc[i]->m_fineLeftModel );
  562. m_oscKnobs[i].m_fineRightKnob->setModel(
  563. &t->m_osc[i]->m_fineRightModel );
  564. m_oscKnobs[i].m_phaseOffsetKnob->setModel(
  565. &t->m_osc[i]->m_phaseOffsetModel );
  566. m_oscKnobs[i].m_stereoPhaseDetuningKnob->setModel(
  567. &t->m_osc[i]->m_stereoPhaseDetuningModel );
  568. m_oscKnobs[i].m_waveShapeBtnGrp->setModel(
  569. &t->m_osc[i]->m_waveShapeModel );
  570. connect( m_oscKnobs[i].m_userWaveButton,
  571. SIGNAL( doubleClicked() ),
  572. t->m_osc[i], SLOT( oscUserDefWaveDblClick() ) );
  573. }
  574. }
  575. extern "C"
  576. {
  577. // necessary for getting instance out of shared lib
  578. PLUGIN_EXPORT Plugin * lmms_plugin_main( Model* model, void * )
  579. {
  580. return new TripleOscillator( static_cast<InstrumentTrack *>( model ) );
  581. }
  582. }