controlling synth with attached pot via midi

Status
Not open for further replies.

benwadub

Active member
hi, i d like to control a synth project with pot on the same board as the code but via midi, can someone tell me if it s doable and how to achieve it please?
do I need to creat to midi interface? how can I tell a pot to change value to a variable over midi please?
i have my synth code working and my controller too and I d like to run them on the same teensy please.
I hope my question is clear?
 
Sorry, not sure what you mean. When you write "tell a pot to change value" it sounds like you have a digital potentiometer or a motor-driven potentiometer.
Perhaps a photo or a step-by-step description of what you want to happen can help us understand.
 
Sorry I wrote something really unclear :)
I wanted to tell when I turn à potentiometer it send midi to my code.
 
If the potentiometer and the synth project are running on the same teensy you shouldn't need midi to communicate. Midi is built for communicating between different pieces of equipment. Perhaps if you post your code it becomes clearer what you want to achieve.
The ResponsiveAnalogRead library is good for reading potentiometers if the plain builtin AnalogRead gives unstable readings.
 
Here is a good writeup on how to build a project where a potentiometer change triggers MIDI CC messages. Scroll down to the "Potentiometers and Faders" heading.
The relevant code:
Code:
const uint8_t analogPin = A0;

const uint8_t channel = 1;        // MIDI channel 1
const uint8_t controller = 0x10;  // General Purpose Controller 1

void setup() {
  Serial.begin(31250);
}

void loop() {
  static uint8_t previousValue = 0b10000000;       // Declare a static variable to save the previous CC value
                                                   // and initialize it to 0b10000000 (the most significant bit is set, 
                                                   // so it is different from any possible 7-bit CC value).

  uint16_t analogValue = analogRead(analogPin);    // Read the value of the analog input
  uint8_t CC_value = analogValue >> 3;             // Convert from a 10-bit number to a 7-bit number by shifting
                                                   // it 3 bits to the right.
  
  if (CC_value != previousValue) {                 // If the current value is different from the previous value
    sendMIDI(CC, channel, controller, CC_value);     // Send the new value over MIDI
    previousValue = CC_value;                        // Remember the new value
  }
}
 
Thanks for your help! I thought that it could be fun that my pots send midi out at the same time, it could allow us to record movement in a daw,
I also wanted midi cause I m a real beginner at coding and I already achieved a midi contrôler so I thought I could use the same library for coding (tttapa control surface)
I ll have around twenty potentiometer wired on mux and really don t know how to achieve it without that very simple to use library, I ll post my code later I don t have it here,
again thanks to try helping me!
I ll also try to find how to code my mix without midi!
 
here is the code I try to make, there is the synth and the controller and I d like that my pots on the mux to control all the variable with the same midi cc that for the midi usb as they where in the code I modified
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <MIDI.h>
#include <Control_Surface.h>
/*
#define MUXcutoff 1
#define MUXreso 2
#define MUXrevol 3
#define MUXrsize 4
#define MUXatk 5
#define MUXdcy 6
#define MUXsus 7
#define MUXrls 8
#define MUXatkf 9
#define MUXdcyf 10
#define MUXsusf 11
#define MUXrlsf 12
#define MUXmd 13
#define MUXphs 14
#define MUXswc 15
#define MUXswc2 16
#define MUX2nse1 1
#define MUX2pnk1 2
#define MUX2amp2 3
#define MUX2shpwm 4
#define MUX2shpwm2 5
#define MUX2lfoamp 6
#define MUX2lfofreq 7

//MIDI CC control numbers

#define CCcutoff 1
#define CCreso 2
#define CCrevol 19
#define CCrsize 20
#define CCatk 13
#define CCdcy 14
#define CCsus 15
#define CCrls 16
#define CCatkf 9
#define CCdcyf 10
#define CCsusf 11
#define CCrlsf 12
#define CCmd 3
#define CCphs 4
#define CCswc 5
#define CCswc2 22
#define CCnse1 6
#define CCpnk1 7
#define CCamp2 8
#define CCshpwm 24
#define CCshpwm2 23
#define CClfoamp 17
#define CClfofreq 18
*/

USBMIDI_Interface midiusb;
HardwareSerialMIDI_Interface midiser = Serial1;
MIDI_PipeFactory<3> pipes;


