FreeBoy.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. /*
  2. * FreeBoy.cpp - GameBoy papu based instrument
  3. *
  4. * Copyright (c) 2008 Attila Herman <attila589/at/gmail.com>
  5. * Csaba Hruska <csaba.hruska/at/gmail.com>
  6. *
  7. * This file is part of LMMS - https://lmms.io
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2 of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public
  20. * License along with this program (see COPYING); if not, write to the
  21. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  22. * Boston, MA 02110-1301 USA.
  23. *
  24. */
  25. #include <cmath>
  26. #include <QPainter>
  27. #include <QDomElement>
  28. #include "FreeBoy.h"
  29. #include "Gb_Apu_Buffer.h"
  30. #include "Multi_Buffer.h"
  31. #include "base64.h"
  32. #include "InstrumentTrack.h"
  33. #include "Knob.h"
  34. #include "Mixer.h"
  35. #include "NotePlayHandle.h"
  36. #include "PixmapButton.h"
  37. #include "ToolTip.h"
  38. #include "Engine.h"
  39. #include "Graph.h"
  40. #include "embed.h"
  41. #include "plugin_export.h"
  42. const blip_time_t FRAME_LENGTH = 70224;
  43. const long CLOCK_RATE = 4194304;
  44. extern "C"
  45. {
  46. Plugin::Descriptor PLUGIN_EXPORT freeboy_plugin_descriptor =
  47. {
  48. STRINGIFY( PLUGIN_NAME ),
  49. "FreeBoy",
  50. QT_TRANSLATE_NOOP( "pluginBrowser", "Emulation of GameBoy (TM) APU" ),
  51. "Attila Herman <attila589/at/gmail.com>"
  52. "Csaba Hruska <csaba.hruska/at/gmail.com>",
  53. 0x0100,
  54. Plugin::Instrument,
  55. new PluginPixmapLoader( "logo" ),
  56. NULL
  57. } ;
  58. }
  59. FreeBoyInstrument::FreeBoyInstrument( InstrumentTrack * _instrument_track ) :
  60. Instrument( _instrument_track, &freeboy_plugin_descriptor ),
  61. m_ch1SweepTimeModel( 4.0f, 0.0f, 7.0f, 1.0f, this, tr( "Sweep time" ) ),
  62. m_ch1SweepDirModel( false, this, tr( "Sweep direction" ) ),
  63. m_ch1SweepRtShiftModel( 4.0f, 0.0f, 7.0f, 1.0f, this,
  64. tr( "Sweep rate shift amount" ) ),
  65. m_ch1WavePatternDutyModel( 2.0f, 0.0f, 3.0f, 1.0f, this,
  66. tr( "Wave pattern duty cycle" ) ),
  67. m_ch1VolumeModel( 15.0f, 0.0f, 15.0f, 1.0f, this,
  68. tr( "Channel 1 volume" ) ),
  69. m_ch1VolSweepDirModel( false, this,
  70. tr( "Volume sweep direction" ) ),
  71. m_ch1SweepStepLengthModel( 0.0f, 0.0f, 7.0f, 1.0f, this,
  72. tr( "Length of each step in sweep" ) ),
  73. m_ch2WavePatternDutyModel( 2.0f, 0.0f, 3.0f, 1.0f, this,
  74. tr( "Wave pattern duty cycle" ) ),
  75. m_ch2VolumeModel( 15.0f, 0.0f, 15.0f, 1.0f, this,
  76. tr( "Channel 2 volume" ) ),
  77. m_ch2VolSweepDirModel( false, this,
  78. tr( "Volume sweep direction" ) ),
  79. m_ch2SweepStepLengthModel( 0.0f, 0.0f, 7.0f, 1.0f, this,
  80. tr( "Length of each step in sweep" ) ),
  81. //m_ch3OnModel( true, this, tr( "Channel 3 Master on/off" ) ),
  82. m_ch3VolumeModel( 3.0f, 0.0f, 3.0f, 1.0f, this,
  83. tr( "Channel 3 volume" ) ),
  84. m_ch4VolumeModel( 15.0f, 0.0f, 15.0f, 1.0f, this,
  85. tr( "Channel 4 volume" ) ),
  86. m_ch4VolSweepDirModel( false, this,
  87. tr( "Volume sweep direction" ) ),
  88. m_ch4SweepStepLengthModel( 0.0f, 0.0f, 7.0f, 1.0f, this,
  89. tr( "Length of each step in sweep" ) ),
  90. m_ch4ShiftRegWidthModel( false, this,
  91. tr( "Shift Register width" ) ),
  92. m_so1VolumeModel( 7.0f, 0.0f, 7.0f, 1.0f, this, tr( "Right output level") ),
  93. m_so2VolumeModel( 7.0f, 0.0f, 7.0f, 1.0f, this, tr( "Left output level" ) ),
  94. m_ch1So1Model( true, this, tr( "Channel 1 to SO2 (Left)" ) ),
  95. m_ch2So1Model( true, this, tr( "Channel 2 to SO2 (Left)" ) ),
  96. m_ch3So1Model( true, this, tr( "Channel 3 to SO2 (Left)" ) ),
  97. m_ch4So1Model( false, this, tr( "Channel 4 to SO2 (Left)" ) ),
  98. m_ch1So2Model( true, this, tr( "Channel 1 to SO1 (Right)" ) ),
  99. m_ch2So2Model( true, this, tr( "Channel 2 to SO1 (Right)" ) ),
  100. m_ch3So2Model( true, this, tr( "Channel 3 to SO1 (Right)" ) ),
  101. m_ch4So2Model( false, this, tr( "Channel 4 to SO1 (Right)" ) ),
  102. m_trebleModel( -20.0f, -100.0f, 200.0f, 1.0f, this, tr( "Treble" ) ),
  103. m_bassModel( 461.0f, -1.0f, 600.0f, 1.0f, this, tr( "Bass" ) ),
  104. m_graphModel( 0, 15, 32, this, false, 1 ),
  105. m_time(0)
  106. {
  107. }
  108. FreeBoyInstrument::~FreeBoyInstrument()
  109. {
  110. }
  111. void FreeBoyInstrument::saveSettings( QDomDocument & _doc,
  112. QDomElement & _this )
  113. {
  114. m_ch1SweepTimeModel.saveSettings( _doc, _this, "st" );
  115. m_ch1SweepDirModel.saveSettings( _doc, _this, "sd" );
  116. m_ch1SweepRtShiftModel.saveSettings( _doc, _this, "srs" );
  117. m_ch1WavePatternDutyModel.saveSettings( _doc, _this, "ch1wpd" );
  118. m_ch1VolumeModel.saveSettings( _doc, _this, "ch1vol" );
  119. m_ch1VolSweepDirModel.saveSettings( _doc, _this, "ch1vsd" );
  120. m_ch1SweepStepLengthModel.saveSettings( _doc, _this, "ch1ssl" );
  121. m_ch2WavePatternDutyModel.saveSettings( _doc, _this, "ch2wpd" );
  122. m_ch2VolumeModel.saveSettings( _doc, _this, "ch2vol" );
  123. m_ch2VolSweepDirModel.saveSettings( _doc, _this, "ch2vsd" );
  124. m_ch2SweepStepLengthModel.saveSettings( _doc, _this, "ch2ssl" );
  125. //m_ch3OnModel.saveSettings( _doc, _this, "ch3on" );
  126. m_ch3VolumeModel.saveSettings( _doc, _this, "ch3vol" );
  127. m_ch4VolumeModel.saveSettings( _doc, _this, "ch4vol" );
  128. m_ch4VolSweepDirModel.saveSettings( _doc, _this, "ch4vsd" );
  129. m_ch4SweepStepLengthModel.saveSettings( _doc, _this, "ch4ssl" );
  130. m_ch4ShiftRegWidthModel.saveSettings( _doc, _this, "srw" );
  131. m_so1VolumeModel.saveSettings( _doc, _this, "so1vol" );
  132. m_so2VolumeModel.saveSettings( _doc, _this, "so2vol" );
  133. m_ch1So1Model.saveSettings( _doc, _this, "ch1so2" );
  134. m_ch2So1Model.saveSettings( _doc, _this, "ch2so2" );
  135. m_ch3So1Model.saveSettings( _doc, _this, "ch3so2" );
  136. m_ch4So1Model.saveSettings( _doc, _this, "ch4so2" );
  137. m_ch1So2Model.saveSettings( _doc, _this, "ch1so1" );
  138. m_ch2So2Model.saveSettings( _doc, _this, "ch2so1" );
  139. m_ch3So2Model.saveSettings( _doc, _this, "ch3so1" );
  140. m_ch4So2Model.saveSettings( _doc, _this, "ch4so1" );
  141. m_trebleModel.saveSettings( _doc, _this, "Treble" );
  142. m_bassModel.saveSettings( _doc, _this, "Bass" );
  143. QString sampleString;
  144. base64::encode( (const char *)m_graphModel.samples(),
  145. m_graphModel.length() * sizeof(float), sampleString );
  146. _this.setAttribute( "sampleShape", sampleString );
  147. }
  148. void FreeBoyInstrument::loadSettings( const QDomElement & _this )
  149. {
  150. m_ch1SweepTimeModel.loadSettings( _this, "st" );
  151. m_ch1SweepDirModel.loadSettings( _this, "sd" );
  152. m_ch1SweepRtShiftModel.loadSettings( _this, "srs" );
  153. m_ch1WavePatternDutyModel.loadSettings( _this, "ch1wpd" );
  154. m_ch1VolumeModel.loadSettings( _this, "ch1vol" );
  155. m_ch1VolSweepDirModel.loadSettings( _this, "ch1vsd" );
  156. m_ch1SweepStepLengthModel.loadSettings( _this, "ch1ssl" );
  157. m_ch2WavePatternDutyModel.loadSettings( _this, "ch2wpd" );
  158. m_ch2VolumeModel.loadSettings( _this, "ch2vol" );
  159. m_ch2VolSweepDirModel.loadSettings( _this, "ch2vsd" );
  160. m_ch2SweepStepLengthModel.loadSettings( _this, "ch2ssl" );
  161. //m_ch3OnModel.loadSettings( _this, "ch3on" );
  162. m_ch3VolumeModel.loadSettings( _this, "ch3vol" );
  163. m_ch4VolumeModel.loadSettings( _this, "ch4vol" );
  164. m_ch4VolSweepDirModel.loadSettings( _this, "ch4vsd" );
  165. m_ch4SweepStepLengthModel.loadSettings( _this, "ch4ssl" );
  166. m_ch4ShiftRegWidthModel.loadSettings( _this, "srw" );
  167. m_so1VolumeModel.loadSettings( _this, "so1vol" );
  168. m_so2VolumeModel.loadSettings( _this, "so2vol" );
  169. m_ch1So1Model.loadSettings( _this, "ch1so2" );
  170. m_ch2So1Model.loadSettings( _this, "ch2so2" );
  171. m_ch3So1Model.loadSettings( _this, "ch3so2" );
  172. m_ch4So1Model.loadSettings( _this, "ch4so2" );
  173. m_ch1So2Model.loadSettings( _this, "ch1so1" );
  174. m_ch2So2Model.loadSettings( _this, "ch2so1" );
  175. m_ch3So2Model.loadSettings( _this, "ch3so1" );
  176. m_ch4So2Model.loadSettings( _this, "ch4so1" );
  177. m_trebleModel.loadSettings( _this, "Treble" );
  178. m_bassModel.loadSettings( _this, "Bass" );
  179. int size = 0;
  180. char * dst = 0;
  181. base64::decode( _this.attribute( "sampleShape"), &dst, &size );
  182. m_graphModel.setSamples( (float*) dst );
  183. }
  184. QString FreeBoyInstrument::nodeName() const
  185. {
  186. return( freeboy_plugin_descriptor.name );
  187. }
  188. /*f_cnt_t FreeBoyInstrument::desiredReleaseFrames() const
  189. {
  190. const float samplerate = Engine::mixer()->processingSampleRate();
  191. int maxrel = 0;
  192. for( int i = 0 ; i < 3 ; ++i )
  193. {
  194. if( maxrel < m_voice[i]->m_releaseModel.value() )
  195. maxrel = m_voice[i]->m_releaseModel.value();
  196. }
  197. return f_cnt_t( float(relTime[maxrel])*samplerate/1000.0 );
  198. }*/
  199. f_cnt_t FreeBoyInstrument::desiredReleaseFrames() const
  200. {
  201. return f_cnt_t( 1000 );
  202. }
  203. void FreeBoyInstrument::playNote( NotePlayHandle * _n,
  204. sampleFrame * _working_buffer )
  205. {
  206. const f_cnt_t tfp = _n->totalFramesPlayed();
  207. const int samplerate = Engine::mixer()->processingSampleRate();
  208. const fpp_t frames = _n->framesLeftForCurrentPeriod();
  209. const f_cnt_t offset = _n->noteOffset();
  210. int data = 0;
  211. int freq = _n->frequency();
  212. if ( tfp == 0 )
  213. {
  214. Gb_Apu_Buffer *papu = new Gb_Apu_Buffer();
  215. papu->set_sample_rate( samplerate, CLOCK_RATE );
  216. // Master sound circuitry power control
  217. papu->write_register( fakeClock(), 0xff26, 0x80 );
  218. data = m_ch1VolumeModel.value();
  219. data = data<<1;
  220. data += m_ch1VolSweepDirModel.value();
  221. data = data<<3;
  222. data += m_ch1SweepStepLengthModel.value();
  223. papu->write_register( fakeClock(), 0xff12, data );
  224. data = m_ch2VolumeModel.value();
  225. data = data<<1;
  226. data += m_ch2VolSweepDirModel.value();
  227. data = data<<3;
  228. data += m_ch2SweepStepLengthModel.value();
  229. papu->write_register( fakeClock(), 0xff17, data );
  230. //channel 4 - noise
  231. data = m_ch4VolumeModel.value();
  232. data = data<<1;
  233. data += m_ch4VolSweepDirModel.value();
  234. data = data<<3;
  235. data += m_ch4SweepStepLengthModel.value();
  236. papu->write_register( fakeClock(), 0xff21, data );
  237. _n->m_pluginData = papu;
  238. }
  239. Gb_Apu_Buffer *papu = static_cast<Gb_Apu_Buffer *>( _n->m_pluginData );
  240. papu->treble_eq( m_trebleModel.value() );
  241. papu->bass_freq( m_bassModel.value() );
  242. //channel 1 - square
  243. data = m_ch1SweepTimeModel.value();
  244. data = data<<1;
  245. data += m_ch1SweepDirModel.value();
  246. data = data << 3;
  247. data += m_ch1SweepRtShiftModel.value();
  248. papu->write_register( fakeClock(), 0xff10, data );
  249. data = m_ch1WavePatternDutyModel.value();
  250. data = data<<6;
  251. papu->write_register( fakeClock(), 0xff11, data );
  252. //channel 2 - square
  253. data = m_ch2WavePatternDutyModel.value();
  254. data = data<<6;
  255. papu->write_register( fakeClock(), 0xff16, data );
  256. //channel 3 - wave
  257. //data = m_ch3OnModel.value()?128:0;
  258. data = 128;
  259. papu->write_register( fakeClock(), 0xff1a, data );
  260. int ch3voldata[4] = { 0, 3, 2, 1 };
  261. data = ch3voldata[(int)m_ch3VolumeModel.value()];
  262. data = data<<5;
  263. papu->write_register( fakeClock(), 0xff1c, data );
  264. //controls
  265. data = m_so1VolumeModel.value();
  266. data = data<<4;
  267. data += m_so2VolumeModel.value();
  268. papu->write_register( fakeClock(), 0xff24, data );
  269. data = m_ch4So2Model.value()?128:0;
  270. data += m_ch3So2Model.value()?64:0;
  271. data += m_ch2So2Model.value()?32:0;
  272. data += m_ch1So2Model.value()?16:0;
  273. data += m_ch4So1Model.value()?8:0;
  274. data += m_ch3So1Model.value()?4:0;
  275. data += m_ch2So1Model.value()?2:0;
  276. data += m_ch1So1Model.value()?1:0;
  277. papu->write_register( fakeClock(), 0xff25, data );
  278. const float * wpm = m_graphModel.samples();
  279. for( char i=0; i<16; i++ )
  280. {
  281. data = (int)floor(wpm[i*2]) << 4;
  282. data += (int)floor(wpm[i*2+1]);
  283. papu->write_register( fakeClock(), 0xff30 + i, data );
  284. }
  285. if( ( freq >= 65 ) && ( freq <=4000 ) )
  286. {
  287. int initflag = (tfp==0)?128:0;
  288. // Hz = 4194304 / ( ( 2048 - ( 11-bit-freq ) ) << 5 )
  289. data = 2048 - ( ( 4194304 / freq )>>5 );
  290. if( tfp==0 )
  291. {
  292. papu->write_register( fakeClock(), 0xff13, data & 0xff );
  293. papu->write_register( fakeClock(), 0xff14, (data>>8) | initflag );
  294. }
  295. papu->write_register( fakeClock(), 0xff18, data & 0xff );
  296. papu->write_register( fakeClock(), 0xff19, (data>>8) | initflag );
  297. papu->write_register( fakeClock(), 0xff1d, data & 0xff );
  298. papu->write_register( fakeClock(), 0xff1e, (data>>8) | initflag );
  299. }
  300. if( tfp == 0 )
  301. {
  302. //PRNG Frequency = (1048576 Hz / (ratio + 1)) / 2 ^ (shiftclockfreq + 1)
  303. char sopt=0;
  304. char ropt=1;
  305. float fopt = 524288.0 / ( ropt * pow( 2.0, sopt + 1.0 ) );
  306. float f;
  307. for ( char s=0; s<16; s++ )
  308. for ( char r=0; r<8; r++ ) {
  309. f = 524288.0 / ( r * pow( 2.0, s + 1.0 ) );
  310. if( fabs( freq-fopt ) > fabs( freq-f ) ) {
  311. fopt = f;
  312. ropt = r;
  313. sopt = s;
  314. }
  315. }
  316. data = sopt;
  317. data = data << 1;
  318. data += m_ch4ShiftRegWidthModel.value();
  319. data = data << 3;
  320. data += ropt;
  321. papu->write_register( fakeClock(), 0xff22, data );
  322. //channel 4 init
  323. papu->write_register( fakeClock(), 0xff23, 128 );
  324. }
  325. int const buf_size = 2048;
  326. int framesleft = frames;
  327. int datalen = 0;
  328. blip_sample_t buf [buf_size*2];
  329. while( framesleft > 0 )
  330. {
  331. int avail = papu->samples_avail();
  332. if( avail <= 0 )
  333. {
  334. m_time = 0;
  335. papu->end_frame(FRAME_LENGTH);
  336. avail = papu->samples_avail();
  337. }
  338. datalen = framesleft>avail?avail:framesleft;
  339. datalen = datalen>buf_size?buf_size:datalen;
  340. long count = papu->read_samples( buf, datalen*2)/2;
  341. for( fpp_t frame = 0; frame < count; ++frame )
  342. {
  343. for( ch_cnt_t ch = 0; ch < DEFAULT_CHANNELS; ++ch )
  344. {
  345. sample_t s = float(buf[frame*2+ch])/32768.0;
  346. _working_buffer[frames-framesleft+frame+offset][ch] = s;
  347. }
  348. }
  349. framesleft -= count;
  350. }
  351. instrumentTrack()->processAudioBuffer( _working_buffer, frames + offset, _n );
  352. }
  353. void FreeBoyInstrument::deleteNotePluginData( NotePlayHandle * _n )
  354. {
  355. delete static_cast<Gb_Apu_Buffer *>( _n->m_pluginData );
  356. }
  357. PluginView * FreeBoyInstrument::instantiateView( QWidget * _parent )
  358. {
  359. return( new FreeBoyInstrumentView( this, _parent ) );
  360. }
  361. class FreeBoyKnob : public Knob
  362. {
  363. public:
  364. FreeBoyKnob( QWidget * _parent ) :
  365. Knob( knobStyled, _parent )
  366. {
  367. setFixedSize( 30, 30 );
  368. setCenterPointX( 15.0 );
  369. setCenterPointY( 15.0 );
  370. setInnerRadius( 8 );
  371. setOuterRadius( 13 );
  372. setTotalAngle( 270.0 );
  373. setLineWidth( 1 );
  374. setOuterColor( QColor( 0xF1, 0xFF, 0x93 ) );
  375. }
  376. };
  377. FreeBoyInstrumentView::FreeBoyInstrumentView( Instrument * _instrument,
  378. QWidget * _parent ) :
  379. InstrumentViewFixedSize( _instrument, _parent )
  380. {
  381. setAutoFillBackground( true );
  382. QPalette pal;
  383. pal.setBrush( backgroundRole(), PLUGIN_NAME::getIconPixmap( "artwork" ) );
  384. setPalette( pal );
  385. m_ch1SweepTimeKnob = new FreeBoyKnob( this );
  386. m_ch1SweepTimeKnob->setHintText( tr( "Sweep time:" ), "" );
  387. m_ch1SweepTimeKnob->move( 5 + 4*32, 106 );
  388. ToolTip::add( m_ch1SweepTimeKnob, tr( "Sweep time" ) );
  389. m_ch1SweepRtShiftKnob = new FreeBoyKnob( this );
  390. m_ch1SweepRtShiftKnob->setHintText( tr( "Sweep rate shift amount:" )
  391. , "" );
  392. m_ch1SweepRtShiftKnob->move( 5 + 3*32, 106 );
  393. ToolTip::add( m_ch1SweepRtShiftKnob, tr( "Sweep rate shift amount" ) );
  394. m_ch1WavePatternDutyKnob = new FreeBoyKnob( this );
  395. m_ch1WavePatternDutyKnob->setHintText( tr( "Wave pattern duty cycle:" )
  396. , "" );
  397. m_ch1WavePatternDutyKnob->move( 5 + 2*32, 106 );
  398. ToolTip::add( m_ch1WavePatternDutyKnob, tr( "Wave pattern duty cycle" ) );
  399. m_ch1VolumeKnob = new FreeBoyKnob( this );
  400. m_ch1VolumeKnob->setHintText( tr( "Square channel 1 volume:" )
  401. , "" );
  402. m_ch1VolumeKnob->move( 5, 106 );
  403. ToolTip::add( m_ch1VolumeKnob, tr( "Square channel 1 volume" ) );
  404. m_ch1SweepStepLengthKnob = new FreeBoyKnob( this );
  405. m_ch1SweepStepLengthKnob->setHintText( tr( "Length of each step in sweep:" )
  406. , "" );
  407. m_ch1SweepStepLengthKnob->move( 5 + 32, 106 );
  408. ToolTip::add( m_ch1SweepStepLengthKnob, tr( "Length of each step in sweep" ) );
  409. m_ch2WavePatternDutyKnob = new FreeBoyKnob( this );
  410. m_ch2WavePatternDutyKnob->setHintText( tr( "Wave pattern duty cycle:" )
  411. , "" );
  412. m_ch2WavePatternDutyKnob->move( 5 + 2*32, 155 );
  413. ToolTip::add( m_ch2WavePatternDutyKnob, tr( "Wave pattern duty cycle" ) );
  414. m_ch2VolumeKnob = new FreeBoyKnob( this );
  415. m_ch2VolumeKnob->setHintText( tr( "Square channel 2 volume:" )
  416. , "" );
  417. m_ch2VolumeKnob->move( 5, 155 );
  418. ToolTip::add( m_ch2VolumeKnob, tr( "Square channel 2 volume" ) );
  419. m_ch2SweepStepLengthKnob = new FreeBoyKnob( this );
  420. m_ch2SweepStepLengthKnob->setHintText( tr( "Length of each step in sweep:" )
  421. , "" );
  422. m_ch2SweepStepLengthKnob->move( 5 + 32, 155 );
  423. ToolTip::add( m_ch2SweepStepLengthKnob, tr( "Length of each step in sweep" ) );
  424. m_ch3VolumeKnob = new FreeBoyKnob( this );
  425. m_ch3VolumeKnob->setHintText( tr( "Wave pattern channel volume:" ), "" );
  426. m_ch3VolumeKnob->move( 5, 204 );
  427. ToolTip::add( m_ch3VolumeKnob, tr( "Wave pattern channel volume" ) );
  428. m_ch4VolumeKnob = new FreeBoyKnob( this );
  429. m_ch4VolumeKnob->setHintText( tr( "Noise channel volume:" ), "" );
  430. m_ch4VolumeKnob->move( 144, 155 );
  431. ToolTip::add( m_ch4VolumeKnob, tr( "Noise channel volume" ) );
  432. m_ch4SweepStepLengthKnob = new FreeBoyKnob( this );
  433. m_ch4SweepStepLengthKnob->setHintText( tr( "Length of each step in sweep:" )
  434. , "" );
  435. m_ch4SweepStepLengthKnob->move( 144 + 32, 155 );
  436. ToolTip::add( m_ch4SweepStepLengthKnob, tr( "Length of each step in sweep" ) );
  437. m_so1VolumeKnob = new FreeBoyKnob( this );
  438. m_so1VolumeKnob->setHintText( tr( "SO1 volume (Right):" ), "" );
  439. m_so1VolumeKnob->move( 5, 58 );
  440. ToolTip::add( m_so1VolumeKnob, tr( "SO1 volume (Right)" ) );
  441. m_so2VolumeKnob = new FreeBoyKnob( this );
  442. m_so2VolumeKnob->setHintText( tr( "SO2 volume (Left):" ), "" );
  443. m_so2VolumeKnob->move( 5 + 32, 58 );
  444. ToolTip::add( m_so2VolumeKnob, tr( "SO2 volume (Left)" ) );
  445. m_trebleKnob = new FreeBoyKnob( this );
  446. m_trebleKnob->setHintText( tr( "Treble:" ), "" );
  447. m_trebleKnob->move( 5 + 2*32, 58 );
  448. ToolTip::add( m_trebleKnob, tr( "Treble" ) );
  449. m_bassKnob = new FreeBoyKnob( this );
  450. m_bassKnob->setHintText( tr( "Bass:" ), "" );
  451. m_bassKnob->move( 5 + 3*32, 58 );
  452. ToolTip::add( m_bassKnob, tr( "Bass" ) );
  453. m_ch1SweepDirButton = new PixmapButton( this, NULL );
  454. m_ch1SweepDirButton->setCheckable( true );
  455. m_ch1SweepDirButton->move( 167, 108 );
  456. m_ch1SweepDirButton->setActiveGraphic(
  457. PLUGIN_NAME::getIconPixmap( "btn_down" ) );
  458. m_ch1SweepDirButton->setInactiveGraphic(
  459. PLUGIN_NAME::getIconPixmap( "btn_up" ) );
  460. ToolTip::add( m_ch1SweepDirButton, tr( "Sweep direction" ) );
  461. m_ch1VolSweepDirButton = new PixmapButton( this, NULL );
  462. m_ch1VolSweepDirButton->setCheckable( true );
  463. m_ch1VolSweepDirButton->move( 207, 108 );
  464. m_ch1VolSweepDirButton->setActiveGraphic(
  465. PLUGIN_NAME::getIconPixmap( "btn_up" ) );
  466. m_ch1VolSweepDirButton->setInactiveGraphic(
  467. PLUGIN_NAME::getIconPixmap( "btn_down" ) );
  468. ToolTip::add( m_ch1VolSweepDirButton, tr( "Volume sweep direction" ) );
  469. m_ch2VolSweepDirButton = new PixmapButton( this,
  470. tr( "Volume sweep direction" ) );
  471. m_ch2VolSweepDirButton->setCheckable( true );
  472. m_ch2VolSweepDirButton->move( 102, 156 );
  473. m_ch2VolSweepDirButton->setActiveGraphic(
  474. PLUGIN_NAME::getIconPixmap( "btn_up" ) );
  475. m_ch2VolSweepDirButton->setInactiveGraphic(
  476. PLUGIN_NAME::getIconPixmap( "btn_down" ) );
  477. ToolTip::add( m_ch2VolSweepDirButton, tr( "Volume sweep direction" ) );
  478. //m_ch3OnButton = new PixmapButton( this, NULL );
  479. //m_ch3OnButton->move( 176, 53 );
  480. m_ch4VolSweepDirButton = new PixmapButton( this,
  481. tr( "Volume sweep direction" ) );
  482. m_ch4VolSweepDirButton->setCheckable( true );
  483. m_ch4VolSweepDirButton->move( 207, 157 );
  484. m_ch4VolSweepDirButton->setActiveGraphic(
  485. PLUGIN_NAME::getIconPixmap( "btn_up" ) );
  486. m_ch4VolSweepDirButton->setInactiveGraphic(
  487. PLUGIN_NAME::getIconPixmap( "btn_down" ) );
  488. ToolTip::add( m_ch4VolSweepDirButton, tr( "Volume sweep direction" ) );
  489. m_ch4ShiftRegWidthButton = new PixmapButton( this, NULL );
  490. m_ch4ShiftRegWidthButton->setCheckable( true );
  491. m_ch4ShiftRegWidthButton->move( 207, 171 );
  492. m_ch4ShiftRegWidthButton->setActiveGraphic(
  493. PLUGIN_NAME::getIconPixmap( "btn_7" ) );
  494. m_ch4ShiftRegWidthButton->setInactiveGraphic(
  495. PLUGIN_NAME::getIconPixmap( "btn_15" ) );
  496. ToolTip::add( m_ch4ShiftRegWidthButton, tr( "Shift register width" ) );
  497. m_ch1So1Button = new PixmapButton( this, NULL );
  498. m_ch1So1Button->setCheckable( true );
  499. m_ch1So1Button->move( 208, 51 );
  500. m_ch1So1Button->setActiveGraphic( PLUGIN_NAME::getIconPixmap( "btn_on" ) );
  501. m_ch1So1Button->setInactiveGraphic( PLUGIN_NAME::getIconPixmap("btn_off") );
  502. ToolTip::add( m_ch1So1Button, tr( "Channel 1 to SO1 (Right)" ) );
  503. m_ch2So1Button = new PixmapButton( this, NULL );
  504. m_ch2So1Button->setCheckable( true );
  505. m_ch2So1Button->move( 208, 51 + 12 );
  506. m_ch2So1Button->setActiveGraphic( PLUGIN_NAME::getIconPixmap( "btn_on" ) );
  507. m_ch2So1Button->setInactiveGraphic( PLUGIN_NAME::getIconPixmap("btn_off") );
  508. ToolTip::add( m_ch2So1Button, tr( "Channel 2 to SO1 (Right)" ) );
  509. m_ch3So1Button = new PixmapButton( this, NULL );
  510. m_ch3So1Button->setCheckable( true );
  511. m_ch3So1Button->move( 208, 51 + 2*12 );
  512. m_ch3So1Button->setActiveGraphic( PLUGIN_NAME::getIconPixmap( "btn_on" ) );
  513. m_ch3So1Button->setInactiveGraphic( PLUGIN_NAME::getIconPixmap("btn_off") );
  514. ToolTip::add( m_ch3So1Button, tr( "Channel 3 to SO1 (Right)" ) );
  515. m_ch4So1Button = new PixmapButton( this, NULL );
  516. m_ch4So1Button->setCheckable( true );
  517. m_ch4So1Button->setChecked( false );
  518. m_ch4So1Button->move( 208, 51 + 3*12 );
  519. m_ch4So1Button->setActiveGraphic( PLUGIN_NAME::getIconPixmap( "btn_on" ) );
  520. m_ch4So1Button->setInactiveGraphic( PLUGIN_NAME::getIconPixmap("btn_off") );
  521. ToolTip::add( m_ch4So1Button, tr( "Channel 4 to SO1 (Right)" ) );
  522. m_ch1So2Button = new PixmapButton( this, NULL );
  523. m_ch1So2Button->setCheckable( true );
  524. m_ch1So2Button->move( 148, 51 );
  525. m_ch1So2Button->setActiveGraphic( PLUGIN_NAME::getIconPixmap( "btn_on" ) );
  526. m_ch1So2Button->setInactiveGraphic( PLUGIN_NAME::getIconPixmap("btn_off") );
  527. ToolTip::add( m_ch1So2Button, tr( "Channel 1 to SO2 (Left)" ) );
  528. m_ch2So2Button = new PixmapButton( this, NULL );
  529. m_ch2So2Button->setCheckable( true );
  530. m_ch2So2Button->move( 148, 51 + 12 );
  531. m_ch2So2Button->setActiveGraphic( PLUGIN_NAME::getIconPixmap( "btn_on" ) );
  532. m_ch2So2Button->setInactiveGraphic( PLUGIN_NAME::getIconPixmap("btn_off") );
  533. ToolTip::add( m_ch2So2Button, tr( "Channel 2 to SO2 (Left)" ) );
  534. m_ch3So2Button = new PixmapButton( this, NULL );
  535. m_ch3So2Button->setCheckable( true );
  536. m_ch3So2Button->move( 148, 51 + 2*12 );
  537. m_ch3So2Button->setActiveGraphic( PLUGIN_NAME::getIconPixmap( "btn_on" ) );
  538. m_ch3So2Button->setInactiveGraphic( PLUGIN_NAME::getIconPixmap("btn_off") );
  539. ToolTip::add( m_ch3So2Button, tr( "Channel 3 to SO2 (Left)" ) );
  540. m_ch4So2Button = new PixmapButton( this, NULL );
  541. m_ch4So2Button->setCheckable( true );
  542. m_ch4So2Button->setChecked( false );
  543. m_ch4So2Button->move( 148, 51 + 3*12 );
  544. m_ch4So2Button->setActiveGraphic( PLUGIN_NAME::getIconPixmap( "btn_on" ) );
  545. m_ch4So2Button->setInactiveGraphic( PLUGIN_NAME::getIconPixmap("btn_off") );
  546. ToolTip::add( m_ch4So2Button, tr( "Channel 4 to SO2 (Left)" ) );
  547. m_graph = new Graph( this );
  548. m_graph->setGraphStyle( Graph::NearestStyle );
  549. m_graph->setGraphColor( QColor(0x4E, 0x83, 0x2B) );
  550. m_graph->move( 37, 199 );
  551. m_graph->resize(208, 47);
  552. ToolTip::add( m_graph, tr( "Wave pattern graph" ) );
  553. }
  554. FreeBoyInstrumentView::~FreeBoyInstrumentView()
  555. {
  556. }
  557. void FreeBoyInstrumentView::modelChanged()
  558. {
  559. FreeBoyInstrument * p = castModel<FreeBoyInstrument>();
  560. m_ch1SweepTimeKnob->setModel( &p->m_ch1SweepTimeModel );
  561. m_ch1SweepDirButton->setModel( &p->m_ch1SweepDirModel );
  562. m_ch1SweepRtShiftKnob->setModel( &p->m_ch1SweepRtShiftModel );
  563. m_ch1WavePatternDutyKnob->setModel( &p->m_ch1WavePatternDutyModel );
  564. m_ch1VolumeKnob->setModel( &p->m_ch1VolumeModel );
  565. m_ch1VolSweepDirButton->setModel( &p->m_ch1VolSweepDirModel );
  566. m_ch1SweepStepLengthKnob->setModel( &p->m_ch1SweepStepLengthModel );
  567. m_ch2WavePatternDutyKnob->setModel( &p->m_ch2WavePatternDutyModel );
  568. m_ch2VolumeKnob->setModel( &p->m_ch2VolumeModel );
  569. m_ch2VolSweepDirButton->setModel( &p->m_ch2VolSweepDirModel );
  570. m_ch2SweepStepLengthKnob->setModel( &p->m_ch2SweepStepLengthModel );
  571. //m_ch3OnButton->setModel( &p->m_ch3OnModel );
  572. m_ch3VolumeKnob->setModel( &p->m_ch3VolumeModel );
  573. m_ch4VolumeKnob->setModel( &p->m_ch4VolumeModel );
  574. m_ch4VolSweepDirButton->setModel( &p->m_ch4VolSweepDirModel );
  575. m_ch4SweepStepLengthKnob->setModel( &p->m_ch4SweepStepLengthModel );
  576. m_ch4ShiftRegWidthButton->setModel( &p->m_ch4ShiftRegWidthModel );
  577. m_so1VolumeKnob->setModel( &p->m_so1VolumeModel );
  578. m_so2VolumeKnob->setModel( &p->m_so2VolumeModel );
  579. m_ch1So1Button->setModel( &p->m_ch1So1Model );
  580. m_ch2So1Button->setModel( &p->m_ch2So1Model );
  581. m_ch3So1Button->setModel( &p->m_ch3So1Model );
  582. m_ch4So1Button->setModel( &p->m_ch4So1Model );
  583. m_ch1So2Button->setModel( &p->m_ch1So2Model );
  584. m_ch2So2Button->setModel( &p->m_ch2So2Model );
  585. m_ch3So2Button->setModel( &p->m_ch3So2Model );
  586. m_ch4So2Button->setModel( &p->m_ch4So2Model );
  587. m_trebleKnob->setModel( &p->m_trebleModel );
  588. m_bassKnob->setModel( &p->m_bassModel );
  589. m_graph->setModel( &p->m_graphModel );
  590. }
  591. extern "C"
  592. {
  593. // necessary for getting instance out of shared lib
  594. PLUGIN_EXPORT Plugin * lmms_plugin_main( Model *m, void * )
  595. {
  596. return( new FreeBoyInstrument(
  597. static_cast<InstrumentTrack *>( m ) ) );
  598. }
  599. }