CLICK THE WATCH ON YOUTUBE BUTTON IF YOU GET "VIDEO IS UNAVAILABLE"
Trying to hook you in with keyboard cat! So far this is what I have done, but I still have a long way to go. The code is still sloppy so their is still some improving. It still does not have to capability to hold down notes that are frets next to each other. I can hold down power chords or just singular notes, as I do in the video. I posted the current code in the comments section if anyone is interested.
Description: Guitar that is accompanied by a synthesizer while being played. Only one not at a time is to be played (for the time being); The guitar functions best as a monophonic guitar but it can play more than one note. This is due to it's current resistance reading setup. So it is a cross between polyphonic and monophonic;
Psuedo Code Approach:
-Read and store analog-in values from each of the strings (E, A, D, G, B, e); Determine which note is being played on each string; Convert notes-analog-value to hexadecimal MIDI value; Output MIDI
-The Array AF set is "variable" in the sense that it depends on the resistances you have chosen to solder to the frets. I have already calculated and measured what the analog reading will be. Since the same input resistance is used, analog readings for all strings are the same. These values are not the exact measured value, padding has been applied arbitrarily to make sure that the desired note, when pressed, is chosen correctly. To summarize, there has been a percentage error or tolerance that needs to be accounted for. [floor(tolerance(analog-in(fret1))), floor(tolerance(analog-in(fret2))), ... cont'd (12)]
MIDI Conversion Chart: Guitar, up to the 12th fret plays from E2 - E5 String (open) [Pitch - Frets 1 to 12] [MIDI - 0x prefix (HEX)]
/*Define globals ----Constants-------- See AF description above these are the measured values: { 786, 613, 578, 547, 508, 441, 375, 317}*/ const int AF[8] = { 750, 600, 565, 530, 490, 410, 320, 300} ; const int midiNotesHex[37] = {0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C}; //All the notes from F2-C4 const int analogPins[6] = {A0, A1, A2, A3, A4, A5}; const int playNote = 0x90; const int stopNote = 0x80; const int velocity = 0x50;
//----Variables------- int analogString[6] = {1023, 1023, 1023, 1023, 1023, 1023}; // [E, A, D, G, B, e] stores values 0 - 1023 bits int midiNotesOut[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; //Midi notes that will be played int prevNotesOut[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; //Notes from previous round int marker[6] = {0, 0, 0, 0, 0, 0}; int average[10];
void setup() { //Set the MIDI Baud rate Serial.begin( 31250); //This makes sure all sounds/tones are off for(int x = 0; x < 37; x++){ MIDIOutput( stopNote, midiNotesHex[x], velocity); } }
void loop(){
for( int x = 0; x < 4; x++){ int temp = 0; prevNotesOut[x] = midiNotesOut[x]; for( int ave = 0; ave < 30; ave++){ analogString[x] = analogRead(analogPins[x]); // temp = temp+analogString[x]; } analogString[x] = temp/30;
if(analogString[x] < 1000){ for( int y = 0; y < 8; y++){ //find the fret position (8 is AF length) if(analogString[x] > AF[y]){ midiNotesOut[x] = midiNotesHex[y+x*5]; //Pull the hex note from the table y = 8; // Break out of the loop marker[x] = 1; } }//inner for }else if(analogString[x] > 1000){ if ((marker[x] == 1)){ MIDIOutput( stopNote, midiNotesOut[x], 0x10); marker[x] = 0; } midiNotesOut[x] = 0x00;
/* Monohonic MIDI Guitar Project
ReplyDeleteDescription:
Guitar that is accompanied by a synthesizer while being played. Only
one not at a time is to be played (for the time being);
The guitar functions best as a monophonic guitar
but it can play more than one note. This is due to it's current resistance
reading setup. So it is a cross between polyphonic and monophonic;
Psuedo Code Approach:
-Read and store analog-in values from each of the strings
(E, A, D, G, B, e);
Determine which note is being played on each string;
Convert notes-analog-value to hexadecimal MIDI value;
Output MIDI
-The Array AF set is "variable" in the sense that it depends on the resistances you have
chosen to solder to the frets. I have already calculated and measured what the analog
reading will be. Since the same input resistance is used, analog readings for all
strings are the same. These values are not the exact measured value, padding has been applied arbitrarily to
make sure that the desired note, when pressed, is chosen correctly. To summarize, there
has been a percentage error or tolerance that needs to be accounted for.
[floor(tolerance(analog-in(fret1))), floor(tolerance(analog-in(fret2))), ... cont'd (12)]
MIDI Conversion Chart:
Guitar, up to the 12th fret plays from E2 - E5
String (open)
[Pitch - Frets 1 to 12]
[MIDI - 0x prefix (HEX)]
E(E2):
[F2, Gb2, G2, Ab2, A2, Bb2, B2, C3, Db3, D3, Eb3, E3]
[29, 2A, 2B, 2C, 2D, 2E, 2F, 30, 31, 32, 33, 34]
A(A2):
[Bb2, B2, C3, Db3, D3, Eb3, E3, F3, Gb3, G3, Ab3, A3]
[ 2E, 2F, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39]
D(D3):
[Eb3, E3, F3, Gb3, G3, Ab3, A3, Bb3, B3, C4, Db4, D4]
[ 33, 34, 35, 36, 37, 38, 39, 3A, 3B, 3C, 3D, 3E]
G(G3):
[Ab3, A3, Bb3, B3, C4, Db4, D4, Eb4, E4, F4 Gb4, G4 ]
[ 38, 39, 3A, 3B, 3C, 3D, 3E, 3F, 40, 41, 42, 43 ]
B(B3)
[C4, Db4, D4, Eb4, E4, F4 Gb4, G4, Ab4, A4, Bb4, B4 ]
[3C, 3D, 3E, 3F, 40, 41, 42, 43, 44, 45, 46, 47 ]
e(E4)
[F4, Gb4, G4, Ab4, A4, Bb4, B4, C5, Db5, D5, Eb5, E5]
[41, 42, 43, 44, 45, 46, 47, 48, 49, 4A, 4B, 4C]
*/
/*Define globals
ReplyDelete----Constants--------
See AF description above
these are the measured values:
{ 786, 613, 578, 547, 508, 441, 375, 317}*/
const int AF[8] = { 750, 600, 565, 530, 490, 410, 320, 300} ;
const int midiNotesHex[37] = {0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35,
0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43,
0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C}; //All the notes from F2-C4
const int analogPins[6] = {A0, A1, A2, A3, A4, A5};
const int playNote = 0x90;
const int stopNote = 0x80;
const int velocity = 0x50;
//----Variables-------
int analogString[6] = {1023, 1023, 1023, 1023, 1023, 1023}; // [E, A, D, G, B, e] stores values 0 - 1023 bits
int midiNotesOut[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; //Midi notes that will be played
int prevNotesOut[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; //Notes from previous round
int marker[6] = {0, 0, 0, 0, 0, 0};
int average[10];
void setup() {
//Set the MIDI Baud rate
Serial.begin( 31250);
//This makes sure all sounds/tones are off
for(int x = 0; x < 37; x++){
MIDIOutput( stopNote, midiNotesHex[x], velocity);
}
}
void loop(){
for( int x = 0; x < 4; x++){
int temp = 0;
prevNotesOut[x] = midiNotesOut[x];
for( int ave = 0; ave < 30; ave++){
analogString[x] = analogRead(analogPins[x]); //
temp = temp+analogString[x];
}
analogString[x] = temp/30;
if(analogString[x] < 1000){
for( int y = 0; y < 8; y++){ //find the fret position (8 is AF length)
if(analogString[x] > AF[y]){
midiNotesOut[x] = midiNotesHex[y+x*5]; //Pull the hex note from the table
y = 8; // Break out of the loop
marker[x] = 1;
}
}//inner for
}else if(analogString[x] > 1000){
if ((marker[x] == 1)){
MIDIOutput( stopNote, midiNotesOut[x], 0x10);
marker[x] = 0;
}
midiNotesOut[x] = 0x00;
}
if((prevNotesOut[x] != midiNotesOut[x]) && (midiNotesOut[x] != 0x00)){
if(prevNotesOut[x] != 0x00){
MIDIOutput( stopNote, prevNotesOut[x], 0x0);
}
MIDIOutput( playNote, midiNotesOut[x], velocity);
}
}//outter for
}//loop
void MIDIOutput( int command, int note, int velocity){
Serial.print(command, BYTE); //MIDI Command - Play (0x90)/Stop (0x80)
Serial.print(note, BYTE); //MIDI DATA1 - Note
Serial.print(velocity, BYTE); //MIDI DATA2 - Velocity
}