Can you use If statements within the curve function ?
I'm trying to create a linear curve that cuts to zero at a certain value with
if $x < 9363 {$y = $x} else {$y = 0}
but it draws a full linear curve regardless
And then likewise (in another file to generate a second curve)
if $x > 9363 {$y = $x} else {$y = 0}
Ta
Curve Generator: Newbie
- NightRadio
- Site Admin
- Posts: 3955
- Joined: Fri Jan 23, 2004 12:28 am
- Location: Ekaterinburg. Russia
- Contact:
Re: Curve Generator: Newbie
Yes. Please show full code of your fn curve_function( $x )Can you use If statements within the curve function ?
Re: Curve Generator: Newbie
Thanks:
fn curve_function( $x )
{
if $x < 9362 {$y = $x} else {$y = 0}
//Linear:
//$y = $x
//Linear with a limited number of levels:
//$levels = 8 ; $y = ( $x / (1/$levels) div 1 ) * (1/($levels-1))
//Sine variations:
//$y = sin( $x * M_PI * 2 ) / 2 + 0.5
//$y = sin( $x * M_PI )
//$y = -sin( $x * M_PI + M_PI/2 ) / 2 + 0.5
//Random:
//$y = rand() / 32768
//Exponential curves:
//$y = pow( $x, 3 )
//$y = pow( $x, 6 ) //Exponential+
//$y = pow( $x, 0.5 ) //...
//Something between the linear and the exponential curve:
//$y = $x * $x + pow( $x, 3 ) * ( 1 - $x )
//Pitch Curves:
//Normal scale:
//$y = note0 + semitone * $x
//Reverse scale:
//$y = note0 + semitone * ( 128 - $x )
//Diatonic scale (major):
//$y = note0 + semitone * remap_note( $x, "CCDDEFFGGAAB" )
//Harmonic major scale:
//$y = note0 + semitone * remap_note( $x, "CCDDEFFGgggB" )
//Melodic major scale:
//$y = note0 + semitone * remap_note( $x, "CCDDEFFGggaa" )
//Double harmonic major scale:
//$y = note0 + semitone * remap_note( $x, "CcccEFFGgggB" )
//Minor scale:
//$y = note0 + semitone * remap_note( $x, "CCDddFFGggaa" )
//Whole tone scale (six-note)
//$y = note0 + semitone * ( $x div 2 * 2 )
//Minor pentatonic:
//$y = note0 + semitone * remap_note( $x, "CCddFFFGGaaa" )
//Major pentatonic:
//$y = note0 + semitone * remap_note( $x, "CCDDEEEGGAAA" )
//Custom tuning (you can set the offset in cents):
/*
$y = note0 + semitone * tuning_cents_offset( $x,
//example: Standard Just (1529)
15.64, //C
-13.69, //c
-1.95, //D
31.28, //d
1.96, //E
13.69, //F
-15.64, //f
17.6, //G
-11.73, //g
0, //A
11.73, //a
3.91 //B
)
*/
//Tuning from the file with a list of frequencies (in Hz, frequency per line):
//if freq_list <= 0 { freq_list = load_list( "freq_series.txt" ) } ; $y = freq_to_pitch( freq_list[ $x ] )
//Equal temperament (ET):
/*
$tones_per_octave = 96;
$note_shift = 0 //the note coinciding with C0 (note 0) in the default 12-TET scale
$pitch_shift = semitone * 12 * 4;
$y = note0 + $pitch_shift + semitone * 12 / $tones_per_octave * ( $x - $note_shift )
*/
ret( $y )
One thing that puzzles me is that the comments at the start of the file say:
1) change the SETUP section:
filename = "file name for your curve";
format =
0 - MultiSynth curve1;
1 - MultiSynth curve2;
2 - MultiSynth curve3;
4 - WaveShaper;
5 - MultiCtl.
But the if format== statements only go up to 4 but 4 is, I think, for multictl so I've set it for that - I have generated other curves with it set for that also.
fn curve_function( $x )
{
if $x < 9362 {$y = $x} else {$y = 0}
//Linear:
//$y = $x
//Linear with a limited number of levels:
//$levels = 8 ; $y = ( $x / (1/$levels) div 1 ) * (1/($levels-1))
//Sine variations:
//$y = sin( $x * M_PI * 2 ) / 2 + 0.5
//$y = sin( $x * M_PI )
//$y = -sin( $x * M_PI + M_PI/2 ) / 2 + 0.5
//Random:
//$y = rand() / 32768
//Exponential curves:
//$y = pow( $x, 3 )
//$y = pow( $x, 6 ) //Exponential+
//$y = pow( $x, 0.5 ) //...
//Something between the linear and the exponential curve:
//$y = $x * $x + pow( $x, 3 ) * ( 1 - $x )
//Pitch Curves:
//Normal scale:
//$y = note0 + semitone * $x
//Reverse scale:
//$y = note0 + semitone * ( 128 - $x )
//Diatonic scale (major):
//$y = note0 + semitone * remap_note( $x, "CCDDEFFGGAAB" )
//Harmonic major scale:
//$y = note0 + semitone * remap_note( $x, "CCDDEFFGgggB" )
//Melodic major scale:
//$y = note0 + semitone * remap_note( $x, "CCDDEFFGggaa" )
//Double harmonic major scale:
//$y = note0 + semitone * remap_note( $x, "CcccEFFGgggB" )
//Minor scale:
//$y = note0 + semitone * remap_note( $x, "CCDddFFGggaa" )
//Whole tone scale (six-note)
//$y = note0 + semitone * ( $x div 2 * 2 )
//Minor pentatonic:
//$y = note0 + semitone * remap_note( $x, "CCddFFFGGaaa" )
//Major pentatonic:
//$y = note0 + semitone * remap_note( $x, "CCDDEEEGGAAA" )
//Custom tuning (you can set the offset in cents):
/*
$y = note0 + semitone * tuning_cents_offset( $x,
//example: Standard Just (1529)
15.64, //C
-13.69, //c
-1.95, //D
31.28, //d
1.96, //E
13.69, //F
-15.64, //f
17.6, //G
-11.73, //g
0, //A
11.73, //a
3.91 //B
)
*/
//Tuning from the file with a list of frequencies (in Hz, frequency per line):
//if freq_list <= 0 { freq_list = load_list( "freq_series.txt" ) } ; $y = freq_to_pitch( freq_list[ $x ] )
//Equal temperament (ET):
/*
$tones_per_octave = 96;
$note_shift = 0 //the note coinciding with C0 (note 0) in the default 12-TET scale
$pitch_shift = semitone * 12 * 4;
$y = note0 + $pitch_shift + semitone * 12 / $tones_per_octave * ( $x - $note_shift )
*/
ret( $y )
One thing that puzzles me is that the comments at the start of the file say:
1) change the SETUP section:
filename = "file name for your curve";
format =
0 - MultiSynth curve1;
1 - MultiSynth curve2;
2 - MultiSynth curve3;
4 - WaveShaper;
5 - MultiCtl.
But the if format== statements only go up to 4 but 4 is, I think, for multictl so I've set it for that - I have generated other curves with it set for that also.
- NightRadio
- Site Admin
- Posts: 3955
- Joined: Fri Jan 23, 2004 12:28 am
- Location: Ekaterinburg. Russia
- Contact:
Re: Curve Generator: Newbie
Please don't forget about the $x and $y ranges. See the comments before fn curve_function( $x ):if $x < 9362 {$y = $x} else {$y = 0}
Code: Select all
//$x = 0...1.0 or 0,1,2,3...127 (note) for MultiSynth Pitch Curve3
//$y = 0...1.0 or 0...65535 (pitch) for MultiSynth Pitch Curve3
You need something like if $x < 0.5 {$y = $x} else {$y = 0}
Thanks for noticing! Of course it's a mistake.One thing that puzzles me is that the comments at the start of the file say:
Here are the correct values:
Code: Select all
format =
0 - MultiSynth curve1;
1 - MultiSynth curve2;
2 - MultiSynth curve3;
3 - WaveShaper;
4 - MultiCtl.
Re: Curve Generator: Newbie
Right, so to be sure, I think you’re saying the max range of multictl is 0 to 1 for the x axis (not that I have to set the range for...I presume a loop)?
So 1 scales to 32768? so my equivalent value for 9362 in my statement should be 0.286? (The 9362 comes from (32768-1)/21*6). It’s to make an aggregated multictl that’s switching 21 amplifiers on and off so there’s a Ctrl that does the first 6 (0 to 9362 then the curve does nothing) and the second Ctrl does nothing until 9362-max. Then a third Ctrl connecting to both of them sweeps the full range with outputted values.
So 1 scales to 32768? so my equivalent value for 9362 in my statement should be 0.286? (The 9362 comes from (32768-1)/21*6). It’s to make an aggregated multictl that’s switching 21 amplifiers on and off so there’s a Ctrl that does the first 6 (0 to 9362 then the curve does nothing) and the second Ctrl does nothing until 9362-max. Then a third Ctrl connecting to both of them sweeps the full range with outputted values.
- NightRadio
- Site Admin
- Posts: 3955
- Joined: Fri Jan 23, 2004 12:28 am
- Location: Ekaterinburg. Russia
- Contact:
Re: Curve Generator: Newbie
For MultiCtl:
$x: 0...1 -> will be scaled to 0...256
$y: 0...1 -> will be scaled to 0...32768
But, as you can see, the MultiCtl curve has a limitation - a small resolution on the X-axis compared to the Y resolution. This will lead to some error in the calculations
$x: 0...1 -> will be scaled to 0...256
$y: 0...1 -> will be scaled to 0...32768
Exactly.So 1 scales to 32768? so my equivalent value for 9362 in my statement should be 0.286?
But, as you can see, the MultiCtl curve has a limitation - a small resolution on the X-axis compared to the Y resolution. This will lead to some error in the calculations