1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836
|
/*
* sid_instrument.cpp - ResID based software-synthesizer
*
* Copyright (c) 2008 Csaba Hruska <csaba.hruska/at/gmail.com>
* Attila Herman <attila589/at/gmail.com>
*
* This file is part of LMMS - https://lmms.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#include <QPainter>
#include <QDomElement>
#include <cmath>
#include <cstdio>
#include "sid.h"
#include "sid_instrument.h"
#include "Engine.h"
#include "InstrumentTrack.h"
#include "Knob.h"
#include "Mixer.h"
#include "NotePlayHandle.h"
#include "PixmapButton.h"
#include "ToolTip.h"
#include "embed.cpp"
#define C64_PAL_CYCLES_PER_SEC 985248
#define NUMSIDREGS 0x19
#define SIDWRITEDELAY 9 // lda $xxxx,x 4 cycles, sta $d400,x 5 cycles
#define SIDWAVEDELAY 4 // and $xxxx,x 4 cycles extra
unsigned char sidorder[] =
{0x15,0x16,0x18,0x17,
0x05,0x06,0x02,0x03,0x00,0x01,0x04,
0x0c,0x0d,0x09,0x0a,0x07,0x08,0x0b,
0x13,0x14,0x10,0x11,0x0e,0x0f,0x12};
static const char *attackTime[16] = { "2 mS", "8 mS", "16 mS", "24 mS",
"38 mS", "56 mS", "68 mS", "80 mS",
"100 mS", "250 mS", "500 mS", "800 mS",
"1 S", "3 S", "5 S", "8 S" };
static const char *decRelTime[16] = { "6 mS", "24 mS", "48 mS", "72 mS",
"114 mS", "168 mS", "204 mS", "240 mS",
"300 mS", "750 mS", "1.5 S", "2.4 S",
"3 S", "9 S", "15 S", "24 S" };
// release time time in ms
static const int relTime[16] = { 6, 24, 48, 72, 114, 168, 204, 240, 300, 750,
1500, 2400, 3000, 9000, 15000, 24000 };
extern "C"
{
Plugin::Descriptor PLUGIN_EXPORT sid_plugin_descriptor =
{
STRINGIFY( PLUGIN_NAME ),
"SID",
QT_TRANSLATE_NOOP( "pluginBrowser", "Emulation of the MOS6581 and MOS8580 "
"SID.\nThis chip was used in the Commodore 64 computer." ),
"Csaba Hruska <csaba.hruska/at/gmail.com>"
"Attila Herman <attila589/at/gmail.com>",
0x0100,
Plugin::Instrument,
new PluginPixmapLoader( "logo" ),
NULL,
NULL
} ;
}
voiceObject::voiceObject( Model * _parent, int _idx ) :
Model( _parent ),
m_pulseWidthModel( 2048.0f, 0.0f, 4095.0f, 1.0f, this,
tr( "Voice %1 pulse width" ).arg( _idx+1 ) ),
m_attackModel( 8.0f, 0.0f, 15.0f, 1.0f, this,
tr( "Voice %1 attack" ).arg( _idx+1 ) ),
m_decayModel( 8.0f, 0.0f, 15.0f, 1.0f, this,
tr( "Voice %1 decay" ).arg( _idx+1 ) ),
m_sustainModel( 15.0f, 0.0f, 15.0f, 1.0f, this,
tr( "Voice %1 sustain" ).arg( _idx+1 ) ),
m_releaseModel( 8.0f, 0.0f, 15.0f, 1.0f, this,
tr( "Voice %1 release" ).arg( _idx+1 ) ),
m_coarseModel( 0.0f, -24.0, 24.0, 1.0f, this,
tr( "Voice %1 coarse detuning" ).arg( _idx+1 ) ),
m_waveFormModel( TriangleWave, 0, NumWaveShapes-1, this,
tr( "Voice %1 wave shape" ).arg( _idx+1 ) ),
m_syncModel( false, this, tr( "Voice %1 sync" ).arg( _idx+1 ) ),
m_ringModModel( false, this, tr( "Voice %1 ring modulate" ).arg( _idx+1 ) ),
m_filteredModel( false, this, tr( "Voice %1 filtered" ).arg( _idx+1 ) ),
m_testModel( false, this, tr( "Voice %1 test" ).arg( _idx+1 ) )
{
}
voiceObject::~voiceObject()
{
}
sidInstrument::sidInstrument( InstrumentTrack * _instrument_track ) :
Instrument( _instrument_track, &sid_plugin_descriptor ),
// filter
m_filterFCModel( 1024.0f, 0.0f, 2047.0f, 1.0f, this, tr( "Cutoff" ) ),
m_filterResonanceModel( 8.0f, 0.0f, 15.0f, 1.0f, this, tr( "Resonance" ) ),
m_filterModeModel( LowPass, 0, NumFilterTypes-1, this, tr( "Filter type" )),
// misc
m_voice3OffModel( false, this, tr( "Voice 3 off" ) ),
m_volumeModel( 15.0f, 0.0f, 15.0f, 1.0f, this, tr( "Volume" ) ),
m_chipModel( sidMOS8580, 0, NumChipModels-1, this, tr( "Chip model" ) )
{
for( int i = 0; i < 3; ++i )
{
m_voice[i] = new voiceObject( this, i );
}
}
sidInstrument::~sidInstrument()
{
}
void sidInstrument::saveSettings( QDomDocument & _doc,
QDomElement & _this )
{
// voices
for( int i = 0; i < 3; ++i )
{
const QString is = QString::number( i );
m_voice[i]->m_pulseWidthModel.saveSettings(
_doc, _this, "pulsewidth" + is );
m_voice[i]->m_attackModel.saveSettings(
_doc, _this, "attack" + is );
m_voice[i]->m_decayModel.saveSettings(
_doc, _this, "decay" + is );
m_voice[i]->m_sustainModel.saveSettings(
_doc, _this, "sustain" + is );
m_voice[i]->m_releaseModel.saveSettings(
_doc, _this, "release" + is );
m_voice[i]->m_coarseModel.saveSettings(
_doc, _this, "coarse" + is );
m_voice[i]->m_waveFormModel.saveSettings(
_doc, _this,"waveform" + is );
m_voice[i]->m_syncModel.saveSettings(
_doc, _this, "sync" + is );
m_voice[i]->m_ringModModel.saveSettings(
_doc, _this, "ringmod" + is );
m_voice[i]->m_filteredModel.saveSettings(
_doc, _this,"filtered" + is );
m_voice[i]->m_testModel.saveSettings(
_doc, _this, "test" + is );
}
// filter
m_filterFCModel.saveSettings( _doc, _this, "filterFC" );
m_filterResonanceModel.saveSettings( _doc, _this, "filterResonance" );
m_filterModeModel.saveSettings( _doc, _this, "filterMode" );
// misc
m_voice3OffModel.saveSettings( _doc, _this, "voice3Off" );
m_volumeModel.saveSettings( _doc, _this, "volume" );
m_chipModel.saveSettings( _doc, _this, "chipModel" );
}
void sidInstrument::loadSettings( const QDomElement & _this )
{
// voices
for( int i = 0; i < 3; ++i )
{
const QString is = QString::number( i );
m_voice[i]->m_pulseWidthModel.loadSettings( _this, "pulsewidth" + is );
m_voice[i]->m_attackModel.loadSettings( _this, "attack" + is );
m_voice[i]->m_decayModel.loadSettings( _this, "decay" + is );
m_voice[i]->m_sustainModel.loadSettings( _this, "sustain" + is );
m_voice[i]->m_releaseModel.loadSettings( _this, "release" + is );
m_voice[i]->m_coarseModel.loadSettings( _this, "coarse" + is );
m_voice[i]->m_waveFormModel.loadSettings( _this, "waveform" + is );
m_voice[i]->m_syncModel.loadSettings( _this, "sync" + is );
m_voice[i]->m_ringModModel.loadSettings( _this, "ringmod" + is );
m_voice[i]->m_filteredModel.loadSettings( _this, "filtered" + is );
m_voice[i]->m_testModel.loadSettings( _this, "test" + is );
}
// filter
m_filterFCModel.loadSettings( _this, "filterFC" );
m_filterResonanceModel.loadSettings( _this, "filterResonance" );
m_filterModeModel.loadSettings( _this, "filterMode" );
// misc
m_voice3OffModel.loadSettings( _this, "voice3Off" );
m_volumeModel.loadSettings( _this, "volume" );
m_chipModel.loadSettings( _this, "chipModel" );
}
QString sidInstrument::nodeName() const
{
return( sid_plugin_descriptor.name );
}
f_cnt_t sidInstrument::desiredReleaseFrames() const
{
const float samplerate = Engine::mixer()->processingSampleRate();
int maxrel = 0;
for( int i = 0 ; i < 3 ; ++i )
{
if( maxrel < m_voice[i]->m_releaseModel.value() )
maxrel = (int)m_voice[i]->m_releaseModel.value();
}
return f_cnt_t( float(relTime[maxrel])*samplerate/1000.0 );
}
static int sid_fillbuffer(unsigned char* sidreg, cSID *sid, int tdelta, short *ptr, int samples)
{
int tdelta2;
int result;
int total = 0;
int c;
// customly added
int residdelay = 0;
int badline = rand() % NUMSIDREGS;
for (c = 0; c < NUMSIDREGS; c++)
{
unsigned char o = sidorder[c];
// Extra delay for loading the waveform (and mt_chngate,x)
if ((o == 4) || (o == 11) || (o == 18))
{
tdelta2 = SIDWAVEDELAY;
result = sid->clock(tdelta2, ptr, samples);
total += result;
ptr += result;
samples -= result;
tdelta -= SIDWAVEDELAY;
}
// Possible random badline delay once per writing
if ((badline == c) && (residdelay))
{
tdelta2 = residdelay;
result = sid->clock(tdelta2, ptr, samples);
total += result;
ptr += result;
samples -= result;
tdelta -= residdelay;
}
sid->write(o, sidreg[o]);
tdelta2 = SIDWRITEDELAY;
result = sid->clock(tdelta2, ptr, samples);
total += result;
ptr += result;
samples -= result;
tdelta -= SIDWRITEDELAY;
}
result = sid->clock(tdelta, ptr, samples);
total += result;
return total;
}
void sidInstrument::playNote( NotePlayHandle * _n,
sampleFrame * _working_buffer )
{
const f_cnt_t tfp = _n->totalFramesPlayed();
const int clockrate = C64_PAL_CYCLES_PER_SEC;
const int samplerate = Engine::mixer()->processingSampleRate();
if ( tfp == 0 )
{
cSID *sid = new cSID();
sid->set_sampling_parameters( clockrate, SAMPLE_FAST, samplerate );
sid->set_chip_model( MOS8580 );
sid->enable_filter( true );
sid->reset();
_n->m_pluginData = sid;
}
const fpp_t frames = _n->framesLeftForCurrentPeriod();
const f_cnt_t offset = _n->noteOffset();
cSID *sid = static_cast<cSID *>( _n->m_pluginData );
int delta_t = clockrate * frames / samplerate + 4;
short buf[frames];
unsigned char sidreg[NUMSIDREGS];
for (int c = 0; c < NUMSIDREGS; c++)
{
sidreg[c] = 0x00;
}
if( (ChipModel)m_chipModel.value() == sidMOS6581 )
{
sid->set_chip_model( MOS6581 );
}
else
{
sid->set_chip_model( MOS8580 );
}
// voices
reg8 data8 = 0;
reg8 data16 = 0;
reg8 base = 0;
float freq = 0.0;
float note = 0.0;
for( reg8 i = 0 ; i < 3 ; ++i )
{
base = i*7;
// freq ( Fn = Fout / Fclk * 16777216 ) + coarse detuning
freq = _n->frequency();
note = 69.0 + 12.0 * log( freq / 440.0 ) / log( 2 );
note += m_voice[i]->m_coarseModel.value();
freq = 440.0 * pow( 2.0, (note-69.0)/12.0 );
data16 = int( freq / float(clockrate) * 16777216.0 );
sidreg[base+0] = data16&0x00FF;
sidreg[base+1] = (data16>>8)&0x00FF;
// pw
data16 = (int)m_voice[i]->m_pulseWidthModel.value();
sidreg[base+2] = data16&0x00FF;
sidreg[base+3] = (data16>>8)&0x000F;
// control: wave form, (test), ringmod, sync, gate
data8 = _n->isReleased()?0:1;
data8 += m_voice[i]->m_syncModel.value()?2:0;
data8 += m_voice[i]->m_ringModModel.value()?4:0;
data8 += m_voice[i]->m_testModel.value()?8:0;
switch( m_voice[i]->m_waveFormModel.value() )
{
default: break;
case voiceObject::NoiseWave: data8 += 128; break;
case voiceObject::SquareWave: data8 += 64; break;
case voiceObject::SawWave: data8 += 32; break;
case voiceObject::TriangleWave: data8 += 16; break;
}
sidreg[base+4] = data8&0x00FF;
// ad
data16 = (int)m_voice[i]->m_attackModel.value();
data8 = (data16&0x0F)<<4;
data16 = (int)m_voice[i]->m_decayModel.value();
data8 += (data16&0x0F);
sidreg[base+5] = data8&0x00FF;
// sr
data16 = (int)m_voice[i]->m_sustainModel.value();
data8 = (data16&0x0F)<<4;
data16 = (int)m_voice[i]->m_releaseModel.value();
data8 += (data16&0x0F);
sidreg[base+6] = data8&0x00FF;
}
// filtered
// FC (FilterCutoff)
data16 = (int)m_filterFCModel.value();
sidreg[21] = data16&0x0007;
sidreg[22] = (data16>>3)&0x00FF;
// res, filt ex,3,2,1
data16 = (int)m_filterResonanceModel.value();
data8 = (data16&0x000F)<<4;
data8 += m_voice[2]->m_filteredModel.value()?4:0;
data8 += m_voice[1]->m_filteredModel.value()?2:0;
data8 += m_voice[0]->m_filteredModel.value()?1:0;
sidreg[23] = data8&0x00FF;
// mode vol
data16 = (int)m_volumeModel.value();
data8 = data16&0x000F;
data8 += m_voice3OffModel.value()?128:0;
switch( m_filterModeModel.value() )
{
default: break;
case LowPass: data8 += 16; break;
case BandPass: data8 += 32; break;
case HighPass: data8 += 64; break;
}
sidreg[24] = data8&0x00FF;
int num = sid_fillbuffer(sidreg, sid,delta_t,buf, frames);
if(num!=frames)
printf("!!!Not enough samples\n");
for( fpp_t frame = 0; frame < frames; ++frame )
{
sample_t s = float(buf[frame])/32768.0;
for( ch_cnt_t ch = 0; ch < DEFAULT_CHANNELS; ++ch )
{
_working_buffer[frame+offset][ch] = s;
}
}
instrumentTrack()->processAudioBuffer( _working_buffer, frames + offset, _n );
}
void sidInstrument::deleteNotePluginData( NotePlayHandle * _n )
{
delete static_cast<cSID *>( _n->m_pluginData );
}
PluginView * sidInstrument::instantiateView( QWidget * _parent )
{
return( new sidInstrumentView( this, _parent ) );
}
class sidKnob : public Knob
{
public:
sidKnob( QWidget * _parent ) :
Knob( knobStyled, _parent )
{
setFixedSize( 16, 16 );
setCenterPointX( 7.5 );
setCenterPointY( 7.5 );
setInnerRadius( 2 );
setOuterRadius( 8 );
setTotalAngle( 270.0 );
setLineWidth( 2 );
}
};
sidInstrumentView::sidInstrumentView( Instrument * _instrument,
QWidget * _parent ) :
InstrumentView( _instrument, _parent )
{
setAutoFillBackground( true );
QPalette pal;
pal.setBrush( backgroundRole(), PLUGIN_NAME::getIconPixmap( "artwork" ) );
setPalette( pal );
m_volKnob = new sidKnob( this );
m_volKnob->setHintText( tr( "Volume:" ), "" );
m_volKnob->move( 7, 64 );
m_resKnob = new sidKnob( this );
m_resKnob->setHintText( tr( "Resonance:" ), "" );
m_resKnob->move( 7 + 28, 64 );
m_cutKnob = new sidKnob( this );
m_cutKnob->setHintText( tr( "Cutoff frequency:" ), "Hz" );
m_cutKnob->move( 7 + 2*28, 64 );
PixmapButton * hp_btn = new PixmapButton( this, NULL );
hp_btn->move( 140, 77 );
hp_btn->setActiveGraphic( PLUGIN_NAME::getIconPixmap( "hpred" ) );
hp_btn->setInactiveGraphic( PLUGIN_NAME::getIconPixmap( "hp" ) );
ToolTip::add( hp_btn, tr( "High-Pass filter ") );
PixmapButton * bp_btn = new PixmapButton( this, NULL );
bp_btn->move( 164, 77 );
bp_btn->setActiveGraphic( PLUGIN_NAME::getIconPixmap( "bpred" ) );
bp_btn->setInactiveGraphic( PLUGIN_NAME::getIconPixmap( "bp" ) );
ToolTip::add( bp_btn, tr( "Band-Pass filter ") );
PixmapButton * lp_btn = new PixmapButton( this, NULL );
lp_btn->move( 185, 77 );
lp_btn->setActiveGraphic( PLUGIN_NAME::getIconPixmap( "lpred" ) );
lp_btn->setInactiveGraphic( PLUGIN_NAME::getIconPixmap( "lp" ) );
ToolTip::add( lp_btn, tr( "Low-Pass filter ") );
m_passBtnGrp = new automatableButtonGroup( this );
m_passBtnGrp->addButton( hp_btn );
m_passBtnGrp->addButton( bp_btn );
m_passBtnGrp->addButton( lp_btn );
m_offButton = new PixmapButton( this, NULL );
m_offButton->setCheckable( true );
m_offButton->move( 207, 77 );
m_offButton->setActiveGraphic( PLUGIN_NAME::getIconPixmap( "3offred" ) );
m_offButton->setInactiveGraphic( PLUGIN_NAME::getIconPixmap( "3off" ) );
ToolTip::add( m_offButton, tr( "Voice3 Off ") );
PixmapButton * mos6581_btn = new PixmapButton( this, NULL );
mos6581_btn->move( 170, 59 );
mos6581_btn->setActiveGraphic( PLUGIN_NAME::getIconPixmap( "6581red" ) );
mos6581_btn->setInactiveGraphic( PLUGIN_NAME::getIconPixmap( "6581" ) );
ToolTip::add( mos6581_btn, tr( "MOS6581 SID ") );
PixmapButton * mos8580_btn = new PixmapButton( this, NULL );
mos8580_btn->move( 207, 59 );
mos8580_btn->setActiveGraphic( PLUGIN_NAME::getIconPixmap( "8580red" ) );
mos8580_btn->setInactiveGraphic( PLUGIN_NAME::getIconPixmap( "8580" ) );
ToolTip::add( mos8580_btn, tr( "MOS8580 SID ") );
m_sidTypeBtnGrp = new automatableButtonGroup( this );
m_sidTypeBtnGrp->addButton( mos6581_btn );
m_sidTypeBtnGrp->addButton( mos8580_btn );
for( int i = 0; i < 3; i++ )
{
Knob *ak = new sidKnob( this );
ak->setHintText( tr("Attack:"), "" );
ak->move( 7, 114 + i*50 );
ak->setWhatsThis( tr ( "Attack rate determines how rapidly the output "
"of Voice %1 rises from zero to peak amplitude." ).arg( i+1 ) );
Knob *dk = new sidKnob( this );
dk->setHintText( tr("Decay:") , "" );
dk->move( 7 + 28, 114 + i*50 );
dk->setWhatsThis( tr ( "Decay rate determines how rapidly the output "
"falls from the peak amplitude to the selected Sustain level." ) );
Knob *sk = new sidKnob( this );
sk->setHintText( tr("Sustain:"), "" );
sk->move( 7 + 2*28, 114 + i*50 );
sk->setWhatsThis( tr ( "Output of Voice %1 will remain at the selected "
"Sustain amplitude as long as the note is held." ).arg( i+1 ) );
Knob *rk = new sidKnob( this );
rk->setHintText( tr("Release:"), "" );
rk->move( 7 + 3*28, 114 + i*50 );
rk->setWhatsThis( tr ( "The output of of Voice %1 will fall from "
"Sustain amplitude to zero amplitude at the selected Release "
"rate." ).arg( i+1 ) );
Knob *pwk = new sidKnob( this );
pwk->setHintText( tr("Pulse Width:"), "" );
pwk->move( 7 + 4*28, 114 + i*50 );
pwk->setWhatsThis( tr ( "The Pulse Width resolution allows the width "
"to be smoothly swept with no discernable stepping. The Pulse "
"waveform on Oscillator %1 must be selected to have any audible"
" effect." ).arg( i+1 ) );
Knob *crsk = new sidKnob( this );
crsk->setHintText( tr("Coarse:"), " semitones" );
crsk->move( 147, 114 + i*50 );
crsk->setWhatsThis( tr ( "The Coarse detuning allows to detune Voice "
"%1 one octave up or down." ).arg( i+1 ) );
PixmapButton * pulse_btn = new PixmapButton( this, NULL );
pulse_btn->move( 187, 101 + i*50 );
pulse_btn->setActiveGraphic(
PLUGIN_NAME::getIconPixmap( "pulsered" ) );
pulse_btn->setInactiveGraphic(
PLUGIN_NAME::getIconPixmap( "pulse" ) );
ToolTip::add( pulse_btn, tr( "Pulse Wave" ) );
PixmapButton * triangle_btn = new PixmapButton( this, NULL );
triangle_btn->move( 168, 101 + i*50 );
triangle_btn->setActiveGraphic(
PLUGIN_NAME::getIconPixmap( "trianglered" ) );
triangle_btn->setInactiveGraphic(
PLUGIN_NAME::getIconPixmap( "triangle" ) );
ToolTip::add( triangle_btn, tr( "Triangle Wave" ) );
PixmapButton * saw_btn = new PixmapButton( this, NULL );
saw_btn->move( 207, 101 + i*50 );
saw_btn->setActiveGraphic(
PLUGIN_NAME::getIconPixmap( "sawred" ) );
saw_btn->setInactiveGraphic(
PLUGIN_NAME::getIconPixmap( "saw" ) );
ToolTip::add( saw_btn, tr( "SawTooth" ) );
PixmapButton * noise_btn = new PixmapButton( this, NULL );
noise_btn->move( 226, 101 + i*50 );
noise_btn->setActiveGraphic(
PLUGIN_NAME::getIconPixmap( "noisered" ) );
noise_btn->setInactiveGraphic(
PLUGIN_NAME::getIconPixmap( "noise" ) );
ToolTip::add( noise_btn, tr( "Noise" ) );
automatableButtonGroup * wfbg =
new automatableButtonGroup( this );
wfbg->addButton( pulse_btn );
wfbg->addButton( triangle_btn );
wfbg->addButton( saw_btn );
wfbg->addButton( noise_btn );
int syncRingWidth[] = { 3, 1, 2 };
PixmapButton * sync_btn = new PixmapButton( this, NULL );
sync_btn->setCheckable( true );
sync_btn->move( 207, 134 + i*50 );
sync_btn->setActiveGraphic(
PLUGIN_NAME::getIconPixmap( "syncred" ) );
sync_btn->setInactiveGraphic(
PLUGIN_NAME::getIconPixmap( "sync" ) );
ToolTip::add( sync_btn, tr( "Sync" ) );
sync_btn->setWhatsThis( tr ( "Sync synchronizes the fundamental "
"frequency of Oscillator %1 with the fundamental frequency of "
"Oscillator %2 producing \"Hard Sync\" effects." ).arg( i+1 )
.arg( syncRingWidth[i] ) );
PixmapButton * ringMod_btn = new PixmapButton( this, NULL );
ringMod_btn->setCheckable( true );
ringMod_btn->move( 170, 116 + i*50 );
ringMod_btn->setActiveGraphic(
PLUGIN_NAME::getIconPixmap( "ringred" ) );
ringMod_btn->setInactiveGraphic(
PLUGIN_NAME::getIconPixmap( "ring" ) );
ToolTip::add( ringMod_btn, tr( "Ring-Mod" ) );
ringMod_btn->setWhatsThis( tr ( "Ring-mod replaces the Triangle "
"Waveform output of Oscillator %1 with a \"Ring Modulated\" "
"combination of Oscillators %1 and %2." ).arg( i+1 )
.arg( syncRingWidth[i] ) );
PixmapButton * filter_btn = new PixmapButton( this, NULL );
filter_btn->setCheckable( true );
filter_btn->move( 207, 116 + i*50 );
filter_btn->setActiveGraphic(
PLUGIN_NAME::getIconPixmap( "filterred" ) );
filter_btn->setInactiveGraphic(
PLUGIN_NAME::getIconPixmap( "filter" ) );
ToolTip::add( filter_btn, tr( "Filtered" ) );
filter_btn->setWhatsThis( tr ( "When Filtered is on, Voice %1 will be "
"processed through the Filter. When Filtered is off, Voice %1 "
"appears directly at the output, and the Filter has no effect on "
"it." ).arg( i+1 ) );
PixmapButton * test_btn = new PixmapButton( this, NULL );
test_btn->setCheckable( true );
test_btn->move( 170, 134 + i*50 );
test_btn->setActiveGraphic(
PLUGIN_NAME::getIconPixmap( "testred" ) );
test_btn->setInactiveGraphic(
PLUGIN_NAME::getIconPixmap( "test" ) );
ToolTip::add( test_btn, tr( "Test" ) );
test_btn->setWhatsThis( tr ( "Test, when set, resets and locks "
"Oscillator %1 at zero until Test is turned off." ).arg( i+1 ) );
m_voiceKnobs[i] = voiceKnobs( ak, dk, sk, rk, pwk, crsk, wfbg,
sync_btn, ringMod_btn, filter_btn, test_btn );
}
}
sidInstrumentView::~sidInstrumentView()
{
}
void sidInstrumentView::updateKnobHint()
{
sidInstrument * k = castModel<sidInstrument>();
for( int i = 0; i < 3; ++i )
{
m_voiceKnobs[i].m_attKnob->setHintText( tr( "Attack:" ) + " ", " (" +
QString::fromLatin1( attackTime[(int)k->m_voice[i]->
m_attackModel.value()] ) + ")" );
ToolTip::add( m_voiceKnobs[i].m_attKnob,
attackTime[(int)k->m_voice[i]->m_attackModel.value()] );
m_voiceKnobs[i].m_decKnob->setHintText( tr( "Decay:" ) + " ", " (" +
QString::fromLatin1( decRelTime[(int)k->m_voice[i]->
m_decayModel.value()] ) + ")" );
ToolTip::add( m_voiceKnobs[i].m_decKnob,
decRelTime[(int)k->m_voice[i]->m_decayModel.value()] );
m_voiceKnobs[i].m_relKnob->setHintText( tr( "Release:" ) + " ", " (" +
QString::fromLatin1( decRelTime[(int)k->m_voice[i]->
m_releaseModel.value()] ) + ")" );
ToolTip::add( m_voiceKnobs[i].m_relKnob,
decRelTime[(int)k->m_voice[i]->m_releaseModel.value()]);
m_voiceKnobs[i].m_pwKnob->setHintText( tr( "Pulse Width:" )+ " ", " (" +
QString::number( (double)k->m_voice[i]->
m_pulseWidthModel.value() / 40.95 ) + "%)" );
ToolTip::add( m_voiceKnobs[i].m_pwKnob,
QString::number( (double)k->m_voice[i]->
m_pulseWidthModel.value() / 40.95 ) + "%" );
}
m_cutKnob->setHintText( tr( "Cutoff frequency:" ) + " ", " (" +
QString::number ( (int) ( 9970.0 / 2047.0 *
(double)k->m_filterFCModel.value() + 30.0 ) ) + "Hz)" );
ToolTip::add( m_cutKnob, QString::number( (int) ( 9970.0 / 2047.0 *
(double)k->m_filterFCModel.value() + 30.0 ) ) + "Hz" );
}
void sidInstrumentView::updateKnobToolTip()
{
sidInstrument * k = castModel<sidInstrument>();
for( int i = 0; i < 3; ++i )
{
ToolTip::add( m_voiceKnobs[i].m_sustKnob,
QString::number( (int)k->m_voice[i]->m_sustainModel.value() ) );
ToolTip::add( m_voiceKnobs[i].m_crsKnob,
QString::number( (int)k->m_voice[i]->m_coarseModel.value() ) +
" semitones" );
}
ToolTip::add( m_volKnob,
QString::number( (int)k->m_volumeModel.value() ) );
ToolTip::add( m_resKnob,
QString::number( (int)k->m_filterResonanceModel.value() ) );
}
void sidInstrumentView::modelChanged()
{
sidInstrument * k = castModel<sidInstrument>();
m_volKnob->setModel( &k->m_volumeModel );
m_resKnob->setModel( &k->m_filterResonanceModel );
m_cutKnob->setModel( &k->m_filterFCModel );
m_passBtnGrp->setModel( &k->m_filterModeModel );
m_offButton->setModel( &k->m_voice3OffModel );
m_sidTypeBtnGrp->setModel( &k->m_chipModel );
for( int i = 0; i < 3; ++i )
{
m_voiceKnobs[i].m_attKnob->setModel(
&k->m_voice[i]->m_attackModel );
m_voiceKnobs[i].m_decKnob->setModel(
&k->m_voice[i]->m_decayModel );
m_voiceKnobs[i].m_sustKnob->setModel(
&k->m_voice[i]->m_sustainModel );
m_voiceKnobs[i].m_relKnob->setModel(
&k->m_voice[i]->m_releaseModel );
m_voiceKnobs[i].m_pwKnob->setModel(
&k->m_voice[i]->m_pulseWidthModel );
m_voiceKnobs[i].m_crsKnob->setModel(
&k->m_voice[i]->m_coarseModel );
m_voiceKnobs[i].m_waveFormBtnGrp->setModel(
&k->m_voice[i]->m_waveFormModel );
m_voiceKnobs[i].m_syncButton->setModel(
&k->m_voice[i]->m_syncModel );
m_voiceKnobs[i].m_ringModButton->setModel(
&k->m_voice[i]->m_ringModModel );
m_voiceKnobs[i].m_filterButton->setModel(
&k->m_voice[i]->m_filteredModel );
m_voiceKnobs[i].m_testButton->setModel(
&k->m_voice[i]->m_testModel );
}
for( int i = 0; i < 3; ++i )
{
connect( &k->m_voice[i]->m_attackModel, SIGNAL( dataChanged() ),
this, SLOT( updateKnobHint() ) );
connect( &k->m_voice[i]->m_decayModel, SIGNAL( dataChanged() ),
this, SLOT( updateKnobHint() ) );
connect( &k->m_voice[i]->m_releaseModel, SIGNAL( dataChanged() ),
this, SLOT( updateKnobHint() ) );
connect( &k->m_voice[i]->m_pulseWidthModel, SIGNAL( dataChanged() ),
this, SLOT( updateKnobHint() ) );
connect( &k->m_voice[i]->m_sustainModel, SIGNAL( dataChanged() ),
this, SLOT( updateKnobToolTip() ) );
connect( &k->m_voice[i]->m_coarseModel, SIGNAL( dataChanged() ),
this, SLOT( updateKnobToolTip() ) );
}
connect( &k->m_volumeModel, SIGNAL( dataChanged() ),
this, SLOT( updateKnobToolTip() ) );
connect( &k->m_filterResonanceModel, SIGNAL( dataChanged() ),
this, SLOT( updateKnobToolTip() ) );
connect( &k->m_filterFCModel, SIGNAL( dataChanged() ),
this, SLOT( updateKnobHint() ) );
updateKnobHint();
updateKnobToolTip();
}
extern "C"
{
// necessary for getting instance out of shared lib
Plugin * PLUGIN_EXPORT lmms_plugin_main( Model *, void * _data )
{
return( new sidInstrument(
static_cast<InstrumentTrack *>( _data ) ) );
}
}
|