Midi note remapping

Hello,

I'm pretty new to this, I would like to make a simple program, just a remapping of two midi notes to two other notes.
I need to remap note 36 to 43 and not 38 to 48.
i figure I need to make the program listen to the midi input and if a note is 36 or 38 remap them to the new value.
Anyone can put me on the right track to do this?

Thanks

You could try something like this:

[color=#5e6d03]#include[/color] [color=#434f54]<[/color][b][color=#d35400]Control_Surface[/color][/b][color=#434f54].[/color][color=#000000]h[/color][color=#434f54]>[/color] [color=#434f54]// [/color][u][color=#434f54]https://github.com/tttapa/Control-Surface[/color][/u]  

[color=#00979c]class[/color] [color=#000000]MappingMIDI_Pipe[/color] [color=#434f54]:[/color] [color=#00979c]public[/color] [color=#000000]MIDI_Pipe[/color] [color=#000000]{[/color]
  [color=#434f54]// Function for sending MIDI Channel Messages over the pipe[/color]
  [color=#00979c]void[/color] [color=#000000]pipeMIDI[/color][color=#000000]([/color][color=#000000]ChannelMessage[/color] [color=#000000]msg[/color][color=#000000])[/color] [color=#5e6d03]override[/color] [color=#000000]{[/color]
    [color=#434f54]// If it is a MIDI note message[/color]
    [color=#5e6d03]if[/color] [color=#000000]([/color][color=#000000]msg[/color][color=#434f54].[/color][color=#000000]header[/color] [color=#434f54]==[/color] [color=#00979c]NOTE_ON[/color] [color=#434f54]||[/color] [color=#000000]msg[/color][color=#434f54].[/color][color=#000000]header[/color] [color=#434f54]==[/color] [color=#00979c]NOTE_OFF[/color][color=#000000])[/color] [color=#000000]{[/color]
      [color=#434f54]// Map note #36 → #43 and #38 → #48[/color]
      [color=#5e6d03]if[/color] [color=#000000]([/color][color=#000000]msg[/color][color=#434f54].[/color][color=#000000]data1[/color] [color=#434f54]==[/color] [color=#000000]36[/color][color=#000000])[/color]
        [color=#000000]msg[/color][color=#434f54].[/color][color=#000000]data1[/color] [color=#434f54]=[/color] [color=#000000]43[/color][color=#000000];[/color]
      [color=#5e6d03]else[/color] [color=#5e6d03]if[/color] [color=#000000]([/color][color=#000000]msg[/color][color=#434f54].[/color][color=#000000]data1[/color] [color=#434f54]==[/color] [color=#000000]38[/color][color=#000000])[/color]
        [color=#000000]msg[/color][color=#434f54].[/color][color=#000000]data1[/color] [color=#434f54]=[/color] [color=#000000]48[/color][color=#000000];[/color]       
    [color=#000000]}[/color]
    [color=#434f54]// Pass on the MIDI message[/color]
    [color=#000000]MIDI_Pipe[/color][color=#434f54]:[/color][color=#434f54]:[/color][color=#000000]pipeMIDI[/color][color=#000000]([/color][color=#000000]msg[/color][color=#000000])[/color][color=#000000];[/color]
  [color=#000000]}[/color]
[color=#000000]}[/color][color=#000000];[/color]

[b][color=#d35400]USBMIDI_Interface[/color][/b] [color=#000000]midi_in[/color][color=#000000];[/color]
[b][color=#d35400]HardwareSerialMIDI_Interface[/color][/b] [color=#000000]midi_out[/color] [color=#434f54]=[/color] [b][color=#d35400]Serial1[/color][/b][color=#000000];[/color]

[color=#000000]MappingMIDI_Pipe[/color] [color=#000000]pipe[/color][color=#000000];[/color]

[color=#00979c]void[/color] [color=#5e6d03]setup[/color][color=#000000]([/color][color=#000000])[/color] [color=#000000]{[/color]
  [color=#434f54]// Connect the MIDI input to the MIDI output using a pipe.[/color]
  [color=#434f54]// The pipe will map the MIDI data as specified above.[/color]
  [color=#000000]midi_in[/color] [color=#434f54]>>[/color] [color=#000000]pipe[/color] [color=#434f54]>>[/color] [color=#000000]midi_out[/color][color=#000000];[/color]
  [color=#434f54]// Initialize the MIDI interfaces[/color]
  [color=#000000]midi_in[/color][color=#434f54].[/color][color=#d35400]begin[/color][color=#000000]([/color][color=#000000])[/color][color=#000000];[/color]
  [color=#000000]midi_out[/color][color=#434f54].[/color][color=#d35400]begin[/color][color=#000000]([/color][color=#000000])[/color][color=#000000];[/color]
[color=#000000]}[/color]

[color=#00979c]void[/color] [color=#5e6d03]loop[/color][color=#000000]([/color][color=#000000])[/color] [color=#000000]{[/color]
  [color=#434f54]// Listen for MIDI input and send it over the pipe[/color]
  [color=#000000]midi_in[/color][color=#434f54].[/color][color=#d35400]update[/color][color=#000000]([/color][color=#000000])[/color][color=#000000];[/color]
[color=#000000]}[/color]

Or if you need just one MIDI interface:

[b][color=#d35400]USBDebugMIDI_Interface[/color][/b] [color=#00979c]midi[/color][color=#000000];[/color]

[color=#000000]MappingMIDI_Pipe[/color] [color=#000000]pipe[/color][color=#000000];[/color]

[color=#00979c]void[/color] [color=#5e6d03]setup[/color][color=#000000]([/color][color=#000000])[/color] [color=#000000]{[/color]
  [color=#00979c]midi[/color] [color=#434f54]>>[/color] [color=#000000]pipe[/color] [color=#434f54]>>[/color] [color=#00979c]midi[/color][color=#000000];[/color]
  [color=#00979c]midi[/color][color=#434f54].[/color][color=#d35400]begin[/color][color=#000000]([/color][color=#000000])[/color][color=#000000];[/color]
[color=#000000]}[/color]

[color=#00979c]void[/color] [color=#5e6d03]loop[/color][color=#000000]([/color][color=#000000])[/color] [color=#000000]{[/color]
  [color=#00979c]midi[/color][color=#434f54].[/color][color=#d35400]update[/color][color=#000000]([/color][color=#000000])[/color][color=#000000];[/color]
[color=#000000]}[/color]

It uses the Control Surface library.
Here’s a list of the available MIDI interfaces.

Pieter

Thanks a lot I’m gonna look at it, I’m gonna use it with this

RK-002 Smart MIDI Cable - DUY (Digitakt)

would this work?

#include <RK002.h>

#define APP_NAME “note to Note Mapper”
#define APP_AUTHOR “Retrokits”
#define APP_VERSION “1.0”
#define APP_GUID “35a97808-ec07-40d8-98c7-9a0f1638b615”

//generate GUIDs at https://www.guidgenerator.com/

/*

  • Parameters:
  • CHANNEL - MIDI Channel to receive note on
  • NOTE_ON - note to remap
  • NOTE_OFF - note to remap

*/

// construct RK002 DUY Header
RK002_DECLARE_INFO(APP_NAME,APP_AUTHOR,APP_VERSION,APP_GUID)

// Define accessible parameters:
RK002_DECLARE_PARAM(CHANNEL,1,1,16,1); // MIDI channel in
RK002_DECLARE_PARAM(NOTE_ON,36,0,127,1) // Note 36
RK002_DECLARE_PARAM(NOTE_ON,38,0,127,1) // Note 38
RK002_DECLARE_PARAM(NOTE_OFF,36,0,127,1) // Note 36
RK002_DECLARE_PARAM(NOTE_OFF,38,0,127,1) // Note 38

if (msg.header == NOTE_ON || msg.header == NOTE_OFF) {
// Map note #36#43 and #38#48
if (msg.data1 == 36)
msg.data1 = 43;
else if (msg.data1 == 38)
msg.data1 = 48;
}
// Pass on the MIDI message
MIDI_Pipe::pipeMIDI(msg);
}
};

void updateParams()
{
dChannel = RK002_paramGet(CHANNEL)-1;
}

void RK002_onParamChange(unsigned param_nr, int val){
updateParams();
}

// called on RK002 Setup
void setup()
{
updateParams();
}

// the main loop
void loop()
{
}

NoteREMAP.ino (1.26 KB)

You can structure that code better by pulling the re-map operation out as a separate function, which
makes the code easier to maintain and understand:

...
    if (msg.header == NOTE_ON || msg.header == NOTE_OFF) {
      msg.data1 = remap_note (msg.data1) ;
    }
...


byte remap_note (byte note)
{
  switch (note)
  {
case 36: return 43;
case 38: return 48;
default:  return note ;
  }
}

thanks Mark
actually I now loaded the library of the unit I’m using and I’m not sure the remap function would work.
I used a different function of offsetting the note

I used this patch as start up

#include <RK002.h>

RK002_DECLARE_INFO("Note Doubler","Retrokits","1.0","7b47d3dd-991a-4197-ac02-d340cdabfb59")

#define MIDICHN 0
#define OFFSET  7

bool RK002_onNoteOn(byte chn, byte key, byte vel)
{
  if (chn == MIDICHN)
  {
    RK002_sendNoteOn(chn,key+OFFSET,vel);
  }
  return true;
}

bool RK002_onNoteOff(byte chn, byte key, byte vel)
{
  if (chn == MIDICHN)
  {
    RK002_sendNoteOff(chn,key+OFFSET,vel);
  }
  return true;
}

void setup() 
{
  RK002_setup();
}

void loop()
{
  RK002_loop();
}

I have never try to code before so it will be clumsy, here it is

#include <RK002.h>

RK002_DECLARE_INFO("Note Swap","Retrokits","1.0","7b47d3dd-991a-4197-ac02-d340cdabfb59")

#define MIDICHN 9
#define OFFSET1  7
#define OFFSET2  10
#define OFFSET3  -7
#define OFFSET4  -10

bool RK002_onNoteOn(byte chn, byte key, byte vel)
{
  if (chn == MIDICHN)
  if (key == 36)
  {
    RK002_sendNoteOn(chn,key+OFFSET1,vel);
  }
   if (key == 38)
   {
    RK002_sendNoteOn(chn,key+OFFSET2,vel);
    }
  if (key == 43)
  {
    RK002_sendNoteOn(chn,key+OFFSET3,vel);
  }
   if (key == 48)
   {
    RK002_sendNoteOn(chn,key+OFFSET4,vel);
    }
  return true;
}

bool RK002_onNoteOff(byte chn, byte key, byte vel)
{
  if (chn == MIDICHN)
  if (key == 36)
  {
    RK002_sendNoteOff(chn,key+OFFSET1,vel);
  }
   if (key == 38)
   {
    RK002_sendNoteOff(chn,key+OFFSET2,vel);
    }
  if (key == 43)
  {
    RK002_sendNoteOff(chn,key+OFFSET3,vel);
  }
   if (key == 48)
   {
    RK002_sendNoteOff(chn,key+OFFSET4,vel);
    }
  return true;
}

void setup() 
{
  RK002_setup();
}

void loop()
{
  RK002_loop();
}