Skip to content

Commit

Permalink
better manage of GUI pan Law combobox items, add 3 quadratic pan laws
Browse files Browse the repository at this point in the history
  • Loading branch information
oddtime committed Jan 11, 2021
1 parent f164f78 commit 90624db
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 64 deletions.
22 changes: 22 additions & 0 deletions src/core/Sampler/Sampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ Sampler::Sampler()
m_panLawAddresses[ POLAR_STRAIGHT_POLYGONAL ] = &this->polarStraightPolygonalPanLaw;
m_panLawAddresses[ POLAR_CONST_POWER ] = &this->polarConstPowerPanLaw;
m_panLawAddresses[ POLAR_CONST_SUM ] = &this->polarConstSumPanLaw;
m_panLawAddresses[ QUADRATIC_STRAIGHT_POLYGONAL ] = &this->quadraticStraightPolygonalPanLaw;
m_panLawAddresses[ QUADRATIC_CONST_POWER ] = &this->quadraticConstPowerPanLaw;
m_panLawAddresses[ QUADRATIC_CONST_SUM ] = &this->quadraticConstSumPanLaw;
m_panLawAddresses[ LINEAR_CONST_K_NORM ] = &this->linearConstKNormPanLaw;
}

Expand Down Expand Up @@ -374,6 +377,25 @@ float Sampler::polarConstSumPanLaw( float fPan ) {
return cos( fTheta ) / ( cos( fTheta ) + sin( fTheta ) );
}

float Sampler::quadraticStraightPolygonalPanLaw( float fPan ) {
// the straight polygonal pan law interpreting fPan as the "quadratic" parameter
if ( fPan <= 0 ) {
return 1.;
} else {
return sqrt( ( 1. - fPan ) / ( 1. + fPan ) );
}
}

float Sampler::quadraticConstPowerPanLaw( float fPan ) {
// the constant power pan law interpreting fPan as the "quadratic" parameter
return sqrt( ( 1. - fPan ) * 0.5 );
}

float Sampler::quadraticConstSumPanLaw( float fPan ) {
// the constant Sum pan law interpreting fPan as the "quadratic" parameter
return sqrt( 1. - fPan ) / ( sqrt( 1. - fPan ) + sqrt( 1. + fPan ) );
}

