Jump to content


Photo

[Solved] How to force reload specific tool if charge new song ???

reload tool new song

  • Please log in to reply
2 replies to this topic

#1 Raul (ulneiz)

Raul (ulneiz)

    Guruh Member

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

Posted 10 July 2017 - 20:35

I am completing a new tool. But I have the same problem as always. When loading a new song with the tool open, this tool stops responding as it should (it does not return errors, it just does not work as it should; some things work and some things do not). It is necessary to reload the tool again, because I have changed of song. Would be the easiest thing to avoid any malfunction.

 

The tool is invoked by a function: main_dialog()

 

What is the correct code to force reload the tool after loading the new song?

 

Note: it is a tool with window. Closing the window is not the solution ( dialog:close() ), because the tool is still loaded in memory.


Edited by Raul (ulneiz), 11 July 2017 - 11:58.

: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 - 07:30

You cannot reload the whole tool on song load, as far as I know. The need you have is covered by:

 

renoise.tool().app_new_document_observable

 

This observable is banging everytime a new song has been loaded. Use this when you need to update something for a new song (like refreshing data in a GUI, for example).

 

Most likely, there is logic in your GUI that is still targeting the old song. The simplest is probably to check if the GUI is open when the new song is loaded, and if so, rebuild the whole thing.



#3 Raul (ulneiz)

Raul (ulneiz)

    Guruh Member

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

Posted 11 July 2017 - 11:57

You cannot reload the whole tool on song load, as far as I know. The need you have is covered by:

 

renoise.tool().app_new_document_observable

 

This observable is banging everytime a new song has been loaded. Use this when you need to update something for a new song (like refreshing data in a GUI, for example).

 

Most likely, there is logic in your GUI that is still targeting the old song. The simplest is probably to check if the GUI is open when the new song is loaded, and if so, rebuild the whole thing.

 

Ok perfect!

 

With this notifier it is possible to recharge the entire tool. In this tool, all functions depend on dialog_main(). I have solved it well and it works fine now:

function dialog_main()
  --Run VPD line timer
  if not renoise.song().transport.edit_mode_observable:has_notifier( vpd_line_timer ) then  
    renoise.song().transport.edit_mode_observable:add_notifier( vpd_line_timer )
  end
  vpd_line_timer()
  
  --Run VPD edit mode notifier bars
  if not renoise.song().transport.edit_mode_observable:has_notifier( vpd_edit_mode_notifier_bars ) then
    renoise.song().transport.edit_mode_observable:add_notifier( vpd_edit_mode_notifier_bars )
  end
  vpd_edit_mode_notifier_bars()

  --Avoid showing the same window several times!
  if ( dialog and dialog.visible ) then dialog:show() return end

  --Load dialog
  dialog = renoise.app():show_custom_dialog( "", content, key_handler )
  
  --reload all dialog main() in new song  
  if not renoise.tool().app_new_document_observable:has_notifier( dialog_main ) then
    renoise.tool().app_new_document_observable:add_notifier( dialog_main )
  end
end

I have added these lines inside dialog_main()

--reload all dialog main() in new song  
if not renoise.tool().app_new_document_observable:has_notifier( dialog_main ) then
  renoise.tool().app_new_document_observable:add_notifier( dialog_main )
end

You need to be inside main_dialog() to avoid loading the tool before loading Renoise to start, because it overlaps the window. I think I had a similar problem with another tool, and the solution is this nonsense.

 

...

 

Separate issue...

 

On the other hand, I use the following features when starting main.lua:
dialog = nil --placeholder for the dialog
vb = renoise.ViewBuilder() --ViewBuilder for dialog_main() function & others

And then I do not use any local to define each function. In this way, it is possible to close the tool and open it and preserve the status of the GUI. Now the tool works exactly as I desire. For simple tools it goes very well, and it is not necessary to add cached preferences. The tool has a specific and defined behavior. Other tools are otherwise defined, full of locals whose behavior with the GUI is different.

 

Thanks for the help!!!  :D

 

Solved!

 

 

 

Note: I can only solve a small problem with add_child and remove_child that I sometimes returns error when invoked again the same add_child or remove_child when he was already charged. Here is not something like "if not has_child xxxxx then" add_child xxxxx end ... I'll open another topic with this query. I need to avoid loading the already loaded child and avoid removing the child that does not exist...


: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