Jump to content


Photo

how to use case or switch or something?


  • Please log in to reply
13 replies to this topic

#1 esaruoho

esaruoho

    Guruh Motha Fakka is Levitating and Knows Everything About Renoise Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPipPip
  • 2679 posts
  • Gender:Male
  • Location:Kontula, Helsinki, Finland
  • Interests://Varying Interests//

Posted 12 January 2018 - 20:37

I'm wondering how to use case or switch to store information - basically, what I'm trying to do is create one script that I call by testscript(value,direction) where direction could have like direction[0] panning.value direction[1] delay.value direction[2] volumevalue

 

and that way be able to go

selected_note_column_index.direction[1] = value

where direction[1] provides "delay_value_amount" or something. so some sort of way of combining "stuff". I have 

 local p = renoise.song().selected_note_column.panning_value
 local nc = renoise.song().selected_note_column

but would like to set it up so that depending on which number, or string i input in the shortcut setting, that one gets used. I see no reason in creating dozens and dozens of different scripts just to change the columns, when one multipurpose (with a case or a switch or something like that) should simplify it very easily.

 

any ideas how i could accomplish this?


http://lackluster.org | on Bandcamp | on YouTube | on Facebook | on Spotify | on iTunes | on TiDAL | on Soundcloud | 

http://twitter.com/esaruoho | http://esaruoho.tumblr.com | GitHubesaruoho@gmail.com | 

| macOS 10.13 High Sierra | MacBook Pro 2.8 GHz Intel Core i7 / 16 Gb 1600 MHz DDR 3 |

| http://renoise.com/tools/paketti | BTC: 1BoZ9rvb8wT7dFNyVPwSX7DLj3stNo7844 | http://paypal.me/esaruoho |

| Latent Impulse Tracker/Scream Tracker 3/Schism Tracker <-> Renoise fanatic |

More API functions, please! ;) http://forum.renoise.com/index.php/topic/26329-the-api-wishlist-thread/page-3#entry240266

#2 Raul (ulneiz)

Raul (ulneiz)

    Guruh Motha Fakka is Levitating and Knows Everything About Renoise Member

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

Posted 12 January 2018 - 22:06

I'm wondering how to use case or switch to store information - basically, what I'm trying to do is create one script that I call by testscript(value,direction) where direction could have like direction[0] panning.value direction[1] delay.value direction[2] volumevalue

 

and that way be able to go

selected_note_column_index.direction[1] = value

where direction[1] provides "delay_value_amount" or something. so some sort of way of combining "stuff". I have 

 local p = renoise.song().selected_note_column.panning_value
 local nc = renoise.song().selected_note_column

but would like to set it up so that depending on which number, or string i input in the shortcut setting, that one gets used. I see no reason in creating dozens and dozens of different scripts just to change the columns, when one multipurpose (with a case or a switch or something like that) should simplify it very easily.

 

any ideas how i could accomplish this?

 

I do not know exactly what you want to do. But first I recommend you avoid calling using tables, unless they are tables that you create yourself.

function vpd_replace_vol_pttr( song, nol, snci, column )
  song = renoise.song()
  nol = song.selected_pattern.number_of_lines
  snci = song.selected_note_column_index
  if ( snci > 0 ) then  
    for l = 1, nol do
      for c = 1, 12 do
        column = song.selected_pattern_track:line( l ):note_column( c )
        if ( column.note_value < 120 ) then
          column.volume_value = vws["VOL_SLIDER"].value
        end
      end
    end
  end
end

Look at this function that I have created to replace values without calling tables. In this line of code:

 

  • column = song.selected_pattern_track:line( l ):note_column( c )

 

you have access to the "line" and the "note column", using    :    () 

 

You will only have to define the variables before, either with a number or iterating within a valid range. Then you can call like that:

 

  • column.volume_value = the value you want

Does this help you to start?


:excl: Development of my tools: Piano Roll EditorKangarooX120SamRenderPhraseTouch

 

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

Spoiler

 

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

Spoiler

#3 esaruoho

esaruoho

    Guruh Motha Fakka is Levitating and Knows Everything About Renoise Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPipPip
  • 2679 posts
  • Gender:Male
  • Location:Kontula, Helsinki, Finland
  • Interests://Varying Interests//

Posted 12 January 2018 - 22:37

I got this far, but started having issues because selected_note_column_index does not exist, if the effect_column is selected, and vice versa:

function columns(chg,thing)

local columns = 
    {
      [1] = renoise.song().selected_note_column.delay_value,
      [2] = renoise.song().selected_note_column.panning_value, 
      [3] = renoise.song().selected_note_column.volume_value,
      [4] = renoise.song().selected_effect_column.number_value,
      [5] = renoise.song().selected_effect_column.amount_value
    }

 local nc = renoise.song().selected_note_column
 local nci = renoise.song().selected_note_column_index

 local currPatt = renoise.song().selected_pattern_index
 local currTrak = renoise.song().selected_track_index
 local currLine = renoise.song().selected_line_index

if thing == 1 then --delay column
 renoise.song().tracks[currTrak].delay_column_visible=true
 nc.delay_value = math.max(0, math.min(255, columns[thing] + chg))
else end
if thing == 2 then --panning column
 renoise.song().tracks[currTrak].panning_column_visible=true
 nc.panning_value = math.max(0, math.min(128, columns[thing] + chg))
 if nc.panning_value < 1 then nc.panning_string=".." else end
else end
if thing == 3 then --volume column
 renoise.song().tracks[currTrak].volume_column_visible=true
 nc.volume_value = math.max(0, math.min(128, columns[thing] + chg))
else end
if thing == 4 then --effect number column

 renoise.song().patterns[currPatt].tracks[currTrak].lines[currLine].effect_columns[1].number_value = math.max(0, math.min(255, columns[thing] + chg)) 
else end
if thing == 5 then --effect amount column
-- renoise.song().tracks[currTrak].sample_effects_column_visible=true
 renoise.song().patterns[currPatt].tracks[currTrak].lines[currLine].effect_columns[1].amount_value = math.max(0, math.min(255, columns[thing] + chg)) 
else end

end

i'm not sure how to create the array without it going "well do they exists?".. i tried to put "if not there then don't write" but couldn't make sense of it.


Edited by esaruoho, 12 January 2018 - 22:58.

http://lackluster.org | on Bandcamp | on YouTube | on Facebook | on Spotify | on iTunes | on TiDAL | on Soundcloud | 

http://twitter.com/esaruoho | http://esaruoho.tumblr.com | GitHubesaruoho@gmail.com | 

| macOS 10.13 High Sierra | MacBook Pro 2.8 GHz Intel Core i7 / 16 Gb 1600 MHz DDR 3 |

| http://renoise.com/tools/paketti | BTC: 1BoZ9rvb8wT7dFNyVPwSX7DLj3stNo7844 | http://paypal.me/esaruoho |

| Latent Impulse Tracker/Scream Tracker 3/Schism Tracker <-> Renoise fanatic |

More API functions, please! ;) http://forum.renoise.com/index.php/topic/26329-the-api-wishlist-thread/page-3#entry240266

#4 esaruoho

esaruoho

    Guruh Motha Fakka is Levitating and Knows Everything About Renoise Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPipPip
  • 2679 posts
  • Gender:Male
  • Location:Kontula, Helsinki, Finland
  • Interests://Varying Interests//

Posted 12 January 2018 - 22:59

i guess i gotta separate the note column stuff and effect column stuff to separate tables in separate functions, which i guess is alright?


http://lackluster.org | on Bandcamp | on YouTube | on Facebook | on Spotify | on iTunes | on TiDAL | on Soundcloud | 

http://twitter.com/esaruoho | http://esaruoho.tumblr.com | GitHubesaruoho@gmail.com | 

| macOS 10.13 High Sierra | MacBook Pro 2.8 GHz Intel Core i7 / 16 Gb 1600 MHz DDR 3 |

| http://renoise.com/tools/paketti | BTC: 1BoZ9rvb8wT7dFNyVPwSX7DLj3stNo7844 | http://paypal.me/esaruoho |

| Latent Impulse Tracker/Scream Tracker 3/Schism Tracker <-> Renoise fanatic |

More API functions, please! ;) http://forum.renoise.com/index.php/topic/26329-the-api-wishlist-thread/page-3#entry240266

#5 joule

joule

    Guruh Motha Fakka is Levitating and Knows Everything About Renoise Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPipPip
  • 1853 posts
  • Gender:Not Telling

Posted 13 January 2018 - 13:44

Btw, the sane syntax would be:

if thing == 1 then
  -- code block
elseif thing == 2 then
  -- code block
elseif thing == 3 then
  -- code block
else 
  -- optional else can be used at the bottom if you need a "default" case when none of the above is true.
end

  • esaruoho likes this

#6 esaruoho

esaruoho

    Guruh Motha Fakka is Levitating and Knows Everything About Renoise Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPipPip
  • 2679 posts
  • Gender:Male
  • Location:Kontula, Helsinki, Finland
  • Interests://Varying Interests//

Posted 13 January 2018 - 22:42

 

Btw, the sane syntax would be:

if thing == 1 then
  -- code block
elseif thing == 2 then
  -- code block
elseif thing == 3 then
  -- code block
else 
  -- optional else can be used at the bottom if you need a "default" case when none of the above is true.
end

 

 

neat, this is pretty hot, this means that i can create a secondary shortcut where no 1-5 is defined, and i can then have that hide, or display volume, panning, delay columns! or reset them, or something.

 

So I made a switch, and I hope it'll work - still not sure about the panning segment of this.

if thing == 1 then
--delay column
 renoise.song().tracks[currTrak].delay_column_visible=true
 nc.delay_value = math.max(0, math.min(255, columns[thing] + chg))
elseif thing == 2 then
--panning column
 renoise.song().tracks[currTrak].panning_column_visible=true
--if panning_string is ".." replace it with "40" (so panning is centered) - this should mean that where we start panning from
--is always center.
   if nc.panning_string==".." then nc.panning_value = 40 else end
--controls for going between -10 and 128 in panning (00-80)
   nc.panning_value = math.max(-10, math.min(128, columns[thing] + chg))
-- if panning_value is below 0, write ".." as panning_string.
   if nc.panning_value < 0 then nc.panning_string=".." else end
elseif thing == 3 then
--volume column
 renoise.song().tracks[currTrak].volume_column_visible=true
 nc.volume_value = math.max(0, math.min(128, columns[thing] + chg))
elseif thing == 4 then
--effect number column
 renoise.song().patterns[currPatt].tracks[currTrak].lines[currLine].effect_columns[1].number_value = math.max(0, math.min(255, columns[thing] + chg)) 
elseif thing == 5 then
--effect amount column
-- renoise.song().tracks[currTrak].sample_effects_column_visible=true
 renoise.song().patterns[currPatt].tracks[currTrak].lines[currLine].effect_columns[1].amount_value = math.max(0, math.min(255, columns[thing] + chg)) 
else
-- default, shows panning, delay, volume columns.
 renoise.song().tracks[currTrak].delay_column_visible=true
 renoise.song().tracks[currTrak].panning_column_visible=true
 renoise.song().tracks[currTrak].volume_column_visible=true
end

I'm still not sure how to proceed with a table with selected_note_column or selected_effect_column, cos neither exists if the other is selected. Kinda hard?


thanks joule for the response btw!


http://lackluster.org | on Bandcamp | on YouTube | on Facebook | on Spotify | on iTunes | on TiDAL | on Soundcloud | 

http://twitter.com/esaruoho | http://esaruoho.tumblr.com | GitHubesaruoho@gmail.com | 

| macOS 10.13 High Sierra | MacBook Pro 2.8 GHz Intel Core i7 / 16 Gb 1600 MHz DDR 3 |

| http://renoise.com/tools/paketti | BTC: 1BoZ9rvb8wT7dFNyVPwSX7DLj3stNo7844 | http://paypal.me/esaruoho |

| Latent Impulse Tracker/Scream Tracker 3/Schism Tracker <-> Renoise fanatic |

More API functions, please! ;) http://forum.renoise.com/index.php/topic/26329-the-api-wishlist-thread/page-3#entry240266

#7 Raul (ulneiz)

Raul (ulneiz)

    Guruh Motha Fakka is Levitating and Knows Everything About Renoise Member

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

Posted 14 January 2018 - 01:35

neat, this is pretty hot, this means that i can create a secondary shortcut where no 1-5 is defined, and i can then have that hide, or display volume, panning, delay columns! or reset them, or something.

 

So I made a switch, and I hope it'll work - still not sure about the panning segment of this.

if thing == 1 then
--delay column
 renoise.song().tracks[currTrak].delay_column_visible=true
 nc.delay_value = math.max(0, math.min(255, columns[thing] + chg))
elseif thing == 2 then
--panning column
 renoise.song().tracks[currTrak].panning_column_visible=true
--if panning_string is ".." replace it with "40" (so panning is centered) - this should mean that where we start panning from
--is always center.
   if nc.panning_string==".." then nc.panning_value = 40 else end
--controls for going between -10 and 128 in panning (00-80)
   nc.panning_value = math.max(-10, math.min(128, columns[thing] + chg))
-- if panning_value is below 0, write ".." as panning_string.
   if nc.panning_value < 0 then nc.panning_string=".." else end
elseif thing == 3 then
--volume column
 renoise.song().tracks[currTrak].volume_column_visible=true
 nc.volume_value = math.max(0, math.min(128, columns[thing] + chg))
elseif thing == 4 then
--effect number column
 renoise.song().patterns[currPatt].tracks[currTrak].lines[currLine].effect_columns[1].number_value = math.max(0, math.min(255, columns[thing] + chg)) 
elseif thing == 5 then
--effect amount column
-- renoise.song().tracks[currTrak].sample_effects_column_visible=true
 renoise.song().patterns[currPatt].tracks[currTrak].lines[currLine].effect_columns[1].amount_value = math.max(0, math.min(255, columns[thing] + chg)) 
else
-- default, shows panning, delay, volume columns.
 renoise.song().tracks[currTrak].delay_column_visible=true
 renoise.song().tracks[currTrak].panning_column_visible=true
 renoise.song().tracks[currTrak].volume_column_visible=true
end

I'm still not sure how to proceed with a table with selected_note_column or selected_effect_column, cos neither exists if the other is selected. Kinda hard?


thanks joule for the response btw!

 

Some suggestions related to optimization / reading / abbreviate:

 

1) Do not call so many times renoise.song() .  Instead, define at the beginning of the function: song = renoise.song() and then use song all the time (song, or rns, or s... the name you want).  For the names I recommend using 3 letters.

 

2) Instead of renoise.song().tracks[currTrak].delay_column_visible = true, use song.selected_track.delay_column_visible = true, It is not necessary to define the value of the index (currTrack) if you can call the object (selected_track). Do the same with similar cases.

 

3.1) Branches the functions: if nc.panning_value < 0 then nc.panning_string=".." else end  better so, to be easier to read for you:

  if ( nc.panning_value < 0 ) then

      nc.panning_string = ".."

  end

 

3.2) else is useless in front of an end. Supposedly, are you going to add something between them? Otherwise, delete else

 

3.3) nc.panning_value < 0 ??? if the function is reading the value in the pattern editor it will never give < 0

 

4) instead nc.panning_string=".." you can use nc.panning_value = 255 (empty). It is not necessary to mix the .string with the .value in a condition

 
5) instead renoise.song().patterns[currPatt].tracks[currTrak].lines[currLine].effect_columns[1].number_value = math.max(0, math.min(255, columns[thing] + chg)), you can use:
                 song.selected_pattern_track.selected_line:effect_column(1).number_value = math.max(0, math.min(255, columns[thing] + chg))
 
6) Can the value thing be greater than 5? If it can not be greater than 5 it does not make sense to write this:
  ...
  else
      -- default, shows panning, delay, volume columns.
      renoise.song().tracks[currTrak].delay_column_visible=true
      renoise.song().tracks[currTrak].panning_column_visible=true
      renoise.song().tracks[currTrak].volume_column_visible=true
  end

 

I think something will not work well in this function. Some things are not coherent. I do not usually try to improve others' codes. But it helps me to practice the code. I am also in continuous learning. If something is wrong, someone can always comment on the error.

 

For example the case 6), look at the red lines:

 

