What do you mean with dynamic though, I’m not talking realtime attenuation of the edit step value according to the cursor placement in the editor or something!
Dynamic simply as in opposite to static as it currently is. Mostly in agreement to your statement “…automatically sets the amount of rows between 2 events as step length when running it.”
Perhaps I’m using the wrong word.
Jonas I believe only wants in run when you hit the keyboard shortcut. Dynamically implies to me that it will automatically update as you change position. This could cause some problems.
So it is static, you hit the button, it changes and is static again until you call the routine again.
If you have the cursor between the last note in a column and the end of a pattern what value would be returned then? No change maybe? With a message?
Got it, I used the wrong term then to describe it. I didn’t mean real time auto update.
Would it be possible, in the same pattern, to read the last note in a column to the first note in the column ?
I tried a bit, but I’m stumped. I have no way to query the column position of the cursor in the API?
The first part of the code is easy:
local rns = renoise.song()
-- Set variables: iter, insrtument_number
local iter = rns.pattern_iterator:lines_in_pattern_track(rns.selected_pattern_index, rns.selected_track_index)
local tmp = renoise.song().selected_instrument_index
renoise.song():capture_nearest_instrument_from_pattern()
local instrument_number = renoise.song().selected_instrument_index
renoise.song().selected_instrument_index = tmp
This uses capture_nearest_instrument_from_pattern()
to find the instrument. There’s a caveat is that it looks forward, not backwards. Don’t think this will affect the outcome of the script too much, but it would be nice to have a backwards option in the API.
Next I thought I would use:
renoise.song().selected_note_column
Which returns a renoise.NoteColumn object. But this object doens’t let me query the column number? E.g.
oprint(renoise.song().selected_note_column)
class: NoteColumn
properties:
delay_string
delay_value
instrument_string
instrument_value
is_empty
is_selected
note_string
note_value
panning_string
panning_value
volume_string
volume_value
methods:
__STRICT
__eq
__tostring
clear
copy_from
The only other option I see is:
renoise.song().patterns[].tracks[].lines[].note_columns[].is_selected
But this works on selection, not cursor, which would make the script stupid.
In order to write this script. The API needs a new feature. We need: Query cursor position. It should return { pattern, track, column }. The column is tricky because the cursor could be in the Effects, which is a renoise.EffectColumn() object. Someone smarter than me will have to chime in.
Or did I miss something in the API that would return the current column position of the cursor?
I may be wrong but the above is how I would understand a dynamic process. Although guess it is dynamic in a way as the result of running it does depend on the changing variables surrounding it. A discretely sampled dynamic process?
Shouldn’t be a problem as far as I can see. Don’t think I’ll have a chance to think about trying to do something like this myself for a while though and there are people out there who could program it in a tenth of the time I could with the eyes closed and arms tied behind their back
Scan a column for note events for a particular instrument (do we even want to go to note value, in case you are using a drum kit instrument?)
When one is found that matches the criterion add the line number to a table. Do the whole pattern.
Find the first entry in the table where the value is higher than current edit position.
Minus entry in table before it to get new Edit Step.
If there is no entry higher than current position use pattern length minus last entry plus first entry.
If I’m not too busy at work tomorrow maybe I’ll try and take a look at it but shit has been hitting the proverbial fan recently!
Damn! I had assumed this would be part of the Edit Position, but that seems only to refer to which pattern is the only being edited out of the sequence. Maybe it could be incorporated into it though, so that it comtains the pattern, track, column result you mention?
EDIT: Think I found it!
It returns a note column object, but no way (I can see) to get the position of said note column?
Nice to see this idea is getting some play time , maybe just forget about column particulars of the track the cursor is in and always take into account the first column?
Doh! Sorry I posted that 4 minutes after I was meant to have left work so didn’t double check against what you had written correctly or do any testing.
Still think cursor position in entirety makes most sense as part of EditPosition.
Except it does work and I did copy and paste the correct bit. Look at the Index!
renoise.song().selected_note_column_index
-> [number or nil (when an effect column is selected)]
Just got it to return different values depending on which note column I was in here anyway
Oh, you are right!
I was using selected_note_column
instead of selected_note_column_index
Doh!
It’s cool, I’m learning more and more. Not really used oprint until just not looking at various objects
Not sure why indexes are not generally part of the objects and rather always separate but it seems to follow that pattern throughout the API so who am I to comment.
Nor am I clear how it gets the format to print the likes of renoise.song().selected_note_column, where you only get some of the listed properties displayed on a normal prints but obviously you can access any of the others by typing renoise.song().selected_note_column.blah_blah.
Really am going off the topic of the thread not though so I apologise Jonas!
as long as there eventually are results, I wont hold it against you
Here’s a start. I’m too lazy to package this as a Tool. “Can’t someone else do it? -Homer Simpson” Also, consider changing the shortcut from “For Jonas” to something else.
I reread what Jonas wrote. I have a bad habit of posting crap before actually thinking it through. The code is a bit different than when I started. To use:
-
- Select an Instrument
-
- Click/Shortcut “For Jonas”
The script will look in the cursor’s note column for two matching instruments for which the cursor is the center, change the Edit Step value, and update the Status Bar.
Enjoy?
[luabox]
function main()
local rns = renoise.song()
local my_iter = rns.pattern_iterator:lines_in_pattern_track(rns.selected_pattern_index, rns.selected_track_index)
local my_col = rns.selected_note_column_index
local my_line = rns.selected_line_index
local my_inst = rns.selected_instrument_index
local start = -1
local finish = -1
for pos,line in my_iter do
local col = line.note_columns[my_col]
if col and not col.is_empty then
if pos.line < my_line and col.instrument_value + 1 == my_inst then
start = pos.line
elseif col.instrument_value + 1 == my_inst then
finish = pos.line
break
end
end
end
my_inst = string.upper(string.format("%02x", my_inst - 1))
if start ~= -1 and finish ~= -1 then
rns.transport.edit_step = finish - start
renoise.app():show_status(
"Selected Instrument " … my_inst … “, Edit Step changed to " … (finish - start) … “.”
)
else
renoise.app():show_status(
“Selected Instrument " … my_inst …”, unable to calculate Edit Step!”
)
end
end
renoise.tool():add_keybinding {
name = “Pattern Editor:Edit Step:For Jonas”,
invoke = main
}
renoise.tool():add_menu_entry {
name = “Main Menu:Tools:For Jonas”,
invoke = main
}
[/luabox]
I will not be improving this. Life is like a relay race. I’m passing the baton?
If this works, you sir are legendary … how would I pack something like this myself? I have the tool browser / editor enabled in the config and also Bantais easy tool tool installed. Pasting yer code & running it in the lua testpad throws up an error. Is there a packing howto somewhere for n00bs like me?
about:
Does one always have to select an instrument in the instrument list before running the script on a particular track? If so, this might defeat the purpose of the request / a quick way to automatically set the step length. I’d like to apply the shortcut without having to check if I’m on the correct instrument. Is there no way to auto fetch this info? If too much of a hassle I can live with the script taking any 2 succeeding note events in a track.
It’s probably faster for me to package it. Attached.
2442 test.xrnx
In the future, just rename test.xrnx to text.zip, unzip it and look at it. You’ll need the manifest.xml and the main.lua file for it to work.
The “Select instrument” is so that if you have something like
C-4 - 00
C-4 - 01
Cursor is here
C-4 - 00
And instrument 00 selected, the edit step caclulation will skip C-4 01.
If you want just “two events” change line ~16 to ~21 from:
if pos.line < my_line and col.instrument_value + 1 == my_inst then
start = pos.line
elseif col.instrument_value + 1 == my_inst then
finish = pos.line
break
end
to:
if pos.line < my_line then
start = pos.line
else
finish = pos.line
break
end
Then, reload all Tools.
The Status bar output will be garbage (Insrument selection will be ignored) but it’s a starting point for more feedback?
Cheers.
Here’s a more automatic version. Paste into the main.lua file of trotch.com.test.xrnx
[luabox]
function main()
local rns = renoise.song()
local my_pattern = rns.selected_pattern_index
local my_track = rns.selected_track_index
local my_col = rns.selected_note_column_index
local my_line = rns.selected_line_index
local my_inst = rns.selected_instrument_index
local my_iter = rns.pattern_iterator:lines_in_pattern_track(my_pattern, my_track)
for pos,line in my_iter do
local col = line.note_columns[my_col]
if col and not col.is_empty then
if pos.line < my_line then
my_inst = col.instrument_value + 1
else
break
end
end
end
local start = -1
local finish = -1
my_iter = rns.pattern_iterator:lines_in_pattern_track(my_pattern, my_track)
for pos,line in my_iter do
local col = line.note_columns[my_col]
if col and not col.is_empty then
if pos.line < my_line and col.instrument_value + 1 == my_inst then
start = pos.line
elseif col.instrument_value + 1 == my_inst then
finish = pos.line
break
end
end
end
my_inst = string.upper(string.format("%02x", my_inst - 1))
if start ~= -1 and finish ~= -1 then
rns.transport.edit_step = finish - start
renoise.app():show_status(
"Selected Instrument " … my_inst … “, Edit Step changed to " … (finish - start) … “.”
)
else
renoise.app():show_status(
“Selected Instrument " … my_inst …”, unable to calculate Edit Step!”
)
end
end
renoise.tool():add_keybinding {
name = “Pattern Editor:Edit Step:For Jonas”,
invoke = main
}
renoise.tool():add_menu_entry {
name = “Main Menu:Tools:For Jonas”,
invoke = main
}
[/luabox]
Better? Discuss amongst yourselves and hack away! I’m dropping out for real now
Amazing works beatifully! Thanks!
Ey Conner,
is it possible you hack this script so it can work between two volume (or pan) column values, but instead of changing the amount of editstep, selects the range in the pattern editor?
I often make a selection between two volume or pan column values and use interpolate in the advanced editor, this new script would definitely beat the fidgety mouse selecting with the press of a keyboard shortcut.