Jump to content


Photo

Obtain the index of the last phrase played

phrase index phrase played

  • Please log in to reply
5 replies to this topic

#1 Raul (ulneiz)

Raul (ulneiz)

    Guruh Motha Fakka is Levitating and Knows Everything About Renoise Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPipPip
  • 1349 posts
  • Gender:Male
  • Location:Spain

Posted 28 January 2018 - 11:53

Load an instrument that has many phrases. In total you can have up to 126 phrases.
 
In the phrases playback panel, you can select a specific phrase and play it.
 
With a tool, it is possible to reproduce any phrase without selecting it before, through the "Keymap" mode. Here each key can have a phrase linked.
 
So:
  1. How to get the index of the phrase associated with the X key? For example, the key B-0, has associated the phrase 0C. How to get the index of that phrase?
  2. Is it possible to obtain the index of the last phrase that has been reproduced? The last phrase played does not have to be selected.

In case there are doubts, the phrases panel is here with Keymap:

phrase-played.png

 

Any ideas? Any way to print that index?

Edited by Raul (ulneiz), 28 January 2018 - 19:37.

:excl: Development of my tools PhraseTouch  |  GT16-Colors (old)

 

:excl: My API wishlist R3.1 (updated 24 July 2017):

Spoiler

 

:excl: My Renoise 3.1 wishlist (updated 26 September 2017):

Spoiler

#2 Circe

Circe

    Advanced Member

  • Normal Members
  • PipPipPip
  • 90 posts
  • Gender:Male
  • Location:Spain
  • Interests:Visual Basic 6.0 Music Programing
    Piano Chords

Posted 28 January 2018 - 12:34

Deleted.... no interest


Edited by Circe, 28 January 2018 - 18:01.


#3 4Tey

4Tey

    Big Daddy Member

  • Normal Members
  • PipPipPipPipPipPipPip
  • 447 posts
  • Gender:Male

Posted 28 January 2018 - 17:38

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

How to get the index of the phrase associated with the X key? For example, the key B-0, has associated the phrase 0C. How to get the index of that phrase?

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.


  • Raul (ulneiz) likes this

#4 Raul (ulneiz)

Raul (ulneiz)

    Guruh Motha Fakka is Levitating and Knows Everything About Renoise Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPipPip
  • 1349 posts
  • Gender:Male
  • Location:Spain

Posted 28 January 2018 - 19:35

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.

 

:D  Ok, great!

--phrase keymapped
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[ 1 ]
      local note_2 = song.selected_instrument:phrase( i ).mapping.note_range[ 2 ]
      for r = note_1, note_2 do
        if ( r == nte ) then
          print( i )
          song.selected_phrase_index = i
          return i
        end
      end
    end
  end
end

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.

 

Thanks 4Tey!!!!

 

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.


:excl: Development of my tools PhraseTouch  |  GT16-Colors (old)

 

:excl: My API wishlist R3.1 (updated 24 July 2017):

Spoiler

 

:excl: My Renoise 3.1 wishlist (updated 26 September 2017):

Spoiler

#5 4Tey

4Tey

    Big Daddy Member

  • Normal Members
  • PipPipPipPipPipPipPip
  • 447 posts
  • Gender:Male

Posted 28 January 2018 - 19:52

Ok Raul...but could I just mention quickly looking at your code snip why you have an inner for loop scan at lines 8-14?  Off the top of my head could be replaced with just an if statement?:

local note1 = blah
local note2 = blah
if nte >= note_1 and nte <= note_2 then
  print(i)
  song.selected_phrase_index = i
  return i
end

I don't know Raul I haven't tested that (you'd have to try it see if it still works)...doesn't really matter so long as it does what you want though :)



#6 Raul (ulneiz)

Raul (ulneiz)

    Guruh Motha Fakka is Levitating and Knows Everything About Renoise Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPipPip
  • 1349 posts
  • Gender:Male
  • Location:Spain

Posted 28 January 2018 - 20:03

Ok Raul...but could I just mention quickly looking at your code snip why you have an inner for loop scan at lines 8-14?  Off the top of my head could be replaced with just an if statement?:

local note1 = blah
local note2 = blah
if nte >= note_1 and nte <= note_2 then
  print(i)
  song.selected_phrase_index = i
  return i
end

I don't know Raul I haven't tested that (you'd have to try it see if it still works)...doesn't really matter so long as it does what you want though :)

 

It also works correctly:

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[ 1 ]
      local note_2 = song.selected_instrument:phrase( i ).mapping.note_range[ 2 ]
      if ( nte >= note_1 ) and ( nte <= note_2 ) then
        print( i )
        song.selected_phrase_index = i
        return i
      end
    end
  end
end

What I would like is to improve these two lines:

local note_1 = song.selected_instrument:phrase( i ).mapping.note_range[ 1 ]
local note_2 = song.selected_instrument:phrase( i ).mapping.note_range[ 2 ]

mapping.note_range is a table of two values. Maybe there is some way to reduce it in this function...


:excl: Development of my tools PhraseTouch  |  GT16-Colors (old)

 

:excl: My API wishlist R3.1 (updated 24 July 2017):

Spoiler

 

:excl: My Renoise 3.1 wishlist (updated 26 September 2017):

Spoiler