Skip to content

Commit 0dadd35

Browse files
committed
Store ignore state and get it from core properly
1 parent f2c4125 commit 0dadd35

File tree

3 files changed

+65
-18
lines changed

3 files changed

+65
-18
lines changed

drmr.c

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ instantiate(const LV2_Descriptor* descriptor,
7777
drmr->curReq = -1;
7878
drmr->rate = rate;
7979
drmr->ignore_velocity = false;
80-
drmr->ignore_note_off = false;
80+
drmr->ignore_note_off = true;
8181

8282
if (pthread_mutex_init(&drmr->load_mutex, 0)) {
8383
fprintf(stderr, "Could not initialize load_mutex.\n");
@@ -179,6 +179,10 @@ static inline LV2_Atom *build_state_message(DrMr *drmr) {
179179
lv2_atom_forge_property_head(&drmr->forge, drmr->uris.kit_path,0);
180180
lv2_atom_forge_string(&drmr->forge, drmr->current_path, strlen(drmr->current_path));
181181
}
182+
lv2_atom_forge_property_head(&drmr->forge, drmr->uris.velocity_toggle,0);
183+
lv2_atom_forge_bool(&drmr->forge, drmr->ignore_velocity?true:false);
184+
lv2_atom_forge_property_head(&drmr->forge, drmr->uris.note_off_toggle,0);
185+
lv2_atom_forge_bool(&drmr->forge, drmr->ignore_note_off?true:false);
182186
lv2_atom_forge_pop(&drmr->forge,&set_frame);
183187
return msg;
184188
}
@@ -410,6 +414,8 @@ void save_state(LV2_Handle instance,
410414
const LV2_Feature *const * features) {
411415
DrMr *drmr = (DrMr*)instance;
412416
LV2_State_Map_Path* map_path = NULL;
417+
int32_t flag;
418+
413419
while(*features) {
414420
if (!strcmp((*features)->URI, LV2_STATE__mapPath))
415421
map_path = (LV2_State_Map_Path*)((*features)->data);
@@ -429,9 +435,26 @@ void save_state(LV2_Handle instance,
429435
mapped_path,
430436
strlen(mapped_path) + 1,
431437
drmr->uris.string_urid,
432-
LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE)) {
433-
fprintf(stderr,"Store failed\n");
434-
}
438+
LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE))
439+
fprintf(stderr,"Store of kit path failed\n");
440+
441+
flag = drmr->ignore_velocity?1:0;
442+
if (store(handle,
443+
drmr->uris.velocity_toggle,
444+
&flag,
445+
sizeof(int32_t),
446+
drmr->uris.bool_urid,
447+
LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE))
448+
fprintf(stderr,"Store of ignore velocity failed\n");
449+
450+
flag = drmr->ignore_note_off?1:0;
451+
if (store(handle,
452+
drmr->uris.note_off_toggle,
453+
&flag,
454+
sizeof(uint32_t),
455+
drmr->uris.bool_urid,
456+
LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE))
457+
fprintf(stderr,"Store of ignore note off failed\n");
435458
}
436459

437460
void restore_state(LV2_Handle instance,
@@ -476,6 +499,16 @@ void restore_state(LV2_Handle instance,
476499
drmr->curReq = reqPos;
477500
if (tmp) free(tmp);
478501
}
502+
503+
const uint32_t* ignore_velocity =
504+
retrieve(handle, drmr->uris.velocity_toggle, &size, &type, &fgs);
505+
if (ignore_velocity)
506+
drmr->ignore_velocity = *ignore_velocity?true:false;
507+
508+
const uint32_t* ignore_note_off =
509+
retrieve(handle, drmr->uris.note_off_toggle, &size, &type, &fgs);
510+
if (ignore_note_off)
511+
drmr->ignore_note_off = *ignore_note_off?true:false;
479512
}
480513

481514

