use program change to switch function of sust pedal (switch between tap tempo / activate sustain

This commit is contained in:
Michael Sippel 2024-12-13 13:00:13 +01:00
parent 52f09d7728
commit c75d61123a
Signed by: senvas
GPG key ID: 060F22F65102F95C
2 changed files with 29 additions and 12 deletions

View file

@ -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];

View file

@ -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
if( data->prog == 0 ) {
uint64_t cur_tap = frame + c->offset; uint64_t cur_tap = frame + c->offset;
uint64_t duration = cur_tap - data->last_tap; uint64_t duration = cur_tap - data->last_tap;
data->last_tap = cur_tap; data->last_tap = cur_tap;
if( duration < (4*position->clock.rate.denom) ) { if( duration < (4*position->clock.rate.denom) ) {
delay_set_time( &data->delay, duration/4 ); 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];