use program change to switch function of sust pedal (switch between tap tempo / activate sustain
This commit is contained in:
parent
52f09d7728
commit
c75d61123a
2 changed files with 29 additions and 12 deletions
4
delay.c
4
delay.c
|
@ -44,8 +44,8 @@ void delay_process(
|
||||||
for( size_t i = 0; i < frame_size; ++i ) {
|
for( size_t i = 0; i < frame_size; ++i ) {
|
||||||
if( delay->duration > 0 ) {
|
if( delay->duration > 0 ) {
|
||||||
out[i] =
|
out[i] =
|
||||||
0.5 * in[i]
|
in[i]
|
||||||
+ 0.5 * delay->mix * delay->buf[ delay->buf_idx ];
|
+ delay->mix * delay->buf[ delay->buf_idx ];
|
||||||
|
|
||||||
delay->buf[ delay->buf_idx ] *= delay->feedback;
|
delay->buf[ delay->buf_idx ] *= delay->feedback;
|
||||||
delay->buf[ delay->buf_idx ] += (1.0 - delay->feedback) * in[i];
|
delay->buf[ delay->buf_idx ] += (1.0 - delay->feedback) * in[i];
|
||||||
|
|
37
guitfx.c
37
guitfx.c
|
@ -35,6 +35,8 @@ struct data {
|
||||||
struct delay delay;
|
struct delay delay;
|
||||||
struct sust sust;
|
struct sust sust;
|
||||||
|
|
||||||
|
unsigned prog;
|
||||||
|
|
||||||
//! elapsed time in number of samples
|
//! elapsed time in number of samples
|
||||||
uint64_t time;
|
uint64_t time;
|
||||||
};
|
};
|
||||||
|
@ -87,12 +89,16 @@ static void on_process(void *userdata, struct spa_io_position *position)
|
||||||
// expr pedal
|
// expr pedal
|
||||||
float val_f = ((float)midi_data[2]) / 128.0;
|
float val_f = ((float)midi_data[2]) / 128.0;
|
||||||
printf("Expr Pedal %f\n", val_f);
|
printf("Expr Pedal %f\n", val_f);
|
||||||
|
if ( val_f > 0.1 ) {
|
||||||
data->delay.mix = val_f;
|
data->delay.mix = val_f;
|
||||||
|
} else {
|
||||||
|
data->delay.mix = 0.0;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x42:
|
case 0x42:
|
||||||
// sust pedal
|
// sust pedal
|
||||||
|
if( data->prog == 1 ) {
|
||||||
if( midi_data[2] >= 64) {
|
if( midi_data[2] >= 64) {
|
||||||
sust_swap( &data->sust );
|
sust_swap( &data->sust );
|
||||||
data->sust.playing = true;
|
data->sust.playing = true;
|
||||||
|
@ -102,21 +108,30 @@ static void on_process(void *userdata, struct spa_io_position *position)
|
||||||
} else {
|
} else {
|
||||||
data->sust.playing = false;
|
data->sust.playing = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// tap tempo
|
// tap tempo
|
||||||
uint64_t cur_tap = frame + c->offset;
|
if( data->prog == 0 ) {
|
||||||
uint64_t duration = cur_tap - data->last_tap;
|
uint64_t cur_tap = frame + c->offset;
|
||||||
data->last_tap = cur_tap;
|
uint64_t duration = cur_tap - data->last_tap;
|
||||||
if( duration < (4*position->clock.rate.denom) ) {
|
data->last_tap = cur_tap;
|
||||||
delay_set_time( &data->delay, duration/4 );
|
if( duration < (4*position->clock.rate.denom) ) {
|
||||||
}
|
delay_set_time( &data->delay, duration );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sust_resize( &data->sust, duration );
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0xc0:
|
case 0xc0:
|
||||||
// program change
|
// program change
|
||||||
printf("program change: %u\n", midi_data[1]);
|
printf("program change: %u\n", midi_data[1]);
|
||||||
|
data->prog = midi_data[1];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -137,10 +152,11 @@ static void on_process(void *userdata, struct spa_io_position *position)
|
||||||
|
|
||||||
|
|
||||||
float * const in = pw_filter_get_dsp_buffer(data->guit_in_port, n_samples);
|
float * const in = pw_filter_get_dsp_buffer(data->guit_in_port, n_samples);
|
||||||
|
float tmp[n_samples];
|
||||||
float * out = pw_filter_get_dsp_buffer(data->out_port, n_samples);
|
float * out = pw_filter_get_dsp_buffer(data->out_port, n_samples);
|
||||||
if( in && out ) {
|
if( in && out ) {
|
||||||
//delay_process( &data->delay, n_samples, in, out );
|
sust_process( &data->sust, n_samples, in, tmp );
|
||||||
sust_process( &data->sust, n_samples, in, out );
|
delay_process( &data->delay, n_samples, tmp, out );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,6 +177,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
delay_init( &data.delay );
|
delay_init( &data.delay );
|
||||||
sust_init( &data.sust );
|
sust_init( &data.sust );
|
||||||
|
data.prog = 0;
|
||||||
|
|
||||||
const struct spa_pod *params[1];
|
const struct spa_pod *params[1];
|
||||||
uint8_t buffer[1024];
|
uint8_t buffer[1024];
|
||||||
|
|
Loading…
Reference in a new issue