Set all notes in selection to selected instrument

So basically what i want my function to do is to set all instrument numbers in the pattern selection to the currently selected instrument, something like:

  
instr = somehow_determine_which_instrument_is_selected();  
  
for column = first_selected_column to last_selected_column  
 for row = first_selected_row to last_selected_row  
 if (there is an instrument number at this position in current pattern) then  
 current_pattern.this_position.instrument_number = instr;  
 end if  
 end for  
end for  
  

I’m having trouble finding the proper names for objects (again) despite going through the examples in the docs and poking around in the lua scripting console… anyone?

Hi delt.
First of all, Grep is your friend. Get the whole Renoise LUA Api documentation, extract the /Documentation/ folder of it, copy it to one single file (cat * >text) then place that somewhere,and write yourself an alias like this:

alias sol="cat Solution.txt | grep $1’

Then do a “sol instrument” or anything. In this case, you’ll benefit immensely by remembering that there’s a selected_ (pretty much anything) that helps you

  
esa@esa-desktop:~$ sol selected_  
'renoise.song().selected_track','selected_instrument','selected_sample'.  
renoise.song().selected_instrument, _observable  
renoise.song().selected_instrument_index, _observable  
renoise.song().selected_sample, _observable  
renoise.song().selected_sample_index, _observable  
renoise.song().selected_track, _observable  
renoise.song().selected_track_index, _observable  
renoise.song().selected_device, _observable  
renoise.song().selected_device_index, _observable  
renoise.song().selected_parameter, _observable  
renoise.song().selected_parameter_index, _observable  
renoise.song().selected_pattern, _observable  
-- and selected_track_index_observable for notifications.  
renoise.song().selected_pattern_track, _observable  
renoise.song().selected_pattern_index, _observable  
renoise.song().selected_sequence_index, _observable  
renoise.song().selected_line  
renoise.song().selected_line_index  
renoise.song().selected_note_column  
renoise.song().selected_note_column_index  
renoise.song().selected_effect_column  
renoise.song().selected_effect_column_index  
renoise.song().selected_sub_column_type  
renoise.song().instruments[].samples[].sample_buffer.selected_channel, _observ  
  

It (the grepper) will help immensely. no, seriously. I know it helped me, because I had absolutely no way of knowing which function was called what, so i just looked for anything called instrument, anything called anything else, etc.

However, about your code - thanks for writing it. it’s somewhat easy for me to modify at least some of it. i think by knowing selected_instrument_index, selection_in_pattern.start_column and selection_in_pattern.end_column and selection_in_pattern.start_line and end_line, this should at least help you somewhat. same with selected_pattern_index. the detection of whether there’s an instrument number on the row or column i’m a bit vague on, so let’s wrangle this further once we get further. i’ve put stuff in bold that i’ve added to your pseudocode.

  
instr = renoise.song().selected_instrument_index;  
for column = renoise.song().selection_in_pattern.start_column,renoise.song().selection_in_pattern.end_column  
 for row = renoise.song().selection_in_pattern.start_line,renoise.song().selection_in_pattern.end_line  
 -- your code: if (there is an instrument number at this position in current pattern) then  
renoise.song().selected_pattern_index -- your code:..this_position.instrument_number = instr;  
 end if  
 end for  
end for  
  

additionally, try this in the Scripting Terminal:

print ("Start Column,Row: " .. renoise.song().selection_in_pattern.start_column .. "," .. renoise.song().selection_in_pattern.start_line .. " End Column,Row: " .. renoise.song().selection_in_pattern.end_column .. "," .. renoise.song().selection_in_pattern.end_line)  

Since Joule helped me immensely originally, try this actual code from Paketti
and see where it takes you:

  
function arpxy(effect,x,y)  
local counter=nil   
local currentamount=nil  
local old_x=nil  
local old_y=nil  
local new_x=nil  
local new_y=nil  
  
for i=renoise.song().selection_in_pattern.start_line,renoise.song().selection_in_pattern.end_line   
do   
  
if   
renoise.song().patterns[renoise.song().selected_pattern_index].tracks[renoise.song().selected_track_index].lines[i].effect_columns[1].amount_value == 0 and (x < 0 or y < 0)  
then renoise.song().patterns[renoise.song().selected_pattern_index].tracks[renoise.song().selected_track_index].lines[i].effect_columns[1].number_string=""   
  
else  
renoise.song().patterns[renoise.song().selected_pattern_index].tracks[renoise.song().selected_track_index].lines[i].effect_columns[1].number_string=effect  
old_y=renoise.song().patterns[renoise.song().selected_pattern_index].tracks[renoise.song().selected_track_index].lines[i].effect_columns[1].amount_value % 16  
old_x=math.floor (renoise.song().patterns[renoise.song().selected_pattern_index].tracks[renoise.song().selected_track_index].lines[i].effect_columns[1].amount_value/16)  
  
new_x=old_x+x  
new_y=old_y+y  
print ("new_x: " .. new_x)  
print ("new_y: " .. new_y)  
if new_x > 15 then new_x = 15 end  
if new_y > 15 then new_y = 15 end  
if new_y < 1 then new_y = 0 end  
if new_x < 1 then new_x = 0 end  
  
counter=(16*new_x)+new_y   
  
renoise.song().patterns[renoise.song().selected_pattern_index].tracks[renoise.song().selected_track_index].lines[i].effect_columns[1].amount_value=counter   
end  
end  
end  
  

Let’s keep at this until we have a functioning “alt-S” (“Set Instrument” (in selection))

Got it done for selection in a single track. Let me work through the fine points of getting across track selections and I might be able to upload something by the end of the day. On shift at work until 3am tonight and believe it’s going to be a quiet one… ;)

Try this. It’s worked in the test conditions I’ve thrown at it.

Shortcut is in a maybe slightly weird place, as I’ve added it to a very incomplete tool I’ve been working on.

Pattern Editor:Kazakore’s Edit Shortcuts:Selection to Current Instrument

Let me know of any problems.

For completeness here’s the code for anybody who might want to look but not download:

[details=“Click to view contents”] --[[===================================================================================
Set all instrument numbers within selection to currently selected instrument

Author: Dale Powell (Kazakore) <dj_kaza>

Version: 0.1

===================================================================================]]–



local tool = renoise.tool()

local rns = renoise.song

local app = renoise.app()



>SET SELECTION TO CURRENT INSTRUMENT<



function set_ins()

local sel = rns().selection_in_pattern

local pat = rns().selected_pattern_index

local ins = rns().selected_instrument_index-1

local edit = nil



if sel == nil then app.show_status(‘No Selection in Pattern’) return else end



–First Track

if sel.start_track==sel.end_track then

for l=sel.start_line, sel.end_line do

for c=sel.start_column, sel.end_column do

if c > rns().tracks[sel.start_track].visible_note_columns then break else end

if rns():pattern(pat):track(sel.start_track):line(l):note_column©.instrument_value==255 then

else edit = rns():pattern(pat):track(sel.start_track):line(l).note_columns[c]

edit.instrument_value = ins

rns():pattern(pat):track(sel.start_track):line(l).note_columns[c] = edit

end

end

end

return

else

for l=sel.start_line, sel.end_line do

for c=sel.start_column, rns().tracks[sel.start_track].visible_note_columns do

if rns():pattern(pat):track(sel.start_track):line(l):note_column©.instrument_value==255 then

else edit = rns():pattern(pat):track(sel.start_track):line(l).note_columns[c]

edit.instrument_value = ins

rns():pattern(pat):track(sel.start_track):line(l).note_columns[c] = edit

end

end

end

end



–Middle Tracks

if sel.start_track+1==sel.end_track then else

for t=sel.start_track+1, sel.end_track-1 do

for l=sel.start_line, sel.end_line do

for c=1, rns().tracks[t].visible_note_columns do

if rns():pattern(pat):track(t):line(l):note_column©.instrument_value==255 then

else edit = rns():pattern(pat):track(t):line(l).note_columns[c]

edit.instrument_value = ins

rns():pattern(pat):track(t):line(l).note_columns[c] = edit

end

end

end

end

end



–Last track

for l=sel.start_line, sel.end_line do

for c=1, sel.end_column do

if c > rns().tracks[sel.end_track].visible_note_columns then break else end

if rns():pattern(pat):track(sel.end_track):line(l):note_column©.instrument_value==255 then

else edit = rns():pattern(pat):track(sel.end_track):line(l).note_columns[c]

edit.instrument_value = ins

rns():pattern(pat):track(sel.end_track):line(l).note_columns[c] = edit

end

end

end





end



– Key Binding

tool:add_keybinding {

name = “Pattern Editor:Kazakore’s Edit Shortcuts:Selection to Current Instrument”,

invoke = function() set_ins() end

}



– MIDI Mapping

tool:add_midi_mapping {

name = “Kazakore’s Edit Shortcuts:Pattern Editor:Selection to Current Instrument”,

invoke = function(message)

if (message:is_trigger()) then

set_ins()

end

end

}

[/details]

</dj_kaza>

Thanks guys!! I’ll try to wrap my head around some of this stuff later today :D :D

The one I’m using still is ledger’s Convert Instrument tool… it’s got KB shortcuts and Instrument Box menus for set instrument in selection, track, whole track (throughout song) - very handy
link