[LV2] Midi output using atomport

David Robillard d at drobilla.net
Fri Apr 4 10:36:32 PDT 2014


On Thu, 2014-04-03 at 20:11 -0300, Lucas Takejame wrote:
> Hello everybody, Im trying to make a lv2 plugin that translate audio to
> MIDI, im using Aubio lib and Im having trouble to send the MIDI output. I
> already saw a bunch of lv2 examples, like fifths, sampler and gxtuner but
> couldn't solve my problem... I'm confuse about the steps i should follow to
> prepare my LV2_Atom_Sequence struct to output. Here's what i did until now
> (This is not the actual code, I modified it to give a context, tried to put
> only things related to the midi output port):

Your best bet is to literally copy from these examples, that's what they
are for.

>     Note2midi *plugin = new Note2midi();
>     plugin->out = new LV2_Atom_Sequence();

Oh my.  Atoms are C structs, not C++ objects, allocation does not work
this way.  LV2_Atom_Sequence is just a header, it is not large enough to
actually contain any data.  I suggest testing with valgrind to find
memory errors.

In any case, outputs are allocated by the *host*, not the plugin, so
this is probably just being overwritten anyway.

> plugin->out->atom.type = plugin->midi_event;
>     plugin->out->atom.size = sizeof(plugin->note.msg);

This is incorrect, the output atom is a Sequence, not a MidiEvent.  This
is probably your real problem.  Set the type to atom:Sequence, and leave
the clearing to lv2_atom_sequence_clear.  Both of these things need to
be done in run() every cycle, not just once at startup.

Assuming you are okay with using the new utility functions like
lv2_atom_sequence_clear (which you're already doing, so I assume you
are), you should just do exactly what fifths does to set up its output
buffer, except instead of being able to simply copy the type from the
input, if you don't have a MIDI input you'll have to map atom:Sequence
and set it to that instead of in_port->atom.type

> Hope this is not asking too much =)

That's what the list is here for :)

-- 
dr





More information about the Devel mailing list