Go Down

Topic: midi script with 2 issues (Read 511 times) previous topic - next topic

Wessie3000

Hallo Everyone,

Im still busy with my project and to finally finish it I need two problems solved...Any help is welcome:)

So here I go.

I am building a midi foot controller. It has a 13 key keyboard that sends Noteon and off messages. Also 7 pushbuttons; the first six sends CC messages and the seventh is a shift button, which i use to change channels and octave up and down.


Problem 1: the six buttons that sends ccmessages only do that once, when i have pressed a button that button becomes inactive. Been staring at the script for some time but cant figure it out...


Problem 2: Sometimes a noteOff message is not send. Is there a way to make sure it will be sended?



Wessie3000

Code: [Select]
#include <LiquidCrystal.h>

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

byte midi_start = 0xfa;
byte midi_stop = 0xfc;
byte midi_clock = 0xf8;
byte midi_continue = 0xfb;
int play_flag = 0;
byte data;
byte counter;
int ledPin = 13;
unsigned long count;
float ccc;
unsigned long lastcount;
int bpm = 120;
int lastbpm = 0;
int bpmhoog;
int bpmlaag;
float calcbpm;
int output_pin = 50;
int val = 0;
const int notes[13] = {22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34};
const int foot[7] = {36, 37, 38, 39, 40, 41, 42};

boolean noteOn[13] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
boolean noteLast[13] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};

boolean footOn[7] = {0, 0, 0, 0, 0, 0, 0};
boolean footLast[7] = {0, 0, 0, 0, 0, 0, 0};

const int noteCount = 13;
const int footCount = 6;


int mode = 0;
boolean shiftOn = 0;
boolean shiftOnLast = 0;

int keysBase = 0x24;
int keysLast = keysBase;
int NoteAanBase = 0x90;
int NoteUitBase = 0x80;
int NoteAanLast = NoteAanBase;
int NoteUitLast = NoteUitBase;
int CCChannelBase = 0xB0;
int CCChannel = CCChannelBase;
int midiCCselect = 22;
int maxmode = 1;


