Don'T Display Vb:Text Content If X

Hi, I’m on/off building a little GUI to test out the API functions I already know how to call. I decided to go with “sample_rate, sample_ch, sample_frames, etc” but the GUI doesn’t load at all if there’s no sampledata in the selected_sample. So here’s my question, how do I make a if blaX then nothing else vb:text type stuff?

  
vb:column {  
 margin =0,  
 vb:column {  
 margin=5,  
 style = "group",  
 --margin = DEFAULT_MARGIN,  
vb:text { text = "Sample Statistics" },  
vb:text { text = "CURRENT SAMPLE: " .. renoise.song().selected_sample.name},  
vb:button { text = "SAVE SAMPLE", notifier = function() savesampleinfolder() end },  
vb:text { text = "CURRENT SAMPLE IS: " ..  
 sb.bit_depth .. " BIT" .. "\nCURRENT SAMPLE IS: " ..  
 sb.sample_rate .. " kHz" .. "\nNUMBER OF CHANNELS: " .. renoise.song().selected_sample.sample_buffer.number_of_channels .. "\nNUMBER OF FRAMES: " .. sb.number_of_frames,  
 }}  

Not sure, but this is where I’d start to go about it.

  
local my_bitdepth_text  
local my_samplerate_text  
local my_numberofchannels_text  
local my_numberofframes_text  
  
if sb.has_sample_data then  
 my_bitdepth_text = sb.bit_depth  
 my_samplerate_text = sb.sample_rate  
 my_numberofchannels_text = renoise.song().selected_sample.sample_buffer.number_of_channels  
 my_numberofframes_text = sb.number_of_frames  
else  
 my_bitdepth_text = ""  
 my_samplerate_text = ""  
 my_numberofchannels_text = ""  
 my_numberofframes_text = ""  
end  
  
  
vb:column {  
 margin =0,  
 vb:column {  
 margin=5,  
 style = "group",  
 --margin = DEFAULT_MARGIN,  
vb:text { text = "Sample Statistics" },  
vb:text { text = "CURRENT SAMPLE: " .. renoise.song().selected_sample.name},  
vb:button { text = "SAVE SAMPLE", notifier = function() savesampleinfolder() end },  
vb:text { text = "CURRENT SAMPLE IS: " ..  
 my_bitdepth_text .. " BIT" .. "\nCURRENT SAMPLE IS: " ..  
 my_samplerate_text .. " kHz" .. "\nNUMBER OF CHANNELS: " .. my_numberofchannels_text .. "\nNUMBER OF FRAMES: " .. my_numberofframes_text,  
 }}  

Where would an if-check like that be placed - if one wanted to show other information also in ViewBuilder()s?
I’m really vague in this. I’ve got Rows and Column of vb stuff going on, text and buttons and stuffs. I had a little list going on, of sample details, and now I’m not sure how to make it appear and how to make it disappear if no sample is available.

I believe it’s enough to place the if-then snippet anywhere before your sample data column. Not sure how you’re building the gui, or updating(?) it. Quick note: I forgot the variable declarations from my snippet, so those have to be added before the If-then -thing.

– Set visible to false to hide a view (make it invisible without removing
– it). Please note that view.visible will also return false when any of its
– parents are invisible (when its implicitly invisible).
– By default a view is visible.
view.visible
→ [boolean]
Stole MKaki’s snippet and processed it a bit, the draft would the look something like:

  
  
local my_bitdepth_text  
local my_samplerate_text  
local my_numberofchannels_text  
local my_numberofframes_text  
  
if sb.has_sample_data then  
 my_bitdepth_text = sb.bit_depth  
 my_samplerate_text = sb.sample_rate  
 my_numberofchannels_text = renoise.song().selected_sample.sample_buffer.number_of_channels  
 my_numberofframes_text = sb.number_of_frames  
end  
  
  
area_sample = vb:column {  
 margin =0,  
 vb:column {  
 margin=5,  
 style = "group",  
 --margin = DEFAULT_MARGIN,  
vb:text { text = "Sample Statistics" },  
vb:text { text = "CURRENT SAMPLE: " .. renoise.song().selected_sample.name},  
vb:button { text = "SAVE SAMPLE", notifier = function() savesampleinfolder() end },  
vb:text { text = "CURRENT SAMPLE IS: " ..  
 my_bitdepth_text .. " BIT" .. "\nCURRENT SAMPLE IS: " ..  
 my_samplerate_text .. " kHz" .. "\nNUMBER OF CHANNELS: " .. my_numberofchannels_text .. "\nNUMBER OF FRAMES: " .. my_numberofframes_text,  
 }}  
  
 if sb.has_sample_data then  
 area_sample.visible = true  
 else  
 area_sample.visible = false  
 end if  
  
 dialog_content = {area_loop, area_transport, area_views, area_config, area_sampler, area_song_stats, area_sample}  
 dialog_frame = show_custom_prompt("Nativity Scene V"..version_number,dialog_content, key_handler)  
  
  

Point is you also need to add a notifier to the sample list observable, so that if the user selects a sample that contains data, that the area with buttons and text is being displayed again so that the GUI frame is updated on-the-fly.

  
function sample_list_notifier()  
..get current selected sample...  
..get has_sample_data state...  
if state = true then   
 area_sample.visible = true  
else  
 area_sample_visible = false  
end   
  
end  
  

Also the area_sample variable has to be global within your own routine, else you can’t call or change objects and properties from it elsewhere.

There are a few pitfalls here to encounter, so these kind of routines require a bit more thoughtfullness.

What i also forgot:I play with the visibility of the note-matrix in the Epic Arpeggiator (hit the page up or page down key to switch between custom or matrix mode, in the keyhandler of the “gui.lua” you can find how the areas are being set to visible or invisible)