// GUItool: begin automatically generated code
AudioSynthWaveformDc     dc1;            //xy=55,229.9999976158142
AudioSynthWaveformModulated waveformMod9;   //xy=228.57149451119562,475.7143028804235
AudioSynthWaveformModulated waveformMod3;   //xy=231.42856979370117,176.85713577270508
AudioSynthWaveformModulated waveformMod4;   //xy=231.42856979370117,211.85713577270508
AudioSynthWaveformModulated waveformMod5;   //xy=231.42858123779297,255.42856407165527
AudioSynthWaveformModulated waveformMod6;   //xy=231.42858123779297,290.4285640716553
AudioSynthWaveformModulated waveformMod7;   //xy=231.42858123779297,325.4285640716553
AudioSynthWaveformModulated waveformMod8;   //xy=231.42858123779297,362.4285640716553
AudioSynthWaveformModulated waveformMod2;   //xy=232.42856979370117,139.85713577270508
AudioSynthWaveformModulated waveformMod1;   //xy=233.42856979370117,102.85713577270508
AudioSynthNoiseWhite     noise1;         //xy=235.71430587768555,527.1428508758545
AudioSynthNoisePink      pink1;          //xy=244.28573608398438,571.4285678863525
AudioEffectEnvelope      envelope7;      //xy=410.4285697937012,325.8571357727051
AudioEffectEnvelope      envelope6;      //xy=414.4285697937012,289.8571357727051
AudioEffectEnvelope      envelope1;      //xy=415.4285697937012,102.85713577270508
AudioEffectEnvelope      envelope5;      //xy=415.4285697937012,254.85713577270508
AudioEffectEnvelope      envelope8;      //xy=415.4285697937012,362.8571357727051
AudioEffectEnvelope      envelope2;      //xy=416.4285697937012,139.85713577270508
AudioEffectEnvelope      envelope4;      //xy=416.4285697937012,216.85713577270508
AudioEffectEnvelope      envelope3;      //xy=417.4285697937012,178.85713577270508
AudioMixer4              mixer4;         //xy=438.5714530944824,517.1428680419922
AudioEffectEnvelope      envelope9;      //xy=601.4286117553711,477.1428565979004
AudioMixer4              mixer1;         //xy=619.4285697937012,171.85713577270508
AudioMixer4              mixer2;         //xy=625.4285697937012,282.8571357727051
AudioMixer4              mixer3;         //xy=806.7858390808105,194.64279556274414
AudioSynthWaveformDc     dc3;            //xy=900.0000152587891,121.25000190734863
AudioSynthWaveformDc     dc2;            //xy=959.107250213623,435.35712242126465
AudioSynthWaveformModulated waveformMod10;  //xy=1038.750015258789,163.75000095367432
AudioFilterStateVariable filter1;        //xy=1068.5714378356934,290.0000591278076
AudioEffectEnvelope      envelope10;     //xy=1099.4643096923828,432.8571529388428
AudioEffectMultiply      multiply1;      //xy=1225.0000190734863,126.25000071525574
AudioMixer4              mixer7;         //xy=1283.7500190734863,245.00000190734863
AudioEffectDelay         delay1;         //xy=1491.1905250549316,414.9405460357666
AudioEffectFreeverbStereo freeverbs1;     //xy=1511.190486907959,253.51194190979004
AudioMixer4              mixer5;         //xy=1671.1904525756836,140.65477180480957
AudioMixer4              mixer6;         //xy=1672.6188468933105,363.5119228363037
AudioOutputAnalogStereo  dacs1;          //xy=1821.4761123657227,290.65477991104126
AudioOutputUSB           usb1;
//AudioOutputI2S           i2s1;
AudioConnection          patchCord1(dc1, 0, waveformMod1, 1);
AudioConnection          patchCord2(dc1, 0, waveformMod2, 1);
AudioConnection          patchCord3(dc1, 0, waveformMod3, 1);
AudioConnection          patchCord4(dc1, 0, waveformMod4, 1);
AudioConnection          patchCord5(dc1, 0, waveformMod5, 1);
AudioConnection          patchCord6(dc1, 0, waveformMod6, 1);
AudioConnection          patchCord7(dc1, 0, waveformMod7, 1);
AudioConnection          patchCord8(dc1, 0, waveformMod8, 1);
AudioConnection          patchCord9(dc1, 0, waveformMod9, 1);
AudioConnection          patchCord10(waveformMod9, 0, mixer4, 0);
AudioConnection          patchCord11(waveformMod3, envelope3);
AudioConnection          patchCord12(waveformMod4, envelope4);
AudioConnection          patchCord13(waveformMod5, envelope5);
AudioConnection          patchCord14(waveformMod6, envelope6);
AudioConnection          patchCord15(waveformMod7, envelope7);
AudioConnection          patchCord16(waveformMod8, envelope8);
AudioConnection          patchCord17(waveformMod2, envelope2);
AudioConnection          patchCord18(waveformMod1, envelope1);
AudioConnection          patchCord19(noise1, 0, mixer4, 1);
AudioConnection          patchCord20(pink1, 0, mixer4, 2);
AudioConnection          patchCord21(envelope7, 0, mixer2, 2);
AudioConnection          patchCord22(envelope6, 0, mixer2, 1);
AudioConnection          patchCord23(envelope1, 0, mixer1, 0);
AudioConnection          patchCord24(envelope5, 0, mixer2, 0);
AudioConnection          patchCord25(envelope8, 0, mixer2, 3);
AudioConnection          patchCord26(envelope2, 0, mixer1, 1);
AudioConnection          patchCord27(envelope4, 0, mixer1, 3);
AudioConnection          patchCord28(envelope3, 0, mixer1, 2);
AudioConnection          patchCord29(mixer4, envelope9);
AudioConnection          patchCord30(envelope9, 0, mixer3, 2);
AudioConnection          patchCord31(mixer1, 0, mixer3, 0);
AudioConnection          patchCord32(mixer2, 0, mixer3, 1);
AudioConnection          patchCord33(mixer3, 0, filter1, 0);
AudioConnection          patchCord34(dc3, 0, waveformMod10, 1);
AudioConnection          patchCord35(dc2, envelope10);
AudioConnection          patchCord36(waveformMod10, 0, multiply1, 1);
AudioConnection          patchCord37(filter1, 0, multiply1, 0);
AudioConnection          patchCord38(filter1, 0, mixer7, 1);
AudioConnection          patchCord39(envelope10, 0, filter1, 1);
AudioConnection          patchCord40(multiply1, 0, mixer7, 0);
AudioConnection          patchCord41(mixer7, freeverbs1);
AudioConnection          patchCord42(mixer7, delay1);
AudioConnection          patchCord43(mixer7, 0, mixer5, 1);
AudioConnection          patchCord44(delay1, 0, mixer6, 1);
AudioConnection          patchCord45(freeverbs1, 0, mixer5, 0);
AudioConnection          patchCord46(freeverbs1, 1, mixer6, 0);
AudioConnection          patchCord47(mixer5, 0, dacs1, 0);
AudioConnection          patchCord48(mixer6, 0, dacs1, 1);
//AudioConnection          patchCord55(mixer5, 0, i2s1, 0);
//AudioConnection          patchCord56(mixer6, 0, i2s1, 1);
AudioConnection          patchCord57(mixer5, 0, usb1, 0);
AudioConnection          patchCord58(mixer6, 0, usb1, 1);
AudioControlSGTL5000  sgtl5000_1;
// GUItool: end automatically generated code