void setup() {
  Serial.begin(115200);
  pinMode(output_pin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  int inMin1 = 22;
  int inMax1 = 34;
  for (int i = inMin1; i <= inMax1; i++) {
    pinMode(i, INPUT);
  }
  int inMin2 = 36;
  int inMax2 = 42;
  for (int j = inMin2; j <= inMax2; j++) {
    pinMode(j, INPUT);
  }





  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("CC");
  lcd.setCursor(5, 0);
  lcd.print("Note");
  lcd.setCursor(12, 0);
  lcd.print("Mode");
  lcd.setCursor(0, 1);
  lcd.print("BPM");
  lcd.setCursor(8, 1);
  lcd.print("Oct");
}
int midiCC(int midiStatusCC, int midiData1CC, int midiData2CC) {
  Serial.write(midiStatusCC);
  Serial.write(midiData1CC);
  Serial.write(midiData2CC);
}

int midi(int midiStatus, int midiData1, int midiData2) {
  Serial.write(midiStatus);
  Serial.write(midiData1);
  Serial.write(midiData2);
}









void loop() {
  if ((counter == 0) && (val == 0)) {
    digitalWrite(output_pin, HIGH);
  }

  count = millis();
  if (Serial.available() > 0) {
    data = Serial.read();
    if (data == midi_start) {
      play_flag = 1;
      counter = 0;
      val = 0;

    }
    else if (data == midi_continue) {
      play_flag = 1;
    }
    else if (data == midi_stop) {

      lcd.setCursor(3, 1);
      lcd.print("   ");
      play_flag = 0;
      counter = 0;
      val = 0;

    }
    else if ((data == midi_clock) && (play_flag == 1)) {
      Sync();

    }
  }
  shiftOn = digitalRead(foot[6]);



  if ((shiftOn == HIGH) && (shiftOn != shiftOnLast)) {
    if (mode < maxmode) {
      mode = (mode + 1);
    }

    else if (mode == maxmode) {
      mode = 0;
    }
  }


  shiftOnLast = shiftOn;






  lcd.setCursor(2, 0);
  if ((CCChannel - 175) > 9) {
    lcd.print(CCChannel - 175);
  }
  if ((CCChannel - 175) < 10) {
    lcd.print("0");
    lcd.print(CCChannel - 175);
  }

  lcd.setCursor(9, 0);
  if ((NoteAanLast - 143) > 9) {
    lcd.print(NoteAanLast - 143);
  }
  if ((NoteAanLast - 143) < 10) {
    lcd.print("0");
    lcd.print(NoteAanLast - 143);
  }




  lcd.setCursor(10, 1);
  lcd.print((keysLast / 12));


  lcd.setCursor(12, 1);
  if (mode == 0) {
    lcd.print("play");
  }
  if (mode != 0) {
    lcd.print("pick");
  }




  if ( mode  == 0) {


    for (char n = 0; n < noteCount; n++) {
      noteOn[n] = digitalRead(notes[n]);

      if ((noteOn[n] == LOW) && (noteLast[n] != noteOn[n])) {
        midi(NoteAanLast, keysLast + n, 0x7F);
        noteLast[n] = noteOn[n];
      }



      if (noteLast[n] != noteOn[n]) {
        midi(NoteUitLast, keysLast + n, 0x7F);
        noteLast[n] = noteOn[n];
      }


    }


    for (char m = 0; m < footCount; m++) {
      footOn[m] = digitalRead(foot[m]);

      if ((footOn[m] == HIGH) && (footLast[m] != footOn[m])) {
        midiCC(CCChannel, midiCCselect + m, 0x7F);
        footLast[m] = footOn[m];
      }



    }










  }

  else if ( mode  == 1) {


    for (char m = 0; m < footCount; m++) {
      footOn[m] = digitalRead(foot[m]);

      if ((footOn[m] == HIGH) && (footLast[m] != footOn[m])) {
        CCChannel = CCChannelBase + m;
        mode = 0;
        footLast[m] = footOn[m];
      
      }
 shiftOnLast = shiftOn;



Wessie3000

Maybe all the code is a bit much so Ill narrow it down a bit


Code: [Select]
#include <LiquidCrystal.h>

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

byte midi_start = 0xfa;
byte midi_stop = 0xfc;
byte midi_clock = 0xf8;
byte midi_continue = 0xfb;
int play_flag = 0;
byte data;
byte counter;
int ledPin = 13;
unsigned long count;
float ccc;
unsigned long lastcount;
int bpm = 120;
int lastbpm = 0;
int bpmhoog;
int bpmlaag;
float calcbpm;
int output_pin = 50;
int val = 0;
const int notes[13] = {22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34};
const int foot[7] = {36, 37, 38, 39, 40, 41, 42};

boolean noteOn[13] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
boolean noteLast[13] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};

boolean footOn[7] = {0, 0, 0, 0, 0, 0, 0};
boolean footLast[7] = {0, 0, 0, 0, 0, 0, 0};

const int noteCount = 13;
const int footCount = 6;



i suppose there is a mistake here
Code: [Select]
  if ( mode  == 0) {


    for (char n = 0; n < noteCount; n++) {
      noteOn[n] = digitalRead(notes[n]);

      if ((noteOn[n] == LOW) && (noteLast[n] != noteOn[n])) {
        midi(NoteAanLast, keysLast + n, 0x7F);
        noteLast[n] = noteOn[n];
      }



      if (noteLast[n] != noteOn[n]) {
        midi(NoteUitLast, keysLast + n, 0x7F);
        noteLast[n] = noteOn[n];
      }


    }
    for (char m = 0; m < footCount; m++) {
      footOn[m] = digitalRead(foot[m]);

      if ((footOn[m] == HIGH) && (footLast[m] != footOn[m])) {
        midiCC(CCChannel, midiCCselect + m, 0x7F);
        footLast[m] = footOn[m];
      }



    }
}


btw because the notes are triggered by switches that break contact and CC are triggered by switches that make contact theres a difference in HIGH and LOW

Go Up