[Solved] Help: Code for MIDI routing of a single button of a tool

I want to create a tool as a simple button to execute a specific function of the gun with the mouse. Simple.

But in addition, the issue is to be able to perform the MIDI mapping of the button, to control that button with the keyboard / MIDI controller.

The tool would look this simple:


| TITLE: BUTTON WITH MIDI MAPPING X |

| |

| |

| [BUTTON] |

| |

|_________________________________________|

The especific function (a example):

-- [BUTTON] tool_01_33: Clean all values in Track/s inside Selected Group
function tool_01_33()
  local song = renoise.song()
  local selected_track = song.tracks[song.selected_track_index]
  ---
  local function filter_Gr( sel_tr , sel_mb )
    sel_tr = song.selected_track_index
    sel_mb = #selected_track.members
    --loop
  for i = sel_tr , sel_tr - sel_mb , - 1 do
    local pattern_iterator_notes = song.pattern_iterator:note_columns_in_track( i , true )
      for pos, note_column in pattern_iterator_notes do
        if ( not note_column.is_empty ) and song.tracks[i].type == renoise.Track.TRACK_TYPE_SEQUENCER then
        if( note_column.note_value >= 0 ) then note_column.note_value = 121 -- 0-119, 120=Off, 121=Empty
      end
          if( note_column.instrument_value >= 0 ) then note_column.instrument_value = 255 -- 0-254, 255==Empty
        end
          if( note_column.volume_value >= 0 ) then note_column.volume_value = 255 -- 0-127, 255==Empty
        end
          if( note_column.panning_value >= 0 ) then note_column.panning_value = 255 -- 0-127, 255==Empty
        end
          if( note_column.delay_value >= 0 ) then note_column.delay_value = 0 -- 0-255, 0==Empty
        end    
          if( note_column.effect_number_value >= 0 ) then note_column.effect_number_value = 0 -- 0-65535 ???, 0==Empty
        end
        if( note_column.effect_number_value >= 0 ) then note_column.effect_amount_value = 0 -- 0-255 ???, 0==Empty (0 & 0, both together)
          end
    end
    end
    local pattern_iterator_effects = song.pattern_iterator:effect_columns_in_track( i , true)
    for pos, effect_column in pattern_iterator_effects do
        if ( not effect_column.is_empty ) and song.tracks[i].type == renoise.Track.TRACK_TYPE_SEQUENCER then
          if( effect_column.number_value >= 0 ) then effect_column.number_value = 0 -- 0-65535 ???, 0==Empty
        end
        if( effect_column.number_value >= 0 ) then effect_column.amount_value = 0 -- 0-255 ???, 0==Empty (0 & 0, both together)
        renoise.app():show_status( "GT16-Colors, GTC: all values inside Track/s in selected Group are cleaned." )
          end
    end
      end
    end
  end
  ---
  local function filter_Tr( sel_tr )
    sel_tr = song.selected_track_index
  local pattern_iterator_notes = song.pattern_iterator:note_columns_in_track( sel_tr , true )
    for pos, note_column in pattern_iterator_notes do
      if ( not note_column.is_empty ) then
      if( note_column.note_value >= 0 ) then note_column.note_value = 121 -- 0-119, 120=Off, 121=Empty
    end
        if( note_column.instrument_value >= 0 ) then note_column.instrument_value = 255 -- 0-254, 255==Empty
      end
        if( note_column.volume_value >= 0 ) then note_column.volume_value = 255 -- 0-127, 255==Empty
      end
        if( note_column.panning_value >= 0 ) then note_column.panning_value = 255 -- 0-127, 255==Empty
      end
        if( note_column.delay_value >= 0 ) then note_column.delay_value = 0 -- 0-255, 0==Empty
      end    
        if( note_column.effect_number_value >= 0 ) then note_column.effect_number_value = 0 -- 0-65535 ???, 0==Empty
      end
      if( note_column.effect_number_value >= 0 ) then note_column.effect_amount_value = 0 -- 0-255 ???, 0==Empty (0 & 0, both together)
        end
      end
  end
  local pattern_iterator_effects = song.pattern_iterator:effect_columns_in_track( sel_tr , true)
  for pos, effect_column in pattern_iterator_effects do
      if ( not effect_column.is_empty ) then
        if( effect_column.number_value >= 0 ) then effect_column.number_value = 0 -- 0-65535 ???, 0==Empty
      end
      if( effect_column.number_value >= 0 ) then effect_column.amount_value = 0 -- 0-255 ???, 0==Empty (0 & 0, both together)
      renoise.app():show_status( "GT16-Colors, GTC: all values inside Track selected are cleaned." )
    end
      end
    end
  end
  ---
  if ( song.selected_track.type == renoise.Track.TRACK_TYPE_GROUP ) then
    filter_Gr()
  elseif ( song.selected_track.type == renoise.Track.TRACK_TYPE_SEQUENCER ) then
    filter_Tr()
  else renoise.app():show_status( "⚠ GT16-Colors, GTC: please, for clean all values inside Track/s select before a Group or Track!" )
  end