/**
 * End generated code block
 */

float hz2;

float cutoff = 1000;
float reso = 1.11;

float revol = 0;
float rsize = 0.1;

float atk = 10.5;
float dcy = 35;
float sus = 0.5;
float rls = 300;
float atkf = 10.5;
float dcyf = 35;
float susf = 0.5;
float rlsf = 300;
float md = 0.0;

float phs = 0;

int swc = 0;
int swc2 = 0;

int wavfrm;
int wavfrm2;

int srlswc = 0;

float nse1 = 0.0;
float pnk1 = 0.0;

float amp2 = 0.00;
float vely = 0.00;

float shpwm = 0.00;
float shpwm2 = 0.00;

float lfofreq = 0.00;
float lfoamp = 0.00;

int valueconvert;
extern const int16_t myWaveform[256];  // defined in myWaveform.ino

#define POLYPHONY 8  // Max # simultaneous notes
#define WAVEFORM WAVEFORM_SAWTOOTH

byte notesSounding[POLYPHONY] = {0};
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
void OnControlChange(byte channel, byte control, byte value){//LPD 8 CONTROL SURFACE// SERIAL BUTTON SWITCH
  if (control == 1) {        //CUTOFF    
    cutoff = (pow(value, 2.04))+20;  
  }
  if (control == 2) {        //RESO
    reso = (value / 29.53)+1.11;    
  }
  if (control == 19) {             //REVERB VOL
    revol = (value / 381.00);         
  }
  if (control == 20) {            //REVERB SIZE
    rsize = (value / 254.00);         
  } 
                        //ADSR                            
  if (control == 13) {           //A
    atk = pow(value, 1.70);          
  }
  if (control == 14) {           //D
    dcy = pow(value, 1.70);           
  }
  if (control == 15) {           //S
    sus = (value / 127.00);        
  }
  if (control == 16) {           //R
    rls = pow(value, 1.91);             
  }
                       //ADSR VCF
  if (control == 9) {            //A  
    atkf = pow(value, 1.70);             
  }
  if (control == 10) {           //D
    dcyf = pow(value, 1.70);        
  }
  if (control == 11) {           //S
    susf = (value / 127.00);        
  }
  if (control == 12) {           //R
    rlsf = pow(value, 1.91);        
  }                              
  if (control == 3) {            // MOD DEPTH
    md = (value / 127.00);          
  }  
  if (control == 4) {            //PHASE 
     phs = (value / 254.00);
  }
  if (control == 5) {             // SWITCH
    swc = value;}
  if (control == 22) {             // SWITCH LFO
    swc2 = value;}  
  if (control == 6) {             // NOISE 
    nse1 = (value/254.00);}
  if (control == 7) {             // PINK 
    pnk1 = (value/254.00);}    
  if (control == 8) {             //3 and 4 OSC VOL's
    amp2 = (value / 254.00);}   
  if (control == 24) {            //SHAPE WAVEFORM
    shpwm = (value / 127.000);}  
  if (control == 23) {            //LFO SHAPE WAVEFORM
    shpwm2 = (value / 127.000);} 
  if (control == 17) {            //LFO AMOUNT
    lfoamp = (value / 127.00);} 
  if (control == 18) {            //LFO FREQ
    lfofreq = pow(value, 2.04);}
       if (srlswc == HIGH){                                   //TASTO SWITCH SERIALE
  
  Serial.print("CC, ch=");
  Serial.print(channel);
  Serial.print(", ctrl= ");
  Serial.print(control);
  Serial.print(", value=");
  Serial.print(value);

  Serial.print("   A=");
  Serial.print(atk);
  Serial.print("   D=");
  Serial.print(dcy);
  Serial.print("   S=");
  Serial.print(sus);
  Serial.print("   R=");
  Serial.print(rls);
  
  Serial.print("   Af=");
  Serial.print(atkf);
  Serial.print("   Df=");
  Serial.print(dcyf);
  Serial.print("   Sf=");
  Serial.print(susf);
  Serial.print("   Rf=");
  Serial.print(rlsf);
  Serial.print("  SWC=");
  Serial.print(swc);
  Serial.print("  SWC2=");
  Serial.print(swc2);
  Serial.println();
       }
       if (srlswc == LOW){
      if(swc <= 14){
      Serial.print ("WAVEFORM = SINE ");
      Serial.println ();}
      if(swc > 14 && swc <= 28){
      Serial.print ("WAVEFORM = TRIANGLE ");
      Serial.println ();}
      if(swc > 28 && swc <= 42){
      Serial.print ("WAVEFORM = TRIANGLE VAR ");
      Serial.println ();}
      if(swc > 42 && swc <= 56){
      Serial.print ("WAVEFORM = SAWTOOTH ");
      Serial.println ();}
      if(swc > 56 && swc <= 70){
      Serial.print ("WAVEFORM = SAWTOOTH REV ");
      Serial.println ();}
      if(swc > 70 && swc <= 84){
      Serial.print ("WAVEFORM = SQUARE ");
      Serial.println ();}
      if(swc > 84 && swc <= 98){
      Serial.print ("WAVEFORM = PULSE ");
      Serial.println ();}
      if(swc > 98 && swc <= 113){
      Serial.print ("WAVEFORM = ARBITRARY ");
      Serial.println ();}
      if(swc > 113 && swc <= 127){
      Serial.print ("WAVEFORM = SAMPLE&HOLD ");
      Serial.println ();}
      
         if(swc2 <= 14){
      Serial.print ("LFO = SINE ");
      Serial.println ();}
      if(swc2 > 14 && swc2 <= 28){
      Serial.print ("LFO = TRIANGLE ");
      Serial.println ();}
      if(swc2 > 28 && swc2 <= 42){
      Serial.print ("LFO = TRIANGLE VAR ");
      Serial.println ();}
      if(swc2 > 42 && swc2 <= 56){
      Serial.print ("LFO = SAWTOOTH ");
      Serial.println ();}
      if(swc2 > 56 && swc2 <= 70){
      Serial.print ("LFO = SAWTOOTH REV ");
      Serial.println ();}
      if(swc2 > 70 && swc2 <= 84){
      Serial.print ("LFO = SQUARE ");
      Serial.println ();}
      if(swc2 > 84 && swc2 <= 98){
      Serial.print ("LFO = PULSE ");
      Serial.println ();}
      if(swc2 > 98 && swc2 <= 113){
      Serial.print ("LFO = ARBITRARY ");
      Serial.println ();}
      if(swc2 > 113 && swc2 <= 127){
      Serial.print ("LFO = SAMPLE&HOLD ");
      Serial.println ();}
      
           Serial.print("CUTOFF=");
           Serial.print(cutoff);
           Serial.print("   Q=");
           Serial.print(reso);
           Serial.print("  MOD DEPTH=");
           Serial.print(md);
           Serial.print("   REV VOL=");
           Serial.print(revol);
           Serial.print("   REV SIZE=");
           Serial.print(rsize);
           Serial.print("   NOISE=");
           Serial.print(nse1);
           Serial.print("   PINK=");
           Serial.print(pnk1);
           Serial.print("  Ø=");
           Serial.print(phs);
           Serial.print("  V's=");
           Serial.print(amp2);
           Serial.print("  pwm=");
           Serial.print(shpwm);
           Serial.print("  LFO pwm=");
           Serial.print(shpwm2);
           Serial.print("  LFO FREQ=");
           Serial.print(lfofreq);
           Serial.print("  LFO AMOUNT=");
           Serial.print(lfoamp);
           Serial.println();
    }
  }
