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