Send mapped CC Events on pot movements

We want to send MIDI events on pot movements. This solution is more flexible than the simple one, since it allows to map each individual pot to a predefined MIDI event.

Copy the SDCC skeleton into a new directory, open the main.c file and enhance the AIN_NotifyChange() function like shown below. Thereafter type "make" in the command shell, and upload the new project.hex file to the core.

// this const definition creates a table of 128 bytes in flash memory
// we create a 2-dimensional array with 64 entries
// each entry consists of two bytes: 
//   o one for the first MIDI byte (MIDI status)
//   o a second for the second MIDI byte (here: CC number)
// The meaning of the bytes can be found in the MIDI spec
// (-> http://www.borg.com/~jglatt/tech/midispec.htm)

const unsigned char pot_event_map[64][2] = {
  // Pot 1..16 send CC#0x5b (Reverb) over MIDI Channel #1..16
  {0xb0, 0x5b},   {0xb1, 0x5b},   {0xb2, 0x5b},   {0xb3, 0x5b}, 
  {0xb4, 0x5b},   {0xb5, 0x5b},   {0xb6, 0x5b},   {0xb7, 0x5b}, 
  {0xb8, 0x5b},   {0xb9, 0x5b},   {0xba, 0x5b},   {0xbb, 0x5b}, 
  {0xbc, 0x5b},   {0xbd, 0x5b},   {0xbe, 0x5b},   {0xbf, 0x5b}, 

  // Pot 17..32 send CC#0x5d (Chorus) over MIDI Channel #1..16
  {0xb0, 0x5d},   {0xb1, 0x5d},   {0xb2, 0x5d},   {0xb3, 0x5d}, 
  {0xb4, 0x5d},   {0xb5, 0x5d},   {0xb6, 0x5d},   {0xb7, 0x5d}, 
  {0xb8, 0x5d},   {0xb9, 0x5d},   {0xba, 0x5d},   {0xbb, 0x5d}, 
  {0xbc, 0x5d},   {0xbd, 0x5d},   {0xbe, 0x5d},   {0xbf, 0x5d}, 

  // Pot 33..48 send CC#0x4a (CutOff) over MIDI Channel #1..16
  {0xb0, 0x4a},   {0xb1, 0x4a},   {0xb2, 0x4a},   {0xb3, 0x4a}, 
  {0xb4, 0x4a},   {0xb5, 0x4a},   {0xb6, 0x4a},   {0xb7, 0x4a}, 
  {0xb8, 0x4a},   {0xb9, 0x4a},   {0xba, 0x4a},   {0xbb, 0x4a}, 
  {0xbc, 0x4a},   {0xbd, 0x4a},   {0xbe, 0x4a},   {0xbf, 0x4a}, 

  // Pot 49..64 send CC#0x07 (Volume) over MIDI Channel #1..16
  {0xb0, 0x07},   {0xb1, 0x07},   {0xb2, 0x07},   {0xb3, 0x07}, 
  {0xb4, 0x07},   {0xb5, 0x07},   {0xb6, 0x07},   {0xb7, 0x07}, 
  {0xb8, 0x07},   {0xb9, 0x07},   {0xba, 0x07},   {0xbb, 0x07}, 
  {0xbc, 0x07},   {0xbd, 0x07},   {0xbe, 0x07},   {0xbf, 0x07}, 
  };


/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS after startup to initialize the 
// application
/////////////////////////////////////////////////////////////////////////////
void Init(void) __wparam
{
  // initialize the AIN driver
  MIOS_AIN_NumberSet(64);  // 64 pots are connected
  MIOS_AIN_Muxed();        // the AINX4 modules are used
  MIOS_AIN_DeadbandSet(7); // should be 7 when 7bit resolution is used
}


/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS when a pot has been moved
/////////////////////////////////////////////////////////////////////////////
void AIN_NotifyChange(unsigned char pin, unsigned int pin_value) __wparam
{
  // send mapped CC value
  MIOS_MIDI_TxBufferPut(pot_event_map[pin][0]); // first value from table
  MIOS_MIDI_TxBufferPut(pot_event_map[pin][1]); // second value from table
  MIOS_MIDI_TxBufferPut(MIOS_AIN_Pin7bitGet(pin)); // 7bit pot value
}

A list of available MIOS function can be found here.



Last update: 2023-11-04

Copyright © 1998-2023, Thorsten Klose. All rights reserved.