Jump to content


Photo

[Solved] Avoid error already registered with add_child and remove_chil

add_child remove_child. error already registered

  • Please log in to reply
5 replies to this topic

#1 Raul (ulneiz)

Raul (ulneiz)

    Guruh Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPip
  • 999 posts
  • Gender:Male
  • Location:Spain

Posted 11 July 2017 - 12:21

I have a somewhat peculiar problem with add_child and remove_child.

 

The case is that I want to add the same add_child every time I change of track, at the time of opening the volume column (also to the contrary with remove_child, child nonexistent). I then use two observables to selected_track_index and volume_column_visible. With observables I have no problem.

 

But I have problems with add_child when it has already been registered and also with remove child, when it has not yet been registered (does not exist). In both cases I can return error.

 

The thing is, I need to put a condition that says (with "if then"): 

  1. If exist add_child, do nothing. (avoid the error: ...was already registered to this viewbuilder instance)
  2. And on the contrary, if the child does not exist, it does not remove_child. (avoid the error of it is not possible to remove a child who does not exist)

How to check both cases to avoid the 2 typical errors of registration of the child?

 

 

Here is an example of the code I use:

local GUI_VOLUME_LVL = vb:row{ id = "GUI_VOLUME_LVL", visible = false }
function add_child_volume()
  if ( vb.views["VPD_CBX_CLR_YW"].value == true ) then
    vb.views["GUI_VOLUME_LVL"].visible = true
    GUI_VOLUME_LVL:add_child( GUI_VOLUME_LEVEL )
  else
    GUI_VOLUME_LVL:remove_child( GUI_VOLUME_LEVEL )
    vb.views["GUI_VOLUME_LVL"].visible = false
  end
end

The child GUI_VOLUME_LEVEL = vb:row { bla bla bla  }

 

What two conditions are needed to avoid these two errors?


Edited by Raul (ulneiz), 12 July 2017 - 15:43.

:excl: Development of my tool: GT16-Colors

 

:excl: My API wishlist R3.1 (updated 24 July 2017):

Spoiler

 

:excl: My Renoise 3.1 wishlist (updated 26 September 2017):

Spoiler

#2 joule

joule

    Guruh Motha Fakka is Levitating and Knows Everything About Renoise Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPipPip
  • 1482 posts
  • Gender:Not Telling
  • Location:Sweden
  • Interests:music, philosophy, engineering

Posted 11 July 2017 - 13:09

1) id = "GUI_VOLUME_LVL"

 

This is found in vb.views.GUI_VOLUME_LVL, so you can just check if that exists.

 

2) Some small advise that might be helpful later on (don't confuse this with your question.. it's just advise). If you find that you want to rebuild registered children that already exists, you will get the "already registered" error even if you have removed them. This is kind of a design flaw imo, but can easily be circumvented by 1) removing the view/gui object, 2) doing vb.views.my_view = nil , 3) rebuilding & adding it.



#3 danoise

danoise

    Probably More God or Borg Than Human Member

  • Renoise Team
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 6404 posts
  • Gender:Male
  • Location:Berlin
  • Interests:wildlife + urban trekking

Posted 11 July 2017 - 18:11

Another approach would be to maintain references to the various views as variables. 

(just like you're already doing with the GUI_VOLUME_LVL)

 

This way, you will not need to rely on ID's, so you can avoid having to tear down the view before rebuilding it (left overs will be garbage collected soon enough). 

I'd especially recommend this approach when you are creating GUIs that does not necessarily have a fixed number of elements. 


Tracking with Stuff. API wishlist | Soundcloud


#4 Raul (ulneiz)

Raul (ulneiz)

    Guruh Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPip
  • 999 posts
  • Gender:Male
  • Location:Spain

Posted 12 July 2017 - 15:43

I can not get the tool to work properly using add_child and remove_child. In the end I decided to use the property visible = true or false. To attach or hide panels more simply.

 

I do not know what happens, but I always showed up vb.views.GUI_VOLUME_LEVEL ( or what is the same vb.views["GUI_VOLUME_LEVEL"])  equal to nil, always, regardless of invoking the add_child or remove_child. Maybe if there was a "has_child" similar to the functioning of observables, this type of error would be avoided, although the query is inside the tool not inside Renoise.

 

I already have my new tool practically finished and running almost everything ok. But I agree with Joule that there may be a design flaw, which perhaps could be revised, it gives the feeling that sometimes it does not behave as it should, as if invoking the remove_child, is executed, but is not well notified internally, or something similar. As it is an unclear matter, I prefer not to use it.

 

Thanks for the help!  :D

:excl: Development of my tool: GT16-Colors

 

:excl: My API wishlist R3.1 (updated 24 July 2017):

Spoiler

 

:excl: My Renoise 3.1 wishlist (updated 26 September 2017):

Spoiler

#5 joule

joule

    Guruh Motha Fakka is Levitating and Knows Everything About Renoise Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPipPip
  • 1482 posts
  • Gender:Not Telling
  • Location:Sweden
  • Interests:music, philosophy, engineering

Posted 12 July 2017 - 20:03

I've had no problem using add_child or remove_child at all (other than the very minor problem I mentioned). It's most likely just a matter of structuring the code correctly.. or perhaps this:

 

You cannot toggle the existence of a view with add_child / remove_child the way your snippet implies. I'm pretty sure you have to rebuild it after it has been removed and you want to add it again. So basically:

 

1) Build the view just before add_child'ing it.

2) use the vb.views.my_view=nil trick right after removing it.

 

Then everything should be fine.



#6 Raul (ulneiz)

Raul (ulneiz)

    Guruh Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPip
  • 999 posts
  • Gender:Male
  • Location:Spain

Posted 13 July 2017 - 00:04

I have problems with add_child and remove_child wanting to invoke them from different tracks and its observables (for wanting to use the same children for all the tracks a rare invention of mine ^_^ )... Then I make a mess...

 

Since in my tool they are only 3 panels, I can place them fixed and hide them with visible = true/false.


:excl: Development of my tool: GT16-Colors

 

:excl: My API wishlist R3.1 (updated 24 July 2017):

Spoiler

 

:excl: My Renoise 3.1 wishlist (updated 26 September 2017):

Spoiler