c_cpp 适用于KORG ES-1和Alesis Trigger IO的Arduino MIDI转换器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 适用于KORG ES-1和Alesis Trigger IO的Arduino MIDI转换器相关的知识,希望对你有一定的参考价值。

#include <MIDI.h>
/*
8/9/13: 

FROM: http://blog.deseipel.com/2013/08/arduino-midi-translator-for-korg-es-1.html

About this sketch:
------------------------------------
This is an Arduino sketch that I wrote to "control" some aspects of a Korg ES-1 via drum triggers/pads.  The Korg ES-1 is a sampler/sequencer, manufactured around 2000.  I didn't want to simply play along with a sequenced track, I wanted to control it and interact with it.  And a lot of drummers use triggers as 'one-shots' and while there is some value to that, I don't want to be limited to that either.  
hardware used:  Korg ES-1, Alesis Trigger IO, Arduino board (specifically a Ruggeduino & thier MIDI shield), triggger pads of your choice, etc.
connections:  Trigger pads ---->  Alesis Trigger IO ----->  Arduino MIDI IN , MIDI Out ----> Korg ES-1 MIDI IN
the trigger voltage(?) is changed to a MIDI note via the Alesis IO, which is then translated to the coded MIDI command in the code below.  You MUST synchronize or plan out what MIDI notes you want to use for this to work.  This means that notes setup in the Trigger IO must match the code below for it to work.  Someday I'd love to install an LCD with a Setup screen so that these could be managed more easily. 

Things this sketch does: 
------------------------------------
1. Program change up/down
  a.  note 60 is up, note 62 is down

2. "Mute"  parts 1-7b (sets the volume to zero)
  a.  note 64 is part 1
  b.  note 66 is part 2
  c.  note 68 is part 3
  d.  note 70 is part 4
  e.  note 72 is part 5
  f.  note 74 is part 6
  g.  note 76 is part 6a
  h.  note 78 is part 6b
  i.  note 79 is part 7a
  j.  note 80 is part 7b


TO DO:
----------------------------
1.  Start/stop via trigger pad

if note X is received
sendRealTime (Start/Stop)? 

2.  MIDI file reader/send out, get sync...

 */
byte P = 0;  //program or patch number
byte M1 = 0;  //mute for part 1 off
byte M2 = 0;  //mute for part 2 off
byte M3 = 0;  //mute for part 3 off
byte M4 = 0;  //mute for part 4 off
byte M5 = 0;  //mute for part 5 off
byte M6a = 0;  //mute for part 6a off
byte M6b = 0;  //mute for part 6b off
byte M7a = 0;  //mute for part 7a off
byte M7b = 0;  //mute for part 7b off

void HandleClock() {

  //do stuff ?

}

