[LV2] Killing the event extension

Robin Gareus robin at gareus.org
Sat Feb 1 11:51:32 PST 2014


On 02/01/2014 07:11 PM, Bent Bisballe Nyeng wrote:

> Would it make sense to write a utility function for reading midi
> notes as well, or is this task simple enough as it is already?

It's easy enough. basically just

-=-
LV2_ATOM_SEQUENCE_FOREACH(seq, ev) {
  my_process_midi( (uint8_t*)(ev+1), ev->body.size, ev->time.frames);
}

..and your function to parse the raw midi-data:

void my_process_midi(
  const uint8_t* raw_midi_data,
  const uint32_t len,
  const int64_t time);

(time is in audio-samples relative to current cycle start)
-=-

But it's very plugin specific.

For example: Does your synth have an internal queue for events?  ie.
first process all events and remember timestamps, then run the synth once.

OR synth audio in chunks up to the next midi event.

I usually use the latter, here's an excerpt of run()

--------------8<---------------
uint32_t written = 0;
LV2_Atom_Event* ev = lv2_atom_sequence_begin(&(self->midiin)->body);

/* explicit LV2_ATOM_SEQUENCE_FOREACH */
while(!lv2_atom_sequence_is_end(&(self->midiin)->body,
                                 (self->midiin)->atom.size, ev))
{
  if (ev->body.type == self->uris.midi_MidiEvent) {

   /* Synth sound until ev->time.frames */
   written = synth_sound(self->synth, written, ev->time.frames, audio);

   /* parse midi event */
   const uint8_t * midi_data = (uint8_t*)(ev+1);
   const uint32_t  event_bytes = ev->body.size;

   parse_raw_midi_data(self->synth, midi_data, event_bytes);
  }

  ev = lv2_atom_sequence_next(ev);
}

/* synthesize [remaining] sound until end*/
synth_sound(self->synth, written, n_samples, audio);

--------------8<---------------



More information about the Devel mailing list