Merge pull request #127 from wongcc966422/LFOBitinvaderVibedCustomWaveforms

Make LFO controller, Bit Invader and Vibed accept custom waveforms
This commit is contained in:
Tobias Doerffel
2014-01-24 14:56:04 -08:00
11 changed files with 147 additions and 70 deletions

View File

@@ -49,7 +49,8 @@ LfoController::LfoController( Model * _parent ) :
m_duration( 1000 ),
m_phaseCorrection( 0 ),
m_phaseOffset( 0 ),
m_sampleFunction( &Oscillator::sinSample )
m_sampleFunction( &Oscillator::sinSample ),
m_userDefSampleBuffer( new SampleBuffer )
{
connect( &m_waveModel, SIGNAL( dataChanged() ),
@@ -61,6 +62,7 @@ LfoController::LfoController( Model * _parent ) :
LfoController::~LfoController()
{
sharedObject::unref( m_userDefSampleBuffer );
m_baseModel.disconnect( this );
m_speedModel.disconnect( this );
m_amountModel.disconnect( this );
@@ -164,7 +166,9 @@ float LfoController::value( int _offset )
// 44100 frames/sec
return m_baseModel.value() + ( m_amountModel.value() *
m_sampleFunction(sampleFrame)
( m_sampleFunction != NULL ?
m_sampleFunction(sampleFrame):
m_userDefSampleBuffer->userWaveSample(sampleFrame) )
/ 2.0f );
}
@@ -196,6 +200,14 @@ void LfoController::updateSampleFunction()
case Oscillator::WhiteNoise:
m_sampleFunction = &Oscillator::noiseSample;
break;
case Oscillator::UserDefinedWave:
m_sampleFunction = NULL;
/*TODO: If C++11 is allowed, should change the type of
m_sampleFunction be std::function<sample_t(const float)>
and use the line below:
*/
//m_sampleFunction = &(m_userDefSampleBuffer->userWaveSample)
break;
}
}

View File

@@ -894,6 +894,23 @@ QString SampleBuffer::openAudioFile() const
}
QString SampleBuffer::openAndSetAudioFile()
{
QString fileName = this->openAudioFile();
if(!fileName.isEmpty())
{
this->setAudioFile( fileName );
}
return fileName;
}
#undef LMMS_HAVE_FLAC_STREAM_ENCODER_H /* not yet... */
#undef LMMS_HAVE_FLAC_STREAM_DECODER_H

View File

@@ -178,15 +178,17 @@ LfoControllerDialog::LfoControllerDialog( Controller * _model, QWidget * _parent
toolTip::add( white_noise_btn,
tr( "Click here for white-noise." ) );
pixmapButton * uwb = new pixmapButton( this, NULL );
uwb->move( CD_LFO_SHAPES_X + 45, CD_LFO_SHAPES_Y + 15 );
uwb->setActiveGraphic( embed::getIconPixmap(
m_userWaveBtn = new pixmapButton( this, NULL );
m_userWaveBtn->move( CD_LFO_SHAPES_X + 45, CD_LFO_SHAPES_Y + 15 );
m_userWaveBtn->setActiveGraphic( embed::getIconPixmap(
"usr_wave_active" ) );
uwb->setInactiveGraphic( embed::getIconPixmap(
m_userWaveBtn->setInactiveGraphic( embed::getIconPixmap(
"usr_wave_inactive" ) );
uwb->setEnabled( false );
toolTip::add( uwb, tr( "Click here for a user-defined "
"shape." ) );
connect( m_userWaveBtn,
SIGNAL( doubleClicked() ),
this, SLOT( askUserDefWave() ) );
toolTip::add( m_userWaveBtn,
tr( "Click here for a user-defined shape.\nDouble click to pick a file." ) );
m_waveBtnGrp = new automatableButtonGroup( this );
m_waveBtnGrp->addButton( sin_wave_btn );
@@ -196,7 +198,7 @@ LfoControllerDialog::LfoControllerDialog( Controller * _model, QWidget * _parent
m_waveBtnGrp->addButton( moog_saw_wave_btn );
m_waveBtnGrp->addButton( exp_wave_btn );
m_waveBtnGrp->addButton( white_noise_btn );
m_waveBtnGrp->addButton( uwb );
m_waveBtnGrp->addButton( m_userWaveBtn );
pixmapButton * x1 = new pixmapButton( this, NULL );
@@ -240,11 +242,26 @@ LfoControllerDialog::LfoControllerDialog( Controller * _model, QWidget * _parent
LfoControllerDialog::~LfoControllerDialog()
{
m_userWaveBtn->disconnect( this );
//delete m_subWindow;
}
void LfoControllerDialog::askUserDefWave()
{
SampleBuffer * sampleBuffer = dynamic_cast<LfoController*>(this->model())->
m_userDefSampleBuffer;
QString fileName = sampleBuffer->openAndSetAudioFile();
if( fileName.isEmpty() == false )
{
// TODO:
toolTip::add( m_userWaveBtn, sampleBuffer->audioFile() );
}
}
void LfoControllerDialog::contextMenuEvent( QContextMenuEvent * )
{
/*

View File

@@ -482,6 +482,25 @@ void graphModel::setWaveToNoise()
emit samplesChanged( 0, length() - 1 );
};
QString graphModel::setWaveToUser()
{
SampleBuffer * sampleBuffer = new SampleBuffer;
QString fileName = sampleBuffer->openAndSetAudioFile();
if( fileName.isEmpty() == false )
{
for( int i = 0; i < length(); i++ )
{
m_samples[i] = sampleBuffer->userWaveSample(
i / static_cast<float>( length() ) );
}
}
sharedObject::unref( sampleBuffer );
emit samplesChanged( 0, length() - 1 );
return fileName;
};
void graphModel::smooth()