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
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
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
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