mallets.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  1. /*
  2. * mallets.cpp - tuned instruments that one would bang upon
  3. *
  4. * Copyright (c) 2006-2008 Danny McRae <khjklujn/at/users.sourceforge.net>
  5. * Copyright (c) 2009-2015 Tobias Doerffel <tobydox/at/users.sourceforge.net>
  6. * Copyright (c) 2016 Oskar Wallgren <oskarwallgren13/at/gmail.com>
  7. *
  8. * This file is part of LMMS - https://lmms.io
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2 of the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public
  21. * License along with this program (see COPYING); if not, write to the
  22. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  23. * Boston, MA 02110-1301 USA.
  24. *
  25. */
  26. #include "mallets.h"
  27. #include <QDir>
  28. #include <QMessageBox>
  29. #include "BandedWG.h"
  30. #include "ModalBar.h"
  31. #include "TubeBell.h"
  32. #include "ConfigManager.h"
  33. #include "Engine.h"
  34. #include "gui_templates.h"
  35. #include "GuiApplication.h"
  36. #include "InstrumentTrack.h"
  37. #include "Mixer.h"
  38. #include "embed.cpp"
  39. extern "C"
  40. {
  41. Plugin::Descriptor PLUGIN_EXPORT malletsstk_plugin_descriptor =
  42. {
  43. STRINGIFY( PLUGIN_NAME ),
  44. "Mallets",
  45. QT_TRANSLATE_NOOP( "pluginBrowser",
  46. "Tuneful things to bang on" ),
  47. "Danny McRae <khjklujn/at/users.sf.net>",
  48. 0x0100,
  49. Plugin::Instrument,
  50. new PluginPixmapLoader( "logo" ),
  51. NULL,
  52. NULL
  53. } ;
  54. }
  55. malletsInstrument::malletsInstrument( InstrumentTrack * _instrument_track ):
  56. Instrument( _instrument_track, &malletsstk_plugin_descriptor ),
  57. m_hardnessModel(64.0f, 0.0f, 128.0f, 0.1f, this, tr( "Hardness" )),
  58. m_positionModel(64.0f, 0.0f, 64.0f, 0.1f, this, tr( "Position" )),
  59. m_vibratoGainModel(0.0f, 0.0f, 128.0f, 0.1f, this, tr( "Vibrato Gain" )),
  60. m_vibratoFreqModel(0.0f, 0.0f, 128.0f, 0.1f, this, tr( "Vibrato Freq" )),
  61. m_stickModel(0.0f, 0.0f, 128.0f, 0.1f, this, tr( "Stick Mix" )),
  62. m_modulatorModel(64.0f, 0.0f, 128.0f, 0.1f, this, tr( "Modulator" )),
  63. m_crossfadeModel(64.0f, 0.0f, 128.0f, 0.1f, this, tr( "Crossfade" )),
  64. m_lfoSpeedModel(64.0f, 0.0f, 128.0f, 0.1f, this, tr( "LFO Speed" )),
  65. m_lfoDepthModel(64.0f, 0.0f, 128.0f, 0.1f, this, tr( "LFO Depth" )),
  66. m_adsrModel(64.0f, 0.0f, 128.0f, 0.1f, this, tr( "ADSR" )),
  67. m_pressureModel(64.0f, 0.1f, 128.0f, 0.1f, this, tr( "Pressure" )),
  68. m_motionModel(64.0f, 0.0f, 128.0f, 0.1f, this, tr( "Motion" )),
  69. // TODO: m_vibratoModel
  70. m_velocityModel(64.0f, 0.1f, 128.0f, 0.1f, this, tr( "Speed" )),
  71. m_strikeModel( true, this, tr( "Bowed" ) ),
  72. m_presetsModel(this),
  73. m_spreadModel(0, 0, 255, 1, this, tr( "Spread" )),
  74. m_versionModel( MALLETS_PRESET_VERSION, 0, MALLETS_PRESET_VERSION, this, "" ),
  75. m_isOldVersionModel( false, this, "" ),
  76. m_filesMissing( !QDir( ConfigManager::inst()->stkDir() ).exists() ||
  77. !QFileInfo( ConfigManager::inst()->stkDir() + "/sinewave.raw" ).exists() )
  78. {
  79. // ModalBar
  80. m_presetsModel.addItem( tr( "Marimba" ) );
  81. m_scalers.append( 4.0 );
  82. m_presetsModel.addItem( tr( "Vibraphone" ) );
  83. m_scalers.append( 4.0 );
  84. m_presetsModel.addItem( tr( "Agogo" ) );
  85. m_scalers.append( 5.0 );
  86. m_presetsModel.addItem( tr( "Wood1" ) );
  87. m_scalers.append( 4.0 );
  88. m_presetsModel.addItem( tr( "Reso" ) );
  89. m_scalers.append( 2.5 );
  90. m_presetsModel.addItem( tr( "Wood2" ) );
  91. m_scalers.append( 5.0 );
  92. m_presetsModel.addItem( tr( "Beats" ) );
  93. m_scalers.append( 20.0 );
  94. m_presetsModel.addItem( tr( "Two Fixed" ) );
  95. m_scalers.append( 5.0 );
  96. m_presetsModel.addItem( tr( "Clump" ) );
  97. m_scalers.append( 4.0 );
  98. // TubeBell
  99. m_presetsModel.addItem( tr( "Tubular Bells" ) );
  100. m_scalers.append( 1.8 );
  101. // BandedWG
  102. m_presetsModel.addItem( tr( "Uniform Bar" ) );
  103. m_scalers.append( 25.0 );
  104. m_presetsModel.addItem( tr( "Tuned Bar" ) );
  105. m_scalers.append( 10.0 );
  106. m_presetsModel.addItem( tr( "Glass" ) );
  107. m_scalers.append( 16.0 );
  108. m_presetsModel.addItem( tr( "Tibetan Bowl" ) );
  109. m_scalers.append( 7.0 );
  110. }
  111. malletsInstrument::~malletsInstrument()
  112. {
  113. }
  114. void malletsInstrument::saveSettings( QDomDocument & _doc, QDomElement & _this )
  115. {
  116. // ModalBar
  117. m_hardnessModel.saveSettings( _doc, _this, "hardness" );
  118. m_positionModel.saveSettings( _doc, _this, "position" );
  119. m_vibratoGainModel.saveSettings( _doc, _this, "vib_gain" );
  120. m_vibratoFreqModel.saveSettings( _doc, _this, "vib_freq" );
  121. m_stickModel.saveSettings( _doc, _this, "stick_mix" );
  122. // TubeBell
  123. m_modulatorModel.saveSettings( _doc, _this, "modulator" );
  124. m_crossfadeModel.saveSettings( _doc, _this, "crossfade" );
  125. m_lfoSpeedModel.saveSettings( _doc, _this, "lfo_speed" );
  126. m_lfoDepthModel.saveSettings( _doc, _this, "lfo_depth" );
  127. m_adsrModel.saveSettings( _doc, _this, "adsr" );
  128. // BandedWG
  129. m_pressureModel.saveSettings( _doc, _this, "pressure" );
  130. // m_motionModel.saveSettings( _doc, _this, "motion" );
  131. // m_vibratoModel.saveSettings( _doc, _this, "vibrato" );
  132. m_velocityModel.saveSettings( _doc, _this, "velocity" );
  133. m_strikeModel.saveSettings( _doc, _this, "strike" );
  134. m_presetsModel.saveSettings( _doc, _this, "preset" );
  135. m_spreadModel.saveSettings( _doc, _this, "spread" );
  136. m_versionModel.saveSettings( _doc, _this, "version" );
  137. m_isOldVersionModel.saveSettings( _doc, _this, "oldversion" );
  138. }
  139. void malletsInstrument::loadSettings( const QDomElement & _this )
  140. {
  141. m_versionModel.loadSettings( _this, "version" );
  142. // ModalBar
  143. m_hardnessModel.loadSettings( _this, "hardness" );
  144. m_positionModel.loadSettings( _this, "position" );
  145. m_vibratoGainModel.loadSettings( _this, "vib_gain" );
  146. m_vibratoFreqModel.loadSettings( _this, "vib_freq" );
  147. m_stickModel.loadSettings( _this, "stick_mix" );
  148. // TubeBell
  149. m_modulatorModel.loadSettings( _this, "modulator" );
  150. m_crossfadeModel.loadSettings( _this, "crossfade" );
  151. m_lfoSpeedModel.loadSettings( _this, "lfo_speed" );
  152. m_lfoDepthModel.loadSettings( _this, "lfo_depth" );
  153. m_adsrModel.loadSettings( _this, "adsr" );
  154. // BandedWG
  155. m_pressureModel.loadSettings( _this, "pressure" );
  156. // m_motionModel.loadSettings( _this, "motion" );
  157. // m_vibratoModel.loadSettings( _this, "vibrato" );
  158. m_velocityModel.loadSettings( _this, "velocity" );
  159. m_strikeModel.loadSettings( _this, "strike" );
  160. m_presetsModel.loadSettings( _this, "preset" );
  161. m_spreadModel.loadSettings( _this, "spread" );
  162. m_isOldVersionModel.loadSettings( _this, "oldversion" );
  163. // To maintain backward compatibility
  164. if( !_this.hasAttribute( "version" ) )
  165. {
  166. m_isOldVersionModel.setValue( true );
  167. m_vibratoGainModel.setValue( 0.0f );
  168. if( m_presetsModel.value() == 1 )
  169. {
  170. /* Earlier mallets used the stk internal
  171. default of 0.2. 0.2 * 128.0 = 25.6 */
  172. m_vibratoGainModel.setValue( 25.6f );
  173. }
  174. if( m_presetsModel.value() != 1 )
  175. {
  176. // Frequency actually worked for Vibraphone!
  177. m_vibratoFreqModel.setValue( 0.0f );
  178. }
  179. /* Modalbar preset values, see stk, ModalBar.cpp
  180. void ModalBar :: setPreset( int preset )
  181. Stick Mix * 128.0
  182. m_positionModel values over 64 is formatted to the
  183. new knob by 128 - x */
  184. switch( m_presetsModel.value() )
  185. {
  186. case 0:
  187. m_hardnessModel.setValue( 55.0f );
  188. m_positionModel.setValue( 57.0f );
  189. m_stickModel.setValue( 12.0f );
  190. break;
  191. case 1:
  192. m_hardnessModel.setValue( 50.0f );
  193. m_positionModel.setValue( 55.0f );// 128 - 73!
  194. m_stickModel.setValue( 10.0f );
  195. break;
  196. case 2:
  197. m_hardnessModel.setValue( 78.0f );
  198. m_positionModel.setValue( 46.0f );
  199. m_stickModel.setValue( 18.0f );
  200. break;
  201. case 3:
  202. m_hardnessModel.setValue( 59.0f );
  203. m_positionModel.setValue( 48.0f );
  204. m_stickModel.setValue( 6.0f );
  205. break;
  206. case 4:
  207. m_hardnessModel.setValue( 58.0f );
  208. m_positionModel.setValue( 32.0f );
  209. m_stickModel.setValue( 13.0f );
  210. break;
  211. case 5:
  212. m_hardnessModel.setValue( 40.0f );
  213. m_positionModel.setValue( 57.0f );
  214. m_stickModel.setValue( 14.0f );
  215. break;
  216. case 6:
  217. m_hardnessModel.setValue( 51.0f );
  218. m_positionModel.setValue( 38.0f );
  219. m_stickModel.setValue( 9.0f );
  220. break;
  221. case 7:
  222. m_hardnessModel.setValue( 58.0f );
  223. m_positionModel.setValue( 58.0f );
  224. m_stickModel.setValue( 9.0f );
  225. break;
  226. case 8:
  227. m_hardnessModel.setValue( 50.0f );
  228. m_positionModel.setValue( 55.0f );// 128 - 73!
  229. m_stickModel.setValue( 10.0f );
  230. break;
  231. }
  232. }
  233. }
  234. QString malletsInstrument::nodeName() const
  235. {
  236. return( malletsstk_plugin_descriptor.name );
  237. }
  238. void malletsInstrument::playNote( NotePlayHandle * _n,
  239. sampleFrame * _working_buffer )
  240. {
  241. if( m_filesMissing )
  242. {
  243. return;
  244. }
  245. int p = m_presetsModel.value();
  246. const float freq = _n->frequency();
  247. if ( _n->totalFramesPlayed() == 0 || _n->m_pluginData == NULL )
  248. {
  249. // If newer projects, adjust velocity to within stk's limits
  250. float velocityAdjust =
  251. m_isOldVersionModel.value() ? 100.0 : 200.0;
  252. const float vel = _n->getVolume() / velocityAdjust;
  253. // critical section as STK is not thread-safe
  254. static QMutex m;
  255. m.lock();
  256. if( p < 9 )
  257. {
  258. _n->m_pluginData = new malletsSynth( freq,
  259. vel,
  260. m_stickModel.value(),
  261. m_hardnessModel.value(),
  262. m_positionModel.value(),
  263. m_vibratoGainModel.value(),
  264. m_vibratoFreqModel.value(),
  265. p,
  266. (uint8_t) m_spreadModel.value(),
  267. Engine::mixer()->processingSampleRate() );
  268. }
  269. else if( p == 9 )
  270. {
  271. _n->m_pluginData = new malletsSynth( freq,
  272. vel,
  273. p,
  274. m_lfoDepthModel.value(),
  275. m_modulatorModel.value(),
  276. m_crossfadeModel.value(),
  277. m_lfoSpeedModel.value(),
  278. m_adsrModel.value(),
  279. (uint8_t) m_spreadModel.value(),
  280. Engine::mixer()->processingSampleRate() );
  281. }
  282. else
  283. {
  284. _n->m_pluginData = new malletsSynth( freq,
  285. vel,
  286. m_pressureModel.value(),
  287. m_motionModel.value(),
  288. m_vibratoModel.value(),
  289. p - 10,
  290. m_strikeModel.value() * 128.0,
  291. m_velocityModel.value(),
  292. (uint8_t) m_spreadModel.value(),
  293. Engine::mixer()->processingSampleRate() );
  294. }
  295. m.unlock();
  296. static_cast<malletsSynth *>(_n->m_pluginData)->setPresetIndex(p);
  297. }
  298. const fpp_t frames = _n->framesLeftForCurrentPeriod();
  299. const f_cnt_t offset = _n->noteOffset();
  300. malletsSynth * ps = static_cast<malletsSynth *>( _n->m_pluginData );
  301. ps->setFrequency( freq );
  302. p = ps->presetIndex();
  303. sample_t add_scale = 0.0f;
  304. if( p == 10 && m_isOldVersionModel.value() == true )
  305. {
  306. add_scale = static_cast<sample_t>( m_strikeModel.value() ) * freq * 2.5f;
  307. }
  308. for( fpp_t frame = offset; frame < frames + offset; ++frame )
  309. {
  310. _working_buffer[frame][0] = ps->nextSampleLeft() *
  311. ( m_scalers[p] + add_scale );
  312. _working_buffer[frame][1] = ps->nextSampleRight() *
  313. ( m_scalers[p] + add_scale );
  314. }
  315. instrumentTrack()->processAudioBuffer( _working_buffer, frames + offset, _n );
  316. }
  317. void malletsInstrument::deleteNotePluginData( NotePlayHandle * _n )
  318. {
  319. delete static_cast<malletsSynth *>( _n->m_pluginData );
  320. }
  321. PluginView * malletsInstrument::instantiateView( QWidget * _parent )
  322. {
  323. return( new malletsInstrumentView( this, _parent ) );
  324. }
  325. malletsInstrumentView::malletsInstrumentView( malletsInstrument * _instrument,
  326. QWidget * _parent ) :
  327. InstrumentView( _instrument, _parent )
  328. {
  329. m_modalBarWidget = setupModalBarControls( this );
  330. setWidgetBackground( m_modalBarWidget, "artwork" );
  331. m_modalBarWidget->move( 0,0 );
  332. m_tubeBellWidget = setupTubeBellControls( this );
  333. setWidgetBackground( m_tubeBellWidget, "artwork" );
  334. m_tubeBellWidget->move( 0,0 );
  335. m_bandedWGWidget = setupBandedWGControls( this );
  336. setWidgetBackground( m_bandedWGWidget, "artwork" );
  337. m_bandedWGWidget->move( 0,0 );
  338. changePreset(); // Show widget
  339. m_presetsCombo = new ComboBox( this, tr( "Instrument" ) );
  340. m_presetsCombo->setGeometry( 140, 50, 99, 22 );
  341. m_presetsCombo->setFont( pointSize<8>( m_presetsCombo->font() ) );
  342. connect( &_instrument->m_presetsModel, SIGNAL( dataChanged() ),
  343. this, SLOT( changePreset() ) );
  344. m_spreadKnob = new Knob( knobVintage_32, this );
  345. m_spreadKnob->setLabel( tr( "Spread" ) );
  346. m_spreadKnob->move( 190, 140 );
  347. m_spreadKnob->setHintText( tr( "Spread:" ), "" );
  348. // try to inform user about missing Stk-installation
  349. if( _instrument->m_filesMissing && gui != NULL )
  350. {
  351. QMessageBox::information( 0, tr( "Missing files" ),
  352. tr( "Your Stk-installation seems to be "
  353. "incomplete. Please make sure "
  354. "the full Stk-package is installed!" ),
  355. QMessageBox::Ok );
  356. }
  357. }
  358. malletsInstrumentView::~malletsInstrumentView()
  359. {
  360. }
  361. void malletsInstrumentView::setWidgetBackground( QWidget * _widget, const QString & _pic )
  362. {
  363. _widget->setAutoFillBackground( true );
  364. QPalette pal;
  365. pal.setBrush( _widget->backgroundRole(),
  366. PLUGIN_NAME::getIconPixmap( _pic.toLatin1().constData() ) );
  367. _widget->setPalette( pal );
  368. }
  369. QWidget * malletsInstrumentView::setupModalBarControls( QWidget * _parent )
  370. {
  371. QWidget * widget = new QWidget( _parent );
  372. widget->setFixedSize( 250, 250 );
  373. m_hardnessKnob = new Knob( knobVintage_32, widget );
  374. m_hardnessKnob->setLabel( tr( "Hardness" ) );
  375. m_hardnessKnob->move( 30, 90 );
  376. m_hardnessKnob->setHintText( tr( "Hardness:" ), "" );
  377. m_positionKnob = new Knob( knobVintage_32, widget );
  378. m_positionKnob->setLabel( tr( "Position" ) );
  379. m_positionKnob->move( 110, 90 );
  380. m_positionKnob->setHintText( tr( "Position:" ), "" );
  381. m_vibratoGainKnob = new Knob( knobVintage_32, widget );
  382. m_vibratoGainKnob->setLabel( tr( "Vib Gain" ) );
  383. m_vibratoGainKnob->move( 30, 140 );
  384. m_vibratoGainKnob->setHintText( tr( "Vib Gain:" ), "" );
  385. m_vibratoFreqKnob = new Knob( knobVintage_32, widget );
  386. m_vibratoFreqKnob->setLabel( tr( "Vib Freq" ) );
  387. m_vibratoFreqKnob->move( 110, 140 );
  388. m_vibratoFreqKnob->setHintText( tr( "Vib Freq:" ), "" );
  389. m_stickKnob = new Knob( knobVintage_32, widget );
  390. m_stickKnob->setLabel( tr( "Stick Mix" ) );
  391. m_stickKnob->move( 190, 90 );
  392. m_stickKnob->setHintText( tr( "Stick Mix:" ), "" );
  393. return( widget );
  394. }
  395. QWidget * malletsInstrumentView::setupTubeBellControls( QWidget * _parent )
  396. {
  397. QWidget * widget = new QWidget( _parent );
  398. widget->setFixedSize( 250, 250 );
  399. m_modulatorKnob = new Knob( knobVintage_32, widget );
  400. m_modulatorKnob->setLabel( tr( "Modulator" ) );
  401. m_modulatorKnob->move( 30, 90 );
  402. m_modulatorKnob->setHintText( tr( "Modulator:" ), "" );
  403. m_crossfadeKnob = new Knob( knobVintage_32, widget );
  404. m_crossfadeKnob->setLabel( tr( "Crossfade" ) );
  405. m_crossfadeKnob->move( 110, 90 );
  406. m_crossfadeKnob->setHintText( tr( "Crossfade:" ), "" );
  407. m_lfoSpeedKnob = new Knob( knobVintage_32, widget );
  408. m_lfoSpeedKnob->setLabel( tr( "LFO Speed" ) );
  409. m_lfoSpeedKnob->move( 30, 140 );
  410. m_lfoSpeedKnob->setHintText( tr( "LFO Speed:" ), "" );
  411. m_lfoDepthKnob = new Knob( knobVintage_32, widget );
  412. m_lfoDepthKnob->setLabel( tr( "LFO Depth" ) );
  413. m_lfoDepthKnob->move( 110, 140 );
  414. m_lfoDepthKnob->setHintText( tr( "LFO Depth:" ), "" );
  415. m_adsrKnob = new Knob( knobVintage_32, widget );
  416. m_adsrKnob->setLabel( tr( "ADSR" ) );
  417. m_adsrKnob->move( 190, 90 );
  418. m_adsrKnob->setHintText( tr( "ADSR:" ), "" );
  419. return( widget );
  420. }
  421. QWidget * malletsInstrumentView::setupBandedWGControls( QWidget * _parent )
  422. {
  423. // BandedWG
  424. QWidget * widget = new QWidget( _parent );
  425. widget->setFixedSize( 250, 250 );
  426. /* m_strikeLED = new LedCheckBox( tr( "Bowed" ), widget );
  427. m_strikeLED->move( 138, 25 );*/
  428. m_pressureKnob = new Knob( knobVintage_32, widget );
  429. m_pressureKnob->setLabel( tr( "Pressure" ) );
  430. m_pressureKnob->move( 30, 90 );
  431. m_pressureKnob->setHintText( tr( "Pressure:" ), "" );
  432. /* m_motionKnob = new Knob( knobVintage_32, widget );
  433. m_motionKnob->setLabel( tr( "Motion" ) );
  434. m_motionKnob->move( 110, 90 );
  435. m_motionKnob->setHintText( tr( "Motion:" ), "" );*/
  436. m_velocityKnob = new Knob( knobVintage_32, widget );
  437. m_velocityKnob->setLabel( tr( "Speed" ) );
  438. m_velocityKnob->move( 30, 140 );
  439. m_velocityKnob->setHintText( tr( "Speed:" ), "" );
  440. /* m_vibratoKnob = new Knob( knobVintage_32, widget, tr( "Vibrato" ) );
  441. m_vibratoKnob->setLabel( tr( "Vibrato" ) );
  442. m_vibratoKnob->move( 110, 140 );
  443. m_vibratoKnob->setHintText( tr( "Vibrato:" ), "" );*/
  444. return( widget );
  445. }
  446. void malletsInstrumentView::modelChanged()
  447. {
  448. malletsInstrument * inst = castModel<malletsInstrument>();
  449. m_hardnessKnob->setModel( &inst->m_hardnessModel );
  450. m_positionKnob->setModel( &inst->m_positionModel );
  451. m_vibratoGainKnob->setModel( &inst->m_vibratoGainModel );
  452. m_vibratoFreqKnob->setModel( &inst->m_vibratoFreqModel );
  453. m_stickKnob->setModel( &inst->m_stickModel );
  454. m_modulatorKnob->setModel( &inst->m_modulatorModel );
  455. m_crossfadeKnob->setModel( &inst->m_crossfadeModel );
  456. m_lfoSpeedKnob->setModel( &inst->m_lfoSpeedModel );
  457. m_lfoDepthKnob->setModel( &inst->m_lfoDepthModel );
  458. m_adsrKnob->setModel( &inst->m_adsrModel );
  459. m_pressureKnob->setModel( &inst->m_pressureModel );
  460. // m_motionKnob->setModel( &inst->m_motionModel );
  461. // m_vibratoKnob->setModel( &inst->m_vibratoModel );
  462. m_velocityKnob->setModel( &inst->m_velocityModel );
  463. // m_strikeLED->setModel( &inst->m_strikeModel );
  464. m_presetsCombo->setModel( &inst->m_presetsModel );
  465. m_spreadKnob->setModel( &inst->m_spreadModel );
  466. }
  467. void malletsInstrumentView::changePreset()
  468. {
  469. malletsInstrument * inst = castModel<malletsInstrument>();
  470. int _preset = inst->m_presetsModel.value();
  471. if( _preset < 9 )
  472. {
  473. m_tubeBellWidget->hide();
  474. m_bandedWGWidget->hide();
  475. m_modalBarWidget->show();
  476. }
  477. else if( _preset == 9 )
  478. {
  479. m_modalBarWidget->hide();
  480. m_bandedWGWidget->hide();
  481. m_tubeBellWidget->show();
  482. }
  483. else
  484. {
  485. m_modalBarWidget->hide();
  486. m_tubeBellWidget->hide();
  487. m_bandedWGWidget->show();
  488. }
  489. }
  490. // ModalBar
  491. malletsSynth::malletsSynth( const StkFloat _pitch,
  492. const StkFloat _velocity,
  493. const StkFloat _control1,
  494. const StkFloat _control2,
  495. const StkFloat _control4,
  496. const StkFloat _control8,
  497. const StkFloat _control11,
  498. const int _control16,
  499. const uint8_t _delay,
  500. const sample_rate_t _sample_rate ) :
  501. m_presetIndex(0)
  502. {
  503. try
  504. {
  505. Stk::setSampleRate( _sample_rate );
  506. Stk::setRawwavePath( QDir( ConfigManager::inst()->stkDir() ).absolutePath()
  507. .toLocal8Bit().constData() );
  508. #ifndef LMMS_DEBUG
  509. Stk::showWarnings( false );
  510. #endif
  511. m_voice = new ModalBar();
  512. m_voice->controlChange( 16, _control16 );
  513. m_voice->controlChange( 1, _control1 );
  514. m_voice->controlChange( 2, _control2 );
  515. m_voice->controlChange( 4, _control4 );
  516. m_voice->controlChange( 8, _control8 );
  517. m_voice->controlChange( 11, _control11 );
  518. m_voice->controlChange( 128, 128.0f );
  519. m_voice->noteOn( _pitch, _velocity );
  520. }
  521. catch( ... )
  522. {
  523. m_voice = NULL;
  524. }
  525. m_delay = new StkFloat[256];
  526. m_delayRead = 0;
  527. m_delayWrite = _delay;
  528. for( int i = 0; i < 256; i++ )
  529. {
  530. m_delay[i] = 0.0;
  531. }
  532. }
  533. // TubeBell
  534. malletsSynth::malletsSynth( const StkFloat _pitch,
  535. const StkFloat _velocity,
  536. const int _preset,
  537. const StkFloat _control1,
  538. const StkFloat _control2,
  539. const StkFloat _control4,
  540. const StkFloat _control11,
  541. const StkFloat _control128,
  542. const uint8_t _delay,
  543. const sample_rate_t _sample_rate ) :
  544. m_presetIndex(0)
  545. {
  546. try
  547. {
  548. Stk::setSampleRate( _sample_rate );
  549. Stk::setRawwavePath( QDir( ConfigManager::inst()->stkDir() ).absolutePath()
  550. .toLocal8Bit().constData() );
  551. #ifndef LMMS_DEBUG
  552. Stk::showWarnings( false );
  553. #endif
  554. m_voice = new TubeBell();
  555. m_voice->controlChange( 1, _control1 );
  556. m_voice->controlChange( 2, _control2 );
  557. m_voice->controlChange( 4, _control4 );
  558. m_voice->controlChange( 11, _control11 );
  559. m_voice->controlChange( 128, _control128 );
  560. m_voice->noteOn( _pitch, _velocity );
  561. }
  562. catch( ... )
  563. {
  564. m_voice = NULL;
  565. }
  566. m_delay = new StkFloat[256];
  567. m_delayRead = 0;
  568. m_delayWrite = _delay;
  569. for( int i = 0; i < 256; i++ )
  570. {
  571. m_delay[i] = 0.0;
  572. }
  573. }
  574. // BandedWG
  575. malletsSynth::malletsSynth( const StkFloat _pitch,
  576. const StkFloat _velocity,
  577. const StkFloat _control2,
  578. const StkFloat _control4,
  579. const StkFloat _control11,
  580. const int _control16,
  581. const StkFloat _control64,
  582. const StkFloat _control128,
  583. const uint8_t _delay,
  584. const sample_rate_t _sample_rate ) :
  585. m_presetIndex(0)
  586. {
  587. try
  588. {
  589. Stk::setSampleRate( _sample_rate );
  590. Stk::setRawwavePath( QDir( ConfigManager::inst()->stkDir() ).absolutePath()
  591. .toLocal8Bit().constData() );
  592. #ifndef LMMS_DEBUG
  593. Stk::showWarnings( false );
  594. #endif
  595. m_voice = new BandedWG();
  596. m_voice->controlChange( 1, 128.0 );
  597. m_voice->controlChange( 2, _control2 );
  598. m_voice->controlChange( 4, _control4 );
  599. m_voice->controlChange( 11, _control11 );
  600. m_voice->controlChange( 16, _control16 );
  601. m_voice->controlChange( 64, _control64 );
  602. m_voice->controlChange( 128, _control128 );
  603. m_voice->noteOn( _pitch, _velocity );
  604. }
  605. catch( ... )
  606. {
  607. m_voice = NULL;
  608. }
  609. m_delay = new StkFloat[256];
  610. m_delayRead = 0;
  611. m_delayWrite = _delay;
  612. for( int i = 0; i < 256; i++ )
  613. {
  614. m_delay[i] = 0.0;
  615. }
  616. }
  617. extern "C"
  618. {
  619. // necessary for getting instance out of shared lib
  620. Plugin * PLUGIN_EXPORT lmms_plugin_main( Model *, void * _data )
  621. {
  622. return new malletsInstrument( static_cast<InstrumentTrack *>( _data ) );
  623. }
  624. }