if thing == 1 then
--delay column
renoise.song().tracks[currTrak].delay_column_visible=true
nc.delay_value = math.max(0, math.min(255, columns[thing] + chg))
elseif thing == 2 then
--panning column
renoise.song().tracks[currTrak].panning_column_visible=true
--if panning_string is ".." replace it with "40" (so panning is centered) - this should mean that where we start panning from
--is always center.
if nc.panning_string==".." then nc.panning_value = 40 else end
--controls for going between -10 and 128 in panning (00-80)
nc.panning_value = math.max(-10, math.min(128, columns[thing] + chg))
-- if panning_value is below 0, write ".." as panning_string.
if nc.panning_value < 0 then nc.panning_string=".." else end
elseif thing == 3 then
--volume column
renoise.song().tracks[currTrak].volume_column_visible=true
nc.volume_value = math.max(0, math.min(128, columns[thing] + chg))
elseif thing == 4 then
--effect number column
renoise.song().patterns[currPatt].tracks[currTrak].lines[currLine].effect_columns[1].number_value = math.max(0, math.min(255, columns[thing] + chg))
elseif thing == 5 then
--effect amount column
-- renoise.song().tracks[currTrak].sample_effects_column_visible=true
renoise.song().patterns[currPatt].tracks[currTrak].lines[currLine].effect_columns[1].amount_value = math.max(0, math.min(255, columns[thing] + chg))
else
-- default, shows panning, delay, volume columns.
renoise.song().tracks[currTrak].delay_column_visible=true
renoise.song().tracks[currTrak].panning_column_visible=true
renoise.song().tracks[currTrak].volume_column_visible=true

end

 

Does that work well?


:excl: Development of my tools: Piano Roll EditorKangarooX120SamRenderPhraseTouch

 

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

Spoiler

 

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

Spoiler

#8 esaruoho

esaruoho

    Guruh Motha Fakka is Levitating and Knows Everything About Renoise Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPipPip
  • 2679 posts
  • Gender:Male
  • Location:Kontula, Helsinki, Finland
  • Interests://Varying Interests//

Posted 14 January 2018 - 11:57

Some suggestions related to optimization / reading / abbreviate:

1) Do not call so many times renoise.song() .  Instead, define at the beginning of the function: song = renoise.song() and then use song all the time (song, or rns, or s... the name you want).  For the names I recommend using 3 letters.

 

Hi, yes, I tend to go for the whole length instead of abbreviations, because if you then take that abbreviated line and dump it into terminal, you have to un-abbreviate it by hand, the chances of creating errors are then multiplied by ^100 at least. 

 

2) Instead of renoise.song().tracks[currTrak].delay_column_visible = true, use song.selected_track.delay_column_visible = true, It is not necessary to define the value of the index (currTrack) if you can call the object (selected_track). Do the same with similar cases.

This here was news to me. I'm seeing selected_track and selected_line - so I could use any of these like s.selected_line and then cut the "currPatt currTrak" out of it. Seems good! Thanks for the advice.

 

I do wonder though, if I do want to have an effect on selected_effect_column_index and it is not selected (because cursor is in selected_note_column_index) - i'm not entirely sure how to get a script to not shoot an error (effect_column_index is nil if you are in note_column_index, unfortunately).

 

3.2) else is useless in front of an end. Supposedly, are you going to add something between them? Otherwise, delete else

This I'm not so sure what to make of. I get that if there's a "if x = y then y = b end" makes sense, but what about "if x = y then return end"? does that make sense to do? I guess it would? I just worry I won't understand that return end has an unstated else between return and end :)

 

3.3) nc.panning_value < 0 ??? if the function is reading the value in the pattern editor it will never give < 0

I guess what's happening here is that I should be using "countednumber < 0" and if it goes below 0, then I revert it to "255". If the pan_value is 255, and something is counted into it (+1/-1/+10/-10) then start from 40.

 

5) instead renoise.song().patterns[currPatt].tracks[currTrak].lines[currLine].effect_columns[1].number_value = math.max(0, math.min(255, columns[thing] + chg)), you can use:

                 song.selected_pattern_track.selected_line:effect_column(1).number_value = math.max(0, math.min(255, columns[thing] + chg))

query, why not 

song.selected_line:

instead of 

song.selected_pattern_track.selected_line

?

 

 

6) Can the value thing be greater than 5? If it can not be greater than 5 it does not make sense to write this:

  ...
  else
      -- default, shows panning, delay, volume columns.
      renoise.song().tracks[currTrak].delay_column_visible=true
      renoise.song().tracks[currTrak].panning_column_visible=true
      renoise.song().tracks[currTrak].volume_column_visible=true
  end

in this case, I'm looking at creating a secondary keyshortcut bind where if I don't set any number to thing, then it makes all the columns visible. because they're not set by default. For all the other instances of thing, the hidden columns will become visible at a need-to-see-basis, i.e. if i'm putting +1/-1/+10/-10 at delay_column, then by all means, make it visible. I don't need to have panning or volume columns visible if i'm not inputting data there. I'll eventually modify numberless-thing so that if there is data in any of the columns, make it visible, otherwise hide.

 

