drobilla / ingen

A realtime modular synthesizer and/or effects processor
GNU Affero General Public License v3.0
30 stars 7 forks source link

Unexpected behaviour when using lv2_atom_sequence and MIDI out #35

Closed loki42 closed 1 year ago

loki42 commented 1 year ago

I have some code where I might be doing something stupid, but it's based on the 5ths LV2 example, i'm just checking when a control changes and sending a MIDI event.

When I get the capacity of the output sequence, with

const uint32_t capacity = plug->midi_out->atom.size; 
lv2_atom_sequence_clear(plug->midi_out);
plug->midi_out->atom.type = plug->midi_ev_urid;

In my run function, it sometimes returns 8 and less often returns 32760. When it returns 8 my calls to

r_v = lv2_atom_sequence_append_event(plug->midi_out, capacity, &midiatom.event);

return null and fail to queue the event, as the capacity check fails.

It appears that sometimes at the start of the function the value of atom.size isn't being set, though again, it could be something stupid I'm doing.

drobilla commented 1 year ago

plug->midi_out->atom.type = plug->midi_ev_urid;

You seem to be setting the type of the entire output buffer to MidiEvent? The buffer needs to be a sequence that contains events.

loki42 commented 1 year ago

totally thought I might be doing something stupid. :)

I'm now doing:


    if (plug->capacity == 0){
        plug->capacity = plug->midi_out->atom.size;
    }

    lv2_atom_forge_set_buffer(&plug->forge, (uint8_t*)plug->midi_out, plug->capacity);
    lv2_atom_forge_sequence_head(&plug->forge, &plug->frame, 0);
drobilla commented 1 year ago

I mean, yes but also, it is kind of confusing. Consequence of making the output port, even sequences, atoms. Hosts could theoretically support individual atom output ports, but in the case of MIDI that's almost never what you'd want because it would only support a single event per call.

I have considered doing it more extensively for arbitrary "value" ports in ingen, but that just replicates the problems with control ports. Probably the other direction is best, where everything is a sequence, which is how it'd be without control ports, but... c'est la vie.