Skip to content
Snippets Groups Projects
Commit 32361d12 authored by moon2's avatar moon2 :speech_balloon:
Browse files

bl00mbox: plugins: add trigger merger

parent 313fbedc
No related branches found
No related tags found
1 merge request!684bl00mbox channel system upgrade
......@@ -15,6 +15,7 @@ idf_component_register(
radspa/standard_plugin_lib/delay.c
radspa/standard_plugin_lib/flanger.c
radspa/standard_plugin_lib/multipitch.c
radspa/standard_plugin_lib/trigger_merge.c
radspa/standard_plugin_lib/sequencer.c
radspa/standard_plugin_lib/noise.c
radspa/standard_plugin_lib/noise_burst.c
......
......@@ -212,6 +212,12 @@ static bool bl00mbox_audio_channel_render(bl00mbox_channel_t * chan, int16_t * o
if(render_pass_id == chan->render_pass_id) return false;
chan->render_pass_id = render_pass_id;
bl00mbox_bud_list_t * always = chan->always_render;
while(always != NULL){
bl00mbox_audio_bud_render(always->bud);
always = always->next;
}
bl00mbox_channel_root_t * root = chan->root_list;
int32_t vol = radspa_mult_shift(chan->volume, chan->sys_gain);
......@@ -221,13 +227,6 @@ static bool bl00mbox_audio_channel_render(bl00mbox_channel_t * chan, int16_t * o
return false;
}
// turns out always is conditional too :D
bl00mbox_bud_list_t * always = chan->always_render;
while(always != NULL){
bl00mbox_audio_bud_render(always->bud);
always = always->next;
}
int32_t acc[full_buffer_len];
bool acc_init = false;
......
......@@ -22,7 +22,13 @@ static void plugin_add(radspa_descriptor_t * descriptor){
if(plast == NULL){
bl00mbox_plugin_registry = p;
} else {
while(plast->next != NULL){ plast = plast->next; }
while(plast->next != NULL){
if(plast->descriptor->id == p->descriptor->id){
printf("bl00mbox: plugin list id collision");
abort();
}
plast = plast->next;
}
plast->next = p;
}
bl00mbox_plugin_registry_len++;
......@@ -102,6 +108,7 @@ radspa_descriptor_t * bl00mbox_plugin_registry_get_id_from_index(uint32_t index)
#include "distortion.h"
#include "mixer.h"
#include "multipitch.h"
#include "trigger_merge.h"
#include "slew_rate_limiter.h"
#include "range_shifter.h"
#include "poly_squeeze.h"
......@@ -114,6 +121,7 @@ void bl00mbox_plugin_registry_init(void){
plugin_add(&sequencer_desc);
plugin_add(&sampler_desc);
plugin_add(&multipitch_desc);
plugin_add(&trigger_merge_desc);
plugin_add(&bl00mbox_line_in_desc);
plugin_add(&distortion_desc);
plugin_add(&mixer_desc);
......
......@@ -687,3 +687,15 @@ class _Sequencer(_Plugin):
def load_pattern(self, beat):
num_tracks = min(len(beat["tracks"]), self.num_tracks)
[self.load_track_pattern(beat["tracks"][i], i) for i in range(num_tracks)]
@_plugin_set_subclass(38)
class _TriggerMerge(_Plugin):
@property
def block_stop(self):
table = self.table_int16_array
return bool(table[0])
@block_stop.setter
def block_stop(self, val):
table = self.table_int16_array
table[0] = 1 if val else 0
#include "trigger_merge.h"
#include <stdio.h>
radspa_descriptor_t trigger_merge_desc = {
.name = "trigger_merge",
.id = 38,
.description = "merges multiple trigger inputs together. lazy. if a start and a stop "
"collide the stop is preferred."
"\ninit_var: number of inputs, default 0, max 127",
.create_plugin_instance = trigger_merge_create,
.destroy_plugin_instance = radspa_standard_plugin_destroy
};
typedef struct {
int16_t trigger_out_prev;
int16_t blocked_stop;
int16_t trigger_in_prev[];
} trigger_merge_data_t;
void trigger_merge_run(radspa_t * plugin, uint16_t num_samples, uint32_t render_pass_id){
int num_inputs = plugin->len_signals - 1;
trigger_merge_data_t * data = plugin->plugin_data;
bool block_stop_events = plugin->plugin_table[0];
int16_t i;
int16_t merged_trigger = 0;
int16_t last_timestamp = -1;
for(uint8_t j = 0; j < num_inputs; j++){
int16_t trigger_in = radspa_trigger_get_const(&plugin->signals[j], &data->trigger_in_prev[j], (uint16_t *) &i, num_samples, render_pass_id);
if((last_timestamp > i) || (!trigger_in)) continue;
if((trigger_in > 0) && (last_timestamp == i)){
if(merged_trigger != -1){
merged_trigger = merged_trigger > trigger_in ? merged_trigger : trigger_in;
}
} else {
merged_trigger = trigger_in;
}
last_timestamp = i;
}
if(merged_trigger > 0){
radspa_trigger_start(merged_trigger, &(data->trigger_out_prev));
data->blocked_stop = false;
} else if(data->blocked_stop && (!block_stop_events)){
radspa_trigger_stop(&(data->trigger_out_prev));
data->blocked_stop = false;
} else if(merged_trigger < 0){
if(!block_stop_events){
radspa_trigger_stop(&(data->trigger_out_prev));
} else {
data->blocked_stop = true;
}
}
radspa_signal_set_const_value(&plugin->signals[num_inputs], data->trigger_out_prev);
}
radspa_t * trigger_merge_create(uint32_t init_var){
if(init_var > 127) init_var = 127;
if(!init_var) init_var = 1;
uint32_t size = sizeof(trigger_merge_data_t) + init_var * sizeof(int16_t);
radspa_t * plugin = radspa_standard_plugin_create(&trigger_merge_desc, init_var + 1, size, 1);
if(plugin == NULL) return NULL;
plugin->render = trigger_merge_run;
radspa_signal_set_group(plugin, init_var, 1, 0, "input", RADSPA_SIGNAL_HINT_INPUT | RADSPA_SIGNAL_HINT_TRIGGER, 0);
radspa_signal_set(plugin, init_var, "output", RADSPA_SIGNAL_HINT_OUTPUT | RADSPA_SIGNAL_HINT_TRIGGER, 0);
return plugin;
}
#pragma once
#include <radspa.h>
#include <radspa_helpers.h>
extern radspa_descriptor_t trigger_merge_desc;
radspa_t * trigger_merge_create(uint32_t init_var);
void trigger_merge_run(radspa_t * osc, uint16_t num_samples, uint32_t render_pass_id);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment