Raul, (looks like joule and danoise have left the country (don’t blame them in the least however…)) my quick thought on this first part (don’t know about the second part)…
Quickly looking at the API docs, you have the note_range span associated with each phrase (the upper and lower note_range would be equal in the above case) yes? So why not loop through (search) each phrase starting at 1 checking your B-0 (note number 11?) with the note_range and if that note number falls within the phrases note_range chances are you have found the phrase index associated with that note?
Also looking at that screenshot it seems like you have a pretty much one to one relationship with the note number B-0 (11) and the phrase number (12). It looks like you have assigned (in order) a phrase to each individual key.
function pht_phrase_keymapped( nte )
local song = renoise.song()
for i = 1, #song.selected_instrument.phrases do
if ( song.selected_instrument:phrase( i ).mapping ~= nil ) then
local note_1 = song.selected_instrument:phrase( i ).mapping.note_range
local note_2 = song.selected_instrument:phrase( i ).mapping.note_range
for r = note_1, note_2 do
if ( r == nte ) then
print( i )
song.selected_phrase_index = i
It is a bit convoluted, but it returns exactly the index value desired. It also works if a range of notes is associated with the same phrase.If a note does not have an associated phrase, it does not return anything.
On the other hand, I believe that the API documentation does not have any control over the play and stop buttons of the phrases. I have not found anything.