Go Down

Topic: Switch Modes for MIDI Controller (Read 1 time) previous topic - next topic

trik

Hi,

I am very new into programming. I am trying to create a 8-note midi controller that can switch modes to different major scales.

I currently have it programmed to C major scale. I want to have a button to switch to D, E, F.. major for all the 8 notes every time I pressed it.

This is how it looks like:

[font=Verdana]// define the pins we use
int switchPin1 = 6;
int switchPin2 = 7;
int switchPin3 = 8;     
int switchPin4 = 9;
int switchPin5 = 10;
int switchPin6 = 11;
int switchPin7 = 12;
int switchPin8 = 13;

// general midi notes
char note1 = 60; //Middle C
char note2 = 62; //D
char note3 = 64; //E
char note4 = 65; //F
char note5 = 67; //G
char note6 = 69; //A
char note7 = 71; //B
char note8 = 72; //High C

// Variables
int switchState1 = LOW;
int switchState2 = LOW;
int switchState3 = LOW;
int switchState4 = LOW;
int switchState5 = LOW;
int switchState6 = LOW;
int switchState7 = LOW;
int switchState8 = LOW;
int currentSwitchState1 = LOW;
int currentSwitchState2 = LOW;
int currentSwitchState3 = LOW;
int currentSwitchState4 = LOW;
int currentSwitchState5 = LOW;
int currentSwitchState6 = LOW;
int currentSwitchState7 = LOW;
int currentSwitchState8 = LOW;


void setup() {

  // set the states of the I/O pins:
  pinMode(switchPin1, INPUT);
  pinMode(switchPin2, INPUT);
  pinMode(switchPin3, INPUT);
  pinMode(switchPin4, INPUT);
  pinMode(switchPin5, INPUT);
  pinMode(switchPin6, INPUT);
  pinMode(switchPin7, INPUT);
  pinMode(switchPin8, INPUT);
  // set MIDI baud rate :
  Serial.begin(31250);

}

void loop() {

  //switchPin1
  currentSwitchState1 = digitalRead(switchPin1);
  if( currentSwitchState1 == LOW && switchState1 == HIGH ) // push
    //Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
    noteOn(0x90, note1, 0x45);
  if( currentSwitchState1 == HIGH && switchState1 == LOW ) // release
    //Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
    noteOn(0x90, note1, 0x00);
  switchState1 = currentSwitchState1;

  //switchPin2
  currentSwitchState2 = digitalRead(switchPin2);
  if( currentSwitchState2 == LOW && switchState2 == HIGH ) // push
    //Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
    noteOn(0x90, note2, 0x45);
  if( currentSwitchState2 == HIGH && switchState2 == LOW ) // release
    //Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
    noteOn(0x90, note2, 0x00);
  switchState2 = currentSwitchState2;

  //switchPin3
  currentSwitchState3 = digitalRead(switchPin3);
  if( currentSwitchState3 == LOW && switchState3 == HIGH ) // push
    //Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
    noteOn(0x90, note3, 0x45);
  if( currentSwitchState3 == HIGH && switchState3 == LOW ) // release
    //Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
    noteOn(0x90, note3, 0x00);
  switchState3 = currentSwitchState3;

  //switchPin4
  currentSwitchState4 = digitalRead(switchPin4);
  if( currentSwitchState4 == LOW && switchState4 == HIGH ) // push
    //Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
    noteOn(0x90, note4, 0x45);
  if( currentSwitchState4 == HIGH && switchState4 == LOW ) // release
    //Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
    noteOn(0x90, note4, 0x00);
  switchState4 = currentSwitchState4;

  //switchPin5
  currentSwitchState5 = digitalRead(switchPin5);
  if( currentSwitchState5 == LOW && switchState5 == HIGH ) // push
    //Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
    noteOn(0x90, note5, 0x45);
  if( currentSwitchState5 == HIGH && switchState5 == LOW ) // release
    //Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
    noteOn(0x90, note5, 0x00);
  switchState5 = currentSwitchState5;

  //switchPin6
  currentSwitchState6 = digitalRead(switchPin6);
  if( currentSwitchState6 == LOW && switchState6 == HIGH ) // push
    //Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
    noteOn(0x90, note6, 0x45);
  if( currentSwitchState6 == HIGH && switchState6 == LOW ) // release
    //Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
    noteOn(0x90, note6, 0x00);
  switchState6 = currentSwitchState6;
 
   //switchPin7
  currentSwitchState7 = digitalRead(switchPin7);
  if( currentSwitchState7 == LOW && switchState7 == HIGH ) // push
    //Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
    noteOn(0x90, note7, 0x45);
  if( currentSwitchState7 == HIGH && switchState7 == LOW ) // release
    //Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
    noteOn(0x90, note7, 0x00);
  switchState7 = currentSwitchState7;
 
   //switchPin8
  currentSwitchState8 = digitalRead(switchPin8);
  if( currentSwitchState8 == LOW && switchState8 == HIGH ) // push
    //Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
    noteOn(0x90, note8, 0x45);
  if( currentSwitchState8 == HIGH && switchState8 == LOW ) // release
    //Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
    noteOn(0x90, note8, 0x00);
  switchState8 = currentSwitchState8;

}

// Send a MIDI note-on/off message. 
void noteOn(char cmd, char data1, char data2) {
  Serial.print(cmd, BYTE);
  Serial.print(data1, BYTE);
  Serial.print(data2, BYTE);
}
[/font]


Hope you can help out in understanding how to go about this.

Thank you!

Go Up