[SOLVED] R2->R3 "copy from note on to note off sample mapping" no

Hi, it would appear that I’m no longer able to use this:

--vV's wonderful sample keyzone noteon/noteoff copier + octave transposition for note-off:
local NOTE_ON = renoise.Instrument.LAYER_NOTE_ON
local NOTE_OFF = renoise.Instrument.LAYER_NOTE_OFF

local function copy_note_layers(source_layer,target_layer, offset)
  local instrument = renoise.song().selected_instrument_index
  
  --delete target layers prior to copying (to prevent overlays)
  if #renoise.song().instruments[instrument].sample_mappings[target_layer] > 0 then
    --Note that when using the delete_sample_mapping, the index is changing on-the-fly
    --So you have to remove the mappings from the last to the first entry instead of vice versa.
    --Else you get errors half-way.
    for i = #renoise.song().instruments[instrument].sample_mappings[target_layer],1,-1 do
      renoise.song().instruments[instrument]:delete_sample_mapping_at(target_layer, i)
    end
  end
  
  for i = 1,#renoise.song().instruments[instrument].sample_mappings[source_layer] do

    local base_note = renoise.song().instruments[instrument].sample_mappings[source_layer][i].base_note
    local map_velocity_to_volume = renoise.song().instruments[instrument].sample_mappings[source_layer][i].map_velocity_to_volume
    local note_range = renoise.song().instruments[instrument].sample_mappings[source_layer][i].note_range
    local sample_index = renoise.song().instruments[instrument].sample_mappings[source_layer][i].sample_index
    local use_envelopes = renoise.song().instruments[instrument].sample_mappings[source_layer][i].use_envelopes
    local velocity_range = renoise.song().instruments[instrument].sample_mappings[source_layer][i].velocity_range
    local oct_base_note=nil
    oct_base_note= base_note + offset
    renoise.song().instruments[instrument]:insert_sample_mapping(target_layer, sample_index,oct_base_note,note_range,velocity_range)
   end
end

local function norm() copy_note_layers(NOTE_ON, NOTE_OFF, 0) end
local function octdn() copy_note_layers(NOTE_ON, NOTE_OFF, 12) end
local function octup() copy_note_layers(NOTE_ON, NOTE_OFF, -12) end
local function octdntwo() copy_note_layers(NOTE_ON, NOTE_OFF, 24) end
local function octuptwo() copy_note_layers(NOTE_ON, NOTE_OFF, -24) end

renoise.tool():add_menu_entry {name="--Sample Mappings:Copy note-on to note-off layer +12", invoke = octup}
renoise.tool():add_menu_entry {name="Sample Mappings:Copy note-on to note-off layer +24", invoke = octuptwo}
renoise.tool():add_menu_entry {name="Sample Mappings:Copy note-on to note-off layer", invoke = norm}
renoise.tool():add_menu_entry {name="Sample Mappings:Copy note-on to note-off layer -12", invoke = octdn}
renoise.tool():add_menu_entry {name="Sample Mappings:Copy note-on to note-off layer -24", invoke = octdntwo}

as it simply shoots errors at sample_index (which, when I switch “sample_index” with “sample”, it shoots errors on “use_envelopes”, which if i comment away, still shoots errors:

*** main.lua:59: unknown property or function 'insert_sample_mapping' for an object of type 'Instrument'
*** stack traceback:
*** [C]: in function '_error'
*** [string "do..."]:48: in function <[string "do..."]:35>
*** main.lua:59: in function 'copy_note_layers'
*** main.lua:65: in function <main.lua:65>

What should I do to get this back to working? Basically it’s a “duplicate current note-on data to note-off, but with a user-specific transposition value…” thing.

As of Renoise 3.0 (API version 4), a sample may only have a single keyzone mapping, in either the note-on layer or the note-off layer.

To duplicate mappings, you must therefore duplicate the sample itself, and assign the appropriate mapping and layer properties to the copy.

1 Like

Aha, so the steps would be…?

  1. Load sample (Note-On)
  2. Right-click on Note-On Keymapping area, run script
  3. Script copies sample to a new slot
  4. Script creates Note-Off Keymapping
  5. Script sets Note-Off Keymapping to one octave higher.

Is this correct?

ok. i have a script that duplicates the sample itself. but it lands in the note-on layer.
do i need to first create an empty sample in the note-off layer, then copy the samplebuffer from note-on-layer[1] to note-off-layer[1]? or…?

@dblue

so here’s what i did:

  1. add a new sample slot
  2. select new sample slot
  3. copy sample[1] to new sample slot (sample[2])
  4. change sample[2] layer from 1 (note-on) to 2 (note-off)
  5. change transposition of sample in layer2.

it’s really stupid, and limited, and has no protections against “what if there’s more than 1 sample in the instrument” and doesn’t even consider any sliced samples or anything like that, but at least it works.

chatgpt gave terrible solutions, none of which worked and it wouldn’t learn from my simplest solution, and kept trying to make it more and more complex.

function noteOnToNoteOff(noteoffPitch)
renoise.song().instruments[renoise.song().selected_instrument_index]:insert_sample_at(2)
renoise.song().selected_sample_index = 2
renoise.song().instruments[renoise.song().selected_instrument_index].samples[renoise.song().selected_sample_index]:copy_from(renoise.song().instruments[renoise.song().selected_instrument_index].samples[1])
renoise.song().instruments[renoise.song().selected_instrument_index].samples[renoise.song().selected_sample_index].sample_mapping.layer=2
renoise.song().instruments[renoise.song().selected_instrument_index].sample_mappings[2][1].sample.transpose=noteoffPitch
end

renoise.tool():add_menu_entry{name="--Sample Mappings:Paketti..:Copy Note-On to Note-Off Layer +12",invoke=function() noteOnToNoteOff(12) end}
renoise.tool():add_menu_entry{name="Sample Mappings:Paketti..:Copy Note-On to Note-Off Layer +24",invoke=function() noteOnToNoteOff(24) end}
renoise.tool():add_menu_entry{name="Sample Mappings:Paketti..:Copy Note-On to Note-Off Layer",invoke=function() noteOnToNoteOff(0) end}
renoise.tool():add_menu_entry{name="Sample Mappings:Paketti..:Copy Note-On to Note-Off Layer -12",invoke=function() noteOnToNoteOff(-12) end}
renoise.tool():add_menu_entry{name="Sample Mappings:Paketti..:Copy Note-On to Note-Off Layer -24",invoke=function() noteOnToNoteOff(-24) end}

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