p.s. thanks for the comments! 


http://lackluster.org | on Bandcamp | on YouTube | on Facebook | on Spotify | on iTunes | on TiDAL | on Soundcloud | 

http://twitter.com/esaruoho | http://esaruoho.tumblr.com | GitHubesaruoho@gmail.com | 

| macOS 10.13 High Sierra | MacBook Pro 2.8 GHz Intel Core i7 / 16 Gb 1600 MHz DDR 3 |

| http://renoise.com/tools/paketti | BTC: 1BoZ9rvb8wT7dFNyVPwSX7DLj3stNo7844 | http://paypal.me/esaruoho |

| Latent Impulse Tracker/Scream Tracker 3/Schism Tracker <-> Renoise fanatic |

More API functions, please! ;) http://forum.renoise.com/index.php/topic/26329-the-api-wishlist-thread/page-3#entry240266

#9 Raul (ulneiz)

Raul (ulneiz)

    Guruh Motha Fakka is Levitating and Knows Everything About Renoise Member

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

Posted 14 January 2018 - 13:16

I do wonder though, if I do want to have an effect on selected_effect_column_index and it is not selected (because cursor is in selected_note_column_index) - i'm not entirely sure how to get a script to not shoot an error (effect_column_index is nil if you are in note_column_index, unfortunately).

 

I use a very simple method that has saved me many errors:

  1. define first: snci = song.selected_note_column_index
  2. Then use it as a condition: if ( snci > 0 ) then "YOUR CODE FOR NOTE COLUMN" end
  • ​snci can take the values from 1 to 12

This way you make sure you avoid errors, if the code tries to execute something inside an effect column when it should be in a note column. "YOUR CODE FOR NOTE COLUMN" will never run inside an effect column. That is, it will not work within a group, master, or send, nor in the effect column within a track (sequencer type). In any case, it will not return any error.

 

...

 

You can do something similar but in reverse, when necessary:

  1. define first: seci = song.selected_effect_column_index
  2. Then use it as a condition: if ( seci > 0 ) then "YOUR CODE FOR EFFECT COLUMN" end
  • seci can take the values from 0 to 8

Here "YOUR CODE FOR EFFECT COLUMN" will work within the group, master, send, and also in the effect column within the track (sequencer type).


:excl: Development of my tools: Piano Roll EditorKangarooX120SamRenderPhraseTouch

 

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

Spoiler

 

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

Spoiler

#10 Raul (ulneiz)

Raul (ulneiz)

    Guruh Motha Fakka is Levitating and Knows Everything About Renoise Member

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

Posted 14 January 2018 - 13:28

Be careful with the equalities: if x = y then y = b end -----> if x == y then y = b end

 

return can serve two purposes:

  1. return serves to skip everything under the function. It's like saying: forget everything under return and end the function with the last "end". This is useful in timers, loops, so as not to repeat an operation when it is no longer necessary.
  2. return to return something concrete, for example when a condition ends. For example:
  if clr.value == 1 then return vpd_clear_pattern() end
  if clr.value == 2 then return vpd_clear_track() end
  ...
  if clr.value == 8 then return vpd_clear_all() end
  
  or
 
  tostring = function( value ) return ("%s"):format( vpd_random_notes_n( value ) ) end

query, why not 

song.selected_line:

instead of 

song.selected_pattern_track.selected_line

?

 

Try it, see if it works.


:excl: Development of my tools: Piano Roll EditorKangarooX120SamRenderPhraseTouch

 

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

Spoiler

 

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

Spoiler

#11 esaruoho

esaruoho

    Guruh Motha Fakka is Levitating and Knows Everything About Renoise Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPipPip
  • 2679 posts
  • Gender:Male
  • Location:Kontula, Helsinki, Finland
  • Interests://Varying Interests//

Posted 14 January 2018 - 13:49

I use a very simple method that has saved me many errors:

  1. define first: snci = song.selected_note_column_index
  2. Then use it as a condition: if ( snci > 0 ) then "YOUR CODE FOR NOTE COLUMN" end
  • ​snci can take the values from 1 to 12