void HandleNoteOn (byte channel, byte note, byte velocity){
  //if note X is sent, send program change control to go up
  //todo: 
  if (note == 60 and velocity >0){   //need to get the actual note number that I'll assign */
    if (P == 127){
      P=0;
      MIDI.sendProgramChange(P,10);
    }
    else
    {
      P++;
      MIDI.sendProgramChange(P,10);
    }
  }

  //if note Y is sent, send program change control to go down
  if (note == 62 and velocity>0){  //need to get the actual note number that I'll assign
    if (P== 0){
      P=127;
      MIDI.sendProgramChange(P,10);
    }
    else {
      P--;
      MIDI.sendProgramChange(P,10);
    }
  }

  //if note Z is sent, send nrpn to set volume to zero (part mute)
//mute for part 1
  if (note == 64 and velocity>0) { 
    //use sendcontrolchange? to mute part 1 only
    if (M1==0) {
      MIDI.sendControlChange(99,5,10);
      MIDI.sendControlChange(98,1,10);
      MIDI.sendControlChange(06,0,10);  //sets level to zero, for part 1
      //need to toggle it
      M1=1;
    }
    else {
      MIDI.sendControlChange(99,5,10);
      MIDI.sendControlChange(98,1,10);
      MIDI.sendControlChange(06,120,10);
      M1=0;
    }
  }
  
  
   //mute for part 2
  
   if (note == 66 and velocity>0) { 
    if (M2==0) {
      MIDI.sendControlChange(99,5,10);
      MIDI.sendControlChange(98,9,10);
      MIDI.sendControlChange(06,0,10);  //sets level to zero, for part 2
      //need to toggle it
      M2=1;
    }
    else {
      MIDI.sendControlChange(99,5,10);
      MIDI.sendControlChange(98,9,10);
      MIDI.sendControlChange(06,120,10);
      M2=0;
    }
  }

  //mute for part 3
     if (note == 68 and velocity>0) { 
    //use sendcontrolchange? to mute part 1 only
    if (M3==0) {
      MIDI.sendControlChange(99,5,10);
      MIDI.sendControlChange(98,17,10);
      MIDI.sendControlChange(06,0,10);  //sets level to zero, for part 3
      //need to toggle it
      M3=1;
    }
    else {
      MIDI.sendControlChange(99,5,10);
      MIDI.sendControlChange(98,17,10);
      MIDI.sendControlChange(06,120,10);
      M3=0;
    }
  }
  //mute for part 4
     if (note == 70 and velocity>0) { 
    //use sendcontrolchange? to mute part 1 only
    if (M4==0) {
      MIDI.sendControlChange(99,5,10);
      MIDI.sendControlChange(98,25,10);
      MIDI.sendControlChange(06,0,10);  //sets level to zero, for part 1
      //need to toggle it
      M4=1;
    }
    else {
      MIDI.sendControlChange(99,5,10);
      MIDI.sendControlChange(98,25,10);
      MIDI.sendControlChange(06,120,10);
      M4=0;
    }
  }
  //mute for part 5
     if (note == 72 and velocity>0) { 
    //use sendcontrolchange? to mute part 1 only
    if (M5==0) {
      MIDI.sendControlChange(99,5,10);
      MIDI.sendControlChange(98,33,10);
      MIDI.sendControlChange(06,0,10);  //sets level to zero, for part 1
      //need to toggle it
      M5=1;
    }
    else {
      MIDI.sendControlChange(99,5,10);
      MIDI.sendControlChange(98,33,10);
      MIDI.sendControlChange(06,120,10);
      M5=0;
    }
  }
  //mute for 6a
     if (note == 74 and velocity>0) { 
    //use sendcontrolchange? to mute part 1 only
    if (M6a==0) {
      MIDI.sendControlChange(99,5,10);
      MIDI.sendControlChange(98,41,10);
      MIDI.sendControlChange(06,0,10);  //sets level to zero, for part 1
      //need to toggle it
      M6a=1;
    }
    else {
      MIDI.sendControlChange(99,5,10);
      MIDI.sendControlChange(98,41,10);
      MIDI.sendControlChange(06,120,10);
      M6a=0;
    }
  }
  //mute for 6b
     if (note == 76 and velocity>0) { 
    //use sendcontrolchange? to mute part 1 only
    if (M6b==0) {
      MIDI.sendControlChange(99,5,10);
      MIDI.sendControlChange(98,49,10);
      MIDI.sendControlChange(06,0,10);  //sets level to zero, for part 1
      //need to toggle it
      M6b=1;
    }
    else {
      MIDI.sendControlChange(99,5,10);
      MIDI.sendControlChange(98,49,10);
      MIDI.sendControlChange(06,120,10);
      M6b=0;
    }
  }
  //mute for 7a
     if (note == 78 and velocity>0) { 
    //use sendcontrolchange? to mute part 1 only
    if (M7a==0) {
      MIDI.sendControlChange(99,5,10);
      MIDI.sendControlChange(98,57,10);
      MIDI.sendControlChange(06,0,10);  //sets level to zero, for part 1
      //need to toggle it
      M7a=1;
    }
    else {
      MIDI.sendControlChange(99,5,10);
      MIDI.sendControlChange(98,57,10);
      MIDI.sendControlChange(06,120,10);
      M7a=0;
    }
  }
  //mute for 7b
     if (note == 80 and velocity>0) { 
    if (M7b==0) {
      MIDI.sendControlChange(99,5,10);
      MIDI.sendControlChange(98,65,10);
      MIDI.sendControlChange(06,0,10);  //sets level to zero, for part 1
      //need to toggle it
      M7b=1;
    }
    else {
      MIDI.sendControlChange(99,5,10);
      MIDI.sendControlChange(98,65,10);
      MIDI.sendControlChange(06,120,10);
      M7b=0;
    }
  }

  //done.
}

void setup() {

  MIDI.begin(MIDI_CHANNEL_OMNI);
  MIDI.turnThruOff();
  MIDI.setHandleNoteOn(HandleNoteOn);
  MIDI.sendProgramChange(P,10);
   MIDI.setHandleClock ( HandleClock );

}

void loop () {

  MIDI.read(); //is there incoming MIDI?


}

以上是关于c_cpp 适用于KORG ES-1和Alesis Trigger IO的Arduino MIDI转换器的主要内容,如果未能解决你的问题,请参考以下文章

c_cpp 适用于ROOT TH1类的PrintWiki功能

c_cpp 适用于C程序员的C ++第2周

c_cpp C ++的序列容器类,其作用类似于可以连接的字符串,但适用于任何类型。

Alesis QS MIDI Sysex 数据转换

c_cpp Taptic API for iPhone 7,7 Plus(公共API)。还适用于iPhone 6s,6s Plus(私有API)。

c_cpp 改进的firmata协议,适用于使用ttyATH0串口接口与arduino端通信的arduino YUN linux端。