Skip to content

Commit

Permalink
Store ignore state and get it from core properly
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklan committed Apr 3, 2012
1 parent f2c4125 commit 0dadd35
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 18 deletions.
41 changes: 37 additions & 4 deletions drmr.c
Expand Up @@ -77,7 +77,7 @@ instantiate(const LV2_Descriptor* descriptor,
drmr->curReq = -1;
drmr->rate = rate;
drmr->ignore_velocity = false;
drmr->ignore_note_off = false;
drmr->ignore_note_off = true;

if (pthread_mutex_init(&drmr->load_mutex, 0)) {
fprintf(stderr, "Could not initialize load_mutex.\n");
Expand Down Expand Up @@ -179,6 +179,10 @@ static inline LV2_Atom *build_state_message(DrMr *drmr) {
lv2_atom_forge_property_head(&drmr->forge, drmr->uris.kit_path,0);
lv2_atom_forge_string(&drmr->forge, drmr->current_path, strlen(drmr->current_path));
}
lv2_atom_forge_property_head(&drmr->forge, drmr->uris.velocity_toggle,0);
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_pop(&drmr->forge,&set_frame);
return msg;
}
Expand Down Expand Up @@ -410,6 +414,8 @@ void save_state(LV2_Handle instance,
const LV2_Feature *const * features) {
DrMr *drmr = (DrMr*)instance;
LV2_State_Map_Path* map_path = NULL;
int32_t flag;

while(*features) {
if (!strcmp((*features)->URI, LV2_STATE__mapPath))
map_path = (LV2_State_Map_Path*)((*features)->data);
Expand All @@ -429,9 +435,26 @@ void save_state(LV2_Handle instance,
mapped_path,
strlen(mapped_path) + 1,
drmr->uris.string_urid,
LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE)) {
fprintf(stderr,"Store failed\n");
}
LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE))
fprintf(stderr,"Store of kit path failed\n");

flag = drmr->ignore_velocity?1:0;
if (store(handle,
drmr->uris.velocity_toggle,
&flag,
sizeof(int32_t),
drmr->uris.bool_urid,
LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE))
fprintf(stderr,"Store of ignore velocity failed\n");

flag = drmr->ignore_note_off?1:0;
if (store(handle,
drmr->uris.note_off_toggle,
&flag,
sizeof(uint32_t),
drmr->uris.bool_urid,
LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE))
fprintf(stderr,"Store of ignore note off failed\n");
}

void restore_state(LV2_Handle instance,
Expand Down Expand Up @@ -476,6 +499,16 @@ void restore_state(LV2_Handle instance,
drmr->curReq = reqPos;
if (tmp) free(tmp);
}

const uint32_t* ignore_velocity =
retrieve(handle, drmr->uris.velocity_toggle, &size, &type, &fgs);
if (ignore_velocity)
drmr->ignore_velocity = *ignore_velocity?true:false;

const uint32_t* ignore_note_off =
retrieve(handle, drmr->uris.note_off_toggle, &size, &type, &fgs);
if (ignore_note_off)
drmr->ignore_note_off = *ignore_note_off?true:false;
}


Expand Down
6 changes: 4 additions & 2 deletions drmr.h
Expand Up @@ -149,6 +149,7 @@ typedef struct {
LV2_URID atom_eventTransfer;
LV2_URID atom_resource;
LV2_URID string_urid;
LV2_URID bool_urid;
LV2_URID get_state;
LV2_URID midi_info;
LV2_URID sample_trigger;
Expand Down Expand Up @@ -200,8 +201,9 @@ void map_drmr_uris(LV2_URID_Map *map,
map->map(map->handle,
"http://lv2plug.in/ns/ext/midi#MidiEvent");
uris->string_urid =
map->map(map->handle,
"http://lv2plug.in/ns/ext/atom#String");
map->map(map->handle, LV2_ATOM__String);
uris->bool_urid =
map->map(map->handle, LV2_ATOM__Bool);
uris->ui_msg =
map->map(map->handle,
DRMR_URI "#uimsg");
Expand Down
36 changes: 24 additions & 12 deletions drmr_ui.c
Expand Up @@ -54,6 +54,7 @@ typedef struct {
float *gain_vals,*pan_vals;

GtkWidget** notify_leds;
GtkWidget *velocity_checkbox, *note_off_checkbox;

gchar *bundle_path;

Expand Down Expand Up @@ -501,8 +502,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,
*velocity_checkbox, *note_off_checkbox;
*base_label, *base_spin, *position_label, *position_combo_box;
GtkCellRenderer *cell_rend;
GtkAdjustment *base_adj;

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

velocity_checkbox = gtk_check_button_new_with_label("Ignore Velocity");
note_off_checkbox = gtk_check_button_new_with_label("Ignore Note Off");
ui->velocity_checkbox = gtk_check_button_new_with_label("Ignore Velocity");
ui->note_off_checkbox = gtk_check_button_new_with_label("Ignore Note Off");

gtk_box_pack_start(GTK_BOX(opts_hbox1),kit_label,
false,false,15);
Expand All @@ -564,9 +564,9 @@ static void build_drmr_ui(DrMrUi* ui) {
false,false,15);
gtk_box_pack_start(GTK_BOX(opts_hbox2),position_combo_box,
false,false,0);
gtk_box_pack_start(GTK_BOX(opts_hbox2),velocity_checkbox,
gtk_box_pack_start(GTK_BOX(opts_hbox2),ui->velocity_checkbox,
true,true,15);
gtk_box_pack_start(GTK_BOX(opts_hbox2),note_off_checkbox,
gtk_box_pack_start(GTK_BOX(opts_hbox2),ui->note_off_checkbox,
true,true,15);

gtk_box_pack_start(GTK_BOX(drmr_ui_widget),GTK_WIDGET(ui->current_kit_label),
Expand All @@ -590,8 +590,8 @@ 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(velocity_checkbox),"toggled",G_CALLBACK(ignore_velocity_toggled),ui);
g_signal_connect(G_OBJECT(note_off_checkbox),"toggled",G_CALLBACK(ignore_note_off_toggled),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);

gtk_widget_show_all(drmr_ui_widget);
gtk_widget_hide(no_kit_label);
Expand Down Expand Up @@ -712,9 +712,7 @@ port_event(LV2UI_Handle handle,
// both state and ui_msg are the same at the moment
const LV2_Atom* path = NULL;
lv2_object_get(obj, ui->uris.kit_path, &path, 0);
if (!path)
fprintf(stderr,"Got UI message without kit_path, ignoring\n");
else {
if (path) {
char *kitpath = LV2_ATOM_BODY(path);
char *realp = realpath(kitpath,NULL);
if (!realp) {
Expand All @@ -732,7 +730,21 @@ port_event(LV2UI_Handle handle,
fprintf(stderr,"Couldn't find kit %s\n",realp);
free(realp);
}
}
if (obj->body.otype == ui->uris.get_state) { // read out extra state info
const LV2_Atom* ignvel = NULL;
const LV2_Atom* ignno = NULL;
lv2_object_get(obj,
ui->uris.velocity_toggle, &ignvel,
ui->uris.note_off_toggle, &ignno,
0);
if (ignvel)
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ui->velocity_checkbox),
((const LV2_Atom_Bool*)ignvel)->body);
if (ignno)
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ui->note_off_checkbox),
((const LV2_Atom_Bool*)ignno)->body);
}
}
else if (obj->body.otype == ui->uris.midi_info) {
const LV2_Atom *midi_atom = NULL;
lv2_object_get(obj, ui->uris.midi_event, &midi_atom, 0);
Expand Down

0 comments on commit 0dadd35

Please sign in to comment.