MusicMan11712

Joined: Aug 08, 2009 Posts: 556 Location: Upstate New York USA
Audio files: 151
|
Posted: Sat Oct 13, 2012 12:05 pm Post subject:
Arduino Midi Arpeggiator |
 |
|
I finally dug out my test-of-concept Arduino Midi Arpeggiator sketch from July 2011. Its very simple--just generates some randomized midi data to send, but it might be of interest. I also have an audio excerpt of what the sketch did. I seem to recall I was sending the midi data to two sound modules. For the first 50 seconds of this excerpt, you can hear just the sketch. After that I started playing along.
Today I did 2 things to the code:
(1) I changed a couple of lines so that it works as an *.ino sketch with the newer ide.
(2) I added some lines to redirect the midi data (in hex) to the serial monitor.
Steve
| Code: | /*
MIDI arpeggiator test
by Dr. Steve
2011-07-18
This sketch is designed to play randomized notes from a hard-coded note array via midi.
A randomized CC command is also sent before each note using 3 hard-coded CCs.
This is just a simple proof-of-concept sketch for the further development arpeggiation
features of a midi controller.
2012-10-13:
MIDI_HEX_Display_Flag and display to serial monitor routines added for testing.
*/
// CONSTANTS
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int CCFilterCutoff = 74; // Use CC 74 for Filter Cutoff
const int CCFilterResonance = 71; // Use CC 71 for Filter Resonance
const int CCReleaseTime = 72; // Use CC 72 for Release Time
// VARIABLES: General
int sensorValue = 0; // value read from the pot
int MIDI_Hex_Display_Flag = 1; // flag added to redirect midi data to the serial monitor
// VARIABLES: Tempo
int tempoValue = 0;
int MaxTempo = 800;
int MinTempo = 60;
// VARIABLES: Note
int randNote = 36;
int randVelocity = 120;
int randNoteArrayOffset = 0;
int randOctaveMultiplier = 0;
int note = 36;
// VARIABLES: Continuous Controllers
int randCC = 0;
int randCCValue = 0;
int CC = 71;
// Arrays for randomization selection
int NoteArray [2][7] = { { 36, 39, 41, 43, 45, 46, 48 } , {38, 40, 41, 43, 45, 48, 50 } };
int CCArray [3] = {CCFilterCutoff, CCFilterResonance, CCReleaseTime};
// SETUP
void setup() {
// Set MIDI baud rate:
if (MIDI_Hex_Display_Flag)
Serial.begin(9600);
else
Serial.begin(31250);
randomSeed(analogRead(0));
}
// MAIN LOOP
void loop() {
// read tempo knob and set tempo value
sensorValue = analogRead(analogInPin);
sensorValue = map(sensorValue, 0, 1023, MinTempo, MaxTempo);
// Select randomized notes from NoteArray
randOctaveMultiplier = random(0,3);
randNoteArrayOffset = random(0,7);
note = ((NoteArray [0][randNoteArrayOffset]) + (randOctaveMultiplier * 12));
// Generate randomized CC values for a randomized CC from CCArray
randCC = random(0,3);
randCCValue = random(60, 100);
CC = CCArray[randCC];
// Either display data to serial monitor or send data out via midi
if (MIDI_Hex_Display_Flag)
{
Serial.print ("Randomized CC Data: ");
Serial.print (0xB0,HEX);
Serial.print (" ");
Serial.print (CC,HEX);
Serial.print (" ");
Serial.print (randCCValue,HEX);
Serial.print (" ");
}
else
{ sendCC(0xB0, CC, randCCValue); }
if (MIDI_Hex_Display_Flag)
{
Serial.print ("Randomized Note Data: ");
Serial.print (0x90,HEX);
Serial.print (" ");
Serial.print (note,HEX);
Serial.print (" ");
Serial.println (0x6F,HEX);
delay (sensorValue);
}
else
{
//Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
noteOn(0x90, note, 0x6F);
delay(sensorValue);
//Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
noteOn(0x90, note, 0x00);
delay(sensorValue);
}
}
// Send Midi Data Routines
// no range checking
void noteOn(int cmd, int pitch, int velocity) {
Serial.write(cmd);
Serial.write(pitch);
Serial.write(velocity);
}
void sendCC(int cmd, int CC, int CCAmount) {
Serial.write(cmd);
Serial.write(CC);
Serial.write(CCAmount);
}
|
| Description: |
|
 Download |
| Filename: |
Arduino_Arp_Excerpt_1_07_18_2011.mp3 |
| Filesize: |
6.56 MB |
| Downloaded: |
136 Time(s) |
|
|