<div dir="ltr"><div>      This is what I talk about (from sampler example):<br><br>LV2_Atom_Forge_Ref   set = <span class="gmail-pl-c1">lv2_atom_forge_object</span>(
      
      
                        forge, &frame, <span class="gmail-pl-c1">0</span>, uris->patch_Set);
      
      
        

      
      
                <span class="gmail-pl-c1">lv2_atom_forge_key</span>(forge, uris->patch_property);
      
      
                <span class="gmail-pl-c1">lv2_atom_forge_urid</span>(forge, uris->eg_sample);
      
      
                <span class="gmail-pl-c1">lv2_atom_forge_key</span>(forge, uris->patch_value);
      
      
                <span class="gmail-pl-c1">lv2_atom_forge_path</span>(forge, filename, filename_len);
      
      
        

      
      
                <span class="gmail-pl-c1">lv2_atom_forge_pop</span>(forge, &frame);<br><br></div>This is what happens after <span class="gmail-pl-c1">lv2_atom_forge_set_buffer. I guess I need to write data from DSP to UI as well when state is reloaded. Also I know the payload size without strlen.<br></span><div><div class="gmail_extra"><br><div class="gmail_quote">2016-11-27 12:08 GMT+01:00 Hanspeter Portner <span dir="ltr"><<a href="mailto:ventosus@airpost.net" target="_blank">ventosus@airpost.net</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 27.11.2016 09:58, Torbjörn Rathsman wrote:<br>
> I need to pass a string from the UI to the plugin. From the eg-sample, it<br>
> appears that an LV2 atom should be written to a atom port.<br>
><br>
> If I understand it correctly<br>
><br>
>  1. Allocate a LV2_Atom_Forge. May that object be on the stack or does it have<br>
>     to survive after the UI event callback has returned?<br>
<br>
This could be on the stack, but it makes sense to make it part of UI/plugin<br>
struct/class directly as the forge needs to be initialized before use<br>
(lv2_atom_forge_init). e.g. initialize once (in your initialize routine), use<br>
many times...<br>
<br>
>  2. Call lv2_atom_forge_set_buffer. How do I know the required size of the<br>
>     buffer? Is it the size of the payload (the string), or does it include any<br>
>     headers. The example sets it to 1024 bytes for no reason. May the buffer be<br>
>     allocated on the stack or does it have to survive the UI after the UI event<br>
>     callback has returned?<br>
<br>
It does include headers (and padding), so for your string, a safe minimum is:<br>
  uint32_t capacity = lv2_atom_pad_size(sizeof(LV2_<wbr>Atom) + strlen(str) + 1)<br>
<br>
Don't forget to initialize the forge structure (lv2_atom_forge_init), this sets<br>
vital variables in the structure.<br>
<br>
I use lv2_atom_forge_set_buffer manly on the DSP side (where you cannot use<br>
malloc et al.). On the UI side it's more convenient to use<br>
lv2_atom_forge_set_sink with which you can implement growing buffers and don't<br>
have to ask yourself about maximal buffer sizes in the first place, e.g. [1].<br>
<br>
>  3. Add some objects. The API uses key-value pairs. Should the size of keys be<br>
>     included in the buffer size?<br>
<br>
Not sure what API you mean, but as mentioned above, just use a growing buffer.<br>
<br>
>  4. Write the data to an atom input port<br>
<br>
Yes, but don't forget to use the proper port protocol in the writer function,<br>
e.g. atom:eventTransfer [2].<br>
<br>
[1]<br>
<a href="https://gitlab.com/OpenMusicKontrollers/tracker.lv2/blob/master/tracker_ui.c#L595" rel="noreferrer" target="_blank">https://gitlab.com/<wbr>OpenMusicKontrollers/tracker.<wbr>lv2/blob/master/tracker_ui.c#<wbr>L595</a><br>
[2]<br>
<a href="https://gitlab.com/OpenMusicKontrollers/tracker.lv2/blob/master/tracker_ui.c#L603" rel="noreferrer" target="_blank">https://gitlab.com/<wbr>OpenMusicKontrollers/tracker.<wbr>lv2/blob/master/tracker_ui.c#<wbr>L603</a><br>
<br>
______________________________<wbr>_________________<br>
Devel mailing list<br>
<a href="mailto:Devel@lists.lv2plug.in">Devel@lists.lv2plug.in</a><br>
<a href="http://lists.lv2plug.in/listinfo.cgi/devel-lv2plug.in" rel="noreferrer" target="_blank">http://lists.lv2plug.in/<wbr>listinfo.cgi/devel-lv2plug.in</a><br>
</blockquote></div><br></div></div></div>