109 lines
2.8 KiB
C
109 lines
2.8 KiB
C
#include "pipewire/keys.h"
|
|
#include "pipewire/port.h"
|
|
#include "spa/pod/iter.h"
|
|
#include "spa/utils/defs.h"
|
|
#include <signal.h>
|
|
#include <stdio.h>
|
|
|
|
#include <spa/control/control.h>
|
|
#include <spa/param/latency-utils.h>
|
|
#include <spa/pod/builder.h>
|
|
#include <spa/pod/pod.h>
|
|
|
|
#include <pipewire/filter.h>
|
|
#include <pipewire/pipewire.h>
|
|
|
|
#include "delay.h"
|
|
#include "gate.h"
|
|
#include "guitfx.h"
|
|
#include "sust.h"
|
|
|
|
void midi_control(
|
|
struct FxData* data,
|
|
|
|
uint64_t frame,
|
|
uint64_t offset,
|
|
unsigned sec,
|
|
unsigned midi_size,
|
|
uint8_t* midi_data,
|
|
struct spa_io_position* position)
|
|
{
|
|
printf("[%d] MIDI message (%d bytes) : %x, %x, %x\n", sec, midi_size,
|
|
midi_data[0], midi_data[1], midi_data[2]);
|
|
|
|
switch (midi_data[0] & 0xff) {
|
|
case 0xb0:
|
|
switch (midi_data[1]) {
|
|
case 0x0b:
|
|
// expr pedal
|
|
float val_f = ((float)midi_data[2]) / 128.0;
|
|
|
|
float thres = 0.5;
|
|
|
|
if (val_f > thres) {
|
|
float expr_mix = (val_f - thres) / (1.0 - thres);
|
|
printf("Expr Pedal %f\n", expr_mix);
|
|
|
|
data->delay.mix = expr_mix;
|
|
} else {
|
|
data->delay.mix = 0.0;
|
|
}
|
|
break;
|
|
|
|
case 0x42:
|
|
|
|
// noise gate calibration
|
|
if (data->prog == 2) {
|
|
if (midi_data[2] >= 64) {
|
|
data->gate.threshold = data->gate.cur_block_sum * 0.8;
|
|
printf("calibrate noise gate: threshold = %f\n",
|
|
data->gate.threshold);
|
|
}
|
|
}
|
|
|
|
// sust pedal
|
|
if (data->prog == 1) {
|
|
if (midi_data[2] >= 64) {
|
|
sust_swap(&data->sust);
|
|
data->sust.playing = true;
|
|
|
|
data->sust.start_idx = data->sust.idx;
|
|
data->sust.idx = 0;
|
|
} else {
|
|
data->sust.playing = false;
|
|
}
|
|
}
|
|
|
|
// tap tempo
|
|
if (data->prog == 0) {
|
|
uint64_t cur_tap = frame + offset;
|
|
uint64_t duration = cur_tap - data->last_tap;
|
|
data->last_tap = cur_tap;
|
|
if (duration < (4 * position->clock.rate.denom)) {
|
|
delay_set_time(&data->delay, duration);
|
|
}
|
|
|
|
sust_resize(&data->sust, duration);
|
|
}
|
|
|
|
break;
|
|
}
|
|
|
|
break;
|
|
|
|
case 0xc0:
|
|
// program change
|
|
if (midi_data[2] >= 64) {
|
|
sust_swap(&data->sust);
|
|
data->sust.playing = true;
|
|
|
|
data->sust.start_idx = data->sust.idx;
|
|
data->sust.idx = 0;
|
|
} else {
|
|
data->sust.playing = false;
|
|
}
|
|
printf("program change: %u\n", midi_data[1]);
|
|
data->prog = midi_data[1];
|
|
break;
|
|
}
|
|
}
|