Skip to content

Commit

Permalink
Merge pull request #1061 from oddtime/panning
Browse files Browse the repository at this point in the history
Working on Implementation of Panning
  • Loading branch information
theGreatWhiteShark authored Feb 2, 2021
2 parents 3cbfe5b + 11bb83f commit fdb5bfb
Show file tree
Hide file tree
Showing 15 changed files with 905 additions and 36 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Deprecating JACK-session
* Instrument main pitch shift offset
* Custom pattern size support with representation in note values
* Custom pan law support in mixer

2020-08-03 the hydrogen team <[email protected]>
* Release 1.0
Expand Down
Binary file added data/img/gray/mixerPanel/openMixerSettings_off.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/img/gray/mixerPanel/openMixerSettings_over.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 58 additions & 1 deletion src/core/Basics/Song.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include <core/Helpers/Xml.h>
#include <core/Helpers/Filesystem.h>
#include <core/Hydrogen.h>
#include <core/Sampler/Sampler.h>

#ifdef H2CORE_HAVE_OSC
#include <core/NsmClient.h>
Expand Down Expand Up @@ -90,7 +91,8 @@ Song::Song( const QString& sName, const QString& sAuthor, float fBpm, float fVol
, m_pVelocityAutomationPath( nullptr )
, m_sLicense( "" )
, m_actionMode( ActionMode::selectMode )

, m_nPanLawType ( Sampler::RATIO_STRAIGHT_POLYGONAL )
, m_fPanLawKNorm ( Sampler::K_NORM_DEFAULT )
{
INFOLOG( QString( "INIT '%1'" ).arg( sName ) );

Expand Down Expand Up @@ -645,6 +647,15 @@ const QString SongReader::getPath ( const QString& sFilename ) const
return nullptr;
}

void Song::setPanLawKNorm( float fKNorm ) {
if ( fKNorm >= 0. ) {
m_fPanLawKNorm = fKNorm;
} else {
WARNINGLOG("negative kNorm. Set default" );
m_fPanLawKNorm = Sampler::K_NORM_DEFAULT;
}
}

///
/// Reads a song.
/// return nullptr = error reading song file.
Expand Down Expand Up @@ -725,6 +736,52 @@ Song* SongReader::readSong( const QString& sFileName )
pSong->setPlaybackTrackEnabled( bPlaybackTrackEnabled );
pSong->setPlaybackTrackVolume( fPlaybackTrackVolume );
pSong->setActionMode( actionMode );

// pan law
QString sPanLawType( LocalFileMng::readXmlString( songNode, "pan_law_type", "RATIO_STRAIGHT_POLYGONAL" ) );
if ( sPanLawType == "RATIO_STRAIGHT_POLYGONAL" ) {
pSong->setPanLawType( Sampler::RATIO_STRAIGHT_POLYGONAL );
} else if ( sPanLawType == "RATIO_CONST_POWER" ) {
pSong->setPanLawType( Sampler::RATIO_CONST_POWER );
} else if ( sPanLawType == "RATIO_CONST_SUM" ) {
pSong->setPanLawType( Sampler::RATIO_CONST_SUM );
} else if ( sPanLawType == "LINEAR_STRAIGHT_POLYGONAL" ) {
pSong->setPanLawType( Sampler::LINEAR_STRAIGHT_POLYGONAL );
} else if ( sPanLawType == "LINEAR_CONST_POWER" ) {
pSong->setPanLawType( Sampler::LINEAR_CONST_POWER );
} else if ( sPanLawType == "LINEAR_CONST_SUM" ) {
pSong->setPanLawType( Sampler::LINEAR_CONST_SUM );
} else if ( sPanLawType == "POLAR_STRAIGHT_POLYGONAL" ) {
pSong->setPanLawType( Sampler::POLAR_STRAIGHT_POLYGONAL );
} else if ( sPanLawType == "POLAR_CONST_POWER" ) {
pSong->setPanLawType( Sampler::POLAR_CONST_POWER );
} else if ( sPanLawType == "POLAR_CONST_SUM" ) {
pSong->setPanLawType( Sampler::POLAR_CONST_SUM );
} else if ( sPanLawType == "QUADRATIC_STRAIGHT_POLYGONAL" ) {
pSong->setPanLawType( Sampler::QUADRATIC_STRAIGHT_POLYGONAL );
} else if ( sPanLawType == "QUADRATIC_CONST_POWER" ) {
pSong->setPanLawType( Sampler::QUADRATIC_CONST_POWER );
} else if ( sPanLawType == "QUADRATIC_CONST_SUM" ) {
pSong->setPanLawType( Sampler::QUADRATIC_CONST_SUM );
} else if ( sPanLawType == "LINEAR_CONST_K_NORM" ) {
pSong->setPanLawType( Sampler::LINEAR_CONST_K_NORM );
} else if ( sPanLawType == "POLAR_CONST_K_NORM" ) {
pSong->setPanLawType( Sampler::POLAR_CONST_K_NORM );
} else if ( sPanLawType == "RATIO_CONST_K_NORM" ) {
pSong->setPanLawType( Sampler::RATIO_CONST_K_NORM );
} else if ( sPanLawType == "QUADRATIC_CONST_K_NORM" ) {
pSong->setPanLawType( Sampler::QUADRATIC_CONST_K_NORM );
} else {
pSong->setPanLawType( Sampler::RATIO_STRAIGHT_POLYGONAL );
WARNINGLOG( "Unknown pan law type in import song. Set default." );
}

float fPanLawKNorm = LocalFileMng::readXmlFloat( songNode, "pan_law_k_norm", Sampler::K_NORM_DEFAULT );
if ( fPanLawKNorm <= 0.0 ) {
fPanLawKNorm = Sampler::K_NORM_DEFAULT;
WARNINGLOG( "Invalid pan law k in import song (<= 0). Set default k." );
}
pSong->setPanLawKNorm( fPanLawKNorm );

QDomNode componentListNode = songNode.firstChildElement( "componentList" );
if ( ( ! componentListNode.isNull() ) ) {
Expand Down
21 changes: 21 additions & 0 deletions src/core/Basics/Song.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ class Song : public H2Core::Object
*/
bool hasMissingSamples() const;
void clearMissingSamples();

void setPanLawType( int nPanLawType );
int getPanLawType() const;
void setPanLawKNorm( float fKNorm );
float getPanLawKNorm() const;

private:

Expand Down Expand Up @@ -273,6 +278,10 @@ class Song : public H2Core::Object

/** Stores the type of interaction with the SongEditor. */
ActionMode m_actionMode;

int m_nPanLawType;
// k such that L^k+R^k = 1. Used in constant k-Norm pan law
float m_fPanLawKNorm;

};

Expand Down Expand Up @@ -516,6 +525,18 @@ inline Song::ActionMode Song::getActionMode() const {
return m_actionMode;
}

inline void Song::setPanLawType( int nPanLawType ) {
m_nPanLawType = nPanLawType;
}

inline int Song::getPanLawType() const {
return m_nPanLawType;
}

inline float Song::getPanLawKNorm() const {
return m_fPanLawKNorm;
}

/**
\ingroup H2CORE
\brief Read XML file of a song
Expand Down
44 changes: 44 additions & 0 deletions src/core/LocalFileMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,50 @@ int SongWriter::writeSong( Song * pSong, const QString& filename )
LocalFileMng::writeXmlString( songNode, "mode", QString( "pattern" ) );
}

Sampler* pSampler = AudioEngine::get_instance()->get_sampler();

QString sPanLawType; // prepare the pan law string to write
int nPanLawType = pSong->getPanLawType();
if ( nPanLawType == Sampler::RATIO_STRAIGHT_POLYGONAL ) {
sPanLawType = "RATIO_STRAIGHT_POLYGONAL";
} else if ( nPanLawType == Sampler::RATIO_CONST_POWER ) {
sPanLawType = "RATIO_CONST_POWER";
} else if ( nPanLawType == Sampler::RATIO_CONST_SUM ) {
sPanLawType = "RATIO_CONST_SUM";
} else if ( nPanLawType == Sampler::LINEAR_STRAIGHT_POLYGONAL ) {
sPanLawType = "LINEAR_STRAIGHT_POLYGONAL";
} else if ( nPanLawType == Sampler::LINEAR_CONST_POWER ) {
sPanLawType = "LINEAR_CONST_POWER";
} else if ( nPanLawType == Sampler::LINEAR_CONST_SUM ) {
sPanLawType = "LINEAR_CONST_SUM";
} else if ( nPanLawType == Sampler::POLAR_STRAIGHT_POLYGONAL ) {
sPanLawType = "POLAR_STRAIGHT_POLYGONAL";
} else if ( nPanLawType == Sampler::POLAR_CONST_POWER ) {
sPanLawType = "POLAR_CONST_POWER";
} else if ( nPanLawType == Sampler::POLAR_CONST_SUM ) {
sPanLawType = "POLAR_CONST_SUM";
} else if ( nPanLawType == Sampler::QUADRATIC_STRAIGHT_POLYGONAL ) {
sPanLawType = "QUADRATIC_STRAIGHT_POLYGONAL";
} else if ( nPanLawType == Sampler::QUADRATIC_CONST_POWER ) {
sPanLawType = "QUADRATIC_CONST_POWER";
} else if ( nPanLawType == Sampler::QUADRATIC_CONST_SUM ) {
sPanLawType = "QUADRATIC_CONST_SUM";
} else if ( nPanLawType == Sampler::LINEAR_CONST_K_NORM ) {
sPanLawType = "LINEAR_CONST_K_NORM";
} else if ( nPanLawType == Sampler::POLAR_CONST_K_NORM ) {
sPanLawType = "POLAR_CONST_K_NORM";
} else if ( nPanLawType == Sampler::RATIO_CONST_K_NORM ) {
sPanLawType = "RATIO_CONST_K_NORM";
} else if ( nPanLawType == Sampler::QUADRATIC_CONST_K_NORM ) {
sPanLawType = "QUADRATIC_CONST_K_NORM";
} else {
WARNINGLOG( "Unknown pan law in saving song. Saved default type." );
sPanLawType = "RATIO_STRAIGHT_POLYGONAL";
}
// write the pan law string in file
LocalFileMng::writeXmlString( songNode, "pan_law_type", sPanLawType );
LocalFileMng::writeXmlString( songNode, "pan_law_k_norm", QString("%1").arg( pSong->getPanLawKNorm() ) );

LocalFileMng::writeXmlString( songNode, "humanize_time", QString("%1").arg( pSong->getHumanizeTimeValue() ) );
LocalFileMng::writeXmlString( songNode, "humanize_velocity", QString("%1").arg( pSong->getHumanizeVelocityValue() ) );
LocalFileMng::writeXmlString( songNode, "swing_factor", QString("%1").arg( pSong->getSwingFactor() ) );
Expand Down
Loading

0 comments on commit fdb5bfb

Please sign in to comment.