Skip to content

Commit

Permalink
Updates for evolving LV2 spec. Fixes atom calls (now have atom in nam…
Browse files Browse the repository at this point in the history
…e) and state interface
  • Loading branch information
nicklan committed Apr 16, 2012
1 parent 8da1de3 commit 8a0bcb4
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 54 deletions.
106 changes: 55 additions & 51 deletions drmr.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,7 @@ static void run(LV2_Handle instance, uint32_t n_samples) {
LV2_Atom_Forge_Frame seq_frame;
lv2_atom_forge_sequence_head(&drmr->forge, &seq_frame, 0);

LV2_SEQUENCE_FOREACH(drmr->control_port, i) {
LV2_Atom_Event* const ev = lv2_sequence_iter_get(i);
LV2_ATOM_SEQUENCE_FOREACH(drmr->control_port, ev) {
if (ev->body.type == drmr->uris.midi_event) {
uint8_t nn;
uint8_t* const data = (uint8_t* const)(ev + 1);
Expand Down Expand Up @@ -312,13 +311,13 @@ static void run(LV2_Handle instance, uint32_t n_samples) {
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);
lv2_atom_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;
char *tmp = NULL;
Expand Down Expand Up @@ -419,14 +418,16 @@ static void cleanup(LV2_Handle instance) {
free(instance);
}

void save_state(LV2_Handle instance,
LV2_State_Store_Function store,
void* handle,
uint32_t flags,
const LV2_Feature *const * features) {
static LV2_State_Status
save_state(LV2_Handle instance,
LV2_State_Store_Function store,
void* handle,
uint32_t flags,
const LV2_Feature *const * features) {
DrMr *drmr = (DrMr*)instance;
LV2_State_Map_Path* map_path = NULL;
int32_t flag;
LV2_State_Status stat = LV2_STATE_SUCCESS;

while(*features) {
if (!strcmp((*features)->URI, LV2_STATE__mapPath))
Expand All @@ -436,52 +437,53 @@ void save_state(LV2_Handle instance,

if (map_path == NULL) {
fprintf(stderr,"Host does not support map_path, cannot save state\n");
return;
return LV2_STATE_ERR_NO_FEATURE;
}

char* mapped_path = map_path->abstract_path(map_path->handle,
drmr->current_path);

if (store(handle,
drmr->uris.kit_path,
mapped_path,
strlen(mapped_path) + 1,
drmr->uris.string_urid,
LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE))
fprintf(stderr,"Store of kit path failed\n");
stat = store(handle,
drmr->uris.kit_path,
mapped_path,
strlen(mapped_path) + 1,
drmr->uris.string_urid,
LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE);
if (stat) return stat;

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");
stat = store(handle,
drmr->uris.velocity_toggle,
&flag,
sizeof(int32_t),
drmr->uris.bool_urid,
LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE);
if (stat) return stat;

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");

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");
stat = store(handle,
drmr->uris.note_off_toggle,
&flag,
sizeof(uint32_t),
drmr->uris.bool_urid,
LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE);
if (stat) return stat;

stat = store(handle,
drmr->uris.zero_position,
&drmr->zero_position,
sizeof(int),
drmr->uris.int_urid,
LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE);
return stat;
}

void restore_state(LV2_Handle instance,
LV2_State_Retrieve_Function retrieve,
void* handle,
uint32_t flags,
const LV2_Feature *const * features) {
static LV2_State_Status
restore_state(LV2_Handle instance,
LV2_State_Retrieve_Function retrieve,
void* handle,
uint32_t flags,
const LV2_Feature *const * features) {
DrMr* drmr = (DrMr*)instance;
size_t size;
uint32_t type;
Expand All @@ -496,7 +498,7 @@ void restore_state(LV2_Handle instance,

if (map_path == NULL) {
fprintf(stderr,"Host does not support map_path, cannot restore state\n");
return;
return LV2_STATE_ERR_NO_FEATURE;
}


Expand All @@ -505,7 +507,7 @@ void restore_state(LV2_Handle instance,

if (!abstract_path) {
fprintf(stderr,"Found no path in state, not restoring\n");
return;
return LV2_STATE_ERR_NO_PROPERTY;
}

char *kit_path = map_path->absolute_path(map_path->handle,abstract_path);
Expand Down Expand Up @@ -534,6 +536,8 @@ void restore_state(LV2_Handle instance,
retrieve(handle, drmr->uris.zero_position, &size, &type, &fgs);
if (zero_position)
drmr->zero_position = *zero_position;

return LV2_STATE_SUCCESS;
}


Expand Down
6 changes: 3 additions & 3 deletions drmr_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ port_event(LV2UI_Handle handle,
obj->body.otype == ui->uris.ui_msg) {
// 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);
lv2_atom_object_get(obj, ui->uris.kit_path, &path, 0);
if (path) {
char *kitpath = LV2_ATOM_BODY(path);
char *realp = realpath(kitpath,NULL);
Expand All @@ -739,7 +739,7 @@ port_event(LV2UI_Handle handle,
const LV2_Atom* ignvel = NULL;
const LV2_Atom* ignno = NULL;
const LV2_Atom* zerop = NULL;
lv2_object_get(obj,
lv2_atom_object_get(obj,
ui->uris.velocity_toggle, &ignvel,
ui->uris.note_off_toggle, &ignno,
ui->uris.zero_position, &zerop,
Expand All @@ -757,7 +757,7 @@ port_event(LV2UI_Handle handle,
}
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);
lv2_atom_object_get(obj, ui->uris.midi_event, &midi_atom, 0);
if(!midi_atom) {
fprintf(stderr,"Midi info with no midi data\n");
return;
Expand Down

0 comments on commit 8a0bcb4

Please sign in to comment.