Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single pan parameter element deprecates pan_L, pan_R #1273

4 changes: 1 addition & 3 deletions src/core/AudioEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,6 @@ inline void AudioEngine::processPlayNotes( unsigned long nframes )
0.0,
0.0,
0.0,
0.0,
-1,
0 );
pOffNote->set_note_off( true );
Expand Down Expand Up @@ -1688,8 +1687,7 @@ inline int AudioEngine::updateNoteQueue( unsigned nFrames )
Note *pMetronomeNote = new Note( m_pMetronomeInstrument,
tick,
fVelocity,
0.5,
0.5,
0.f, // pan
-1,
fPitch
);
Expand Down
33 changes: 19 additions & 14 deletions src/core/Basics/Instrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <core/Basics/InstrumentList.h>
#include <core/Basics/InstrumentComponent.h>
#include <core/Basics/InstrumentLayer.h>
#include <core/Sampler/Sampler.h>

namespace H2Core
{
Expand All @@ -48,8 +49,7 @@ Instrument::Instrument( const int id, const QString& name, std::shared_ptr<ADSR>
, __name( name )
, __gain( 1.0 )
, __volume( 1.0 )
, __pan_l( 1.0 )
, __pan_r( 1.0 )
, m_fPan( 0.f )
, __peak_l( 0.0 )
, __peak_r( 0.0 )
, __adsr( adsr )
Expand Down Expand Up @@ -101,8 +101,7 @@ Instrument::Instrument( std::shared_ptr<Instrument> other )
, __name( other->get_name() )
, __gain( other->__gain )
, __volume( other->get_volume() )
, __pan_l( other->get_pan_l() )
, __pan_r( other->get_pan_r() )
, m_fPan( other->getPan() )
, __peak_l( other->get_peak_l() )
, __peak_r( other->get_peak_r() )
, __adsr( std::make_shared<ADSR>( *( other->get_adsr() ) ) )
Expand Down Expand Up @@ -221,8 +220,7 @@ void Instrument::load_from( Drumkit* pDrumkit, std::shared_ptr<Instrument> pInst
this->set_drumkit_name( pDrumkit->get_name() );
this->set_gain( pInstrument->get_gain() );
this->set_volume( pInstrument->get_volume() );
this->set_pan_l( pInstrument->get_pan_l() );
this->set_pan_r( pInstrument->get_pan_r() );
this->setPan( pInstrument->getPan() );
this->set_adsr( std::make_shared<ADSR>( *( pInstrument->get_adsr() ) ) );
this->set_filter_active( pInstrument->is_filter_active() );
this->set_filter_cutoff( pInstrument->get_filter_cutoff() );
Expand Down Expand Up @@ -273,8 +271,18 @@ std::shared_ptr<Instrument> Instrument::load_from( XMLNode* node, const QString&
pInstrument->set_drumkit_name( dk_name );
pInstrument->set_volume( node->read_float( "volume", 1.0f ) );
pInstrument->set_muted( node->read_bool( "isMuted", false ) );
pInstrument->set_pan_l( node->read_float( "pan_L", 1.0f ) );
pInstrument->set_pan_r( node->read_float( "pan_R", 1.0f ) );
bool bFound, bFound2;
float fPan = node->read_float( "pan", 0.f, &bFound );
if ( !bFound ) {
// check if pan is expressed in the old fashion (version <= 1.1 ) with the pair (pan_L, pan_R)
float fPanL = node->read_float( "pan_L", 1.f, &bFound );
float fPanR = node->read_float( "pan_R", 1.f, &bFound2 );
if ( bFound == true && bFound2 == true ) { // found nodes pan_L and pan_R
fPan = Sampler::getRatioPan( fPanL, fPanR ); // convert to single pan parameter
}
}
pInstrument->setPan( fPan );

// may not exist, but can't be empty
pInstrument->set_apply_velocity( node->read_bool( "applyVelocity", true, false ) );
pInstrument->set_filter_active( node->read_bool( "filterActive", true, false ) );
Expand Down Expand Up @@ -352,8 +360,7 @@ void Instrument::save_to( XMLNode* node, int component_id )
InstrumentNode.write_float( "volume", __volume );
InstrumentNode.write_bool( "isMuted", __muted );
InstrumentNode.write_bool( "isSoloed", __soloed );
InstrumentNode.write_float( "pan_L", __pan_l );
InstrumentNode.write_float( "pan_R", __pan_r );
InstrumentNode.write_float( "pan", m_fPan );
InstrumentNode.write_float( "pitchOffset", __pitch_offset );
InstrumentNode.write_float( "randomPitchFactor", __random_pitch_factor );
InstrumentNode.write_float( "gain", __gain );
Expand Down Expand Up @@ -422,8 +429,7 @@ QString Instrument::toQString( const QString& sPrefix, bool bShort ) const {
.append( QString( "%1%2drumkit_name: %3\n" ).arg( sPrefix ).arg( s ).arg( __drumkit_name ) )
.append( QString( "%1%2gain: %3\n" ).arg( sPrefix ).arg( s ).arg( __gain ) )
.append( QString( "%1%2volume: %3\n" ).arg( sPrefix ).arg( s ).arg( __volume ) )
.append( QString( "%1%2pan_l: %3\n" ).arg( sPrefix ).arg( s ).arg( __pan_l ) )
.append( QString( "%1%2pan_r: %3\n" ).arg( sPrefix ).arg( s ).arg( __pan_r ) )
.append( QString( "%1%2pan: %3\n" ).arg( sPrefix ).arg( s ).arg( m_fPan ) )
.append( QString( "%1%2peak_l: %3\n" ).arg( sPrefix ).arg( s ).arg( __peak_l ) )
.append( QString( "%1%2peak_r: %3\n" ).arg( sPrefix ).arg( s ).arg( __peak_r ) )
.append( QString( "%1" ).arg( __adsr->toQString( sPrefix + s, bShort ) ) )
Expand Down Expand Up @@ -468,8 +474,7 @@ QString Instrument::toQString( const QString& sPrefix, bool bShort ) const {
.append( QString( ", drumkit_name: %1" ).arg( __drumkit_name ) )
.append( QString( ", gain: %1" ).arg( __gain ) )
.append( QString( ", volume: %1" ).arg( __volume ) )
.append( QString( ", pan_l: %1" ).arg( __pan_l ) )
.append( QString( ", pan_r: %1" ).arg( __pan_r ) )
.append( QString( ", pan: %1" ).arg( m_fPan ) )
.append( QString( ", peak_l: %1" ).arg( __peak_l ) )
.append( QString( ", peak_r: %1" ).arg( __peak_r ) )
.append( QString( ", [%1" ).arg( __adsr->toQString( sPrefix + s, bShort ).replace( "\n", "]" ) ) )
Expand Down
47 changes: 23 additions & 24 deletions src/core/Basics/Instrument.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,19 @@ class Instrument : public H2Core::Object
/** get muted status of the instrument */
bool is_muted() const;

/** set left pan of the instrument */
void set_pan_l( float val );
/** get left pan of the instrument */
float get_pan_l() const;
/** set pan of the instrument */
void setPan( float val );
/** set pan of the instrument, assuming the input range in [0;1] */
void setPanWithRangeFrom0To1( float fVal ) {
this->setPan( -1.f + 2.f * fVal ); // scale and translate into [-1;1]
};
/** get pan of the instrument */
float getPan() const;
/** get pan of the instrument scaling and translating the range from [-1;1] to [0;1] */
float getPanWithRangeFrom0To1() const {
return 0.5f * ( 1.f + m_fPan );
}

/** set right pan of the instrument */
void set_pan_r( float val );
/** get right pan of the instrument */
float get_pan_r() const;

/** set gain of the instrument */
void set_gain( float gain );
Expand Down Expand Up @@ -302,8 +306,7 @@ class Instrument : public H2Core::Object
QString __drumkit_name; ///< the name of the drumkit this instrument belongs to
float __gain; ///< gain of the instrument
float __volume; ///< volume of the instrument
float __pan_l; ///< left pan of the instrument
float __pan_r; ///< right pan of the instrument
float m_fPan; ///< pan of the instrument, [-1;1] from left to right, as requested by Sampler PanLaws
float __peak_l; ///< left current peak value
float __peak_r; ///< right current peak value
std::shared_ptr<ADSR> __adsr; ///< attack delay sustain release instance
Expand Down Expand Up @@ -417,24 +420,20 @@ inline bool Instrument::is_muted() const
return __muted;
}

inline void Instrument::set_pan_l( float val )
inline void Instrument::setPan( float val ) //TODO check boundary factorize function?
{
__pan_l = val;
}

inline float Instrument::get_pan_l() const
{
return __pan_l;
}

inline void Instrument::set_pan_r( float val )
{
__pan_r = val;
if ( val > 1.0 ) {
m_fPan = 1.0;
} else if ( val < -1.0 ) {
m_fPan = -1.0;
} else {
m_fPan = val;
}
}

inline float Instrument::get_pan_r() const
inline float Instrument::getPan() const
{
return __pan_r;
return m_fPan;
}

inline void Instrument::set_gain( float gain )
Expand Down
54 changes: 26 additions & 28 deletions src/core/Basics/Note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,21 @@
#include <core/Basics/Instrument.h>
#include <core/Basics/InstrumentComponent.h>
#include <core/Basics/InstrumentList.h>
#include <core/Sampler/Sampler.h>

namespace H2Core
{

const char* Note::__class_name = "Note";
const char* Note::__key_str[] = { "C", "Cs", "D", "Ef", "E", "F", "Fs", "G", "Af", "A", "Bf", "B" };

Note::Note( std::shared_ptr<Instrument> instrument, int position, float velocity, float pan_l, float pan_r, int length, float pitch )
Note::Note( std::shared_ptr<Instrument> instrument, int position, float velocity, float pan, int length, float pitch )
: Object( __class_name ),
__instrument( instrument ),
__instrument_id( 0 ),
__specific_compo_id( -1 ),
__position( position ),
__velocity( velocity ),
__pan_l( PAN_MAX ),
__pan_r( PAN_MAX ),
__length( length ),
__pitch( pitch ),
__key( C ),
Expand Down Expand Up @@ -79,8 +78,7 @@ Note::Note( std::shared_ptr<Instrument> instrument, int position, float velocity
}
}

set_pan_l(pan_l);
set_pan_r(pan_r);
setPan( pan ); // this checks the boundaries
}

Note::Note( Note* other, std::shared_ptr<Instrument> instrument )
Expand All @@ -90,8 +88,7 @@ Note::Note( Note* other, std::shared_ptr<Instrument> instrument )
__specific_compo_id( -1 ),
__position( other->get_position() ),
__velocity( other->get_velocity() ),
__pan_l( other->get_pan_l() ),
__pan_r( other->get_pan_r() ),
m_fPan( other->getPan() ),
__length( other->get_length() ),
__pitch( other->get_pitch() ),
__key( other->get_key() ),
Expand Down Expand Up @@ -147,14 +144,8 @@ void Note::set_lead_lag( float lead_lag )
__lead_lag = check_boundary( lead_lag, LEAD_LAG_MIN, LEAD_LAG_MAX );
}

void Note::set_pan_l( float pan )
{
__pan_l = check_boundary( pan, PAN_MIN, PAN_MAX );
}

void Note::set_pan_r( float pan )
{
__pan_r = check_boundary( pan, PAN_MIN, PAN_MAX );
void Note::setPan( float val ) {
m_fPan = check_boundary( val, -1.0f, 1.0f );
}

void Note::map_instrument( InstrumentList* instruments )
Expand Down Expand Up @@ -210,8 +201,7 @@ void Note::save_to( XMLNode* node )
node->write_int( "position", __position );
node->write_float( "leadlag", __lead_lag );
node->write_float( "velocity", __velocity );
node->write_float( "pan_L", __pan_l );
node->write_float( "pan_R", __pan_r );
node->write_float( "pan", m_fPan );
node->write_float( "pitch", __pitch );
node->write_string( "key", key_to_string() );
node->write_int( "length", __length );
Expand All @@ -222,14 +212,24 @@ void Note::save_to( XMLNode* node )

Note* Note::load_from( XMLNode* node, InstrumentList* instruments )
{
bool bFound, bFound2;
float fPan = node->read_float( "pan", 0.f, &bFound );
if ( !bFound ) {
// check if pan is expressed in the old fashion (version <= 1.1 ) with the pair (pan_L, pan_R)
float fPanL = node->read_float( "pan_L", 1.f, &bFound );
float fPanR = node->read_float( "pan_R", 1.f, &bFound2 );
if ( bFound == true && bFound2 == true ) { // found nodes pan_L and pan_R
fPan = Sampler::getRatioPan( fPanL, fPanR ); // convert to single pan parameter
}
}

Note* note = new Note(
nullptr,
node->read_int( "position", 0 ),
node->read_float( "velocity", 0.8f ),
node->read_float( "pan_L", 0.5f ),
node->read_float( "pan_R", 0.5f ),
node->read_int( "length", -1 ),
node->read_float( "pitch", 0.0f )
nullptr,
node->read_int( "position", 0 ),
node->read_float( "velocity", 0.8f ),
fPan,
node->read_int( "length", -1 ),
node->read_float( "pitch", 0.0f )
);
note->set_lead_lag( node->read_float( "leadlag", 0, false, false ) );
note->set_key_octave( node->read_string( "key", "C0", false, false ) );
Expand All @@ -250,8 +250,7 @@ QString Note::toQString( const QString& sPrefix, bool bShort ) const {
.append( QString( "%1%2specific_compo_id: %3\n" ).arg( sPrefix ).arg( s ).arg( __specific_compo_id ) )
.append( QString( "%1%2position: %3\n" ).arg( sPrefix ).arg( s ).arg( __position ) )
.append( QString( "%1%2velocity: %3\n" ).arg( sPrefix ).arg( s ).arg( __velocity ) )
.append( QString( "%1%2pan_l: %3\n" ).arg( sPrefix ).arg( s ).arg( __pan_l ) )
.append( QString( "%1%2pan_r: %3\n" ).arg( sPrefix ).arg( s ).arg( __pan_r ) )
.append( QString( "%1%2pan: %3\n" ).arg( sPrefix ).arg( s ).arg( m_fPan ) )
.append( QString( "%1%2length: %3\n" ).arg( sPrefix ).arg( s ).arg( __length ) )
.append( QString( "%1%2pitch: %3\n" ).arg( sPrefix ).arg( s ).arg( __pitch ) )
.append( QString( "%1%2key: %3\n" ).arg( sPrefix ).arg( s ).arg( __key ) )
Expand Down Expand Up @@ -288,8 +287,7 @@ QString Note::toQString( const QString& sPrefix, bool bShort ) const {
.append( QString( ", specific_compo_id: %1" ).arg( __specific_compo_id ) )
.append( QString( ", position: %1" ).arg( __position ) )
.append( QString( ", velocity: %1" ).arg( __velocity ) )
.append( QString( ", pan_l: %1" ).arg( __pan_l ) )
.append( QString( ", pan_r: %1" ).arg( __pan_r ) )
.append( QString( ", pan: %1" ).arg( m_fPan ) )
.append( QString( ", length: %1" ).arg( __length ) )
.append( QString( ", pitch: %1" ).arg( __pitch ) )
.append( QString( ", key: %1" ).arg( __key ) )
Expand Down
42 changes: 18 additions & 24 deletions src/core/Basics/Note.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class Note : public H2Core::Object
* \param length it's length
* \param pitch it's pitch
*/
Note( std::shared_ptr<Instrument> instrument, int position, float velocity, float pan_l, float pan_r, int length, float pitch );
Note( std::shared_ptr<Instrument> instrument, int position, float velocity, float pan, int length, float pitch );

/**
* copy constructor with an optional parameter
Expand Down Expand Up @@ -148,20 +148,20 @@ class Note : public H2Core::Object
void set_velocity( float value );
/** #__velocity accessor */
float get_velocity() const;
/**
* #__pan_l setter
* \param value the new value
*/
void set_pan_l( float value );
/** #__pan_l accessor */
float get_pan_l() const;
/**
* #__pan_r setter
* \param value the new value
*/
void set_pan_r( float value );
/** #__pan_r accessor */
float get_pan_r() const;

/** set pan of the note. assumes the input range in [-1;1]*/
void setPan( float val );
/** set pan of the note, assuming the input range in [0;1] */
void setPanWithRangeFrom0To1( float fVal ) {
this->setPan( -1.f + 2.f * fVal ); // scale and translate into [-1;1]
};
/** get pan of the note. Output pan range: [-1;1] */
float getPan() const;
/** get pan of the note, scaling and translating the range from [-1;1] to [0;1] */
float getPanWithRangeFrom0To1() const {
return 0.5f * ( 1.f + m_fPan );
}

/**
* #__lead_lag setter
* \param value the new value
Expand Down Expand Up @@ -317,8 +317,7 @@ class Note : public H2Core::Object
int __specific_compo_id; ///< play a specific component, -1 if playing all
int __position; ///< note position inside the pattern
float __velocity; ///< velocity (intensity) of the note [0;1]
float __pan_l; ///< pan of the note (left volume) [0;0.5]
float __pan_r; ///< pan of the note (right volume) [0;0.5]
float m_fPan; ///< pan of the note, [-1;1] from left to right, as requested by Sampler PanLaws
int __length; ///< the length of the note
float __pitch; ///< the frequency of the note
Key __key; ///< the key, [0;11]==[C;B]
Expand Down Expand Up @@ -393,14 +392,9 @@ inline float Note::get_velocity() const
return __velocity;
}

inline float Note::get_pan_l() const
{
return __pan_l;
}

inline float Note::get_pan_r() const
inline float Note::getPan() const
{
return __pan_r;
return m_fPan;
}

inline float Note::get_lead_lag() const
Expand Down
Loading