float Sampler::linearConstKNormPanLaw( float fPan ) {
// the constant k norm pan law interpreting fPan as the "linear" parameter
Song* pSong = Hydrogen::get_instance()->getSong();
Expand Down
10 changes: 8 additions & 2 deletions src/core/Sampler/Sampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@
#define POLAR_STRAIGHT_POLYGONAL 6
#define POLAR_CONST_POWER 7
#define POLAR_CONST_SUM 8
#define LINEAR_CONST_K_NORM 9
#define QUADRATIC_STRAIGHT_POLYGONAL 9
#define QUADRATIC_CONST_POWER 10
#define QUADRATIC_CONST_SUM 11
#define LINEAR_CONST_K_NORM 12


/* define default k for pan law with -4.5dB center compensation, given L^k + R^k = const
Expand Down Expand Up @@ -141,8 +144,11 @@ class Sampler : public H2Core::Object
static float polarStraightPolygonalPanLaw( float fPan );
static float polarConstPowerPanLaw( float fPan );
static float polarConstSumPanLaw( float fPan );
static float quadraticStraightPolygonalPanLaw( float fPan );
static float quadraticConstPowerPanLaw( float fPan );
static float quadraticConstSumPanLaw( float fPan );
static float linearConstKNormPanLaw( float fPan );
float ( *m_panLawAddresses[10] ) ( float );
float ( *m_panLawAddresses[13] ) ( float );
float ( *getPanLawAddress( int idx ) ) ( float );

private:
Expand Down
38 changes: 27 additions & 11 deletions src/gui/src/PreferencesDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,24 +204,38 @@ PreferencesDialog::PreferencesDialog(QWidget* parent)
}

resampleComboBox->setCurrentIndex( (int) AudioEngine::get_instance()->get_sampler()->getInterpolateMode() );


// pan law
// insert the item here so they are consistent with sampler indices, no matter of their order in this menu
panLawComboBox->addItem( QString("Balance Law (0dB) - linear pan parameter"), QVariant( LINEAR_STRAIGHT_POLYGONAL ) );
panLawComboBox->addItem( QString("Constant Power (-3dB) - linear pan parameter"), QVariant( LINEAR_CONST_POWER ) );
panLawComboBox->addItem( QString("Constant Sum (-6dB) - linear pan parameter"), QVariant( LINEAR_CONST_SUM ) );
panLawComboBox->addItem( QString("Constant k-Norm (Custom dB compensation) - linear parameter"),
QVariant( LINEAR_CONST_K_NORM ) );
panLawComboBox->insertSeparator(100);
panLawComboBox->addItem( QString("Balance Law (0dB) - polar pan parameter"), QVariant( POLAR_STRAIGHT_POLYGONAL ) );
panLawComboBox->addItem( QString("Constant Power (-3dB) - polar pan parameter"), QVariant( POLAR_CONST_POWER ) );
panLawComboBox->addItem( QString("Constant Sum (-6dB) - polar pan parameter"), QVariant( POLAR_CONST_SUM ) );
panLawComboBox->insertSeparator(100);
panLawComboBox->addItem( QString("Balance Law (0dB) - ratio pan parameter"), QVariant( RATIO_STRAIGHT_POLYGONAL ) );
panLawComboBox->addItem( QString("Constant Power (-3dB) - ratio pan parameter"), QVariant( RATIO_CONST_POWER ) );
panLawComboBox->addItem( QString("Constant Sum (-6dB) - ratio pan parameter"), QVariant( RATIO_CONST_SUM ) );
panLawComboBox->insertSeparator(100);
panLawComboBox->addItem( QString("Balance Law (0dB) - quadratic pan parameter"), QVariant( QUADRATIC_STRAIGHT_POLYGONAL ) );
panLawComboBox->addItem( QString("Constant Power (-3dB) - quadratic pan parameter"), QVariant( QUADRATIC_CONST_POWER ) );
panLawComboBox->addItem( QString("Constant Sum (-6dB) - quadratic pan parameter"), QVariant( QUADRATIC_CONST_SUM ) );

Song* pSong = Hydrogen::get_instance()->getSong();
panLawComboBox->setCurrentIndex( pSong->getPanLawIdx() );
panLawComboBox->setCurrentIndex( panLawComboBox->findData( pSong->getPanLawIdx() ) );
panLawChanged(); // to hide dB SPL compensation
connect(panLawComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT( panLawChanged() ));

QValidator *validator = new QDoubleValidator( -10000., 0., 20, this );
dBCompensationLineEdit->setValidator( validator );

dBCompensationLineEdit->setText( QString( "%1" ).arg( -6.0206 / pSong->getPanLawKNorm() ) );

if ( panLawComboBox->currentIndex() == 9 ) {
dBCompensationLineEdit->show();
dBCompensationLbl->show();
} else {
dBCompensationLineEdit->hide();
dBCompensationLbl->hide();
}

// Appearance tab
QString applicationFamily = pPref->getApplicationFontFamily();
int applicationPointSize = pPref->getApplicationFontPointSize();
Expand Down Expand Up @@ -496,9 +510,10 @@ void PreferencesDialog::on_okBtn_clicked()
pPref->m_nSampleRate = 96000;
}


Song* pSong = Hydrogen::get_instance()->getSong();
pSong->setPanLawIdx( panLawComboBox->currentIndex() );
bool bOk;
pSong->setPanLawIdx( ( panLawComboBox->currentData() ).toInt( &bOk ) );
// allowing both point or comma decimal separator
float fdBCenterCompensation = ( dBCompensationLineEdit->text() ).replace( ",", "." ).toFloat( &bOk );
if ( !bOk ) { // this should never happen
Expand Down Expand Up @@ -1019,7 +1034,8 @@ void PreferencesDialog::toggleOscCheckBox(bool toggled)
}

void PreferencesDialog::panLawChanged(){
if ( panLawComboBox->currentIndex() == 9 ) {
bool bOk;
if ( ( panLawComboBox->currentData() ).toInt( &bOk) == LINEAR_CONST_K_NORM ) {
dBCompensationLineEdit->show();
dBCompensationLbl->show();
} else {
Expand Down
52 changes: 1 addition & 51 deletions src/gui/src/PreferencesDialog_UI.ui
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@
<rect>
<x>10</x>
<y>10</y>
<width>451</width>
<width>458</width>
<height>451</height>
</rect>
</property>
Expand Down Expand Up @@ -619,56 +619,6 @@
<height>16777215</height>
</size>
</property>
<item>
<property name="text">
<string>Balance Law (0dB) - ratio pan parameter</string>
</property>
</item>
<item>
<property name="text">
<string>Constant Power (-3dB) - ratio pan parameter</string>
</property>
</item>
<item>
<property name="text">
<string>Constant Sum (-6dB) - ratio pan parameter</string>
</property>
</item>
<item>
<property name="text">
<string>Balance Law - linear weighted pan parameter</string>
</property>
</item>
<item>
<property name="text">
<string>Constant Power - linear weighted pan parameter</string>
</property>
</item>
<item>
<property name="text">
<string>Constant Sum - linear weighted pan parameter</string>
</property>
</item>
<item>
<property name="text">
<string>Balance Law - polar pan parameter</string>
</property>
</item>
<item>
<property name="text">
<string>Constant Power - polar pan parameter</string>
</property>
</item>
<item>
<property name="text">
<string>Constant Sum - polar pan parameter</string>
</property>
</item>
<item>
<property name="text">
<string>Constant k-Norm (Custom dB compensation!) - linear parameter</string>
</property>
</item>
</widget>
</item>
<item row="0" column="0">
Expand Down

0 comments on commit 90624db

Please sign in to comment.