Select instrument

Hello. I am new to this and wondering if there is any way to select the instrument that I want. I have read the API but it is still not clear to me.

Another question I have is if there is a function that tells me how many phrases there are in total for each instrument, I know that there is a function that does this for tracks.

Thank you

Hi @Xavi

For instrument index:
renoise.song().selected_instrument_index, _observable
  -> [number]
For Terminal:
print(renoise.song().selected_instrument_index)
--return the selected instrument index (range 1 to 254), start with 1.
--255 to clear the .instrument_value

Use the containing tables of phrases. # returns the number of items:

For instrument index: i:
#renoise.song().instruments[i].phrases
  -> [number]
or most suitable (faster):
#renoise.song():instrument(i).phrases
  -> [number]

For selected instrument:
#renoise.song().selected_instrument.phrases
  -> [number]
For Terminal:
print(#renoise.song().selected_instrument.phrases)
--range of phrases 0 to 126.

Hello @Raul

Thank you very much for your answer. You have solved my second question.

But the first one is not yet clear to me. What I want to do is get a function that selects a specific instrument.

I don’t know if its related but what does this function do? or what can I do with it?

– Access to a single instrument by index. Use properties ‘instruments’ to iterate
– over all instruments and to query the instrument count.
renoise.song():instrument(index)
→ [renoise.Instrument object]

renoise.song().selected_instrument_index = 3

This code select the instrument with index 3.

print(renoise.song().selected_instrument_index)

This code return the index of the current instrument.

Example:

local function sel_ins(idx)
  renoise.song().selected_instrument_index = idx
  --see inside the terminal
  print("The current instrument is:", renoise.song().selected_instrument_index)
end
--bang!
sel_ins(3)

amazing! Thank you @Raul

Something that looks simple but could not understand…

All programmers have started at some point. This code is the most basic (execution of a very basic function that is passing a variable, a number).

Here you should learn the ins and outs of the LUA code (it’s really not very complicated), and besides, the ins and outs of the API code (how it works and how to understand its published documentation).

yeah honestly its so hard for me to try to make sense of the API. At least thanks to the little tutorial on how to build the vb I was able to understand that part, but without examples and just reading the song API I find it very complicated haha

I went through, and still spend a lot of time with trial and error.
A good tip is to know how to use the Terminal and get results with print, oprint and rprint. So you can test things.

The API is quite extensive and fairly well ordered, but it is complex. Keep in mind that thanks to it it is possible to build almost anything, although with certain limitations. In the forums of tools you can receive guidance. But don’t expect feature solutions continually. Only with guidance you can save a lot of time. At least this is my experience here.

Fortunately, there are a handful of programmers of different levels who can answer questions.

thanks Raul, the good thing is that every day I am learning something new, and I cannot deny that it is a lot of fun, I will search on rprint and oprint, cheers!

That is very true! Be careful! It can be very addictive! :grinning:

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