electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Articles  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links  |  Store
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » Arduino
Arduino Midi Arpeggiator
Post new topic   Reply to topic
Page 1 of 1 [2 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
MusicMan11712



Joined: Aug 08, 2009
Posts: 720
Location: Upstate New York USA
Audio files: 148

PostPosted: Sat Oct 13, 2012 12:05 pm    Post subject: Arduino Midi Arpeggiator Reply with quote  Mark this post and the followings unread

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);
}




Arduino_Arp_Excerpt_1_07_18_2011.mp3
 Description:

Download
 Filename:  Arduino_Arp_Excerpt_1_07_18_2011.mp3
 Filesize:  6.56 MB
 Downloaded:  263 Time(s)

Back to top
View user's profile Send private message
elmegil



Joined: Mar 20, 2012
Posts: 1473
Location: Chicago
Audio files: 14

PostPosted: Sat Oct 13, 2012 1:38 pm    Post subject: Reply with quote  Mark this post and the followings unread

That sounds awesome!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic
Page 1 of 1 [2 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » Arduino
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum
e-m mkii

Please support our site. If you click through and buy from
our affiliate partners, we earn a small commission.


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use