Fixed Midi din

This commit is contained in:
Oleksiy 2021-02-27 02:57:20 +02:00
parent 290d7772dc
commit e2cc163eca
2 changed files with 10 additions and 13 deletions

View File

@ -58,14 +58,14 @@ Smooth <long> aSmoothIntensity(smoothness);
int carrier_freq = 440;
void noteOn(byte channel, byte note, byte velocity) {
if (channel == MIDI_CHANNEL + 143) { //I have no ide why it's 143 here and 127 on noteoff
if (channel == MIDI_CHANNEL) {
carrier_freq = mtof((int) note);
gate = 1;
}
}
void noteOff(byte channel, byte note, byte velocity) {
if (channel == MIDI_CHANNEL + 127) {
if (channel == MIDI_CHANNEL) {
gate = 0;
}
}
@ -78,18 +78,17 @@ void setup(){
MIDI.setHandleNoteOn(noteOn);
MIDI.setHandleNoteOff(noteOff);
MIDI.begin();
MIDI.begin(MIDI_CHANNEL);
}
void updateControl(){
midiEventPacket_t rx;
do {
rx = MidiUSB.read();
if (rx.header == 0x09) {
noteOn(rx.byte1, rx.byte2, rx.byte3);
noteOn(rx.byte1 - 143, rx.byte2, rx.byte3); //need to figure out what's with this 143 and 127 on noteoff
} else if (rx.header == 0x08) {
noteOff(rx.byte1, rx.byte2, rx.byte3);
noteOff(rx.byte1 - 127, rx.byte2, rx.byte3);
}
} while (rx.header != 0);
@ -107,22 +106,22 @@ void updateControl(){
aModulator.setFreq(mod_freq);
// read the light dependent resistor on the width Analog input pin
int LDR1_value= mozziAnalogRead(CONTROLL1); // value is 0-1023
int Knob1value= mozziAnalogRead(CONTROLL1); // value is 0-1023
int LDR1_calibrated = kMapIntensity(LDR1_value);
int Knob1calibrated = kMapIntensity(Knob1value);
// calculate the fm_intensity
fm_intensity = ((long)LDR1_calibrated * knob2Val * (kIntensityMod.next()+128))>>8; // shift back to range after 8 bit multiply
fm_intensity = ((long)Knob1calibrated * knob2Val * (kIntensityMod.next()+128))>>8; // shift back to range after 8 bit multiply
// read the light dependent resistor on the speed Analog input pin
int LDR2_value= mozziAnalogRead(CONTROLL2); // value is 0-1023
int Knob2value= mozziAnalogRead(CONTROLL2); // value is 0-1023
// use a float here for low frequencies
float mod_speed = (float)kMapModSpeed(LDR2_value)/1000;
float mod_speed = (float)kMapModSpeed(Knob2value)/1000;
kIntensityMod.setFreq(mod_speed);

View File

@ -3,7 +3,5 @@
DIY Arduino-based synth built with [Mozzi library](https://sensorium.github.io/Mozzi/)
## ToDo:
- Fix Midi-Din
- Add note buffer
- Tidy up the code (e.g. remove LDR references)
- Tune the values and remap the knobs