Go Down

Topic: Volca sample (Read 397 times) previous topic - next topic

AndreLynch

Jul 26, 2019, 05:50 am Last Edit: Jul 26, 2019, 06:00 am by AndreLynch Reason: poor structure
I know nothing ,but i got this program (see below)it works great ,but i only want part of the functionality .  i use a midi sequencer so  i only want it to
receive Midi on channel 16 and ignore the other ones .
the only function I need is the Midi output redirect
the part that plays notes 0 to 9 on channels 1 to 10

sorry for being dumb , I'm only a musician
--------------------------------------------------------------------------------------------------------------
/* vim: set filetype=c++:
/* vim: set filetype=c++:
*******************************************************************************
* Volca Sample Synth
* Note to pitch enabled for Korg Volca Sample
* Copyright 2015 Mauricio Maisterrena
*
* Requires:
* Arduino MIDI library
* http://playground.arduino.cc/Main/MIDILibrary
*
*
* Note:
*  If you want use with Leonardo, you must choose Arduino MIDI library v4.0 or higher.
*******************************************************************************
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>
*******************************************************************************
*/


//////////////////////////
// MIDI Pin assign
// 2 : GND
// 4 : +5V(Vcc) with 220ohm
// 5 : TX
//////////////////////////

#include <MIDI.h>

//If you'r using a Mac and are getting a compilation error delete the next 3 lines of code
#ifdef MIDI_CREATE_DEFAULT_INSTANCE
MIDI_CREATE_DEFAULT_INSTANCE();
#endif

// -----------------------------------------------------------------------------



//Note: Midi CC value 64 = Speed value 0
const int vSpeedValue[] = { //Pitches (speed) for each note
0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  19,  20,  21,  22,  23,  24,  25,  
26, 27, 28, 29, 30, 32, 34, 37, 40, 43, 45, 48, 51, 53, 56, 59, 61, 64, 67, 69, 72, 75, 78, 80, 83, 85, 88, 91, 93, 96, 97, 99, 100, 102, 103, 104, 106, 107, 108, 109, 111, 112
};




int vVolcaMode = 1;

//Default Channel to send MIDI to Volca (Midi msg will be redirected to the corresponding channel on the Volca Sample)
int vPolyChan=16;

int vFirstVoice = 7;
int vVoiceChan = vFirstVoice;

int vNote;

// Range of notes that the Volca Sample can generate
int vPitchFirstNote = 36;
int vPitchLastNote = 84;


// Synth code, will assign the speed(pitch) depending on the note that was played
void fVoiceSend(int vVoiceChan, int vSpeed)
 {
   //MIDI.send(midi::NoteOff,60,0,vVoiceChan); //Thw Midi "Note Off" msg is not recognized by the volca Sample
   MIDI.sendControlChange(43,vSpeed,vVoiceChan);
   MIDI.send(MIDI.getType(),60,MIDI.getData2(),vVoiceChan);
 }
// -----------------------------------------------------------------------------


//This code will make it possibble to play each sample using a single midi channel (channel 16 by default) on mini notes 0 to 9 (the lowest notes)
void fChannelRedir(int vChan)
{
     MIDI.send(MIDI.getType(),
     MIDI.getData1(),
     MIDI.getData2(),
     vChan);
}


// -----------------------------------------------------------------------------

// This function will be automatically called when a NoteOn is received.
void handleNoteOn(byte channel, byte pitch, byte velocity)
{

   digitalWrite(13,HIGH); //Turns on led on pin 13 when note on is recived on channnel 16
   
   
   if (MIDI.getChannel() != vPolyChan)
   {
     vVoiceChan =  MIDI.getChannel();
   }
   
   vNote = MIDI.getData1();
   
   if( vNote < 10 & MIDI.getChannel() == vPolyChan)
   {
      fChannelRedir(vNote+1);
   };
 
 
  //Polyphonic 4 voices Synth
   if (vNote>= vPitchFirstNote & vNote <=vPitchLastNote) //Just notes on pitched range
   {
     fVoiceSend(vVoiceChan,vSpeedValue[vNote]);
     if (vVoiceChan <  vFirstVoice + 3 & MIDI.getChannel() == vPolyChan)
       {
           vVoiceChan++; //Go to the next voice
       }
       else
       {
           vVoiceChan = vFirstVoice; //Return to first voice channel
       }
   };
   
}
   
void setup()
{
   pinMode(13, OUTPUT);
   MIDI.turnThruOff();
   
   // Connect the handleNoteOn function to the library,
   // so it is called upon reception of a NoteOn.
   MIDI.setHandleNoteOn(handleNoteOn);  // Put only the name of the function

   // Initiate MIDI communications, listen to all channels
   MIDI.begin(MIDI_CHANNEL_OMNI);

   //Set the pitch envelopes to 0 (Midi cc value of 64)
   int counter = 1;
   while (counter <= 10)
   {
     MIDI.sendControlChange(43,64,vVoiceChan);
     MIDI.sendControlChange(44,64,vVoiceChan);
     counter++;
   }

   vVoiceChan = vFirstVoice;
}

void loop()
{
   // Call MIDI.read the fastest you can for real-time performance.
   MIDI.read();
}




Go Up