Hello, I am new to MIDI and I am trying to make wireless MIDI switches. I know that this code works for notes just fine, as I tested it with a keyboard, but I want to use Control Changes. I've used the "controlChange(byte channel, byte control, byte value)" function from the documents, but it seems whatever values I put in here, my different software and devices can't recognize them.
The "rd" value is being read from another microcontroller, and is either 1 or 2 depending on which button is pressed.
#include "MIDIUSB.h"
#include <Wire.h>
#define SLAVE_ADDR 9
int rd;
// The setup function runs once when you press reset or power the board
void setup() {
Wire.begin(SLAVE_ADDR);
Wire.onReceive(receiveEvent);
Serial.begin(9600);
while (!Serial) {
;
}
Serial.println("Starting");
}
// The loop function runs over and over again forever
void loop() {
}
void noteOn(byte pitch) {
MidiUSB.sendMIDI({0x09, 0x90, pitch, 127});
MidiUSB.flush();
}
void noteOff(byte pitch) {
MidiUSB.sendMIDI({0x08, 0x80, pitch, 0});
MidiUSB.flush();
}
void receiveEvent(){
rd = Wire.read();
Serial.println(rd);
startMIDI(rd);
}
void startMIDI(int rd){
byte value = rd + 20;
Serial.println(value);
controlChange(0x01,value, 0x7F);
delay(2000);
Serial.println("sound");
/*
noteOn(value);
delay(2000);
noteOff(value);
*/
}
void controlChange(byte channel, byte control, byte value) {
midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value};
MidiUSB.sendMIDI(event);
MidiUSB.flush();
}
Sorry, I removed that comment, it was there from something that used to be there.
The wire stuff is receiving input from another microcontroller. When it receives an event, the control change function gets called. I'm basically pushing one of two buttons, and depending on which one it is, it sends 1 or 2.
Seriously, most DAW's have a Midi filter, and with some (like Ableton) only 'key' is enabled by default, allowing only for noteOn and noteOff. Remore and Sync need to be enabled manually.
I have not found this to be the case when I have used Ableton. If I want to assign a control message to a parameter all I need to do is to send the control parameter while the parameter is selected.