"variable 'song' Is Not Declared"

Been trying to work out how to use tables and get information about slices. A lot of things I do throw up errors such as:

Although ‘song’ clearly is defined as it’s part of the Classes(?) built into Renoise’s API. Although I have had similar problem, eg trying to do shortcuts and buttons, that would not work on the testing terminal but do once made into a tool…

Currently trying to get my head around Markers.

A snippet of code how to use “song().instruments.samples.slice_markers,” eg how to read the specific location of markers. It says " → [table of numbers - sample positions]" does that mean this is already a full table? So do you need to always use “samples[1]” as only the first slot can actually have markers? Or do you use “samples” where x is the sample slot the particular slice is in? Had been assuming the first. Have tried multiple things just trying to get this to print in the terminal but so far just confusing myself further I think!

Also how do I get the value from “#samples[1].slice_markers” so I can do the correct thing at the end/beginning of a sample?

The variable “song” doesn’t exist, but we have a method called renoise.song(), which will return the current song (I guess this is future-proof, in case we eventually get a multiple song interface)

A lot of methods (notifiers and such) need to attach themselves to a permanent process, or they automatically will become garbage collected. And this permanent process would be your tool. So, you can examine the structure of existing API objects exposed in Renoise, write your own functions - as long as they are mostly self-contained - in this console, but for more continuous, “process-like” stuff, you would need to roll your code into a tool of some kind.

OK think I have found to errors in the documentation.


Should start renoise.song()… no?


song() is repeated twice (IE renoise.song()song()…)

But getting something to print now. Seems the sample[] number might relate to slice but unsure, still get a result as long as I use a number within the range of amount of slices.

BUT if I run the same print command a number of times I get a different output every time.

EG: print (renoise.song().instruments[1].samples[2].slice_markers)
ran four times.
table: 0AC84858
table: 0AC84A38
table: 0AC84B00
table: 0AC84C68

What am I not understanding?

OK kinda of getting there. This will print the location of the first 10 markers. It was the missing square (long?) bracket associated with sample_slices which caused me some confused.

x = renoise.song().selected_instrument_index  
for i=1,10 do  
print (renoise.song().instruments[x].samples[1].slice_markers[i])  
end  

So getting there slowly. See if I can get much further after lunch…

Well spotted. These will be corrected.

If you have a sliced instrument then samples[1] will always refer to the original sample. The slice marker positions are then contained in samples[1].slice_markers, which is a table of positions within the original sample. Then samples[2] will refer to the read-only sample data for the first slice, samples[3] will be the read-only sample data for the second slice, and so on.

When you access the slice_markers property you do not get a direct reference to the actual slice markers. Instead you get back a new table containing the slice marker positions, so the unique output values you’re seeing here refer to each new table’s position in memory. You can pretty safely ignore this and just focus on the values contained within the table itself.

To quickly print out the values within a table, try this:
rprint(renoise.song().instruments[1].samples[1].slice_markers)

You can also use oprint() to see all the available properties and functions for an object:
oprint(renoise.song().instruments[1].samples[1])

Thanks, I was unclear that .slice_markers would be the number of markers and then there would be a table in .slice_markers[] with the actual positional values. Think I’m getting my head around it now, or at least how to use it. Any object (last phrase on a x.y.z string) has variables stored in a table so although the brackets aren’t shown I guess they are always implied, correct?

Another possible typo related to what I mentioned earlier about getting amount of slices present.


“Test for #samples[1].slice_markers > 1 to find out if the instrument is sliced.”

Only way I could manage to get it to return(print) number of slices was with “print (#renoise.song().instruments[x].samples[1].slice_markers)” but I guess the renoise.song().instrument[] is meant to be implicit? Is this a general way of truncating the terms in the docs or is there something else I’m actually missing?

From Renoise.Song.API.lua:

  
renoise.song().instruments[].samples[].slice_markers, _observable   
 -> [table of numbers - sample positions]  
  

This tells us that the slice_markers property actually returns a table of values. So to get back the table you just access the property, but to access a value within the table then you of course need the .

We can then use the # operator to find out the number of entries in the table itself.

So you might do something like:

  
local slices = renoise.song().instruments[1].samples[1].slice_markers  
local number_of_slices = #slices  
local first_slice_position = slices[1]  
  

Yep, the full path including renoise.song()… was implied. I suspect it was just taking a shortcut in the comments to avoid having to repeat the same long bit of text over and over again. Maybe this is not as clear as it could be, but hopefully it only takes a few moments to see what is actually going on. If not then we can try to address this in the future.

Generally speaking you will always need the fully qualified object path, ie. renoise.song().instruments[1].blah.blah.blah, but in your actual code you will probably be working with local variables anyway.

For example:

  
local song = renoise.song()  
local instrument = song.selected_instrument  
local sample = instrument.samples[1]  
  

OK thanks, making more and more sense all the time.

As I can find now way to centre the Sample Editor view around a particular position I think I need to leave this here now anyway though… :(

I wasn’t aware that the sample editor or gui dialog windows can be placed in a specific position on the screen?

think he means a selection in the editor, or something to do with slices, as per here: https://forum.renoise.com/t/the-api-wishlist-thread/29285

The viewable window, if you are zoomed in. Selected areas can be out of sight.

So to centre the zoomed view to a position without changing zoom factor ;)