color colours[]=new color[12]; boolean played[]=new boolean[12]; String noteName[]= { "c", "c#", "d", "d#", "e", "f", "f#", "g", "g#", "a", "a#", "b" }; //int intervals[]= { 5, 5, 5, 5, 4, 5 }; float frequency[]=new float[12]; float baseWidth=55; float fretWidth=baseWidth; float position=0; int fretHeight=20; boolean inverted=false; PImage neck; int offset[][]= { // To do: turn all these upside down, and invert the thing by default { 4, 11, 19, 26, 33, 40 // EADGBE - standard } , { 2, 11, 19, 26, 33, 38 // DADGBD - Double drop-D } , { 2, 9, 19, 26, 33, 38 // DADGAD } , { 2, 9, 18, 26, 33, 38 // Open D - DADF#AD } , { 2, 11, 7, 2, 7, 2 // Open G - DGDGBD } , { 28, 24, 19, 12, 7, 0 // Open C - CGCGCE } , { 21, 16, 12, 7 // Soprano ukulele - GCEA } , { 28, 21, 14, 7 // Mandolin / violin - DGAE } }; int tuning=0; final int ROOT=0, MAJOR=1, SUSTWO=2, MINOR=3, SUSFOUR=4, FIVE=5, SIX=6, SEVEN=7, MAJSEVEN=8, ADDNINE=9, MAJORSCALE=10, PENTATONICONE=11; int currentChordType=1; int noteNumber=0; int positions[][]= { { 0 // Root note only } , { 0, 4, 7 // Major } , { 0, 2, 7 // sus2 } , { 0, 3, 7 // minor } , { 0, 5, 7 // sus4 } , { 0, 7 // 5 ('power chord') } , { 0, 4, 7, 9 // 6 } , { 0, 4, 7, 10 // 7 } , { 0, 4, 7, 11 // maj7 } , { 0, 4, 7, 2 // Add9 } , { 0, 2, 4, 5, 7, 9, 11 // Major scale } , { 0, 2, 3, 5, 7, 8, 10 // Natural minor scale } , { 0, 2, 5, 7, 9 // Pentatonic } }; void setup() { size(500, 140); colorMode(HSB, 12); noLoop(); for (int i=0; i<12; i++) { colours[i]=color(i, 12, 12); } smooth(); showChord(); //neck=loadImage("guitarneck4.jpg"); ellipseMode(CORNER); textAlign(CENTER); } void draw() { background(12, 10, 3); int bottomOfFretboard=offset[tuning].length*fretHeight; noStroke(); fill(2, 11, 8); rect(0, 0, 600, bottomOfFretboard); fill(0); rect(0, bottomOfFretboard+20, width, height); for (int i=0; i0) { // Draw strings starting after the bridge ('fret 0'); strokeWeight((float)(i+2)/3); stroke(2, 9, 4); line(position-1, (i+0.5)*(float)fretHeight, position+fretWidth+2, (i+0.5)*(float)fretHeight); } if (played[(j+offset[tuning][k])%12]&&j>0) { // Draw ovals on played strings fill(12); stroke(0); strokeWeight(1.2); ellipse(position+fretWidth-24, (i*fretHeight)+1, fretHeight-1, fretHeight-3); fill(0); } else { fill (6); } if (j>0) text (noteName[(j+offset[tuning][k])%12], position+fretWidth-14, 14+(i*fretHeight)); fill(2, 10, 11); noStroke(); if (j==5|j==7) { ellipse(position+fretWidth/4, bottomOfFretboard+6, 8, 8); } else if (j==12) { ellipse(position+fretWidth/4, bottomOfFretboard+1, 7, 7); ellipse(position+fretWidth/4, bottomOfFretboard+10, 7, 7); } position+=fretWidth; fretWidth*=pow(0.5, (1/12.0)); } fill(0); text (noteName[(offset[tuning][i])%12], 8, 14+(i*fretHeight)); } } void keyPressed() { for (int i=0; i<12; i++) { if (key==noteName[i].charAt(0)&¬eName[i].length()==1||key==Character.toUpperCase(noteName[i].charAt(0))) { println(noteName[i]); noteNumber=i; } else if (key==Integer.toString(i).charAt(0)&&i<10) { currentChordType=i; println(currentChordType); } } if (key==' ') { tuning=(tuning+1)%offset.length; } if (key=='i') { inverted=!inverted; } showChord(noteNumber, currentChordType); } void setChordType(int chordType) { this.currentChordType=chordType; } void setRootNote(int rootNote) { this.noteNumber=rootNote; } void setTuning(int tuning) { this.tuning=tuning; } void setInversion(int handedness) { if (handedness==0) this.inverted=false; else this.inverted=true; } void showChord() { showChord(noteNumber, currentChordType); } void showChord(int noteNumber, int chordType) { for (int i=12; i<24; i++) { played[i-12]=false; for (int j=0; j