Skip to content

Commit

Permalink
Communicate sample zero position to plugin so it can store/restore it…
Browse files Browse the repository at this point in the history
…, and code to actually do the store/restore
  • Loading branch information
nicklan committed Apr 3, 2012
1 parent 0dadd35 commit 8da1de3
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
25 changes: 25 additions & 0 deletions drmr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}


Expand Down
8 changes: 8 additions & 0 deletions drmr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -169,6 +171,7 @@ typedef struct {
// params
bool ignore_velocity;
bool ignore_note_off;
int zero_position;
float** gains;
float** pans;
float* baseNote;
Expand Down Expand Up @@ -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");
Expand All @@ -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 =
Expand Down
20 changes: 15 additions & 5 deletions drmr_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -414,13 +414,18 @@ 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));
if (ss != ui->startSamp) {
ui->startSamp = ss;
ui->forceUpdate = true;
kit_callback(ui);
send_ui_msg(ui,&position_data,GINT_TO_POINTER(ss));
}
}

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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");
Expand All @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -733,16 +738,21 @@ 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),
((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);
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) {
Expand Down

0 comments on commit 8da1de3

Please sign in to comment.