inserting notes into a pattern

Hello All,

I’m completely new to lua and Renoise’s API. I’m currently trying to get start with my first script, but there is one API command that is eluding me.

Inserting notes on a track within a pattern

Or to be more specific:

If I wanted to insert a “C-4” note from the first instrument “00” on line “00” of the first track of pattern “0”, what would be the command for that?

I’ve been looking for this one line of code in the documentation and i can’t seem to find anything close to it.

So, far I know how to access notes within a track, but I have no idea how to write them (using lua that is)

Please Help!!!

local note_col = renoise.song():pattern(1):track(1):line(1):note_column(1)

note_col.note_value = 48
note_col.instrument_value = 0
local note_col = renoise.song():pattern(1):track(1):line(1):note_column(1)

note_col.note_value = 48
note_col.instrument_value = 0

Thank you … Much Obliged

Well, I remember when I started learning these things, I also had similar doubts.I would say that the main problem is knowing how to interpret the available API, that is, the available documentation…

To access the note column, you can do it in 3 ways. The documentation is this:

1)For the selected note column (this is the most direct way):

renoise.song().selected_note_column

–Find this line in the documentation and have it located!!!

Thus, you can modify any property of the selected note column:

renoise.song().selected_note_column:clear()

renoise.song().selected_note_column.note_value = 48

renoise.song().selected_note_column.instrument_value = 0

etc.

  1. Now, if you want to access a specific note column (not precisely the selected note column):

renoise.song().patterns.tracks.lines.note_columns

–Find this line in the documentation and have it located!!!

renoise.song().patterns[index].tracks[index].lines[index].note_columns[index]

This is what you will usually see in the documentation. In this case, you have access to the configuration of all the parts of which note_column depends,but access to them is much slower, since you will have to search each table, by using the brackets s[].

  1. So it is not advisable to use the code in this way. It is better to do it as Joule indicates, using **( ):**without the “s”, whose access is direct and fast:

renoise.song():pattern(index):track(index):line(index):note_column(index)

If you also want to have access to the selected line, directly, you can do this:

renoise.song().selected_line:note_column(index)

So you substitute**:pattern(index):track(index):line(index)**for .selected_line

And you can continue with all the dependents:

renoise.song().selected_pattern_track:line(index):note_column(index)

It is strange to want to change a property (note value, instrument value, volume value…) of the note column that is not selected.So, one way to understand the code is that, by using renoise.song ().selected_note_column, you’re acting on:

  • the current song
  • the selected pattern
  • the selected track
  • tle selected line
  • and the selected note_column

Now, to avoid errorsthe function should always check that you are on a track of type SEQUENCE and are not selecting any of its effect columns.The best way to do this is to verify that the cursor is selecting a note column:

local song=renoise.song()

if (song.selected_note_column) then

–your code

end

A typical function would be (the definition of the function and its execution):

local function change_nte_ins(nte,ins)
  local nte_col=renoise.song().selected_note_column
  if (nte_col) then
    nte_col.note_value=nte
    nte_col.instrument_value=ins
  end
end

change_nte_ins(48,0)

This function will only work if a note column is selected, by the if (nte_col) then. You can apply all this and combine it as you like also for the effect columns, valid for any type of track.

On the other hand, it is good to remember to be careful with the indexes.For example, pattern 0 does not exist, note value 122 does not exist…

Edit: so I review all this for myself too :slight_smile:

Well, I remember when I started learning these things, I also had similar doubts.I would say that the main problem is knowing how to interpret the available API, that is, the available documentation…

To access the note column, you can do it in 3 ways. The documentation is this:

1)For the selected note column (this is the most direct way):

Thus, you can modify any property of the selected note column:

  1. Now, if you want to access a specific note column (not precisely the selected note column):

This is what you will usually see in the documentation. In this case, you have access to the configuration of all the parts of which note_column depends,but access to them is much slower, since you will have to search each table, by using the brackets s[].

  1. So it is not advisable to use the code in this way. It is better to do it as Joule indicates, using **( ):**without the “s”, whose access is direct and fast:

If you also want to have access to the selected line, directly, you can do this:

So you substitute**:pattern(index):track(index):line(index)**for .selected_line

And you can continue with all the dependents:

It is strange to want to change a property (note value, instrument value, volume value…) of the note column that is not selected.So, one way to understand the code is that, by using renoise.song ().selected_note_column, you’re acting on:

  • the current song
  • the selected pattern
  • the selected track
  • tle selected line
  • and the selected note_column

Now, to avoid errorsthe function should always check that you are on a track of type SEQUENCE and are not selecting any of its effect columns.The best way to do this is to verify that the cursor is selecting a note column:

A typical function would be (the definition of the function and its execution):

local function change_nte_ins(nte,ins)
local nte_col=renoise.song().selected_note_column
if (nte_col) then
nte_col.note_value=nte
nte_col.instrument_value=ins
end
end

change_nte_ins(48,0)

This function will only work if a note column is selected, by the if (nte_col) then. You can apply all this and combine it as you like also for the effect columns, valid for any type of track.

On the other hand, it is good to remember to be careful with the indexes.For example, pattern 0 does not exist, note value 122 does not exist…

Edit: so I review all this for myself too :slight_smile:

Wow … that was extensive
I truly appreciate the help

Okay Guys,

I have the script doing what I want it to do when I execute.

How to do make it a behavior that can have a keyboard shortcut mapped to it in the preferences menu.

How to do make it a behavior that can have a keyboard shortcut mapped to it in the preferences menu.

function my_function()
 print("Someone pressed it!")
end

renoise.tool():add_keybinding {
 name = "Global:Tools:My Keybinding",
 invoke = my_function
}

see: https://github.com/renoise/xrnx/blob/master/Documentation/Renoise.ScriptingTool.API.lua#L119