-
Notifications
You must be signed in to change notification settings - Fork 173
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
Working on Implementation of Panning #1061
Changes from 2 commits
5703755
c908c32
83db742
617ffd3
f847974
60574be
e977d81
90bd8a5
f164f78
6e5cfbc
cf4f147
19329e7
c7dd952
f1cf556
093bb6a
7ecf62b
f606a60
2655e93
dad1cc0
99ae760
5089fab
98813cd
9b5a79b
e799a46
dc21783
07c7afc
bface81
11bb83f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -233,6 +233,29 @@ void Sampler::noteOff(Note* pNote ) | |
} | ||
|
||
|
||
/// functions for pan parameters and laws----------------- | ||
float Sampler::getRatioPan( float fPan_L, float fPan_R ) { | ||
// returns the single pan parameter in [-1,1] from the L,R gains | ||
// It doesn't return ERROR if (L,R) = (0,0) nor if they are negative!!!!! | ||
if ( fPan_L >= fPan_R ) { | ||
return fPan_R / fPan_L - 1.; | ||
} else { | ||
return 1. - fPan_L / fPan_R; | ||
} | ||
} | ||
|
||
//pan laws | ||
float Sampler::ratioStraightPolPanLaw( float fPan ) { | ||
// this return pan_L in the straight polygonal pan law, "ratio" pan parameter in [-1;1] | ||
// It doesn't return ERROR if p is out of [-1;1] !!!!! | ||
if ( fPan <= 0 ) { | ||
return 1.; | ||
} else { | ||
return ( 1. - fPan ); | ||
} | ||
} | ||
//------------------------------------------------------------------ | ||
|
||
/// Render a note | ||
/// Return false: the note is not ended | ||
/// Return true: the note is ended | ||
|
@@ -257,6 +280,30 @@ bool Sampler::renderNote( Note* pNote, unsigned nBufferSize, Song* pSong ) | |
return 1; | ||
} | ||
|
||
// new instrument and note pan interaction-------------------------- | ||
// note pan moves the pan in a smaller pan range centered at instrument pan | ||
|
||
// get the note and instrument pan parameters in [-1,1] | ||
// TODO a new song member, set in preferences, must point the desired pan parameter Sampler member function | ||
float (*getPan)( float, float ); | ||
// use "ratio" pan parameter (due to the current pan law) | ||
getPan = &this->getRatioPan; | ||
oddtime marked this conversation as resolved.
Show resolved
Hide resolved
|
||
float fNotePan = getPan( pNote->get_pan_l(), pNote->get_pan_r() ); | ||
float fInstrPan = getPan( pInstr->get_pan_l(), pInstr->get_pan_r() ); | ||
|
||
// resultant pan: note pan moves the pan in a smaller pan range centered at instrument pan | ||
float fPan = fInstrPan + fNotePan * ( 1 - fabs( fInstrPan ) ); | ||
oddtime marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Pass fResPan to the Pan Law | ||
// use Straight pol pan law. | ||
// TODO a new song member, set in preferences, must point the desired pan law Sampler member function | ||
float (*panLaw)( float ); | ||
panLaw = &this->ratioStraightPolPanLaw; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about making a single There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I preferred to use pointers to bypass the conditions checks and to go straight to the function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As the addresses of pan law methods depend on the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I see. But I would like to ask you to use switch-case or if statements nevertheless. It's not because I have a personal reference but the code base of Hydrogen does use the former over function pointers. It's more easy to maintain it if there is a consistent coding style. (Admittedly, the one we deal with is not the best but, well, it works. 😉 ) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand the reason. |
||
float a = 0.5; // max gain (it has been 0.5 until version 1.0) | ||
oddtime marked this conversation as resolved.
Show resolved
Hide resolved
|
||
float fPan_L = a * panLaw( fPan ); | ||
float fPan_R = a * panLaw( -fPan ); | ||
//--------------------------------------------------------- | ||
|
||
bool nReturnValues [pInstr->get_components()->size()]; | ||
|
||
for(int i = 0; i < pInstr->get_components()->size(); i++){ | ||
|
@@ -604,9 +651,12 @@ bool Sampler::renderNote( Note* pNote, unsigned nBufferSize, Song* pSong ) | |
cost_L = cost_L * pNote->get_velocity(); // note velocity | ||
cost_R = cost_R * pNote->get_velocity(); // note velocity | ||
} | ||
cost_L = cost_L * pNote->get_pan_l(); // note pan | ||
|
||
|
||
cost_L *= fPan_L; //pan | ||
//cost_L = cost_L * pNote->get_pan_l(); // note pan | ||
cost_L = cost_L * fLayerGain; // layer gain | ||
cost_L = cost_L * pInstr->get_pan_l(); // instrument pan | ||
//cost_L = cost_L * pInstr->get_pan_l(); // instrument pan | ||
cost_L = cost_L * pInstr->get_gain(); // instrument gain | ||
|
||
cost_L = cost_L * pCompo->get_gain(); // Component gain | ||
|
@@ -619,9 +669,10 @@ bool Sampler::renderNote( Note* pNote, unsigned nBufferSize, Song* pSong ) | |
cost_L = cost_L * pSong->get_volume(); // song volume | ||
cost_L = cost_L * 2; // max pan is 0.5 | ||
oddtime marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
cost_R = cost_R * pNote->get_pan_r(); // note pan | ||
cost_R *= fPan_R; // pan | ||
//cost_R = cost_R * pNote->get_pan_r(); // note pan | ||
cost_R = cost_R * fLayerGain; // layer gain | ||
cost_R = cost_R * pInstr->get_pan_r(); // instrument pan | ||
//cost_R = cost_R * pInstr->get_pan_r(); // instrument pan | ||
cost_R = cost_R * pInstr->get_gain(); // instrument gain | ||
|
||
cost_R = cost_R * pCompo->get_gain(); // Component gain | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the errors in those two functions: If there is no straight forward default value one can return/set, the C++ way of implementing errors would be an exception. But in Hydrogen it's almost never used (and introducing it would make the code most probably harder to maintain).
I would suggest to introduce these limits to
Instrument::set_pan
andNote::set_pan
instead. If > 0,0
will be assigned and a WARNINGLOG triggered and the same for 1 from above.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I keep it for the final version. please don't resolve this conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is already a check for negative pan:
In this way H2 one can set both pan_L = pan_R = 0. In this case there is a problem to reconvert back to the pan parameter. It could happen importing a bad song.