AudioSynthWaveformModulated *waveforms[POLYPHONY] = {
  &waveformMod1,
  &waveformMod2,
  &waveformMod3,
  &waveformMod4,
  &waveformMod5,
  &waveformMod6,
  &waveformMod7,
  &waveformMod8
};
AudioEffectEnvelope *envelopes[POLYPHONY] = {
  &envelope1,
  &envelope2,
  &envelope3,
  &envelope4,
  &envelope5,
  &envelope6,
  &envelope7,
  &envelope8
};
byte currentNote = 0;
double noteToFrequency(byte note) {
  return 440.0 * pow(2, ((note - 69.0) / 12.0));
}
byte getFreeWaveform() {
  for (byte i = 0; i < POLYPHONY; i++) {
    if (notesSounding[i] == 0) {
      return i;
    }
  }
    
  return 0;
}

void onNoteOn(byte channel, byte note, byte velocity) {
  vely = velocity / 127.00;                                        // VELOCITY

  envelope9.noteOn();
  envelope10.noteOn();
  
  byte index = getFreeWaveform();
  
  
  AudioSynthWaveformModulated *waveform = waveforms[index];
  waveform->frequency(noteToFrequency(note));
  
  AudioEffectEnvelope *envelope = envelopes[index];
  envelope->noteOn();
    
  notesSounding[index] = note;

  hz2  = 440 * pow (2.0, ((note +  7) - 69.0) / 12.0); 

  if (srlswc == HIGH){
  Serial.print("ON,       ch=");
  Serial.print(channel);
  Serial.print(", note=");
  Serial.print(note);
  Serial.print(", velocity=");
  Serial.print(velocity);
  Serial.println();
  }
}
void onNoteOff(byte channel, byte note, byte velocity) {

  envelope9.noteOff();
  envelope10.noteOff();
  
  for (byte i = 0; i < POLYPHONY; i++) {
    if (notesSounding[i] == note) {
      AudioEffectEnvelope *envelope = envelopes[i];
      envelope->noteOff();
      notesSounding[i] = 0;
    }
  }
                                           //SERIAL
  if (srlswc == HIGH){
  Serial.print("OFF,     ch=");
  Serial.print(channel);
  Serial.print(", note=");
  Serial.print(note);
  Serial.print(", velocity=");
  Serial.print(velocity);
  Serial.println();
  
  CD74HC4067 mux1 = {
  A2
  ,       // Analog input pin
  {2, 3, 4, 5} // Address pins S0, S1, S2};
};


//Instantiate multiplexer for 16 switch
CCPotentiometer filtre [] = {
  {mux1.pin(0), {1, CHANNEL_1}},//cutofffreq
  {mux1.pin(1), {2, CHANNEL_1}},//reso
  {mux1.pin(2), {3, CHANNEL_1}},//mod depth
  {mux1.pin(3), {4, CHANNEL_1}},//phase
  {mux1.pin(4), {5, CHANNEL_1}},//wave select
  {mux1.pin(5), {22, CHANNEL_1}},//switch lfo
  {mux1.pin(6), {6, CHANNEL_1}},//noise vol
  {mux1.pin(7), {7, CHANNEL_1}},//pink noise vol
  {mux1.pin(8), {24, CHANNEL_1}},//shape waveform
  {mux1.pin(9), {17, CHANNEL_1}},//lfo amount
  {mux1.pin(10), {18, CHANNEL_1}},//lfo freq
  {mux1.pin(11), {21, CHANNEL_1}},//delayvol
  {mux1.pin(12), {23, CHANNEL_1}},//delay fb
  {mux1.pin(13), {22, CHANNEL_1}},//reverb damp
  {mux1.pin(14), {19, CHANNEL_1}},//reverb vol
  {mux1.pin(15), {20, CHANNEL_1}},//reverb size
};
Bank<2> bank1 = {-4}; // 2 banks, 8 addresse per banks

CD74HC4067 mux2 = {// deuxième multiplexeur cette fois si avec 16 entrées
  A0,              // analog pin
  {2, 3, 4, 5}, // Address pins S0, S1, S2, S3
  // 7, // Optionally, specify the enable pin
};
//Instantiate multiplexer for 16 switch
Bankable::CCPotentiometer fx [] = {
  {{bank1, BankType::CHANGE_ADDRESS},mux2.pin(0), {13, CHANNEL_1}},
  {{bank1, BankType::CHANGE_ADDRESS},mux2.pin(1), {14, CHANNEL_1}},
  {{bank1, BankType::CHANGE_ADDRESS},mux2.pin(2), {15, CHANNEL_1}},
  {{bank1, BankType::CHANGE_ADDRESS},mux2.pin(3), {16, CHANNEL_1}},
  {{bank1, BankType::CHANGE_ADDRESS},mux2.pin(4), {83, CHANNEL_1}},
  {{bank1, BankType::CHANGE_ADDRESS},mux2.pin(5), {83, CHANNEL_1}},
  {{bank1, BankType::CHANGE_ADDRESS},mux2.pin(6), {83, CHANNEL_1}},
  {{bank1, BankType::CHANGE_ADDRESS},mux2.pin(7), {83, CHANNEL_1}},
  {{bank1, BankType::CHANGE_ADDRESS},mux2.pin(8), {82, CHANNEL_1}},
  {{bank1, BankType::CHANGE_ADDRESS},mux2.pin(9), {82, CHANNEL_1}},
  {{bank1, BankType::CHANGE_ADDRESS},mux2.pin(10), {82, CHANNEL_1}},
  {{bank1, BankType::CHANGE_ADDRESS},mux2.pin(11), {82, CHANNEL_1}},
  {{bank1, BankType::CHANGE_ADDRESS},mux2.pin(12), {82, CHANNEL_1}},
  {{bank1, BankType::CHANGE_ADDRESS},mux2.pin(13), {82, CHANNEL_1}},
  {{bank1, BankType::CHANGE_ADDRESS},mux2.pin(14), {82, CHANNEL_1}},
  {{bank1, BankType::CHANGE_ADDRESS},mux2.pin(15), {82, CHANNEL_1}},
};
}
}
void setup() {                 //                     S  E  T  U  P
  Control_Surface.begin();
   midiusb >> pipes >> midiser; // all incoming midi from USB is sent to serial
  midiusb << pipes << midiser; // all incoming midi from Serial is sent to USB
  midiusb >> pipes >> midiusb; // all incoming midi from USB is looped back

  midiusb.begin();
  midiser.begin();

  Serial.begin(38400);
  AudioMemory(20);
MIDI.begin();
  mixer5.gain(1, 0.5);
  mixer6.gain(1, 0.5);

  waveformMod1.arbitraryWaveform(myWaveform, 172.0);
  waveformMod2.arbitraryWaveform(myWaveform, 172.0);
  waveformMod3.arbitraryWaveform(myWaveform, 172.0);
  waveformMod4.arbitraryWaveform(myWaveform, 172.0);
  waveformMod5.arbitraryWaveform(myWaveform, 172.0);
  waveformMod6.arbitraryWaveform(myWaveform, 172.0);
  waveformMod7.arbitraryWaveform(myWaveform, 172.0);
  waveformMod8.arbitraryWaveform(myWaveform, 172.0);
  waveformMod9.arbitraryWaveform(myWaveform, 172.0);
  
  for (byte i = 0; i < POLYPHONY; i++) {
    waveforms[i]->amplitude(0.5);
    waveforms[i]->begin(WAVEFORM);
    envelopes[i]->delay(0.0);
    envelopes[i]->hold(0.0);
  }

  envelope9.delay(0);
  envelope9.hold(0);
  envelope10.delay(0);
  envelope10.hold(0);
  
  usbMIDI.setHandleControlChange(OnControlChange);
  usbMIDI.setHandleNoteOn(onNoteOn);
  usbMIDI.setHandleNoteOff(onNoteOff);
MIDI.setHandleControlChange(OnControlChange);
MIDI.setHandleNoteOn(onNoteOn);
MIDI.setHandleNoteOff(onNoteOff);

  delay1.disable(1);
  delay1.disable(2);
  delay1.disable(3);
  delay1.disable(4);
  delay1.disable(5);
  delay1.disable(6);
  delay1.disable(7);

  freeverbs1.damping(1.0);
  filter1.octaveControl(24);
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.32);
}
void loop() {                        //                L   O   O   P
Control_Surface.loop();
   srlswc = digitalRead(24);
    midiusb.update();
  midiser.update();
  
   if(swc <= 14){                    // SINE
    wavfrm = WAVEFORM_SINE;}
    if(swc > 14 && swc <= 28){        //TRIANGLE
    wavfrm = WAVEFORM_TRIANGLE;}
    if(swc > 28 && swc <= 42){        //TRIANGLE VAR
    wavfrm = WAVEFORM_TRIANGLE_VARIABLE;}
    if(swc > 42 && swc <= 56){        //SAWTOOTH
    wavfrm = WAVEFORM_SAWTOOTH;}
    if(swc > 56 && swc <= 70){        //SAWTOOTH REV
    wavfrm = WAVEFORM_SAWTOOTH_REVERSE;}
    if(swc > 70 && swc <= 84){        //SQUARE
    wavfrm = WAVEFORM_SQUARE;}
    if(swc > 84 && swc <= 98){        //PULSE
    wavfrm = WAVEFORM_PULSE;}
    if(swc > 98 && swc <= 113){       //ARBITRARY
    wavfrm = WAVEFORM_ARBITRARY;}
    if(swc > 113 && swc <= 127){      //SAMPLE&HOLD
    wavfrm = WAVEFORM_SAMPLE_HOLD;}
                                                                 //LFO SHAPE
    if(swc2 <= 14){                    // SINE
    wavfrm2 = WAVEFORM_SINE;}
    if(swc2 > 14 && swc2 <= 28){        //TRIANGLE
    wavfrm2 = WAVEFORM_TRIANGLE;}
    if(swc2 > 28 && swc2 <= 42){        //TRIANGLE VAR
    wavfrm2 = WAVEFORM_TRIANGLE_VARIABLE;}
    if(swc2 > 42 && swc2 <= 56){        //SAWTOOTH
    wavfrm2 = WAVEFORM_SAWTOOTH;}
    if(swc2 > 56 && swc2 <= 70){        //SAWTOOTH REV
    wavfrm2 = WAVEFORM_SAWTOOTH_REVERSE;}
    if(swc2 > 70 && swc2 <= 84){        //SQUARE
    wavfrm2 = WAVEFORM_SQUARE;}
    if(swc2 > 84 && swc2 <= 98){        //PULSE
    wavfrm2 = WAVEFORM_PULSE;}
    if(swc2 > 98 && swc2 <= 113){       //ARBITRARY
    wavfrm2 = WAVEFORM_ARBITRARY;}
    if(swc2 > 113 && swc2 <= 127){      //SAMPLE&HOLD
    wavfrm2 = WAVEFORM_SAMPLE_HOLD;}

  waveformMod9.begin(0.3, 440, wavfrm);  //loader waveform
  waveformMod9.frequency(hz2);
  waveformMod9.amplitude(amp2);

  waveformMod10.begin(0.3, 440, wavfrm2);
  waveformMod10.frequency(lfofreq);
  waveformMod10.amplitude(lfoamp);
  
  envelope1.attack(atk);
  envelope1.decay(dcy);
  envelope1.sustain(sus);
  envelope1.release(rls);
  
  envelope2.attack(atk);
  envelope2.decay(dcy);
  envelope2.sustain(sus);
  envelope2.release(rls);

  envelope3.attack(atk);
  envelope3.decay(dcy);
  envelope3.sustain(sus);
  envelope3.release(rls);

  envelope4.attack(atk);
  envelope4.decay(dcy);
  envelope4.sustain(sus);
  envelope4.release(rls);

  envelope5.attack(atk);
  envelope5.decay(dcy);
  envelope5.sustain(sus);
  envelope5.release(rls);

  envelope6.attack(atk);
  envelope6.decay(dcy);
  envelope6.sustain(sus);
  envelope6.release(rls);  

  envelope7.attack(atk);
  envelope7.decay(dcy);
  envelope7.sustain(sus);
  envelope7.release(rls);  

  envelope8.attack(atk);
  envelope8.decay(dcy);
  envelope8.sustain(sus);
  envelope8.release(rls);

  envelope9.attack(atk);
  envelope9.decay(dcy);
  envelope9.sustain(sus);
  envelope9.release(rls);  

  envelope10.attack(atkf);
  envelope10.decay(dcyf);
  envelope10.sustain(susf);
  envelope10.release(rlsf);  

  filter1.frequency(cutoff);
  filter1.resonance(reso);
         

  delay1.delay(0,phs);      //stereoize
  
  dc1.amplitude(shpwm);     //pwm
  dc3.amplitude(shpwm2);    //Lfo waveform pwm
  dc2.amplitude(md);        //mod depth env 

  pink1.amplitude(pnk1);
  noise1.amplitude(nse1);
  freeverbs1.roomsize(rsize);
  mixer5.gain(0, revol);
  mixer6.gain(0, revol);

  
    
    for (byte i = 0; i < POLYPHONY; i++) {
     waveforms[i]->begin(wavfrm);
     waveforms[i]->amplitude(vely); 
    }
   
  usbMIDI.read();
}
 
So this is apparently a rather large project. Looks interesting!
I won't have the time to make myself understand all of your code and it is not clear where you want the midi triggered by the potentiometer to be sent. Could you please write a small sketch where you try to do only the part you are asking about?
Then if you explain exactly what you want to happen, I could have a better chance in helping you forward :)
 
hi, thanks for your interest, I have been very busy these days didn't have time to comeback here, it seems that it s too difficult for me to achieve what I wanted so I ll try to use analog read instead but it s very difficult for me!!
I look on internet to find good tutorials to do it!
 
Status
Not open for further replies.
Back
Top