drmr.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ typedef struct {
149149
LV2_URID atom_eventTransfer;
150150
LV2_URID atom_resource;
151151
LV2_URID string_urid;
152+
LV2_URID bool_urid;
152153
LV2_URID get_state;
153154
LV2_URID midi_info;
154155
LV2_URID sample_trigger;
@@ -200,8 +201,9 @@ void map_drmr_uris(LV2_URID_Map *map,
200201
map->map(map->handle,
201202
"http://lv2plug.in/ns/ext/midi#MidiEvent");
202203
uris->string_urid =
203-
map->map(map->handle,
204-
"http://lv2plug.in/ns/ext/atom#String");
204+
map->map(map->handle, LV2_ATOM__String);
205+
uris->bool_urid =
206+
map->map(map->handle, LV2_ATOM__Bool);
205207
uris->ui_msg =
206208
map->map(map->handle,
207209
DRMR_URI "#uimsg");

drmr_ui.c

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ typedef struct {
5454
float *gain_vals,*pan_vals;
5555

5656
GtkWidget** notify_leds;
57+
GtkWidget *velocity_checkbox, *note_off_checkbox;
5758

5859
gchar *bundle_path;
5960

@@ -501,8 +502,7 @@ static void build_drmr_ui(DrMrUi* ui) {
501502
GtkWidget *drmr_ui_widget;
502503
GtkWidget *opts_hbox1, *opts_hbox2,
503504
*kit_combo_box, *kit_label, *no_kit_label,
504-
*base_label, *base_spin, *position_label, *position_combo_box,
505-
*velocity_checkbox, *note_off_checkbox;
505+
*base_label, *base_spin, *position_label, *position_combo_box;
506506
GtkCellRenderer *cell_rend;
507507
GtkAdjustment *base_adj;
508508

@@ -546,8 +546,8 @@ static void build_drmr_ui(DrMrUi* ui) {
546546
position_label = gtk_label_new("Sample Zero Position: ");
547547
position_combo_box = create_position_combo();
548548

549-
velocity_checkbox = gtk_check_button_new_with_label("Ignore Velocity");
550-
note_off_checkbox = gtk_check_button_new_with_label("Ignore Note Off");
549+
ui->velocity_checkbox = gtk_check_button_new_with_label("Ignore Velocity");
550+
ui->note_off_checkbox = gtk_check_button_new_with_label("Ignore Note Off");
551551

552552
gtk_box_pack_start(GTK_BOX(opts_hbox1),kit_label,
553553
false,false,15);
@@ -564,9 +564,9 @@ static void build_drmr_ui(DrMrUi* ui) {
564564
false,false,15);
565565
gtk_box_pack_start(GTK_BOX(opts_hbox2),position_combo_box,
566566
false,false,0);
567-
gtk_box_pack_start(GTK_BOX(opts_hbox2),velocity_checkbox,
567+
gtk_box_pack_start(GTK_BOX(opts_hbox2),ui->velocity_checkbox,
568568
true,true,15);
569-
gtk_box_pack_start(GTK_BOX(opts_hbox2),note_off_checkbox,
569+
gtk_box_pack_start(GTK_BOX(opts_hbox2),ui->note_off_checkbox,
570570
true,true,15);
571571

572572
gtk_box_pack_start(GTK_BOX(drmr_ui_widget),GTK_WIDGET(ui->current_kit_label),
@@ -590,8 +590,8 @@ static void build_drmr_ui(DrMrUi* ui) {
590590
g_signal_connect(G_OBJECT(kit_combo_box),"changed",G_CALLBACK(kit_combobox_changed),ui);
591591
g_signal_connect(G_OBJECT(base_spin),"value-changed",G_CALLBACK(base_changed),ui);
592592
g_signal_connect(G_OBJECT(position_combo_box),"changed",G_CALLBACK(position_combobox_changed),ui);
593-
g_signal_connect(G_OBJECT(velocity_checkbox),"toggled",G_CALLBACK(ignore_velocity_toggled),ui);
594-
g_signal_connect(G_OBJECT(note_off_checkbox),"toggled",G_CALLBACK(ignore_note_off_toggled),ui);
593+
g_signal_connect(G_OBJECT(ui->velocity_checkbox),"toggled",G_CALLBACK(ignore_velocity_toggled),ui);
594+
g_signal_connect(G_OBJECT(ui->note_off_checkbox),"toggled",G_CALLBACK(ignore_note_off_toggled),ui);
595595

596596
gtk_widget_show_all(drmr_ui_widget);
597597
gtk_widget_hide(no_kit_label);
@@ -712,9 +712,7 @@ port_event(LV2UI_Handle handle,
712712
// both state and ui_msg are the same at the moment
713713
const LV2_Atom* path = NULL;
714714
lv2_object_get(obj, ui->uris.kit_path, &path, 0);
715-
if (!path)
716-
fprintf(stderr,"Got UI message without kit_path, ignoring\n");
717-
else {
715+
if (path) {
718716
char *kitpath = LV2_ATOM_BODY(path);
719717
char *realp = realpath(kitpath,NULL);
720718
if (!realp) {
@@ -732,7 +730,21 @@ port_event(LV2UI_Handle handle,
732730
fprintf(stderr,"Couldn't find kit %s\n",realp);
733731
free(realp);
734732
}
735-
}
733+
if (obj->body.otype == ui->uris.get_state) { // read out extra state info
734+
const LV2_Atom* ignvel = NULL;
735+
const LV2_Atom* ignno = NULL;
736+
lv2_object_get(obj,
737+
ui->uris.velocity_toggle, &ignvel,
738+
ui->uris.note_off_toggle, &ignno,
739+
0);
740+
if (ignvel)
741+
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ui->velocity_checkbox),
742+
((const LV2_Atom_Bool*)ignvel)->body);
743+
if (ignno)
744+
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ui->note_off_checkbox),
745+
((const LV2_Atom_Bool*)ignno)->body);
746+
}
747+
}
736748
else if (obj->body.otype == ui->uris.midi_info) {
737749
const LV2_Atom *midi_atom = NULL;
738750
lv2_object_get(obj, ui->uris.midi_event, &midi_atom, 0);

0 commit comments

Comments
 (0)