[LV2] Midi output using atomport

Lucas Takejame lucas at takejame.com.br
Thu Apr 3 16:11:49 PDT 2014

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):

class Note2midi {
LV2_Atom_Sequence *out;
MIDINoteEvent note;

    LV2_URID_Map* map;
    LV2_URID midi_event;

uint32_t out_capacity;

/*****(MIDINoteEvent is the struct used in fifths example:

typedef struct {
LV2_Atom_Event event;
uint8_t        msg[3];
} MIDINoteEvent;

) *****/

LV2_Handle Note2midi::instantiate(const LV2_Descriptor* descriptor, double
SampleRate, const char* bundle_path, const LV2_Feature* const* features)
    Note2midi *plugin = new Note2midi();
    plugin->out = new LV2_Atom_Sequence();

    for (int i = 0; features[i]; ++i) {
        if (!strcmp(features[i]->URI, LV2_URID__map)) {
            plugin->map = (LV2_URID_Map*)features[i]->data;

    if (!plugin->map) {
        // fprintf(stderr, "Missing feature urid:map\n");
        delete (plugin);
        return NULL;

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

    out_capacity = plugin->out->atom.size;


void Note2midi::run(LV2_Handle instance, uint32_t SampleCount)
    Note2midi *plugin = (Note2midi *) instance;


    plugin->note.event.body.size = 3;
    plugin->note.event.body.type = 19;
    plugin->note.event.time.frames = rand()%256;
    plugin->note.msg[2] = velo;
    plugin->note.msg[1] = mpitch;
    if (velo == 0) {
      plugins->note.msg[0] = 0x80;      /* note off */
      plugin->note.msg[0] = 0x90;      /* note on */

    lv2_atom_sequence_append_event(plugin->out, out_capacity,


Hope this is not asking too much =)
Thanks in advance
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lv2plug.in/pipermail/devel-lv2plug.in/attachments/20140403/0a4b933b/attachment.htm>

More information about the Devel mailing list