This way you make sure you avoid errors, if the code tries to execute something inside an effect column when it should be in a note column. "YOUR CODE FOR NOTE COLUMN" will never run inside an effect column. That is, it will not work within a group, master, or send, nor in the effect column within a track (sequencer type). In any case, it will not return any error.

 

...

 

You can do something similar but in reverse, when necessary:

  1. define first: seci = song.selected_effect_column_index
  2. Then use it as a condition: if ( seci > 0 ) then "YOUR CODE FOR EFFECT COLUMN" end
  • seci can take the values from 0 to 8

Here "YOUR CODE FOR EFFECT COLUMN" will work within the group, master, send, and also in the effect column within the track (sequencer type).

 

 

query - can i use if ( seci > 0 ) then inside an array? Like, only set 1-3 array content (which references selected_note_column) if it exists, otherwise only set selected_effect_column in the array (4-5)? this would help with evading errors, when in NC as opposed to EC, and when being in EC and NC array content cannot be set.

 

hmm.

is this the way to safely set an array content so that they won't get wrecked and the terminal doesn't constantly shoot errors?

-- Columnizer, +1 / -1 / +10 / -10 on current_row, display needed column
function columns(chg,thing)
local song=renoise.song()
local s=renoise.song()
local snci=song.selected_note_column_index
local seci=song.selected_effect_column_index
local sst=s.selected_track
local columns={}

if ( snci > 0 ) then 
columns[1] = s.selected_note_column.delay_value
columns[2] = s.selected_note_column.panning_value
columns[3] = s.selected_note_column.volume_value
elseif ( seci > 0 ) then
columns[4] = s.selected_effect_column.number_value
columns[5] = s.selected_effect_column.amount_value
end

 local nc = s.selected_note_column
 local nci = s.selected_note_column_index
 local currPatt = s.selected_pattern_index
 local currTrak = s.selected_track_index
 local currLine = s.selected_line_index
 
if thing == 1 then
--delay column
 sst.delay_column_visible=true
 nc.delay_value = math.max(0, math.min(255, columns[thing] + chg))
elseif thing == 2 then
--panning column
local pancount=nil
 sst.panning_column_visible=true
 print (nc.panning_value)
   if nc.panning_value==255 then 
   nc.panning_value=64 return
   end
   print(pancount)
   pancount = math.max(-20, math.min(128, columns[thing] + chg))
   if pancount < 0 then nc.panning_string = ".." else nc.panning_value = pancount end

elseif thing == 3 then
--volume column
 sst.volume_column_visible=true
 nc.volume_value = math.max(0, math.min(128, columns[thing] + chg))
elseif thing == 4 then
--effect number column
 s.selected_line.effect_columns[seci].number_value = math.max(0, math.min(255, columns[thing] + chg)) 
elseif thing == 5 then
--effect amount column
 s.selected_line.effect_columns[seci].amount_value = math.max(0, math.min(255, columns[thing] + chg)) 
else
-- default, shows panning, delay, volume columns.
 sst.delay_column_visible=true
 sst.panning_column_visible=true
 sst.volume_column_visible=true
end
end

what seems to be going on here is that i can now set effect column data, but only if i'm in the effect column itself. then note column settings shoot errors. then if i'm in note columns, then effect column shortcuts shoot errors. i was hoping to evade that somehow. i'm wondering how.


http://lackluster.org | on Bandcamp | on YouTube | on Facebook | on Spotify | on iTunes | on TiDAL | on Soundcloud | 

http://twitter.com/esaruoho | http://esaruoho.tumblr.com | GitHubesaruoho@gmail.com | 

| macOS 10.13 High Sierra | MacBook Pro 2.8 GHz Intel Core i7 / 16 Gb 1600 MHz DDR 3 |

| http://renoise.com/tools/paketti | BTC: 1BoZ9rvb8wT7dFNyVPwSX7DLj3stNo7844 | http://paypal.me/esaruoho |

| Latent Impulse Tracker/Scream Tracker 3/Schism Tracker <-> Renoise fanatic |

More API functions, please! ;) http://forum.renoise.com/index.php/topic/26329-the-api-wishlist-thread/page-3#entry240266

#12 Raul (ulneiz)

Raul (ulneiz)

    Guruh Motha Fakka is Levitating and Knows Everything About Renoise Member

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

Posted 14 January 2018 - 14:20

To build the function, one way to do it is to separate everything you want to control within the note column and then everything you want to control within the effect column. Something like that:

if ( snci > 0 ) then
  ALL CODE FOR NOTE COLUMNS
end

if ( seci > 0 ) then
  ALL CODE FOR EFFECT COLUMNS
end

I recommend that you separate in two blocks, within two mother conditions, not to mix things of note column with note effects inside one if...elseif...else...end. Separate it. In the end it is like following the cursor of the pattern editor.


Edited by Raul (ulneiz), 14 January 2018 - 19:11.

  • esaruoho likes this

:excl: Development of my tools: Piano Roll EditorKangarooX120SamRenderPhraseTouch

 

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

Spoiler

 

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

Spoiler

#13 esaruoho

esaruoho

    Guruh Motha Fakka is Levitating and Knows Everything About Renoise Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPipPip
  • 2679 posts
  • Gender:Male
  • Location:Kontula, Helsinki, Finland
  • Interests://Varying Interests//

Posted 14 January 2018 - 15:04

 

To build the function, one way to do it is to separate everything you want to control within the note column and then everything you want to control within the effect column. Something like that:

if ( snnci > 0 ) then
  ALL CODE FOR NOTE COLUMNS
end

if ( seci > 0 ) then
  ALL CODE FOR EFFECT COLUMNS
end

I recommend that you separate in two blocks, within two mother conditions, not to mix things of note column with note effects inside one if...elseif...else...end. Separate it. In the end it is like following the cursor of the pattern editor.

 

 

Thanks ,I'll try and use this. Thing is, however, is that i have shortcuts that should write to effect column when note column is selected, and shortcuts that should write to note column (pan,volume,delay) when effect column is selected - so they should "always work", regardless or where one is in the track. i'm not sure how to circumvent that issue.


http://lackluster.org | on Bandcamp | on YouTube | on Facebook | on Spotify | on iTunes | on TiDAL | on Soundcloud | 

http://twitter.com/esaruoho | http://esaruoho.tumblr.com | GitHubesaruoho@gmail.com | 

| macOS 10.13 High Sierra | MacBook Pro 2.8 GHz Intel Core i7 / 16 Gb 1600 MHz DDR 3 |

| http://renoise.com/tools/paketti | BTC: 1BoZ9rvb8wT7dFNyVPwSX7DLj3stNo7844 | http://paypal.me/esaruoho |

| Latent Impulse Tracker/Scream Tracker 3/Schism Tracker <-> Renoise fanatic |

More API functions, please! ;) http://forum.renoise.com/index.php/topic/26329-the-api-wishlist-thread/page-3#entry240266

#14 Raul (ulneiz)

Raul (ulneiz)

    Guruh Motha Fakka is Levitating and Knows Everything About Renoise Member

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

Posted 14 January 2018 - 19:11

It does not really matter that the cursor is inside a note column in order to write or modify something within an effect column. But first, you should show the user what you are manipulating with the command. The user has to visually see what he is doing at all times.

 

At a minimum, you have to refer to the selected track always, unless you make a specific tool to manipulate several tracks at the same time.

 

After this, you can write a value within the first effect column (or the one you want), even if the cursor is in any note column. To do this, be sure to make the destination effect column visible.

 

You just have to refer to that effect column to write there. seci = song.selected_effect_column_index is "the cursor" in pattern editor. Replace seci with a number from 1 to 8.

 

Write in the selected effect column:

  • s.selected_line.effect_columns[seci].number_value = math.max(0, math.min(255, columns[thing] + chg))
  • s.selected_line.effect_columns[seci].amount_value = math.max(0, math.min(255, columns[thing] + chg))

...

Write in the first column of effect:

  • s.selected_line.effect_columns[1].number_value = math.max(0, math.min(255, columns[thing] + chg))
  • s.selected_line.effect_columns[1].amount_value = math.max(0, math.min(255, columns[thing] + chg))

better use it like this ( get used to always use : and () ):

  • s.selected_line:effect_column(1).number_value = math.max(0, math.min(255, columns[thing] + chg))
  • s.selected_line:effect_column(1).amount_value = math.max(0, math.min(255, columns[thing] + chg))

Now it does not matter much, but if you iterate, you'll get more performance, even drastically.


Edited by Raul (ulneiz), 14 January 2018 - 19:12.

:excl: Development of my tools: Piano Roll EditorKangarooX120SamRenderPhraseTouch

 

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

Spoiler

 

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

Spoiler