Communicate sample zero position to plugin so it can store/restore it, and code to actually do the store/restore

This commit is contained in:
Nick Lanham 2012-04-03 23:38:41 +02:00
parent 0dadd354c3
commit 8da1de3091
3 changed files with 48 additions and 5 deletions

25
drmr.c
View File

@ -79,6 +79,12 @@ instantiate(const LV2_Descriptor* descriptor,
drmr->ignore_velocity = false;
drmr->ignore_note_off = true;
#ifdef DRMR_UI_ZERO_SAMP
drmr->zero_position = DRMR_UI_ZERO_SAMP;
#else
drmr->zero_position = 0;
#endif
if (pthread_mutex_init(&drmr->load_mutex, 0)) {
fprintf(stderr, "Could not initialize load_mutex.\n");
free(drmr);
@ -183,6 +189,8 @@ static inline LV2_Atom *build_state_message(DrMr *drmr) {
lv2_atom_forge_bool(&drmr->forge, drmr->ignore_velocity?true:false);
lv2_atom_forge_property_head(&drmr->forge, drmr->uris.note_off_toggle,0);
lv2_atom_forge_bool(&drmr->forge, drmr->ignore_note_off?true:false);
lv2_atom_forge_property_head(&drmr->forge, drmr->uris.zero_position,0);
lv2_atom_forge_int(&drmr->forge, drmr->zero_position);
lv2_atom_forge_pop(&drmr->forge,&set_frame);
return msg;
}
@ -303,11 +311,13 @@ static void run(LV2_Handle instance, uint32_t n_samples) {
const LV2_Atom* trigger = NULL;
const LV2_Atom* ignvel = NULL;
const LV2_Atom* ignno = NULL;
const LV2_Atom* zerop = NULL;
lv2_object_get(obj,
drmr->uris.kit_path, &path,
drmr->uris.sample_trigger, &trigger,
drmr->uris.velocity_toggle, &ignvel,
drmr->uris.note_off_toggle, &ignno,
drmr->uris.zero_position, &zerop,
0);
if (path) {
int reqPos = (drmr->curReq+1)%REQ_BUF_SIZE;
@ -331,6 +341,8 @@ static void run(LV2_Handle instance, uint32_t n_samples) {
drmr->ignore_velocity = ((const LV2_Atom_Bool*)ignvel)->body;
if (ignno)
drmr->ignore_note_off = ((const LV2_Atom_Bool*)ignno)->body;
if (zerop)
drmr->zero_position = ((const LV2_Atom_Int*)zerop)->body;
} else if (obj->body.otype == drmr->uris.get_state) {
lv2_atom_forge_frame_time(&drmr->forge, 0);
build_state_message(drmr);
@ -455,6 +467,14 @@ void save_state(LV2_Handle instance,
drmr->uris.bool_urid,
LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE))
fprintf(stderr,"Store of ignore note off failed\n");
if (store(handle,
drmr->uris.zero_position,
&drmr->zero_position,
sizeof(int),
drmr->uris.int_urid,
LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE))
fprintf(stderr,"Store of sample zero position failed\n");
}
void restore_state(LV2_Handle instance,
@ -509,6 +529,11 @@ void restore_state(LV2_Handle instance,
retrieve(handle, drmr->uris.note_off_toggle, &size, &type, &fgs);
if (ignore_note_off)
drmr->ignore_note_off = *ignore_note_off?true:false;
const int* zero_position =
retrieve(handle, drmr->uris.zero_position, &size, &type, &fgs);
if (zero_position)
drmr->zero_position = *zero_position;
}

8
drmr.h
View File

@ -150,11 +150,13 @@ typedef struct {
LV2_URID atom_resource;
LV2_URID string_urid;
LV2_URID bool_urid;
LV2_URID int_urid;
LV2_URID get_state;
LV2_URID midi_info;
LV2_URID sample_trigger;
LV2_URID velocity_toggle;
LV2_URID note_off_toggle;
LV2_URID zero_position;
} drmr_uris;
typedef struct {
@ -169,6 +171,7 @@ typedef struct {
// params
bool ignore_velocity;
bool ignore_note_off;
int zero_position;
float** gains;
float** pans;
float* baseNote;
@ -204,6 +207,8 @@ void map_drmr_uris(LV2_URID_Map *map,
map->map(map->handle, LV2_ATOM__String);
uris->bool_urid =
map->map(map->handle, LV2_ATOM__Bool);
uris->int_urid =
map->map(map->handle, LV2_ATOM__Int);
uris->ui_msg =
map->map(map->handle,
DRMR_URI "#uimsg");
@ -225,6 +230,9 @@ void map_drmr_uris(LV2_URID_Map *map,
uris->note_off_toggle =
map->map(map->handle,
DRMR_URI "#noteofftoggle");
uris->zero_position =
map->map(map->handle,
DRMR_URI "#zeroposition");
uris->atom_eventTransfer =
map->map(map->handle, LV2_ATOM__eventTransfer);
uris->atom_resource =

View File

@ -54,7 +54,7 @@ typedef struct {
float *gain_vals,*pan_vals;
GtkWidget** notify_leds;
GtkWidget *velocity_checkbox, *note_off_checkbox;
GtkWidget *position_combo_box, *velocity_checkbox, *note_off_checkbox;
gchar *bundle_path;
@ -414,6 +414,10 @@ static void kit_combobox_changed(GtkComboBox* box, gpointer data) {
}
}
static void position_data(DrMrUi *ui, gpointer data) {
lv2_atom_forge_property_head(&ui->forge, ui->uris.zero_position,0);
lv2_atom_forge_int(&ui->forge, GPOINTER_TO_INT(data));
}
static void position_combobox_changed(GtkComboBox* box, gpointer data) {
DrMrUi* ui = (DrMrUi*)data;
gint ss = gtk_combo_box_get_active (GTK_COMBO_BOX(box));
@ -421,6 +425,7 @@ static void position_combobox_changed(GtkComboBox* box, gpointer data) {
ui->startSamp = ss;
ui->forceUpdate = true;
kit_callback(ui);
send_ui_msg(ui,&position_data,GINT_TO_POINTER(ss));
}
}
@ -502,7 +507,7 @@ static void build_drmr_ui(DrMrUi* ui) {
GtkWidget *drmr_ui_widget;
GtkWidget *opts_hbox1, *opts_hbox2,
*kit_combo_box, *kit_label, *no_kit_label,
*base_label, *base_spin, *position_label, *position_combo_box;
*base_label, *base_spin, *position_label;
GtkCellRenderer *cell_rend;
GtkAdjustment *base_adj;
@ -544,7 +549,7 @@ static void build_drmr_ui(DrMrUi* ui) {
base_spin = gtk_spin_button_new(base_adj, 1.0, 0);
position_label = gtk_label_new("Sample Zero Position: ");
position_combo_box = create_position_combo();
ui->position_combo_box = create_position_combo();
ui->velocity_checkbox = gtk_check_button_new_with_label("Ignore Velocity");
ui->note_off_checkbox = gtk_check_button_new_with_label("Ignore Note Off");
@ -562,7 +567,7 @@ static void build_drmr_ui(DrMrUi* ui) {
gtk_box_pack_start(GTK_BOX(opts_hbox2),position_label,
false,false,15);
gtk_box_pack_start(GTK_BOX(opts_hbox2),position_combo_box,
gtk_box_pack_start(GTK_BOX(opts_hbox2),ui->position_combo_box,
false,false,0);
gtk_box_pack_start(GTK_BOX(opts_hbox2),ui->velocity_checkbox,
true,true,15);
@ -589,7 +594,7 @@ static void build_drmr_ui(DrMrUi* ui) {
g_signal_connect(G_OBJECT(kit_combo_box),"changed",G_CALLBACK(kit_combobox_changed),ui);
g_signal_connect(G_OBJECT(base_spin),"value-changed",G_CALLBACK(base_changed),ui);
g_signal_connect(G_OBJECT(position_combo_box),"changed",G_CALLBACK(position_combobox_changed),ui);
g_signal_connect(G_OBJECT(ui->position_combo_box),"changed",G_CALLBACK(position_combobox_changed),ui);
g_signal_connect(G_OBJECT(ui->velocity_checkbox),"toggled",G_CALLBACK(ignore_velocity_toggled),ui);
g_signal_connect(G_OBJECT(ui->note_off_checkbox),"toggled",G_CALLBACK(ignore_note_off_toggled),ui);
@ -733,9 +738,11 @@ port_event(LV2UI_Handle handle,
if (obj->body.otype == ui->uris.get_state) { // read out extra state info
const LV2_Atom* ignvel = NULL;
const LV2_Atom* ignno = NULL;
const LV2_Atom* zerop = NULL;
lv2_object_get(obj,
ui->uris.velocity_toggle, &ignvel,
ui->uris.note_off_toggle, &ignno,
ui->uris.zero_position, &zerop,
0);
if (ignvel)
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ui->velocity_checkbox),
@ -743,6 +750,9 @@ port_event(LV2UI_Handle handle,
if (ignno)
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ui->note_off_checkbox),
((const LV2_Atom_Bool*)ignno)->body);
if (zerop)
gtk_combo_box_set_active(GTK_COMBO_BOX(ui->position_combo_box),
((const LV2_Atom_Int*)zerop)->body);
}
}
else if (obj->body.otype == ui->uris.midi_info) {