Basic KeyBindings

Okay,

I have my script doing what I wanted it to do … when I execute

how do I go about implementing the “renoise.tool():add_keybinding {}” so, the script can be mapped to a key command?

i’ve been going over the documentation for this all day and this part doesn’t exactly make sense to me.

I’ve been dealing with Lua and Renoise’s API for a maximum of 18 hours

Here is the script that would like to make into a keybinding:

local inst = renoise.song().selected_instrument_index
 local b = renoise.song().selected_track_index
 local a = renoise.song().selected_pattern_index
 local c = renoise.song().selected_note_column_index

 for i=1,128,16
 do
  local note_col = renoise.song():pattern(a):track(b):line(i):note_column(c)
  note_col.note_string = "C-4"
  note_col.instrument_value = inst
 end
rprint(_G)

Okay,

I have my script doing what I wanted it to do … when I execute

how do I go about implementing the “renoise.tool():add_keybinding {}” so, the script can be mapped to a key command?

i’ve been going over the documentation for this all day and this part doesn’t exactly make sense to me.

I’ve been dealing with Lua and Renoise’s API for a maximum of 18 hours

Here is the script that would like to make into a keybinding:

local inst = renoise.song().selected_instrument_index
local b = renoise.song().selected_track_index
local a = renoise.song().selected_pattern_index
local c = renoise.song().selected_note_column_index

for i=1,128,16
do
local note_col = renoise.song():pattern(a):track(b):line(i):note_column(c)
note_col.note_string = "C-4"
note_col.instrument_value = inst
end
rprint(_G)

Basically you can make 2 types of tools, one with a window and another that are links for the Renoise menus. You can usetwo ways to link commands, keyhandler or keybinding.

For keyhandler:

I suggest you download my tool KangarooX120. The functions are sufficiently well done to serve as multiple examples. In it you will see a file called keyhandler.lua. Check it out, find the function kng_keyhandler( dialog, key ).I suggest you do not copy. Try to do the functions by yourself to learn.

For example, for window, read the documentation on:

-- Shows a non modal dialog (a floating tool window) with custom content.
-- Again see Renoise.ViewBuilder.API for more info about custom views.
-- key_handler is an optional notifier function for keyboard events that are received by the dialog.
renoise.app():show_custom_dialog(title, content_view [, key_handler]) -> [renoise.Dialog object]

…and focus on the key_handler.

For keybinding:

Now, if you are not going to use a window, only functions and a direct command to that function, use the keybindings :

--[[

keybindings: Register key bindings somewhere in Renoise's existing
set of bindings.

The Lua table passed to add_keybinding is defined as:

* Required fields:
  + ["name"] = The scope, name and category of the key binding.
  + ["invoke"] = A function that is called as soon as the mapped key is
      pressed. The callback has one argument: "repeated", indicating
      if its a virtual key repeat.
The key binding's 'name' must have 3 parts, separated by ":" e.g.
[scope:topic_name:binding_name]

* 'scope' is where the shortcut will be applied, just like those
  in the categories list for the keyboard assignment preference pane.
* 'topic_name' is useful when grouping entries in the key assignment pane.
  Use "tool" if you can't come up with something meaningful.
* 'binding_name' is the name of the binding.

Currently available scopes are:
> "Global", "Automation", "Disk Browser", "Instrument Box", "Mixer",
> "Pattern Editor", "Pattern Matrix", "Pattern Sequencer", "Sample Editor"
> "Track DSPs Chain"

Using an unavailable scope will not fire an error, instead it will render the
binding useless. It will be listed and mappable, but never be invoked.

There's no way to define default keyboard shortcuts for your entries. Users
manually have to bind them in the keyboard prefs pane. As soon as they do,
they'll get saved just like any other key binding in Renoise.

]]

-- Returns true when the given keybinging already exists, otherwise false.
renoise.tool():has_keybinding(keybinding_name)
  -> [boolean]

-- Add a new keybinding entry as described above.
renoise.tool():add_keybinding(keybinding_definition_table)

-- Remove a previously added key binding by specifying its name and path.
renoise.tool():remove_keybinding(keybinding_name)

This will appear in Renose: Preferences/Keys, but the user will need to assign a free command.A example:

rnt=renoise.tool()
-------------------------------------------------------------------------------------------------
--register keybinding
rnt:add_keybinding {
  name = "Global:Tools:KangarooX120:Dialog_1",
  invoke = function() kng_main_dialog() end
}

rnt:add_keybinding {
name = "Global:Tools:KangarooX120:Dialog_2",
invoke = function() kng_main_dialog_2() end
}

In a tool you can use both:

  1. keyhandler : with fixed commandpreviously scheduled by the programmer (the window needs to be in the foreground).
  2. keybinding : the user will need to assing a free command (that does not conflict with the Renonise commands already used).

I suggest you always look for references in your API documentation, and always have them located.

Regarding your function, you are accessing at all times all the parties that are selected. You can optimize it like this:

local function change_nte_ins()
  local song = renoise.song()
  local pat_trk = song.selected_pattern_track
  local col_idx = song.selected_note_column_index
  local ins_idx = song.selected_instrument_index
  for lne_idx = 1,128,16 do
    pat_trk:line(lne_idx):note_column(col_idx).note_value = 48
    pat_trk:line(lne_idx):note_column(col_idx).instrument_value = ins_idx
  end
end

Edit:it is not necessary to define the index of the pattern and the index of the track, since you can directly access the selected_pattern_track object.

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