end

The simple Button [BUTTON] :

},
        vb:button {
          color = { 0x66,0x00,0x00 },
          text = 'CLM',
          id = '33',
          tooltip = '33: Clean all Parameter Columns all Tracks inside selected Group.\n[MOUSE CLICK]',
          midi_mapping = 'NAME', <-------- SEE HERE!
          height = 24,
          width = 40,
          notifier = function()tool_01_33() end
        },
        vb:button {
...

Midi Mapping Code

--------------------------------------------------------------------------------
-- MIDI/KEY MAPPING
--------------------------------------------------------------------------------

renoise.tool():add_midi_mapping {
  name = 'Tools:GT16-Colors:Clean All values in Track/Group [Trigger]', <-------- SEE HERE!
  invoke = function()tool_01_33() end
}

Apparently, I need to unite the code of the button with the drop-down menu of the Midi Mapping Panel, to work together.At the same time, it seems that something is missing (MIDI code) for the specific function “function tool_01_33()” to work.

My MIDI keyboard:

What I desire is simple.I have the following MIDI keyboard:

[sharedmedia=core:attachments:7063]

When you press button 1 (CC51) on the MIDI keyboard, execute the function: “function tool_01_33()”.This is a simple example. Actually I need it to implement it to an already created tool (GT16-Colors) or even create a new tool with specific new functions.In short, buttons (and other type of controls) with MIDI routing…The MIDI keyboard is another example. It can work with any MIDI keyboard.

A related screenshot (Midi Mapping Panel):

[sharedmedia=core:attachments:7064]

Can anyone help me with the code?

Why?

I often use the MIDI keyboard to compose. In some cases I am continuously jumping from the MIDI keyboard to the alphanumeric keypad. Maybe I can organize myself to avoid it and control the essentials of my custom with the MIDI keyboard only.I would like to master a simple code to be able to MIDI route the buttons with specific functions…

The xrnx starter kit (get it on our github page) contains an example tool which you can pick apart.

I think the example, once you have installed the tool within the download), is called Example Tool GUI > Midi Mapping

The xrnx starter kit (get it on our github page) contains an example tool which you can pick apart.

I think the example, once you have installed the tool within the download), is called Example Tool GUI > Midi Mapping

Guauu!!! SOLVED!!!

The solution is very simple. I copy the code here for future reference:

vb:button {
          color = { 0x66,0x00,0x00 },
          text = 'CLM',
          id = '33',
          tooltip = '33: Clean all Parameter Columns all Tracks inside selected Group.\n[MOUSE CLICK]',
          midi_mapping = 'Tools:GT16-Colors:Clean All values in Track [Trigger]', <---------LOOK HERE
          height = 24,
          width = 40,
          notifier = function()tool_01_33() end
        },

--------------------------------------------------------------------------------
-- MIDI/KEY MAPPING
--------------------------------------------------------------------------------

renoise.tool():add_midi_mapping {
  name = 'Tools:GT16-Colors:Clean All values in Track [Trigger]', <---------LOOK HERE
  invoke = function()tool_01_33() end
}
  • midi_mapping of button = name of add_midi_mapping
  • The button of MIDI Keyboard executes the assigned functionfunction()tool_01_33() thanks torenoise.tool():add_midi_mapping { }

Guauu! Knowing this simple code, I can solve a lot of shortcuts for my MIDI keyboard, even create a 4-row tool with 8 buttons to control up to 32 specific functions using the MIDI keyboard. Something like a Matrix of MIDI buttons (4x8).

I find it a bit of a beast, but I could even make my GT16-Colors tool fully compatible with MIDI mapping.Long ago I thought this was much more complicated.

The MIDI mapping is already saved in the XRNS song or in the file XRNM (XML).

Archive buttonCC51.XRNM:

<?xml version="1.0" encoding="UTF-8"?>
<MidiActionMappingSet doc_version="0">
  <ActionMappings>
    <ActionMapping>
      <Action>Tools:GT16-Colors:Clean All values in Track [Trigger]</Action>
      <MidiMappings>
        <MidiMapping>
          <MappingMode>Controllers</MappingMode>
          <ControllerMode>Absolute 7 bit</ControllerMode>
          <NoteMode>Trigger</NoteMode>
          <Channel>0</Channel>
          <CCNumberOrNote>51</CCNumberOrNote>
          <Min>0.0</Min>
          <Max>1.0</Max>
        </MidiMapping>
      </MidiMappings>
    </ActionMapping>
  </ActionMappings>
</MidiActionMappingSet>

Thanks you Danoise!!! ^^ ^^ ^^ ^^ ^^ ^^ :slight_smile: