[solved] Visible_Note_Columns & Note_Column[X].is_Empty?

hi. I’m trying to make something which outputs a note to the current_track. got that working fine, but decided to go for improvements. so now if note_column (NC from now on) [1-12] are full, it doesn’t put a note to the lines[1].notecolumn. if notecolumn2 is empty, it will write to notecolumn2. so the point of the script is to put a c-4 (+specific instrument) to an empty notecolumn on the selected_track. i did a load of elseif’s and ands and got it working.

but what broke was when i tried to control visible_note_columns. easiest method would be to just make 12 notecolumns visible at the start of the scrip, but that’s just not really required, especially if then you’ll have a 12 notecolumn track which only has stuff on one note column.

so then i tried to “if this many are empty, then make this visible and write to this notecolumn”, but obviously if you have notes on 1, 2, 3, 5-12, inputting a note via script to #4 will change visibility to 1-4.

so what i’m after is a method of recognizing NC.is_empty in such a way that it will display the amount of notecolumns that have information and nothing else.

how would i go about doing something like this? What I have right now (and which seems to work after a fashion, but is clunky), is really clunky.

[details=“Click to view contents”] ```lua
function recordtocurrenttrack()
local s=renoise.song()
local ss=s.selected_sample
local nol=s.selected_pattern.number_of_lines
local t=renoise.song().transport
local w=renoise.app().window

local currInst = s.selected_instrument_index
local currTrak = s.selected_track_index
local currPatt = s.selected_pattern_index
w.sample_record_dialog_is_visible=true
s.transport:start_stop_sample_recording()
s.patterns[currPatt].tracks[currTrak].lines[1].effect_columns[1].number_string=“05”
s.patterns[currPatt].tracks[currTrak].lines[1].effect_columns[1].amount_string=“01”
local tulos=renoise.song().selected_instrument_index -1
local nc=s.patterns[currPatt].tracks[currTrak].lines[1].note_columns
local place=nil
local zero=nil
print (renoise.song().tracks[currTrak].visible_note_columns)
print (“start of:”)
for i=1,12 do
print (renoise.song().patterns[currPatt].tracks[currTrak].lines[1].note_columns[i].is_empty)
end
–if renoise.song().patterns[currPatt].tracks[currTrak].lines[1].note_columns[1].is_empty==true then

if nc[1].note_string==“C-4” and
nc[2].note_string==“C-4” and
nc[3].note_string==“C-4” and
nc[4].note_string==“C-4” and
nc[5].note_string==“C-4” and
nc[6].note_string==“C-4” and
nc[7].note_string==“C-4” and
nc[8].note_string==“C-4” and
nc[9].note_string==“C-4” and
nc[10].note_string==“C-4” and
nc[11].note_string==“C-4” and
nc[12].note_string==“C-4” then
renoise.app():show_status(“I think you should switch to a different channel already”)
renoise.song().tracks[currTrak].visible_note_columns=12
place=nil
elseif nc[1].note_string==“C-4” and
nc[2].note_string==“C-4” and
nc[3].note_string==“C-4” and
nc[4].note_string==“C-4” and
nc[5].note_string==“C-4” and
nc[6].note_string==“C-4” and
nc[7].note_string==“C-4” and
nc[8].note_string==“C-4” and
nc[9].note_string==“C-4” and
nc[10].note_string==“C-4” and
nc[11].note_string==“C-4” then
place=12
renoise.song().tracks[currTrak].visible_note_columns=place
elseif nc[1].note_string==“C-4” and
nc[2].note_string==“C-4” and
nc[3].note_string==“C-4” and
nc[4].note_string==“C-4” and
nc[5].note_string==“C-4” and
nc[6].note_string==“C-4” and
nc[7].note_string==“C-4” and
nc[8].note_string==“C-4” and
nc[9].note_string==“C-4” and
nc[10].note_string==“C-4” then
place=11
renoise.song().tracks[currTrak].visible_note_columns=place
elseif nc[1].note_string==“C-4” and
nc[2].note_string==“C-4” and
nc[3].note_string==“C-4” and
nc[4].note_string==“C-4” and
nc[5].note_string==“C-4” and
nc[6].note_string==“C-4” and
nc[7].note_string==“C-4” and
nc[8].note_string==“C-4” and
nc[9].note_string==“C-4” then
place=10
renoise.song().tracks[currTrak].visible_note_columns=place
elseif nc[1].note_string==“C-4” and
nc[2].note_string==“C-4” and
nc[3].note_string==“C-4” and
nc[4].note_string==“C-4” and
nc[5].note_string==“C-4” and
nc[6].note_string==“C-4” and
nc[7].note_string==“C-4” and
nc[8].note_string==“C-4” then
place=9
renoise.song().tracks[currTrak].visible_note_columns=place
elseif nc[1].note_string==“C-4” and
nc[2].note_string==“C-4” and
nc[3].note_string==“C-4” and
nc[4].note_string==“C-4” and
nc[5].note_string==“C-4” and
nc[6].note_string==“C-4” and
nc[7].note_string==“C-4” then
place=8
renoise.song().tracks[currTrak].visible_note_columns=place
elseif nc[1].note_string==“C-4” and
nc[2].note_string==“C-4” and
nc[3].note_string==“C-4” and
nc[4].note_string==“C-4” and
nc[5].note_string==“C-4” and
nc[6].note_string==“C-4” then
place=7
renoise.song().tracks[currTrak].visible_note_columns=place
elseif nc[1].note_string==“C-4” and
nc[2].note_string==“C-4” and
nc[3].note_string==“C-4” and
nc[4].note_string==“C-4” and
nc[5].note_string==“C-4” then
place=6
renoise.song().tracks[currTrak].visible_note_columns=place
elseif nc[1].note_string==“C-4” and
nc[2].note_string==“C-4” and
nc[3].note_string==“C-4” and
nc[4].note_string==“C-4” then
place=5
renoise.song().tracks[currTrak].visible_note_columns=place
elseif nc[1].note_string==“C-4” and
nc[2].note_string==“C-4” and
nc[3].note_string==“C-4” then
place=4
renoise.song().tracks[currTrak].visible_note_columns=place
elseif nc[1].note_string==“C-4” and
nc[2].note_string==“C-4” then
place=3
renoise.song().tracks[currTrak].visible_note_columns=place
elseif nc[1].note_string==“C-4” then
place=2
renoise.song().tracks[currTrak].visible_note_columns=place
elseif nc[1].note_string==“—” then
place=1
renoise.song().tracks[currTrak].visible_note_columns=place
end

if place==zero then return
else s.patterns[currPatt].tracks[currTrak].lines[1].note_columns[place].note_string=“C-4”
s.patterns[currPatt].tracks[currTrak].lines[1].note_columns[place].instrument_value=tulos
end

ss.autoseek=true
ss.sample_buffer_observable:add_notifier(function() w.sample_record_dialog_is_visible=false end)
end

renoise.tool():add_menu_entry {name = “Pattern Editor:RecordToCurrent”, invoke = function() recordtocurrenttrack() end}

First i would change the bunches of ifs to smaller chunks and simply set a free column to the value where you would not find a note:

  
for i = 1,12 do   
 if nc[i].note_string=="---" then  
 place = i  
 break  
 end   
end  
  

This would already save you a lot of hassle, it scans each column until it finds an empty one, puts the empty one into the variable place and then breaks the for-loop.

If you are specifically are scanning for a note-column not being C-4 then you could also solve it in this manner:

  
 for i = 1,12 do   
 if nc[i].note_string~="C-4" then  
 place = i  
 break  
 end   
 end  
  

Now every column is picked that doesn’t has a C-4 as a note (and breaks at the first one it finds ofcourse).
As soon as place is filled, you can also create a column marker so that you can toggle the column visibility by the highest added column:

  
if column_high < place then  
 column_high = place  
end  
  
--... more code  
--...  
renoise.song().tracks[currTrak].visible_note_columns = column_high--Reset column_high again for the next track  
 column_high = 1  
  

Thanks very much. I did this modification and realized that the script is going where it shouldn’t be going (first start_record imprints notecolumn#1 with C-4 note, but when you start_record again, it imprints the same instrument and same c-4 to the second notecolumn, so basically it’s already broken even before it’s finished :) … i’ll have to think about this, maybe read selected_instrument_index and make sure the “stop recording” (i use one script to start and stop recording so hence the issue) reads the current index and does not imprint notecolumn#2 with the same sample… will have to think about this a bit.

thanks for all your help again vV!

Ok, massaged it around myself and with some help from a friend who came to my apartment for some lackluster.org drupal development but ended up getting sucked into the renoise api vortex:

function recordtocurrenttrack()  
 local s=renoise.song()  
 local ss=s.selected_sample  
 local t=renoise.song().transport  
 local w=renoise.app().window   
  
 w.sample_record_dialog_is_visible=true  
 t:start_stop_sample_recording()  
  
 if ss.sample_buffer_observable:has_notifier(finalrecord) == false then   
 ss.sample_buffer_observable:add_notifier(finalrecord)  
 end  
end  
  
function finalrecord()  
 local s=renoise.song()  
 local ss=s.selected_sample  
 local currSamp=renoise.song().selected_sample_index  
 local currInst=s.selected_instrument_index  
 local currTrak=s.selected_track_index  
 local currPatt=s.selected_pattern_index  
 local w=renoise.app().window  
 local rightinstrument=nil  
 local place=nil   
 local zero=nil  
 local o=nil  
 local rightinstrument=renoise.song().selected_instrument_index-1  
 local nc=s.patterns[currPatt].tracks[currTrak].lines[1].note_columns  
 local selnotcol=renoise.song().selected_note_column_index  
 local vnc=renoise.song().tracks[currTrak].visible_note_columns  
  
 w.sample_record_dialog_is_visible=false   
 ss.autoseek=true  
 s.patterns[currPatt].tracks[currTrak].lines[1].effect_columns[1].number_string="05"  
 s.patterns[currPatt].tracks[currTrak].lines[1].effect_columns[1].amount_string="01"  
  
 for o = 1,12 do   
 if nc[o].note_string=="---" then   
 s.patterns[currPatt].tracks[currTrak].lines[1].note_columns[o].note_string="C-4"  
 s.patterns[currPatt].tracks[currTrak].lines[1].note_columns[o].instrument_value=rightinstrument  
 if vnc < o then  
 s.tracks[currTrak].visible_note_columns=o  
 end  
 break  
 end   
 end  
  
 ss.sample_buffer_observable:remove_notifier(finalrecord)  
 w.lock_keyboard_focus=true  
end  

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.