changeset 50:f4c6999ecfe9 tip

added the files on my computer that aren't aiff s> these shoudl be everything for the big bang fair 2011 - heresy, and tim's file's also here
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Sat, 08 Oct 2011 22:12:49 +0100
parents 0eeda0223db3
children
files Ableton Project/AbletonExCel_v2.als Ableton Project/AbletonExCel_v3.als Ableton Project/AbletonExCel_v4.als Ableton Project/AbletonExCel_v5.als Ableton Project/AbletonExCel_v6.als HeresyBigBangDone/application.macosx/HeresyBigBangDone.app/Contents/Info.plist HeresyBigBangDone/application.macosx/HeresyBigBangDone.app/Contents/MacOS/JavaApplicationStub HeresyBigBangDone/application.macosx/HeresyBigBangDone.app/Contents/MacOS/JavaApplicationStub64 HeresyBigBangDone/application.macosx/HeresyBigBangDone.app/Contents/PkgInfo HeresyBigBangDone/application.macosx/HeresyBigBangDone.app/Contents/Resources/Java/HeresyBigBangDone.jar HeresyBigBangDone/application.macosx/HeresyBigBangDone.app/Contents/Resources/Java/core.jar HeresyBigBangDone/application.macosx/HeresyBigBangDone.app/Contents/Resources/Java/gluegen-rt.jar HeresyBigBangDone/application.macosx/HeresyBigBangDone.app/Contents/Resources/Java/jogl.jar HeresyBigBangDone/application.macosx/HeresyBigBangDone.app/Contents/Resources/Java/libgluegen-rt.jnilib HeresyBigBangDone/application.macosx/HeresyBigBangDone.app/Contents/Resources/Java/libjogl.jnilib HeresyBigBangDone/application.macosx/HeresyBigBangDone.app/Contents/Resources/Java/libjogl_awt.jnilib HeresyBigBangDone/application.macosx/HeresyBigBangDone.app/Contents/Resources/Java/libjogl_cg.jnilib HeresyBigBangDone/application.macosx/HeresyBigBangDone.app/Contents/Resources/Java/opengl.jar HeresyBigBangDone/application.macosx/HeresyBigBangDone.app/Contents/Resources/Java/oscP5.jar HeresyBigBangDone/application.macosx/HeresyBigBangDone.app/Contents/Resources/sketch.icns HeresyBigBangDone/application.macosx/NoteEvent.java HeresyBigBangDone/application.macosx/Track.java HeresyBigBangDone/application.macosx/source/DrawingStuff.pde HeresyBigBangDone/application.macosx/source/Header.pde HeresyBigBangDone/application.macosx/source/HeresyAl.pde HeresyBigBangDone/application.macosx/source/HeresyBigBangDone.java HeresyBigBangDone/application.macosx/source/HeresyBigBangDone.pde HeresyBigBangDone/application.macosx/source/HeresyVoicingTables.pde HeresyBigBangDone/application.macosx/source/IO.pde HeresyBigBangDone/application.macosx/source/NoteEvent.java HeresyBigBangDone/application.macosx/source/Track.java HeresyBigBangDone/application.macosx/source/VirtualPlayingArray.pde HeresyBigBangDone/application.macosx/source/chord_changer.pde HeresyBigBangDone/application.macosx/source/sequences.pde mophoControl.maxpat of/testApp.cpp.orig of/testApp.h.orig tim_grid_mapper/OSC.pyc tim_grid_mapper/grid_mapper.app/Contents/Info.plist tim_grid_mapper/grid_mapper.app/Contents/MacOS/Python tim_grid_mapper/grid_mapper.app/Contents/MacOS/grid_mapper tim_grid_mapper/grid_mapper.app/Contents/PkgInfo tim_grid_mapper/grid_mapper.app/Contents/Resources/PythonApplet.icns tim_grid_mapper/grid_mapper.app/Contents/Resources/__argvemulator_grid_mapper.py tim_grid_mapper/grid_mapper.app/Contents/Resources/grid_mapper.py tim_grid_mapper/grid_mapper.pyc
diffstat 46 files changed, 5853 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
Binary file Ableton Project/AbletonExCel_v2.als has changed
Binary file Ableton Project/AbletonExCel_v3.als has changed
Binary file Ableton Project/AbletonExCel_v4.als has changed
Binary file Ableton Project/AbletonExCel_v5.als has changed
Binary file Ableton Project/AbletonExCel_v6.als has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HeresyBigBangDone/application.macosx/HeresyBigBangDone.app/Contents/Info.plist	Sat Oct 08 22:12:49 2011 +0100
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
+<plist version="0.9">
+  <dict>
+    <key>CFBundleName</key>
+    <string>HeresyBigBangDone</string>
+    <key>CFBundleVersion</key>
+    <string>1.0</string>
+    <key>CFBundleAllowMixedLocalizations</key>
+    <string>true</string>
+    <key>CFBundleExecutable</key>
+    <string>JavaApplicationStub</string>
+    <key>CFBundleDevelopmentRegion</key>
+    <string>English</string>
+    <key>CFBundlePackageType</key>
+    <string>APPL</string>
+    <key>CFBundleSignature</key>
+    <string>????</string>
+    <key>CFBundleInfoDictionaryVersion</key>
+    <string>6.0</string>
+    <key>CFBundleIconFile</key>
+    <string>sketch.icns</string>
+    <key>CFBundleIdentifier</key> 
+    <string>HeresyBigBangDone</string>
+
+    <!-- http://developer.apple.com/documentation/MacOSX/Conceptual/BPRuntimeConfig/Articles/PListKeys.html#//apple_ref/doc/uid/20001431-113616 -->
+    <key>LSUIPresentationMode</key>
+    <integer>0</integer>
+
+    <!-- make sure that applications open in 32-bit mode on Snow Leopard,
+	 otherwise video and most other native libraries will choke 
+	 http://developer.apple.com/mac/library/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html#//apple_ref/doc/uid/TP40009250-SW1 -->
+    <key>LSArchitecturePriority</key>
+    <array>
+      <string>i386</string>
+      <string>ppc</string>
+    </array> 
+
+    <key>Java</key>
+    <dict>
+      <key>VMOptions</key>
+      <string></string>
+      <key>MainClass</key>
+      <string>HeresyBigBangDone</string>
+      <key>JVMVersion</key>
+      <string>1.5*</string>
+      <key>JVMArchs</key>
+      <array>
+	<string>i386</string>
+	<string>ppc</string>
+      </array>
+      <key>ClassPath</key>
+      <string>$JAVAROOT/oscP5.jar:$JAVAROOT/HeresyBigBangDone.jar:$JAVAROOT/core.jar:$JAVAROOT/oscP5.jar:$JAVAROOT/oscP5.jar:$JAVAROOT/opengl.jar:$JAVAROOT/jogl.jar:$JAVAROOT/gluegen-rt.jar</string>
+
+      <!-- http://developer.apple.com/releasenotes/Java/java141/system_properties/chapter_4_section_1.html#//apple_ref/doc/uid/TP30000285 -->
+      <key>Properties</key>
+      <dict>
+	<key>apple.laf.useScreenMenuBar</key>
+	<string>true</string>
+	<key>apple.awt.showGrowBox</key>
+	<string>false</string>
+	<key>com.apple.smallTabs</key>
+	<string>true</string>
+	<key>apple.awt.Antialiasing</key>
+	<string>false</string>
+	<key>apple.awt.TextAntialiasing</key>
+	<string>true</string>
+	<key>com.apple.hwaccel</key>
+	<string>true</string>
+	<key>apple.awt.use-file-dialog-packages</key>
+	<string>false</string>
+      </dict>
+    </dict>
+  </dict>
+</plist>
Binary file HeresyBigBangDone/application.macosx/HeresyBigBangDone.app/Contents/MacOS/JavaApplicationStub has changed
Binary file HeresyBigBangDone/application.macosx/HeresyBigBangDone.app/Contents/MacOS/JavaApplicationStub64 has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HeresyBigBangDone/application.macosx/HeresyBigBangDone.app/Contents/PkgInfo	Sat Oct 08 22:12:49 2011 +0100
@@ -0,0 +1,1 @@
+APPL????
\ No newline at end of file
Binary file HeresyBigBangDone/application.macosx/HeresyBigBangDone.app/Contents/Resources/Java/HeresyBigBangDone.jar has changed
Binary file HeresyBigBangDone/application.macosx/HeresyBigBangDone.app/Contents/Resources/Java/core.jar has changed
Binary file HeresyBigBangDone/application.macosx/HeresyBigBangDone.app/Contents/Resources/Java/gluegen-rt.jar has changed
Binary file HeresyBigBangDone/application.macosx/HeresyBigBangDone.app/Contents/Resources/Java/jogl.jar has changed
Binary file HeresyBigBangDone/application.macosx/HeresyBigBangDone.app/Contents/Resources/Java/libgluegen-rt.jnilib has changed
Binary file HeresyBigBangDone/application.macosx/HeresyBigBangDone.app/Contents/Resources/Java/libjogl.jnilib has changed
Binary file HeresyBigBangDone/application.macosx/HeresyBigBangDone.app/Contents/Resources/Java/libjogl_awt.jnilib has changed
Binary file HeresyBigBangDone/application.macosx/HeresyBigBangDone.app/Contents/Resources/Java/libjogl_cg.jnilib has changed
Binary file HeresyBigBangDone/application.macosx/HeresyBigBangDone.app/Contents/Resources/Java/opengl.jar has changed
Binary file HeresyBigBangDone/application.macosx/HeresyBigBangDone.app/Contents/Resources/Java/oscP5.jar has changed
Binary file HeresyBigBangDone/application.macosx/HeresyBigBangDone.app/Contents/Resources/sketch.icns has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HeresyBigBangDone/application.macosx/NoteEvent.java	Sat Oct 08 22:12:49 2011 +0100
@@ -0,0 +1,61 @@
+ class MidiEvent { // the basic super class for all midi events
+  
+    int firstDataByte;
+    int secondDataByte;
+    int channel;
+
+}
+
+//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+
+ class NoteEvent extends MidiEvent{ //  the note event class
+  
+    int notePitch = 60;
+    int[] notePosition = new int[4];
+    int[] noteLength = new int[4];
+    int noteVelocity;  
+    boolean noteIgnore;
+    boolean noteOn;
+    
+    
+    public NoteEvent(int notePitch, int channel, int bar, int beat, int fraction, int pulse, boolean noteOff) {
+        this.notePitch = notePitch;
+        this.channel = channel;
+        this.noteVelocity = 80;     
+        if (noteOff)
+        this.noteVelocity = 0;
+        boolean noteIgnore = false;
+        this.noteOn = true;
+    }
+  
+    public NoteEvent(int notePitch, int channel, int bar, int beat, int fraction, int pulse) {
+        this(notePitch, channel, bar, beat, fraction, pulse, false);
+    }
+    
+    public NoteEvent(int notePitch, int channel, int veloc, int bar, int beat, int fraction, int pulse) {
+        this.notePitch = notePitch;
+        this.channel = channel;
+        this.noteVelocity = veloc;     
+        boolean noteIgnore = false;
+        this.noteOn = true;
+    }
+
+    
+    public NoteEvent(int notePitch, int channel, int bar, int beat, int fraction, int pulse, int lengthBar, int lengthBeat, int lengthFraction, int lengthPulse) {
+        this.notePitch = notePitch;
+        this.channel = channel;
+        this.noteVelocity = 80;     
+        boolean noteIgnore = false;
+        this.noteOn = true;
+        notePosition[0] = bar;
+        notePosition[1] = beat;
+        notePosition[2] = fraction;
+        notePosition[3] = pulse;
+        noteLength[0] = lengthBar;
+        noteLength[1] = lengthBeat;
+        noteLength[2] = lengthFraction;
+        noteLength[3] = lengthPulse;
+    }
+        
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HeresyBigBangDone/application.macosx/Track.java	Sat Oct 08 22:12:49 2011 +0100
@@ -0,0 +1,41 @@
+class Track{ // the track class
+  
+    boolean polyphonic;
+    int loopLength;
+    int trackNumber;
+    static int currentNumberOfTracks;
+    boolean selected;
+    NoteEvent[][] sequence;
+    int quantize;
+    boolean forceLegato;
+    String name;
+    boolean ducking;
+    boolean cycled;
+    int cycledPosition;
+    boolean mute;
+    boolean muteDone;
+    int muteIn;
+
+
+    
+    public Track(String name, boolean polyphonic, int loopLength, int quantize, boolean forceLegato, boolean increment){
+      
+        if (polyphonic)
+            this.polyphonic = true;
+        else
+            this.polyphonic = false;
+        this.name = name;
+        this.ducking = false;
+        this.cycled = true;
+        this.forceLegato = forceLegato;
+        this.quantize = quantize;
+        this.loopLength = loopLength;
+        if (increment) this.trackNumber = currentNumberOfTracks++;
+        this.selected = false;
+        this.mute = false;
+        this.muteIn = 0;
+        sequence = new NoteEvent[16][loopLength];
+     
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HeresyBigBangDone/application.macosx/source/DrawingStuff.pde	Sat Oct 08 22:12:49 2011 +0100
@@ -0,0 +1,221 @@
+//-------------------------------------------------------------------------------------------------------------------------------
+
+void drawNotes(){ // places the note display grid into the apropriate screen positions
+        int loopsOnScreen = ((width-playArea) / tracks[trSelected].loopLength) + 1;
+        if (loopsOnScreen > currentPulse / tracks[trSelected].loopLength)
+            loopsOnScreen = currentPulse / tracks[trSelected].loopLength;
+        for (int i = 0; i <= loopsOnScreen; i++)
+          image (imgNotes, (width-playArea-(i*tracks[trSelected].loopLength))-currentPulse%(tracks[trSelected].loopLength),0); 
+    }
+
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+public void pulseFrame(int frameNo){ // Draws a pulsing line at left hand side of the input area when loop restarts
+    strokeWeight(3);
+    if (currentPulse % (tracks[trSelected].loopLength) == 0 || (currentPulse-1) % (tracks[trSelected].loopLength) == 0 || (currentPulse-2) % (tracks[trSelected].loopLength) == 0)
+        stroke(255,255,255);
+    else
+        stroke(255,111,111);
+    line (width-playArea+3, 1, width-playArea+3, 300);  
+} 
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+      
+void drawTempImageGrid(){ // draws the note display image grid
+    imgNotes.stroke(209,137,255);
+    imgNotes.strokeWeight(15); 
+    for(int i = 0; i < 16; i++){
+       if ((tracks[trSelected].sequence[i][currentPulse%(tracks[trSelected].loopLength)] != null && tracks[trSelected].sequence[i][currentPulse%(tracks[trSelected].loopLength)].noteVelocity > 0) || displayNoteOnArray[i]){
+            imgNotes.beginDraw();
+            imgNotes.line (currentPulse%(tracks[trSelected].loopLength), i*imageHeight/16+imageHeight/32, currentPulse%(tracks[trSelected].loopLength)+1, i*imageHeight/16+imageHeight/32);
+            imgNotes.endDraw(); 
+            displayNoteOnArray[i] = true;
+        }
+        if (tracks[trSelected].sequence[i][currentPulse%(tracks[trSelected].loopLength)] != null && tracks[trSelected].sequence[i][currentPulse%(tracks[trSelected].loopLength)].noteVelocity == 0){
+            displayNoteOnArray[i] = false;
+        }
+    
+        if(trSelected ==0){
+            if ((chordsTemp.sequence[i][currentPulse%(chordsTemp.loopLength)] != null && chordsTemp.sequence[i][currentPulse%(chordsTemp.loopLength)].noteVelocity > 0) || displayNoteOnArray[i]){
+                imgNotes.beginDraw();
+                imgNotes.line (currentPulse%(chordsTemp.loopLength), i*imageHeight/16+imageHeight/32, currentPulse%(chordsTemp.loopLength)+1, i*imageHeight/16+imageHeight/32);
+                imgNotes.endDraw(); 
+                displayNoteOnArray[i] = true;
+            }
+            if (chordsTemp.sequence[i][currentPulse%(chordsTemp.loopLength)] != null && chordsTemp.sequence[i][currentPulse%(chordsTemp.loopLength)].noteVelocity == 0){
+                displayNoteOnArray[i] = false;
+            }
+        }
+    }
+}
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+public void drawLines(){ // draws beat lines
+     int linePosition = 1;
+     int i = 0;
+     for (; linePosition <= imageWidth;){
+         linePosition = i * grid;
+         img.beginDraw();
+         img.stroke(lineColour);
+         img.strokeWeight(2);
+         img.line (linePosition, 0, linePosition, imageHeight);
+         img.endDraw();
+         i++;
+     }
+}
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+public void drawBarLines(){ // draws bar lines
+     int linePosition = 1;    
+     for (int i = 0; linePosition <= imageWidth;){
+         linePosition = i * grid * beatsPerBar;
+         img.beginDraw();
+         img.stroke(barLineColour);
+         img.strokeWeight(2);
+         img.line (linePosition, 0, linePosition, imageHeight);
+         img.endDraw();
+         i++;
+     }
+}
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+public void backgroundColour(){ // sets background colour
+     img.beginDraw();
+     img.background (backGround);
+     img.endDraw();
+}
+
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+public void createNoteFan(){ // creates the input fan
+    if (rpulseup)
+        rpulse++;
+    else rpulse--;
+    if (rpulse == grid)
+        rpulseup = false;
+    if (rpulse < 1)
+        rpulseup = true;
+    imgNoteFan.beginDraw();
+    imgNoteFan.stroke(rpulse/grid*255,50,50);
+    imgNoteFan.strokeWeight(1);
+    for (int i = 0; i < 16; i++){
+        if (!chordSelecter)
+            if ((tracks[trSelected].sequence[i][currentPulse%(tracks[trSelected].loopLength)] != null && tracks[trSelected].sequence[i][currentPulse%(tracks[trSelected].loopLength)].noteVelocity > 0) || displayNoteOnArray[i]){
+                imgNoteFan.fill(209,137,255);
+            }
+            else
+                imgNoteFan.fill(0,0,0);
+         else
+            if (i == 14 || i == 12 || i == 9 || i == 7 || i == 5 || i == 3 || i == 2 || i == 1 || i == 0)
+                imgNoteFan.fill(0,0,0);
+         else
+                imgNoteFan.fill(255,255,255);    
+      imgNoteFan.quad(0, i*(imageHeight/16.0), 0, (i+1)*(imageHeight/16.0), fanWidth, (imageHeight/2.0), fanWidth, (imageHeight/2.0));
+    }
+
+    imgNoteFan.endDraw();
+    
+}
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+void calcColours(){ // sets up colour values for background, bar and beat lines
+
+    if(heresyChordChanged){
+
+        if(currentChord == 0){
+            redC = 0;
+            greenC = 0;
+            blueC = 0;
+        }
+        
+        if(currentChord == 1){
+            redC = 90;
+            greenC = 76;
+            blueC = 3;
+        }
+        
+        if(currentChord == 2){
+            redC = 254;
+            greenC = 255;
+            blueC = 18;
+        }
+        
+         if(currentChord == 3){
+            redC = 0;
+            greenC = 0;
+            blueC = 0;
+        }
+        
+        if(currentChord == 4){
+            redC = 136;
+            greenC = 245;
+            blueC = 49;
+        }
+        
+        if(currentChord == 5){
+            redC = 9;
+            greenC = 18;
+            blueC = 232;
+        }
+        
+        if(currentChord == 6){
+            redC = 99;
+            greenC = 99;
+            blueC = 100;
+        }
+        
+        if(currentChord == 7){
+            redC = 255;
+            greenC = 166;
+            blueC = 21;
+        }
+        
+        if(currentChord == 8){
+            redC = 13;
+            greenC = 79;
+            blueC = 147;
+        }
+        
+        if(currentChord == 9){
+            redC = 255;
+            greenC = 165;
+            blueC = 165;
+        }
+        
+        if(currentChord == 10){
+            redC = 89;
+            greenC = 110;
+            blueC = 134;
+        }
+        
+        if(currentChord == 11){
+            redC = 68;
+            greenC = 242;
+            blueC = 250;
+        }
+
+        backGround = color(redC, greenC, blueC);
+        lineColour = color((redC + 100) % 255,(greenC + 69) % 255,(blueC + 214) % 255);
+        barLineColour = color((redC + 205) % 255, (greenC + 174) % 255, (blueC + 159) % 255);
+        
+        backgroundColour();
+        drawLines();
+        drawBarLines();
+    }
+}
+        
+        
+      
+     
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HeresyBigBangDone/application.macosx/source/Header.pde	Sat Oct 08 22:12:49 2011 +0100
@@ -0,0 +1,64 @@
+import oscP5.*; 
+import netP5.*; 
+import maxlink.*;
+
+OscP5 oscP5return;
+NetAddress ableton = new NetAddress("localhost", 12345); // OSC to ableton
+MaxLink link = new MaxLink(this, "midiCom");
+import processing.opengl.*;
+int imageWidth = 1000;
+int imageHeight = 300;
+int fanWidth = 400;
+
+float rpulse;
+boolean rpulseup;
+boolean clickTrack;
+int currentPulse = 0;
+int grid = 32;
+int fractions = 4;
+int pulseFrequency = grid / fractions;
+int beatsPerBar = 4;
+int bar = 0, beat = 0, fraction = 0, pulse = 0;
+int pulsesPerBar = beatsPerBar * grid;
+
+color lineColour = color(150,150,150);
+color barLineColour = color(255,255,95);
+color backGround = color(50,81,191);
+int redC = 50;
+int greenC = 81;
+int blueC = 191;
+PImage screenImage;
+PGraphics img, imgNotes, imgNoteFan;
+PImage test;
+
+int barOfPixels = grid * beatsPerBar;
+int playArea = 200;
+int x= 0;
+int x2= 0;
+PFont arial;
+int arraySize = 800-playArea;
+int bpm = 130;
+int tempo = bpm/60*grid;
+int noOfBars = 2;
+int loopLength = grid*beatsPerBar*noOfBars;
+Track[] tracks = new Track[16];
+Track chordsTemp;
+int trSelected;
+boolean[] noteOnArray = new boolean[16];
+boolean[] displayNoteOnArray = new boolean[16];
+int[] noteOnArrayLength = new int[16];
+boolean chordSelecter, clickTrackOn;
+int lastTrack;
+int trackStorer, screenAni;
+boolean quantizeValueIn, loopLengthValueIn, haveQuestion, aniOut, muteValueIn;
+String screenQuestion;
+boolean eraseOn;
+
+int crneeded = 24;
+int noOfChords;
+boolean tonicNeeded;
+boolean chordAI = true;
+int lastChordChange;
+boolean lastMinor; 
+int barCounter;
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HeresyBigBangDone/application.macosx/source/HeresyAl.pde	Sat Oct 08 22:12:49 2011 +0100
@@ -0,0 +1,574 @@
+boolean heresyMinor, oldHeresyMinor, heresy7th, oldHeresy7th, heresy9th, oldHeresy9th, heresy11th, oldHeresy11th, heresy13th, oldHeresy13th, heresyDom; 
+boolean heresyMinorChanged, heresyChordChanged, heresy7thChanged, heresy9thChanged, heresy11thChanged, heresy13thChanged, heresyChange, dontRevoice;
+int currentChord, lastChord;
+VPArray[] VPA = new VPArray[16];
+int[] notesOnArray = new int[16];
+int no1s = 0; int no3s = 0; int no5s = 0; int no7s = 0; int no9s = 0; int no11s = 0; int no13s = 0;
+int tonic = 0;
+
+
+
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+  /*  public int getHeresyPitch(int extension, int notePosition){  // delivers heresy pitches
+        int value = getExtentionPitch(extension) % 12;
+        if (notePosition == 15) value += 24;
+        if (notePosition == 14) value += 36;
+        if (notePosition == 13) value += 36;
+        if (notePosition == 12) value += 48;
+        if (notePosition == 11) value += 48;        
+        if (notePosition == 10) value += 48;     
+        if (notePosition == 9) value += 48;
+        if (notePosition == 8) value += 60;
+        if (notePosition == 7) value += 60;
+        if (notePosition == 6) value += 60;
+        if (notePosition == 5) value += 60;        
+        if (notePosition == 4) value += 72;  
+        if (notePosition == 3) value += 72;
+        if (notePosition == 2) value += 72;
+        if (notePosition == 1) value += 72;
+        if (notePosition == 0) value += 84;
+        return value;
+    }*/
+    
+ 
+    public int heresyPitchInfo(int arrayPosition){ // returns a value for checking if note required is currently playing
+        int value = 0;
+        if (heresyMinor && heresy7th && heresy9th && heresy11th && !heresy13th){
+            if (arrayPosition == 15) value = (15-currentChord) + 24;
+            if (arrayPosition == 14) value = (15-currentChord) + 36;
+            if (arrayPosition == 13) value = (15-currentChord) + 43;
+            if (arrayPosition == 12) value = (15-currentChord) + 50;
+            if (arrayPosition == 11) value = (15-currentChord) + 51;
+            if (arrayPosition == 10) value = (15-currentChord) + 58; 
+            if (arrayPosition == 9) value = (15-currentChord) + 65;
+            if (arrayPosition == 8) value = (15-currentChord) + 67;
+            if (arrayPosition == 7) value = (15-currentChord) + 70;
+            if (arrayPosition == 6) value = (15-currentChord) + 72;
+            if (arrayPosition == 5) value = (15-currentChord) + 74;
+            if (arrayPosition == 4) value = (15-currentChord) + 75;
+            if (arrayPosition == 3) value = (15-currentChord) + 77;
+            if (arrayPosition == 2) value = (15-currentChord) + 79;
+            if (arrayPosition == 1) value = (15-currentChord) + 82;
+            if (arrayPosition == 0) value = (15-currentChord) + 84;
+        }
+        if (!heresyMinor && heresy7th && heresy9th && heresy11th && !heresy13th){
+            if (arrayPosition == 15) value = (15-currentChord) + 24;
+            if (arrayPosition == 14) value = (15-currentChord) + 36;
+            if (arrayPosition == 13) value = (15-currentChord) + 43;
+            if (arrayPosition == 12) value = (15-currentChord) + 50;
+            if (arrayPosition == 11) value = (15-currentChord) + 52;
+            if (arrayPosition == 10) value = (15-currentChord) + 59; 
+            if (arrayPosition == 9) value = (15-currentChord) + 66;
+            if (arrayPosition == 8) value = (15-currentChord) + 71;
+            if (arrayPosition == 7) value = (15-currentChord) + 74;
+            if (arrayPosition == 6) value = (15-currentChord) + 78;
+            if (arrayPosition == 5) value = (15-currentChord) + 83;
+            if (arrayPosition == 4) value = (15-currentChord) + 75;
+            if (arrayPosition == 3) value = (15-currentChord) + 77;
+            if (arrayPosition == 2) value = (15-currentChord) + 79;
+            if (arrayPosition == 1) value = (15-currentChord) + 82;
+            if (arrayPosition == 0) value = (15-currentChord) + 84;
+        }
+    return value;
+    }
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+    public void playTrackEvents(){ // initiates the playing Heresy AI logic
+      
+        workOutExtensions();
+        //workOutChord();
+        heresyChangeHistory();
+        VpaNoteStater();
+   //   heresyVoicingArray();
+        countNoteOns();
+
+        
+     }
+
+
+ //-------------------------------------------------------------------------------------------------------------------------------
+     
+    public void sendNoteEvents(){  // sends sequencer evernts to the IO section for out put to max
+        for(int i = 1; i < Track.currentNumberOfTracks; i++){
+            if (tracks[i] != null ){
+                for (int ii = 0; ii < 16; ii++) {
+                   if (!VPA[i].VPArrayNotes[ii].played){
+                       outputToMax (VPA[i].VPArrayNotes[ii].VPNotePitch, VPA[i].VPArrayNotes[ii].VPNoteVelocity, i);
+                       VPA[i].VPArrayNotes[ii].played = true;
+                   }
+               }
+            }
+        }
+    }
+    
+
+//-------------------------------------------------------------------------------------------------------------------------------
+     
+    public void VpaNoteStater(){  // calculates pitches based on Heresy AI voice leading and voicing tables.
+      for(int i = 1; i < Track.currentNumberOfTracks; i++){
+            if (tracks[i] != null){
+                for (int ii = 0; ii < 16; ii++) {
+                    if (tracks[i].sequence[ii][currentPulse%(tracks[i].loopLength)] != null){
+                        if (tracks[i].sequence[ii][currentPulse%(tracks[i].loopLength)].noteVelocity != 0){
+                            if (VPA[i].VPArrayNotes[ii].VPNoteOn && heresyPitchInfo(ii) != VPA[i].VPArrayNotes[ii].VPNotePitch){
+                           //   println("in...");
+                                VPA[i].VPArrayNotes[ii].VPNoteVelocity = 0;
+                                sendNote(VPA[i].VPArrayNotes[ii], i);
+                                if (i != 1 && i != 5)
+                                    VPA[i].VPArrayNotes[ii].VPNotePitch = heresyPitch(ii, 3);
+                                else
+                                    VPA[i].VPArrayNotes[ii].VPNotePitch = heresyPitch(ii, 1);
+                                VPA[i].VPArrayNotes[ii].VPNoteVelocity = tracks[i].sequence[ii][currentPulse%(tracks[i].loopLength)].noteVelocity;
+                                sendNote(VPA[i].VPArrayNotes[ii], i);
+                            }else{
+                           //      println("in2...");
+                                if (i != 1 && i != 5)
+                                    VPA[i].VPArrayNotes[ii].VPNotePitch = heresyPitch(ii, 3);
+                                else
+                                    VPA[i].VPArrayNotes[ii].VPNotePitch = heresyPitch(ii, 1);
+                                VPA[i].VPArrayNotes[ii].VPNoteVelocity = tracks[i].sequence[ii][currentPulse%(tracks[i].loopLength)].noteVelocity;
+                                sendNote(VPA[i].VPArrayNotes[ii], i);
+                            }
+                        }
+                        if (tracks[i].sequence[ii][currentPulse%(tracks[i].loopLength)].noteVelocity == 0){
+                            VPA[i].VPArrayNotes[ii].VPNoteVelocity = 0;
+                            sendNote(VPA[i].VPArrayNotes[ii], i);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+/*    public void heresyVoicingArray(){  // sets the voicing array to be used for note ons
+        if (!heresy7th && !heresy9th && !heresy11th && !heresy13th) hvArray = hchoice135;
+        if (heresy7th && !heresy9th && !heresy11th && !heresy13th) hvArray = hchoice7;
+        if (!heresy7th && heresy9th && !heresy11th && !heresy13th) hvArray = hchoice9;
+        if (!heresy7th && !heresy9th && heresy11th && !heresy13th) hvArray = hchoice11;
+        if (!heresy7th && !heresy9th && !heresy11th && heresy13th) hvArray = hchoice13;
+        if (heresy7th && heresy9th && !heresy11th && !heresy13th) hvArray = hchoice79;
+        if (heresy7th && !heresy9th && heresy11th && !heresy13th) hvArray = hchoice711;
+        if (heresy7th && !heresy9th && !heresy11th && heresy13th) hvArray = hchoice713;
+        if (!heresy7th && heresy9th && heresy11th && !heresy13th) hvArray = hchoice911;
+        if (!heresy7th && heresy9th && !heresy11th && heresy13th) hvArray = hchoice913;
+        if (!heresy7th && !heresy9th && heresy11th && heresy13th) hvArray = hchoice1113;
+        if (heresy7th && heresy9th && heresy11th && !heresy13th) hvArray = hchoice7911;
+        if (heresy7th && heresy9th && !heresy11th && heresy13th) hvArray = hchoice7913;
+        if (heresy7th && !heresy9th && !heresy11th && heresy13th) hvArray = hchoice71113;
+        if (!heresy7th && heresy9th && heresy11th && heresy13th) hvArray = hchoice91113;
+    }
+    
+    */
+    
+    
+//------------------------------------------------------------------------------------------------------------------------------- 
+ 
+    public void countNoteOns(){    // counts the note ons for all tracks
+        for (int ii = 0; ii < 16; ii++){
+            notesOnArray[ii] = 0;}
+        for(int i = 1; i < Track.currentNumberOfTracks; i++){
+            for (int ii = 0; ii < 16; ii++){
+                if (VPA[i].VPArrayNotes[ii].VPNoteOn == true)
+                notesOnArray[i]++;
+            }
+        }
+    }
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+ /*   public void calculateHeresyNoteExtensions(){
+        for(int tracki = 1; tracki < Track.currentNumberOfTracks; tracki++){
+            no1s = 0; no3s = 0; no5s = 0; no7s = 0; no9s = 0; no11s = 0; no13s = 0;
+            
+            checkIfNotesAlreadyFit(tracki);
+            
+            calcRemainingNotes(tracki);
+            
+            for (int t = 0; t < 16; t++){
+                VPA[tracki].VPArrayNotes[t].done = false;
+            }
+         }
+     }
+     
+     */
+    
+    
+//-------------------------------------------------------------------------------------------------------------------------------
+
+/*    public void calcRemainingNotes(int tracki){
+        int counter = -1;
+        int looped = 0;
+        while (no1s + no3s + no5s + no7s + no9s + no11s + no13s != 0){
+            counter++;
+            if (counter >= notesOnArray[tracki]){
+                counter = 0;
+                looped++;
+            }
+            int nextExtension = hvArray[counter];
+            if(extensionNeeded(nextExtension)){
+                for (int playingNotesi = 0; playingNotesi < 16; playingNotesi++){
+                    if (VPA[tracki].VPArrayNotes[playingNotesi].VPNoteOn == true && !VPA[tracki].VPArrayNotes[playingNotesi].done){
+                        if (extensionPossible(playingNotesi, nextExtension)){
+                            VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch = getHeresyPitch(nextExtension, playingNotesi);
+                            VPA[tracki].VPArrayNotes[playingNotesi].done = true;
+                            println("got pitch " + VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch); 
+                      //    correctIfNeeded(tracki, playingNotesi, nextExtension); 
+                        }else println("wasn't possible");
+                    }
+                }
+            }
+            if (looped > 3) {
+                for (int playingNotesi = 0; playingNotesi < 16; playingNotesi++){
+                    if (VPA[tracki].VPArrayNotes[playingNotesi].VPNoteOn == true && !VPA[tracki].VPArrayNotes[playingNotesi].done){
+                        VPA[tracki].VPArrayNotes[playingNotesi].VPNoteOn = false;
+                        VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch = -1;
+                    }
+                }
+                System.out.println("Had to break_________________");
+                break;
+            }
+        }
+    }
+    
+    */
+    
+    
+//-------------------------------------------------------------------------------------------------------------------------------    
+  
+ /*   public void correctIfNeeded(int tracki, int playingNotesi, int nextExtension){ // changes note pitch of a virtual note on to a different octave in needed for voice leading
+        boolean alreadyGotNote = false; boolean alreadyGotNotePlus12 = false; boolean alreadyGotNoteMinus12 = false; 
+        int pitchAverage = 0;
+        for (int i = 0; i < 16; i++)
+            if (i != playingNotesi){
+                if (VPA[tracki].VPArrayNotes[i].done)
+                    pitchAverage += VPA[tracki].VPArrayNotes[i].VPNotePitch;
+                if (VPA[tracki].VPArrayNotes[i].VPNotePitch == VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch) 
+                    alreadyGotNote = true;
+                if (VPA[tracki].VPArrayNotes[i].VPNotePitch == VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch + 12) 
+                    alreadyGotNotePlus12 = true;
+                if (VPA[tracki].VPArrayNotes[i].VPNotePitch == VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch - 12) 
+                    alreadyGotNoteMinus12 = true;  
+            }
+            if (notesOnArray[tracki]-1 > 0)
+                pitchAverage = pitchAverage / (notesOnArray[tracki]-1);
+            else 
+                pitchAverage = VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch;
+            boolean correctedIt = false;
+            if (alreadyGotNote){
+                println("correcting note..........");
+                if (!alreadyGotNotePlus12 && pitchAverage > VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch){
+                    VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch = VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch + 12;
+                    correctedIt = true;
+                }else
+                    if (!alreadyGotNoteMinus12){
+                        VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch = VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch - 12;
+                        correctedIt = true;
+                    }
+                if (!alreadyGotNoteMinus12 && pitchAverage < VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch){
+                    VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch = VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch - 12;
+                    correctedIt = true;
+                }else
+                    if (!alreadyGotNotePlus12){
+                        VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch = VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch + 12;
+                        correctedIt = true;
+                    }
+               }
+               if (alreadyGotNote && !correctedIt)
+                   VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch = -2;
+               if (!alreadyGotNote || correctedIt){
+                   VPA[tracki].VPArrayNotes[playingNotesi].VPNoteVelocity = 80;
+                   VPA[tracki].VPArrayNotes[playingNotesi].done = true;
+                   VPA[tracki].VPArrayNotes[playingNotesi].played = false;
+                   extensionCounter(false, nextExtension);    
+               }else{
+                   VPA[tracki].VPArrayNotes[playingNotesi].VPNoteVelocity = 80;
+                   VPA[tracki].VPArrayNotes[playingNotesi].done = true;
+               }
+    }
+    
+    */
+
+
+//------------------------------------------------------------------------------------------------------------------------------- 
+
+
+
+ /*   public void checkIfNotesAlreadyFit(int tracki){
+        for (int extensioni = 0; extensioni < notesOnArray[tracki]; extensioni++){
+            boolean extensionFound = false;
+            for (int playingNotesi = 0; playingNotesi < 16; playingNotesi++){
+                if (VPA[tracki].VPArrayNotes[playingNotesi].VPNoteOn && !VPA[tracki].VPArrayNotes[playingNotesi].done && !extensionFound && VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch >= 24){
+                    if (disiredPitch(VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch, hvArray[extensioni])){
+                        VPA[tracki].VPArrayNotes[playingNotesi].done = true;
+                        extensionFound = true;
+                    }
+                }
+            }
+            if (!extensionFound){
+                extensionCounter(true, hvArray[extensioni]);
+            }
+        }
+    }
+    
+*/
+            
+            
+//-------------------------------------------------------------------------------------------------------------------------------             
+
+ /*   public boolean pitchInChord(int currentPitch){
+        boolean returnValue = false;
+        for (int i = 0; i < 16; i++){
+          //  println("currentPitch " + currentPitch + " getHeresyPitch(hvArray[i], 5) % 12) " + (getHeresyPitch(hvArray[i], 5)));
+            if (currentPitch % 12 == (getHeresyPitch(hvArray[i], 5) % 12));
+                returnValue = true;
+        }
+        return returnValue;
+    }
+ */       
+    
+//-------------------------------------------------------------------------------------------------------------------------------           
+
+ /*    public boolean extensionNeeded(int extension){
+     boolean needed = false;
+         if (extension == 1 && no1s > 0) needed = true;
+         if (extension == 3 && no3s > 0) needed = true;
+         if (extension == 5 && no5s > 0) needed = true;
+         if (extension == 7 && no7s > 0) needed = true;
+         if (extension == 9 && no9s > 0) needed = true;
+         if (extension == 11 && no11s > 0) needed = true;
+         if (extension == 13 && no13s > 0) needed = true;
+         return needed;
+     }
+   */
+    
+
+//------------------------------------------------------------------------------------------------------------------------------- 
+
+  /*  public int extensionMatch(){
+        int returnValue = -1;
+        for (int i = 0; i < 16; i++){
+            if( hvArray[i] == 1 && no1s > 0){
+                returnValue =  hvArray[i];
+                break;
+            }
+            if( hvArray[i] == 3 && no3s > 0){
+                returnValue =  hvArray[i];
+                break;
+            }
+            if( hvArray[i] == 5 && no5s > 0){
+                returnValue = hvArray[i];
+                break;
+            }
+            if( hvArray[i] == 7 && no7s > 0){
+                returnValue = hvArray[i];
+                break;
+            }
+            if( hvArray[i] == 9 && no9s > 0){
+                returnValue = hvArray[i];
+                break;
+            }
+            if( hvArray[i] == 11 && no11s > 0){
+                returnValue = hvArray[i];
+                break;
+            }
+            if( hvArray[i] == 13 && no13s > 0){
+                returnValue = hvArray[i];
+                break;
+            }
+        }
+        return returnValue;
+    }
+    
+    */
+      
+
+    
+    
+//-------------------------------------------------------------------------------------------------------------------------------   
+
+/*    public boolean extensionPossible(int playingNotesi, int extentionNeeded){
+        Boolean returnValue = true;
+        if (extentionNeeded != 1 && playingNotesi < 2) returnValue =  false;
+        if ((extentionNeeded == 5 || extentionNeeded == 7 || extentionNeeded == 1) && playingNotesi == 3) returnValue = false;
+        if (!returnValue) println ("returning no on playingNotesi = " + playingNotesi + " and " + extentionNeeded);
+        return returnValue;
+    }
+ */   
+    
+//-------------------------------------------------------------------------------------------------------------------------------
+
+/*    public boolean disiredPitch(int pitch, int extension){  // returns a value for voice leading purposes.  If true then pitch is already in current chord
+        if (pitch % 12 == getExtentionPitch(extension) % 12)
+            return true;
+        else return false;
+    }
+  */ 
+    
+//-------------------------------------------------------------------------------------------------------------------------------
+
+  /*  public int getExtentionPitch(int extension){  //
+        if (!heresyMinor){
+            if (currentChord-tonic == 1)  return tritoneSystem[extension/2]+currentChord;
+            if (currentChord-tonic == 7)  return dom7System[extension/2]+currentChord;
+            if (currentChord-tonic != 1 || currentChord-tonic != 7) return major7System[extension/2]+currentChord;
+        }
+        if (heresyMinor)
+            return minorSystem[extension/2]+currentChord;
+        else
+            return -1;
+   }
+    */
+    
+    
+//-------------------------------------------------------------------------------------------------------------------------------
+
+ /*   public void extensionCounter(boolean positive, int currentDesiredExtention){
+        if (currentDesiredExtention == 1) if (positive) no1s++; else no1s--;
+        if (currentDesiredExtention == 3) if (positive) no3s++; else no3s--;
+        if (currentDesiredExtention == 5) if (positive) no5s++; else no5s--;
+        if (currentDesiredExtention == 7) if (positive) no7s++; else no7s--;
+        if (currentDesiredExtention == 9) if (positive) no9s++; else no9s--;
+        if (currentDesiredExtention == 11) if (positive) no11s++; else no11s--;
+        if (currentDesiredExtention == 13) if (positive) no13s++; else no13s--;
+    }
+ */                                   
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+    public void workOutExtensions(){  // calculates whether the performer wants chord extensions
+        if (tracks[0].sequence[3][currentPulse%(tracks[0].loopLength)] != null && tracks[0].sequence[3][currentPulse%(tracks[0].loopLength)].noteVelocity == 0  && trSelected == 0 && noteOnArray[3])
+            tracks[0].sequence[3][currentPulse%(tracks[0].loopLength)] = null;
+        if (tracks[0].sequence[2][currentPulse%(tracks[0].loopLength)] != null && tracks[0].sequence[2][currentPulse%(tracks[0].loopLength)].noteVelocity == 0  && trSelected == 0 && noteOnArray[2])
+            tracks[0].sequence[2][currentPulse%(tracks[0].loopLength)] = null;
+        if (tracks[0].sequence[1][currentPulse%(tracks[0].loopLength)] != null && tracks[0].sequence[1][currentPulse%(tracks[0].loopLength)].noteVelocity == 0  && trSelected == 0 && noteOnArray[1])
+            tracks[0].sequence[1][currentPulse%(tracks[0].loopLength)] = null;
+        if (tracks[0].sequence[0][currentPulse%(tracks[0].loopLength)] != null && tracks[0].sequence[0][currentPulse%(tracks[0].loopLength)].noteVelocity == 0  && trSelected == 0 && noteOnArray[0])
+            tracks[0].sequence[0][currentPulse%(tracks[0].loopLength)] = null;         
+
+        if (tracks[0].sequence[3][currentPulse%(tracks[0].loopLength)] != null && tracks[0].sequence[3][currentPulse%(tracks[0].loopLength)].noteVelocity > 0)
+            heresy7th = true;
+        if (tracks[0].sequence[3][currentPulse%(tracks[0].loopLength)] != null && tracks[0].sequence[3][currentPulse%(tracks[0].loopLength)].noteVelocity == 0)
+            heresy7th = false;
+        if (tracks[0].sequence[2][currentPulse%(tracks[0].loopLength)] != null && tracks[0].sequence[2][currentPulse%(tracks[0].loopLength)].noteVelocity > 0)
+            heresy9th = true;
+        if (tracks[0].sequence[2][currentPulse%(tracks[0].loopLength)] != null && tracks[0].sequence[2][currentPulse%(tracks[0].loopLength)].noteVelocity == 0)
+            heresy9th = false;    
+        if (tracks[0].sequence[1][currentPulse%(tracks[0].loopLength)] != null && tracks[0].sequence[1][currentPulse%(tracks[0].loopLength)].noteVelocity > 0)
+            heresy11th = true;
+        if (tracks[0].sequence[1][currentPulse%(tracks[0].loopLength)] != null && tracks[0].sequence[1][currentPulse%(tracks[0].loopLength)].noteVelocity == 0)
+            heresy11th = false;
+        if (tracks[0].sequence[0][currentPulse%(tracks[0].loopLength)] != null && tracks[0].sequence[0][currentPulse%(tracks[0].loopLength)].noteVelocity > 0)
+            heresy13th = true;
+        if (tracks[0].sequence[0][currentPulse%(tracks[0].loopLength)] != null && tracks[0].sequence[0][currentPulse%(tracks[0].loopLength)].noteVelocity == 0)
+            heresy13th = false;
+            //---
+        if (chordsTemp.sequence[3][currentPulse%(chordsTemp.loopLength)] != null && chordsTemp.sequence[3][currentPulse%(chordsTemp.loopLength)].noteVelocity == 0  && trSelected == 0 && noteOnArray[3])
+            chordsTemp.sequence[3][currentPulse%(chordsTemp.loopLength)] = null;
+        if (chordsTemp.sequence[2][currentPulse%(chordsTemp.loopLength)] != null && chordsTemp.sequence[2][currentPulse%(chordsTemp.loopLength)].noteVelocity == 0  && trSelected == 0 && noteOnArray[2])
+            chordsTemp.sequence[2][currentPulse%(chordsTemp.loopLength)] = null;
+        if (chordsTemp.sequence[1][currentPulse%(chordsTemp.loopLength)] != null && chordsTemp.sequence[1][currentPulse%(chordsTemp.loopLength)].noteVelocity == 0  && trSelected == 0 && noteOnArray[1])
+            chordsTemp.sequence[1][currentPulse%(chordsTemp.loopLength)] = null;
+        if (chordsTemp.sequence[0][currentPulse%(chordsTemp.loopLength)] != null && chordsTemp.sequence[0][currentPulse%(chordsTemp.loopLength)].noteVelocity == 0  && trSelected == 0 && noteOnArray[0])
+            chordsTemp.sequence[0][currentPulse%(chordsTemp.loopLength)] = null;         
+
+        if (chordsTemp.sequence[3][currentPulse%(chordsTemp.loopLength)] != null && chordsTemp.sequence[3][currentPulse%(chordsTemp.loopLength)].noteVelocity > 0)
+            heresy7th = true;
+        if (chordsTemp.sequence[3][currentPulse%(chordsTemp.loopLength)] != null && chordsTemp.sequence[3][currentPulse%(chordsTemp.loopLength)].noteVelocity == 0)
+            heresy7th = false;
+        if (chordsTemp.sequence[2][currentPulse%(chordsTemp.loopLength)] != null && chordsTemp.sequence[2][currentPulse%(chordsTemp.loopLength)].noteVelocity > 0)
+            heresy9th = true;
+        if (chordsTemp.sequence[2][currentPulse%(chordsTemp.loopLength)] != null && chordsTemp.sequence[2][currentPulse%(chordsTemp.loopLength)].noteVelocity == 0)
+            heresy9th = false;    
+        if (chordsTemp.sequence[1][currentPulse%(chordsTemp.loopLength)] != null && chordsTemp.sequence[1][currentPulse%(chordsTemp.loopLength)].noteVelocity > 0)
+            heresy11th = true;
+        if (chordsTemp.sequence[1][currentPulse%(chordsTemp.loopLength)] != null && chordsTemp.sequence[1][currentPulse%(chordsTemp.loopLength)].noteVelocity == 0)
+            heresy11th = false;
+        if (chordsTemp.sequence[0][currentPulse%(chordsTemp.loopLength)] != null && chordsTemp.sequence[0][currentPulse%(chordsTemp.loopLength)].noteVelocity > 0)
+            heresy13th = true;
+        if (chordsTemp.sequence[0][currentPulse%(chordsTemp.loopLength)] != null && chordsTemp.sequence[0][currentPulse%(chordsTemp.loopLength)].noteVelocity == 0)
+            heresy13th = false;
+            
+    }
+    
+    
+//-------------------------------------------------------------------------------------------------------------------------------
+    
+    public void workOutChord(){ // calculates current chord and major minor tonality
+        for (int i = 4; i < 16; i++) {
+            if (tracks[0] != null){
+                if ((tracks[0].sequence[i][currentPulse%(tracks[0].loopLength)] != null && tracks[0].sequence[i][currentPulse%(tracks[0].loopLength)].noteVelocity > 0 )||
+                   (chordsTemp.sequence[i][currentPulse%(tracks[0].loopLength)] != null && chordsTemp.sequence[i][currentPulse%(chordsTemp.loopLength)].noteVelocity > 0 )){
+                    currentChord = 15 - i;
+                    boolean iiDone = false;
+                    for (int ii = 0;; ii--){
+                        if (ii == 0 && iiDone)
+                            break;
+                        if (currentPulse%(tracks[0].loopLength)+ii  == 0)
+                            ii = tracks[0].loopLength+ii-1;
+                        if (i > 3){
+                            if ((tracks[0].sequence[i-1][currentPulse%(tracks[0].loopLength)+ii] != null && tracks[0].sequence[i-1][currentPulse%(tracks[0].loopLength)+ii].noteVelocity == 0 ) ||
+                                 (chordsTemp.sequence[i-1][currentPulse%(chordsTemp.loopLength)+ii] != null && chordsTemp.sequence[i-1][currentPulse%(chordsTemp.loopLength)+ii].noteVelocity == 0 ))
+                                 break;
+                            if ((tracks[0].sequence[i-1][currentPulse%(tracks[0].loopLength)+ii] != null && tracks[0].sequence[i-1][currentPulse%(tracks[0].loopLength)+ii].noteVelocity != 0 ) ||
+                                 (chordsTemp.sequence[i-1][currentPulse%(chordsTemp.loopLength)+ii] != null && chordsTemp.sequence[i-1][currentPulse%(chordsTemp.loopLength)+ii].noteVelocity != 0 )){
+                                heresyMinor = true;
+                                break;
+                            }else
+                                heresyMinor = false;
+                        }
+                        iiDone = true;
+                    }
+                }
+            }
+        }
+    }
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+    
+    public void heresyChangeHistory(){  // remembers whether the chords or extensions have changed
+        if (currentChord != lastChord){
+            heresyChordChanged = true;
+            lastChord = currentChord;
+            heresyChange = true; 
+        }
+        if (heresyMinor != oldHeresyMinor){
+            heresyMinorChanged = true;
+            oldHeresyMinor = heresyMinor;
+            heresyChange = true;
+        }
+        if (heresy7th != oldHeresy7th){
+            heresy7thChanged = true;
+            oldHeresy7th = heresy7th;
+            heresyChange = true;
+        }
+        if (heresy9th != oldHeresy9th){
+            heresy9thChanged = true;
+            oldHeresy9th = heresy9th;
+            heresyChange = true;
+        }
+        if (heresy11th != oldHeresy11th){
+            heresy11thChanged = true;
+            oldHeresy11th = heresy11th;
+            heresyChange = true;
+        }
+        if (heresy13th != oldHeresy13th){
+            heresy13thChanged = true;
+            oldHeresy13th = heresy13th;
+            heresyChange = true;
+        }
+    }
+
+
+      
+       
+    
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HeresyBigBangDone/application.macosx/source/HeresyBigBangDone.java	Sat Oct 08 22:12:49 2011 +0100
@@ -0,0 +1,2326 @@
+import processing.core.*; 
+import processing.xml.*; 
+
+import oscP5.*; 
+import netP5.*; 
+import maxlink.*; 
+import processing.opengl.*; 
+
+import com.cycling74.max.*; 
+import com.cycling74.net.*; 
+import com.cycling74.msp.*; 
+import netP5.*; 
+import maxlink.*; 
+import com.cycling74.io.*; 
+import com.cycling74.util.*; 
+import com.cycling74.mxjedit.*; 
+import oscP5.*; 
+
+import java.applet.*; 
+import java.awt.Dimension; 
+import java.awt.Frame; 
+import java.awt.event.MouseEvent; 
+import java.awt.event.KeyEvent; 
+import java.awt.event.FocusEvent; 
+import java.awt.Image; 
+import java.io.*; 
+import java.net.*; 
+import java.text.*; 
+import java.util.*; 
+import java.util.zip.*; 
+import java.util.regex.*; 
+
+public class HeresyBigBangDone extends PApplet {
+
+ 
+
+public void setup(){
+    markovStuff();
+    for (int i = 0; i < 16; i++)
+        VPA[i] = new VPArray(); // creates the virtual playing array for Heresy AI.
+    for (int i = 0; i < noteOnArray.length; i++)   
+        noteOnArray[i] = false; // makes sure there are initial random inputs from openFrameworks
+        
+    oscP5return = new OscP5(this,12346); 
+ 
+    frameRate(tempo);
+    img = createGraphics(imageWidth,imageHeight,P2D);
+    size(800,imageHeight,P2D);
+    arial = createFont("Arial",32);
+    textFont(arial,15);
+    
+    // initialize the tracks
+    
+    tracks[0] = new Track("Chord track", true, grid * beatsPerBar, 8, true, true);
+    tracks[1] = new Track("Drums", true, grid * beatsPerBar, 8, false, true);
+    tracks[2] = new Track("Bass", true, grid * beatsPerBar, 8, false, true);
+    tracks[3] = new Track("Pizz Strings", true, grid * beatsPerBar, 8, false, true);
+    tracks[4] = new Track("Synth", true, grid * beatsPerBar, 8, false, true);
+    tracks[5] = new Track("Voice", true, grid * beatsPerBar, 8, false, true);
+    tracks[6] = new Track("Voice", true, grid * beatsPerBar, 8, false, true);
+    chordsTemp = new Track("Chord track", true, loopLength, 8, true, false);
+    trSelected = 1;
+    backgroundColour();
+    drawLines();
+    drawBarLines();
+    imgNoteFan = createGraphics(fanWidth,imageHeight,P2D);
+    lastTrack = trSelected;
+    clickTrackOn = true;
+ //   loadSequences();
+ //   tracks[2].sequence[15][16] = new NoteEvent (14, 2, bar,beat,fraction,pulse);
+ //   tracks[2].sequence[15][grid * beatsPerBar -20] = new NoteEvent (14, 2, bar,beat,fraction,pulse, true);
+  
+ //   tracks[3].sequence[13][16] = new NoteEvent (13, 3, bar,beat,fraction,pulse);
+ //   tracks[3].sequence[13][20] = new NoteEvent (13, 3, bar,beat,fraction,pulse, true); 
+ //   tracks[3].sequence[12][16] = new NoteEvent (12, 3, bar,beat,fraction,pulse);
+ //   tracks[3].sequence[12][20] = new NoteEvent (12, 3, bar,beat,fraction,pulse, true);     
+ //   tracks[3].sequence[11][16] = new NoteEvent (11, 3, bar,beat,fraction,pulse);
+ //   tracks[3].sequence[11][20] = new NoteEvent (11, 3, bar,beat,fraction,pulse, true);   
+ //   tracks[3].sequence[10][16] = new NoteEvent (10, 3, bar,beat,fraction,pulse);
+ //   tracks[3].sequence[10][20] = new NoteEvent (10, 3, bar,beat,fraction,pulse, true);  
+}
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+public void draw(){
+ /*   if (currentPulse % (grid * beatsPerBar) == grid * beatsPerBar -1){
+        int tempTrackSelected = trSelected;
+        for (int j = 0; j < 16; j++){
+            trSelected = j; 
+            if (tracks[j] != null){
+                for (int i = 0; i < 16; i++){
+                    noteOnArray[i] = false;
+                    finishNote(i);
+                    displayNoteOnArray[i] = false;
+                    for (int z = 24; z < 109; z++)
+                        outputToMax(z, 0, j);
+                }
+                tracks[j] = new Track(tracks[j].name, true,  tracks[j].loopLength, tracks[j].quantize, false, false);
+                imgNotes = null;
+            }
+        }
+        trSelected = tempTrackSelected;
+    }
+    */
+  //  tracks[0] = new Track("Chord track", true, grid * beatsPerBar, 8, true, true);
+  //  tracks[1] = new Track("Drums", true, grid * beatsPerBar, 8, false, true);
+  //  tracks[2] = new Track("Bass", true, grid * beatsPerBar, 8, false, true);
+  //  tracks[3] = new Track("Pizz Strings", true, grid * beatsPerBar, 8, false, true);
+  //  tracks[4] = new Track("Synth", true, grid * beatsPerBar, 8, false, true);
+  //  tracks[5] = new Track("Voice", true, grid * beatsPerBar, 8, false, true);
+  //  }
+    workOutPosition(); // calculates current bar, beat and pulse position
+    //println(bar + " " + beat + " " + fraction + " " + pulse);
+//    if (chordAI && bar > 1)
+//        chordCalc();
+    if (eraseOn)
+        eraseNotes();
+    calcColours(); // calcs chord colours for background and grid
+    heresyChange = false;
+    heresyChordChanged = false;
+    if (trackStorer != trSelected){ // resets display when changing tracks
+        for (int i = 0; i < 16; i++)
+            if (noteOnArray[i] = true){
+                noteOnArray[i] = false;
+                displayNoteOnArray[i] = false;
+            }
+        trackStorer = trSelected;    
+        imgNotes = null;
+    }
+    if (imgNotes == null)
+        imgNotes = createGraphics(tracks[trSelected].loopLength,imageHeight,P2D);
+    background(0);
+    image (img,width-x2-playArea,0);
+    drawTempImageGrid();
+    createNoteFan(); 
+    drawNotes();
+    fill (0);
+    noStroke();
+    rect (width-playArea,0,playArea,height);
+    image (imgNoteFan, width-playArea+3,0);
+    pulseFrame(x); // Draws a pulsing white line at the left edge of the edit area
+    if (haveQuestion) writeQuestion(); // for input request messages
+    x++; // counter for grid movement
+    x2++; // counter for note image movement
+    if (x2 == width - playArea + grid * beatsPerBar)
+        x2 = width - playArea;
+    if (x == width - playArea + tracks[trSelected].loopLength)
+        x = width - playArea;
+
+    
+   /* if (clickTrackOn){ // click track
+        if (fraction == 1){
+            if (pulse == 1){
+                String noteOut = ("37 80 1");
+                link.output(noteOut);
+            }
+            if (pulse == 2){
+                String noteOut = ("37 0 1" );
+                link.output(noteOut); 
+            } 
+        }
+    }
+    */
+    checkForMutes();
+    checkCycled();
+    playTrackEvents();
+
+    fill(255,255,255);
+    textSize(15);
+    text(bar + " " + beat + " " + fraction + " " + pulse, 10,20); // draws current time position to screen
+
+    fill(200,0,0);
+    textSize(15);
+    // this section draws current track and track info to screen
+    if (tracks[trSelected].ducking) 
+        text(tracks[trSelected].name + " ducking", 100,20); 
+    else
+        text(tracks[trSelected].name, 100,20); 
+    if (tracks[trSelected].muteIn > bar)
+        if (!tracks[trSelected].mute)
+             text("mute in " + (tracks[trSelected].muteIn - bar), 200,20);
+         else 
+             text("unmute in " + (tracks[trSelected].muteIn - bar), 200,20);
+             
+    if (haveQuestion){ // asks input questions
+        writeQuestion();
+    }
+ //   println(currentPulse + " ");
+
+
+    currentPulse++; // advances the sequencer to next pulse
+}
+        
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+public void eraseNotes(){ // erases notes in current track if selected
+    if (trSelected != 0){
+        for (int i = 0; i < 16; i++){
+           if (tracks[trSelected].sequence[i][(currentPulse%(tracks[trSelected].loopLength))] != null){
+               tracks[trSelected].sequence[i][(currentPulse%(tracks[trSelected].loopLength))] = null;
+           }
+        }
+    }
+    if (trSelected == 0){
+        for (int i = 0; i < 16; i++){
+           if (chordsTemp.sequence[i][(currentPulse%(tracks[trSelected].loopLength))] != null){
+               chordsTemp.sequence[i][(currentPulse%(tracks[trSelected].loopLength))] = null;
+           }
+        }
+    }     
+}  
+           
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+public void workOutPosition(){ // works out current position
+  if (currentPulse%(grid*beatsPerBar) == 0)
+    ++bar;
+  if (currentPulse%grid == 0)
+    ++beat;
+  if (beat > beatsPerBar)
+    beat = 1;
+  if (currentPulse%(grid/fractions) == 0)
+    ++fraction;
+  if (fraction > fractions)
+    fraction = 1;
+    ++pulse;
+  if (pulse > (grid/fractions))
+    pulse = 1;
+}
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+public void finishNote(int noteArrayPosition){ // writes note offs into the sequencers
+  if (trSelected != 0)
+      tracks[trSelected].sequence[noteArrayPosition][(currentPulse%(tracks[trSelected].loopLength))] = new NoteEvent (noteArrayPosition, trSelected+1, bar,beat,fraction,pulse, true);
+  if (trSelected == 0)
+      chordsTemp.sequence[noteArrayPosition][(currentPulse%(chordsTemp.loopLength))] = new NoteEvent (noteArrayPosition, trSelected+1, bar,beat,fraction,pulse, true);
+  displayNoteOnArray[noteArrayPosition] = false;
+}
+
+public void finishNote(int noteArrayPosition, int channel){ // writes note offs into the sequencers
+  if (trSelected != 0)
+      tracks[trSelected].sequence[noteArrayPosition][(currentPulse%(tracks[trSelected].loopLength))] = new NoteEvent (noteArrayPosition, channel, bar,beat,fraction,pulse, true);
+  if (trSelected == 0)
+      chordsTemp.sequence[noteArrayPosition][(currentPulse%(chordsTemp.loopLength))] = new NoteEvent (noteArrayPosition, channel, bar,beat,fraction,pulse, true);
+  displayNoteOnArray[noteArrayPosition] = false;
+}
+
+
+//-----------------------------------------------------------------------------------------------------------------------------
+
+public void finishNoteCutOff(int noteArrayPosition){ // writes note offs for unfinished notes in to the last track if track is changed and note ons are active
+    tracks[lastTrack].sequence[noteArrayPosition][(currentPulse%(tracks[lastTrack].loopLength))] = new NoteEvent (noteArrayPosition, lastTrack+1, bar,beat,fraction,pulse, true);
+}
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+public void writeNote(int noteArrayPosition, int veloc){ // writes note ons into the sequencers
+    if (trSelected != 0){
+        int quantizeOffset = getQuantizeOffset();
+        if (quantizeOffset >= 0){
+            tracks[trSelected].sequence[noteArrayPosition][(currentPulse+quantizeOffset)%(tracks[trSelected].loopLength)] = new NoteEvent (noteArrayPosition, trSelected+1, bar,beat,fraction,pulse);
+        }
+        if (quantizeOffset < 0){
+            tracks[trSelected].sequence[noteArrayPosition][(currentPulse+quantizeOffset)%(tracks[trSelected].loopLength)] = new NoteEvent (noteArrayPosition, trSelected+1, bar,beat,fraction,pulse);  
+
+            VPA[trSelected].VPArrayNotes[noteArrayPosition].VPNoteOn = true;
+            if (trSelected !=1 && trSelected !=5)
+                VPA[trSelected].VPArrayNotes[noteArrayPosition].VPNotePitch = heresyPitch(noteArrayPosition, 3);
+            else
+                VPA[trSelected].VPArrayNotes[noteArrayPosition].VPNotePitch = heresyPitch(noteArrayPosition, 1);
+            VPA[trSelected].VPArrayNotes[noteArrayPosition].VPNoteVelocity = veloc;
+            sendNote(VPA[trSelected].VPArrayNotes[noteArrayPosition], trSelected);
+            displayNoteOnArray[noteArrayPosition] = true;
+            
+        }
+    }
+    if (trSelected == 0){
+        int quantizeOffset = getQuantizeOffset();
+        if (quantizeOffset >= 0){
+            chordsTemp.sequence[noteArrayPosition][(currentPulse+quantizeOffset)%(tracks[trSelected].loopLength)] = new NoteEvent (noteArrayPosition, trSelected+1, bar,beat,fraction,pulse);
+        }
+        if (quantizeOffset < 0){
+            chordsTemp.sequence[noteArrayPosition][(currentPulse+quantizeOffset)%(tracks[trSelected].loopLength)] = new NoteEvent (noteArrayPosition, trSelected+1, bar,beat,fraction,pulse);  
+
+            if (noteArrayPosition > 3)
+                currentChord = 15 - noteArrayPosition;
+             displayNoteOnArray[noteArrayPosition] = true;
+        }
+    }
+}
+
+public void writeNote(int noteArrayPosition, int veloc, int channel){ // writes note ons into the sequencers
+    VPA[channel].VPArrayNotes[noteArrayPosition].VPNoteOn = true;
+    VPA[channel].VPArrayNotes[noteArrayPosition].VPNotePitch = heresyPitch(noteArrayPosition, 1);
+    VPA[channel].VPArrayNotes[noteArrayPosition].VPNoteVelocity = veloc;
+    sendNote(VPA[channel].VPArrayNotes[noteArrayPosition], channel);
+}
+
+
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+public int getQuantizeOffset(){  // tells write note method the quantize offset.
+    int quantizeInPulses = pulsesPerBar/(tracks[trSelected].quantize);
+    int quantizeOffset = currentPulse % quantizeInPulses;
+    if (quantizeOffset > quantizeInPulses/2.0f){
+        return ((quantizeOffset - quantizeInPulses) * -1) ;
+    }
+    else{
+        return quantizeOffset * -1;
+    }
+}
+
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+public void drawNotes(){ // places the note display grid into the apropriate screen positions
+        int loopsOnScreen = ((width-playArea) / tracks[trSelected].loopLength) + 1;
+        if (loopsOnScreen > currentPulse / tracks[trSelected].loopLength)
+            loopsOnScreen = currentPulse / tracks[trSelected].loopLength;
+        for (int i = 0; i <= loopsOnScreen; i++)
+          image (imgNotes, (width-playArea-(i*tracks[trSelected].loopLength))-currentPulse%(tracks[trSelected].loopLength),0); 
+    }
+
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+public void pulseFrame(int frameNo){ // Draws a pulsing line at left hand side of the input area when loop restarts
+    strokeWeight(3);
+    if (currentPulse % (tracks[trSelected].loopLength) == 0 || (currentPulse-1) % (tracks[trSelected].loopLength) == 0 || (currentPulse-2) % (tracks[trSelected].loopLength) == 0)
+        stroke(255,255,255);
+    else
+        stroke(255,111,111);
+    line (width-playArea+3, 1, width-playArea+3, 300);  
+} 
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+      
+public void drawTempImageGrid(){ // draws the note display image grid
+    imgNotes.stroke(209,137,255);
+    imgNotes.strokeWeight(15); 
+    for(int i = 0; i < 16; i++){
+       if ((tracks[trSelected].sequence[i][currentPulse%(tracks[trSelected].loopLength)] != null && tracks[trSelected].sequence[i][currentPulse%(tracks[trSelected].loopLength)].noteVelocity > 0) || displayNoteOnArray[i]){
+            imgNotes.beginDraw();
+            imgNotes.line (currentPulse%(tracks[trSelected].loopLength), i*imageHeight/16+imageHeight/32, currentPulse%(tracks[trSelected].loopLength)+1, i*imageHeight/16+imageHeight/32);
+            imgNotes.endDraw(); 
+            displayNoteOnArray[i] = true;
+        }
+        if (tracks[trSelected].sequence[i][currentPulse%(tracks[trSelected].loopLength)] != null && tracks[trSelected].sequence[i][currentPulse%(tracks[trSelected].loopLength)].noteVelocity == 0){
+            displayNoteOnArray[i] = false;
+        }
+    
+        if(trSelected ==0){
+            if ((chordsTemp.sequence[i][currentPulse%(chordsTemp.loopLength)] != null && chordsTemp.sequence[i][currentPulse%(chordsTemp.loopLength)].noteVelocity > 0) || displayNoteOnArray[i]){
+                imgNotes.beginDraw();
+                imgNotes.line (currentPulse%(chordsTemp.loopLength), i*imageHeight/16+imageHeight/32, currentPulse%(chordsTemp.loopLength)+1, i*imageHeight/16+imageHeight/32);
+                imgNotes.endDraw(); 
+                displayNoteOnArray[i] = true;
+            }
+            if (chordsTemp.sequence[i][currentPulse%(chordsTemp.loopLength)] != null && chordsTemp.sequence[i][currentPulse%(chordsTemp.loopLength)].noteVelocity == 0){
+                displayNoteOnArray[i] = false;
+            }
+        }
+    }
+}
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+public void drawLines(){ // draws beat lines
+     int linePosition = 1;
+     int i = 0;
+     for (; linePosition <= imageWidth;){
+         linePosition = i * grid;
+         img.beginDraw();
+         img.stroke(lineColour);
+         img.strokeWeight(2);
+         img.line (linePosition, 0, linePosition, imageHeight);
+         img.endDraw();
+         i++;
+     }
+}
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+public void drawBarLines(){ // draws bar lines
+     int linePosition = 1;    
+     for (int i = 0; linePosition <= imageWidth;){
+         linePosition = i * grid * beatsPerBar;
+         img.beginDraw();
+         img.stroke(barLineColour);
+         img.strokeWeight(2);
+         img.line (linePosition, 0, linePosition, imageHeight);
+         img.endDraw();
+         i++;
+     }
+}
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+public void backgroundColour(){ // sets background colour
+     img.beginDraw();
+     img.background (backGround);
+     img.endDraw();
+}
+
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+public void createNoteFan(){ // creates the input fan
+    if (rpulseup)
+        rpulse++;
+    else rpulse--;
+    if (rpulse == grid)
+        rpulseup = false;
+    if (rpulse < 1)
+        rpulseup = true;
+    imgNoteFan.beginDraw();
+    imgNoteFan.stroke(rpulse/grid*255,50,50);
+    imgNoteFan.strokeWeight(1);
+    for (int i = 0; i < 16; i++){
+        if (!chordSelecter)
+            if ((tracks[trSelected].sequence[i][currentPulse%(tracks[trSelected].loopLength)] != null && tracks[trSelected].sequence[i][currentPulse%(tracks[trSelected].loopLength)].noteVelocity > 0) || displayNoteOnArray[i]){
+                imgNoteFan.fill(209,137,255);
+            }
+            else
+                imgNoteFan.fill(0,0,0);
+         else
+            if (i == 14 || i == 12 || i == 9 || i == 7 || i == 5 || i == 3 || i == 2 || i == 1 || i == 0)
+                imgNoteFan.fill(0,0,0);
+         else
+                imgNoteFan.fill(255,255,255);    
+      imgNoteFan.quad(0, i*(imageHeight/16.0f), 0, (i+1)*(imageHeight/16.0f), fanWidth, (imageHeight/2.0f), fanWidth, (imageHeight/2.0f));
+    }
+
+    imgNoteFan.endDraw();
+    
+}
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+public void calcColours(){ // sets up colour values for background, bar and beat lines
+
+    if(heresyChordChanged){
+
+        if(currentChord == 0){
+            redC = 0;
+            greenC = 0;
+            blueC = 0;
+        }
+        
+        if(currentChord == 1){
+            redC = 90;
+            greenC = 76;
+            blueC = 3;
+        }
+        
+        if(currentChord == 2){
+            redC = 254;
+            greenC = 255;
+            blueC = 18;
+        }
+        
+         if(currentChord == 3){
+            redC = 0;
+            greenC = 0;
+            blueC = 0;
+        }
+        
+        if(currentChord == 4){
+            redC = 136;
+            greenC = 245;
+            blueC = 49;
+        }
+        
+        if(currentChord == 5){
+            redC = 9;
+            greenC = 18;
+            blueC = 232;
+        }
+        
+        if(currentChord == 6){
+            redC = 99;
+            greenC = 99;
+            blueC = 100;
+        }
+        
+        if(currentChord == 7){
+            redC = 255;
+            greenC = 166;
+            blueC = 21;
+        }
+        
+        if(currentChord == 8){
+            redC = 13;
+            greenC = 79;
+            blueC = 147;
+        }
+        
+        if(currentChord == 9){
+            redC = 255;
+            greenC = 165;
+            blueC = 165;
+        }
+        
+        if(currentChord == 10){
+            redC = 89;
+            greenC = 110;
+            blueC = 134;
+        }
+        
+        if(currentChord == 11){
+            redC = 68;
+            greenC = 242;
+            blueC = 250;
+        }
+
+        backGround = color(redC, greenC, blueC);
+        lineColour = color((redC + 100) % 255,(greenC + 69) % 255,(blueC + 214) % 255);
+        barLineColour = color((redC + 205) % 255, (greenC + 174) % 255, (blueC + 159) % 255);
+        
+        backgroundColour();
+        drawLines();
+        drawBarLines();
+    }
+}
+        
+        
+      
+     
+ 
+ 
+
+
+OscP5 oscP5return;
+NetAddress ableton = new NetAddress("localhost", 12345); // OSC to ableton
+MaxLink link = new MaxLink(this, "midiCom");
+
+int imageWidth = 1000;
+int imageHeight = 300;
+int fanWidth = 400;
+
+float rpulse;
+boolean rpulseup;
+boolean clickTrack;
+int currentPulse = 0;
+int grid = 32;
+int fractions = 4;
+int pulseFrequency = grid / fractions;
+int beatsPerBar = 4;
+int bar = 0, beat = 0, fraction = 0, pulse = 0;
+int pulsesPerBar = beatsPerBar * grid;
+
+int lineColour = color(150,150,150);
+int barLineColour = color(255,255,95);
+int backGround = color(50,81,191);
+int redC = 50;
+int greenC = 81;
+int blueC = 191;
+PImage screenImage;
+PGraphics img, imgNotes, imgNoteFan;
+PImage test;
+
+int barOfPixels = grid * beatsPerBar;
+int playArea = 200;
+int x= 0;
+int x2= 0;
+PFont arial;
+int arraySize = 800-playArea;
+int bpm = 130;
+int tempo = bpm/60*grid;
+int noOfBars = 2;
+int loopLength = grid*beatsPerBar*noOfBars;
+Track[] tracks = new Track[16];
+Track chordsTemp;
+int trSelected;
+boolean[] noteOnArray = new boolean[16];
+boolean[] displayNoteOnArray = new boolean[16];
+int[] noteOnArrayLength = new int[16];
+boolean chordSelecter, clickTrackOn;
+int lastTrack;
+int trackStorer, screenAni;
+boolean quantizeValueIn, loopLengthValueIn, haveQuestion, aniOut, muteValueIn;
+String screenQuestion;
+boolean eraseOn;
+
+int crneeded = 24;
+int noOfChords;
+boolean tonicNeeded;
+boolean chordAI = true;
+int lastChordChange;
+boolean lastMinor; 
+int barCounter;
+
+boolean heresyMinor, oldHeresyMinor, heresy7th, oldHeresy7th, heresy9th, oldHeresy9th, heresy11th, oldHeresy11th, heresy13th, oldHeresy13th, heresyDom; 
+boolean heresyMinorChanged, heresyChordChanged, heresy7thChanged, heresy9thChanged, heresy11thChanged, heresy13thChanged, heresyChange, dontRevoice;
+int currentChord, lastChord;
+VPArray[] VPA = new VPArray[16];
+int[] notesOnArray = new int[16];
+int no1s = 0; int no3s = 0; int no5s = 0; int no7s = 0; int no9s = 0; int no11s = 0; int no13s = 0;
+int tonic = 0;
+
+
+
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+  /*  public int getHeresyPitch(int extension, int notePosition){  // delivers heresy pitches
+        int value = getExtentionPitch(extension) % 12;
+        if (notePosition == 15) value += 24;
+        if (notePosition == 14) value += 36;
+        if (notePosition == 13) value += 36;
+        if (notePosition == 12) value += 48;
+        if (notePosition == 11) value += 48;        
+        if (notePosition == 10) value += 48;     
+        if (notePosition == 9) value += 48;
+        if (notePosition == 8) value += 60;
+        if (notePosition == 7) value += 60;
+        if (notePosition == 6) value += 60;
+        if (notePosition == 5) value += 60;        
+        if (notePosition == 4) value += 72;  
+        if (notePosition == 3) value += 72;
+        if (notePosition == 2) value += 72;
+        if (notePosition == 1) value += 72;
+        if (notePosition == 0) value += 84;
+        return value;
+    }*/
+    
+ 
+    public int heresyPitchInfo(int arrayPosition){ // returns a value for checking if note required is currently playing
+        int value = 0;
+        if (heresyMinor && heresy7th && heresy9th && heresy11th && !heresy13th){
+            if (arrayPosition == 15) value = (15-currentChord) + 24;
+            if (arrayPosition == 14) value = (15-currentChord) + 36;
+            if (arrayPosition == 13) value = (15-currentChord) + 43;
+            if (arrayPosition == 12) value = (15-currentChord) + 50;
+            if (arrayPosition == 11) value = (15-currentChord) + 51;
+            if (arrayPosition == 10) value = (15-currentChord) + 58; 
+            if (arrayPosition == 9) value = (15-currentChord) + 65;
+            if (arrayPosition == 8) value = (15-currentChord) + 67;
+            if (arrayPosition == 7) value = (15-currentChord) + 70;
+            if (arrayPosition == 6) value = (15-currentChord) + 72;
+            if (arrayPosition == 5) value = (15-currentChord) + 74;
+            if (arrayPosition == 4) value = (15-currentChord) + 75;
+            if (arrayPosition == 3) value = (15-currentChord) + 77;
+            if (arrayPosition == 2) value = (15-currentChord) + 79;
+            if (arrayPosition == 1) value = (15-currentChord) + 82;
+            if (arrayPosition == 0) value = (15-currentChord) + 84;
+        }
+        if (!heresyMinor && heresy7th && heresy9th && heresy11th && !heresy13th){
+            if (arrayPosition == 15) value = (15-currentChord) + 24;
+            if (arrayPosition == 14) value = (15-currentChord) + 36;
+            if (arrayPosition == 13) value = (15-currentChord) + 43;
+            if (arrayPosition == 12) value = (15-currentChord) + 50;
+            if (arrayPosition == 11) value = (15-currentChord) + 52;
+            if (arrayPosition == 10) value = (15-currentChord) + 59; 
+            if (arrayPosition == 9) value = (15-currentChord) + 66;
+            if (arrayPosition == 8) value = (15-currentChord) + 71;
+            if (arrayPosition == 7) value = (15-currentChord) + 74;
+            if (arrayPosition == 6) value = (15-currentChord) + 78;
+            if (arrayPosition == 5) value = (15-currentChord) + 83;
+            if (arrayPosition == 4) value = (15-currentChord) + 75;
+            if (arrayPosition == 3) value = (15-currentChord) + 77;
+            if (arrayPosition == 2) value = (15-currentChord) + 79;
+            if (arrayPosition == 1) value = (15-currentChord) + 82;
+            if (arrayPosition == 0) value = (15-currentChord) + 84;
+        }
+    return value;
+    }
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+    public void playTrackEvents(){ // initiates the playing Heresy AI logic
+      
+        workOutExtensions();
+        //workOutChord();
+        heresyChangeHistory();
+        VpaNoteStater();
+   //   heresyVoicingArray();
+        countNoteOns();
+
+        
+     }
+
+
+ //-------------------------------------------------------------------------------------------------------------------------------
+     
+    public void sendNoteEvents(){  // sends sequencer evernts to the IO section for out put to max
+        for(int i = 1; i < Track.currentNumberOfTracks; i++){
+            if (tracks[i] != null ){
+                for (int ii = 0; ii < 16; ii++) {
+                   if (!VPA[i].VPArrayNotes[ii].played){
+                       outputToMax (VPA[i].VPArrayNotes[ii].VPNotePitch, VPA[i].VPArrayNotes[ii].VPNoteVelocity, i);
+                       VPA[i].VPArrayNotes[ii].played = true;
+                   }
+               }
+            }
+        }
+    }
+    
+
+//-------------------------------------------------------------------------------------------------------------------------------
+     
+    public void VpaNoteStater(){  // calculates pitches based on Heresy AI voice leading and voicing tables.
+      for(int i = 1; i < Track.currentNumberOfTracks; i++){
+            if (tracks[i] != null){
+                for (int ii = 0; ii < 16; ii++) {
+                    if (tracks[i].sequence[ii][currentPulse%(tracks[i].loopLength)] != null){
+                        if (tracks[i].sequence[ii][currentPulse%(tracks[i].loopLength)].noteVelocity != 0){
+                            if (VPA[i].VPArrayNotes[ii].VPNoteOn && heresyPitchInfo(ii) != VPA[i].VPArrayNotes[ii].VPNotePitch){
+                           //   println("in...");
+                                VPA[i].VPArrayNotes[ii].VPNoteVelocity = 0;
+                                sendNote(VPA[i].VPArrayNotes[ii], i);
+                                if (i != 1 && i != 5)
+                                    VPA[i].VPArrayNotes[ii].VPNotePitch = heresyPitch(ii, 3);
+                                else
+                                    VPA[i].VPArrayNotes[ii].VPNotePitch = heresyPitch(ii, 1);
+                                VPA[i].VPArrayNotes[ii].VPNoteVelocity = tracks[i].sequence[ii][currentPulse%(tracks[i].loopLength)].noteVelocity;
+                                sendNote(VPA[i].VPArrayNotes[ii], i);
+                            }else{
+                           //      println("in2...");
+                                if (i != 1 && i != 5)
+                                    VPA[i].VPArrayNotes[ii].VPNotePitch = heresyPitch(ii, 3);
+                                else
+                                    VPA[i].VPArrayNotes[ii].VPNotePitch = heresyPitch(ii, 1);
+                                VPA[i].VPArrayNotes[ii].VPNoteVelocity = tracks[i].sequence[ii][currentPulse%(tracks[i].loopLength)].noteVelocity;
+                                sendNote(VPA[i].VPArrayNotes[ii], i);
+                            }
+                        }
+                        if (tracks[i].sequence[ii][currentPulse%(tracks[i].loopLength)].noteVelocity == 0){
+                            VPA[i].VPArrayNotes[ii].VPNoteVelocity = 0;
+                            sendNote(VPA[i].VPArrayNotes[ii], i);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+/*    public void heresyVoicingArray(){  // sets the voicing array to be used for note ons
+        if (!heresy7th && !heresy9th && !heresy11th && !heresy13th) hvArray = hchoice135;
+        if (heresy7th && !heresy9th && !heresy11th && !heresy13th) hvArray = hchoice7;
+        if (!heresy7th && heresy9th && !heresy11th && !heresy13th) hvArray = hchoice9;
+        if (!heresy7th && !heresy9th && heresy11th && !heresy13th) hvArray = hchoice11;
+        if (!heresy7th && !heresy9th && !heresy11th && heresy13th) hvArray = hchoice13;
+        if (heresy7th && heresy9th && !heresy11th && !heresy13th) hvArray = hchoice79;
+        if (heresy7th && !heresy9th && heresy11th && !heresy13th) hvArray = hchoice711;
+        if (heresy7th && !heresy9th && !heresy11th && heresy13th) hvArray = hchoice713;
+        if (!heresy7th && heresy9th && heresy11th && !heresy13th) hvArray = hchoice911;
+        if (!heresy7th && heresy9th && !heresy11th && heresy13th) hvArray = hchoice913;
+        if (!heresy7th && !heresy9th && heresy11th && heresy13th) hvArray = hchoice1113;
+        if (heresy7th && heresy9th && heresy11th && !heresy13th) hvArray = hchoice7911;
+        if (heresy7th && heresy9th && !heresy11th && heresy13th) hvArray = hchoice7913;
+        if (heresy7th && !heresy9th && !heresy11th && heresy13th) hvArray = hchoice71113;
+        if (!heresy7th && heresy9th && heresy11th && heresy13th) hvArray = hchoice91113;
+    }
+    
+    */
+    
+    
+//------------------------------------------------------------------------------------------------------------------------------- 
+ 
+    public void countNoteOns(){    // counts the note ons for all tracks
+        for (int ii = 0; ii < 16; ii++){
+            notesOnArray[ii] = 0;}
+        for(int i = 1; i < Track.currentNumberOfTracks; i++){
+            for (int ii = 0; ii < 16; ii++){
+                if (VPA[i].VPArrayNotes[ii].VPNoteOn == true)
+                notesOnArray[i]++;
+            }
+        }
+    }
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+ /*   public void calculateHeresyNoteExtensions(){
+        for(int tracki = 1; tracki < Track.currentNumberOfTracks; tracki++){
+            no1s = 0; no3s = 0; no5s = 0; no7s = 0; no9s = 0; no11s = 0; no13s = 0;
+            
+            checkIfNotesAlreadyFit(tracki);
+            
+            calcRemainingNotes(tracki);
+            
+            for (int t = 0; t < 16; t++){
+                VPA[tracki].VPArrayNotes[t].done = false;
+            }
+         }
+     }
+     
+     */
+    
+    
+//-------------------------------------------------------------------------------------------------------------------------------
+
+/*    public void calcRemainingNotes(int tracki){
+        int counter = -1;
+        int looped = 0;
+        while (no1s + no3s + no5s + no7s + no9s + no11s + no13s != 0){
+            counter++;
+            if (counter >= notesOnArray[tracki]){
+                counter = 0;
+                looped++;
+            }
+            int nextExtension = hvArray[counter];
+            if(extensionNeeded(nextExtension)){
+                for (int playingNotesi = 0; playingNotesi < 16; playingNotesi++){
+                    if (VPA[tracki].VPArrayNotes[playingNotesi].VPNoteOn == true && !VPA[tracki].VPArrayNotes[playingNotesi].done){
+                        if (extensionPossible(playingNotesi, nextExtension)){
+                            VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch = getHeresyPitch(nextExtension, playingNotesi);
+                            VPA[tracki].VPArrayNotes[playingNotesi].done = true;
+                            println("got pitch " + VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch); 
+                      //    correctIfNeeded(tracki, playingNotesi, nextExtension); 
+                        }else println("wasn't possible");
+                    }
+                }
+            }
+            if (looped > 3) {
+                for (int playingNotesi = 0; playingNotesi < 16; playingNotesi++){
+                    if (VPA[tracki].VPArrayNotes[playingNotesi].VPNoteOn == true && !VPA[tracki].VPArrayNotes[playingNotesi].done){
+                        VPA[tracki].VPArrayNotes[playingNotesi].VPNoteOn = false;
+                        VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch = -1;
+                    }
+                }
+                System.out.println("Had to break_________________");
+                break;
+            }
+        }
+    }
+    
+    */
+    
+    
+//-------------------------------------------------------------------------------------------------------------------------------    
+  
+ /*   public void correctIfNeeded(int tracki, int playingNotesi, int nextExtension){ // changes note pitch of a virtual note on to a different octave in needed for voice leading
+        boolean alreadyGotNote = false; boolean alreadyGotNotePlus12 = false; boolean alreadyGotNoteMinus12 = false; 
+        int pitchAverage = 0;
+        for (int i = 0; i < 16; i++)
+            if (i != playingNotesi){
+                if (VPA[tracki].VPArrayNotes[i].done)
+                    pitchAverage += VPA[tracki].VPArrayNotes[i].VPNotePitch;
+                if (VPA[tracki].VPArrayNotes[i].VPNotePitch == VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch) 
+                    alreadyGotNote = true;
+                if (VPA[tracki].VPArrayNotes[i].VPNotePitch == VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch + 12) 
+                    alreadyGotNotePlus12 = true;
+                if (VPA[tracki].VPArrayNotes[i].VPNotePitch == VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch - 12) 
+                    alreadyGotNoteMinus12 = true;  
+            }
+            if (notesOnArray[tracki]-1 > 0)
+                pitchAverage = pitchAverage / (notesOnArray[tracki]-1);
+            else 
+                pitchAverage = VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch;
+            boolean correctedIt = false;
+            if (alreadyGotNote){
+                println("correcting note..........");
+                if (!alreadyGotNotePlus12 && pitchAverage > VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch){
+                    VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch = VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch + 12;
+                    correctedIt = true;
+                }else
+                    if (!alreadyGotNoteMinus12){
+                        VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch = VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch - 12;
+                        correctedIt = true;
+                    }
+                if (!alreadyGotNoteMinus12 && pitchAverage < VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch){
+                    VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch = VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch - 12;
+                    correctedIt = true;
+                }else
+                    if (!alreadyGotNotePlus12){
+                        VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch = VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch + 12;
+                        correctedIt = true;
+                    }
+               }
+               if (alreadyGotNote && !correctedIt)
+                   VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch = -2;
+               if (!alreadyGotNote || correctedIt){
+                   VPA[tracki].VPArrayNotes[playingNotesi].VPNoteVelocity = 80;
+                   VPA[tracki].VPArrayNotes[playingNotesi].done = true;
+                   VPA[tracki].VPArrayNotes[playingNotesi].played = false;
+                   extensionCounter(false, nextExtension);    
+               }else{
+                   VPA[tracki].VPArrayNotes[playingNotesi].VPNoteVelocity = 80;
+                   VPA[tracki].VPArrayNotes[playingNotesi].done = true;
+               }
+    }
+    
+    */
+
+
+//------------------------------------------------------------------------------------------------------------------------------- 
+
+
+
+ /*   public void checkIfNotesAlreadyFit(int tracki){
+        for (int extensioni = 0; extensioni < notesOnArray[tracki]; extensioni++){
+            boolean extensionFound = false;
+            for (int playingNotesi = 0; playingNotesi < 16; playingNotesi++){
+                if (VPA[tracki].VPArrayNotes[playingNotesi].VPNoteOn && !VPA[tracki].VPArrayNotes[playingNotesi].done && !extensionFound && VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch >= 24){
+                    if (disiredPitch(VPA[tracki].VPArrayNotes[playingNotesi].VPNotePitch, hvArray[extensioni])){
+                        VPA[tracki].VPArrayNotes[playingNotesi].done = true;
+                        extensionFound = true;
+                    }
+                }
+            }
+            if (!extensionFound){
+                extensionCounter(true, hvArray[extensioni]);
+            }
+        }
+    }
+    
+*/
+            
+            
+//-------------------------------------------------------------------------------------------------------------------------------             
+
+ /*   public boolean pitchInChord(int currentPitch){
+        boolean returnValue = false;
+        for (int i = 0; i < 16; i++){
+          //  println("currentPitch " + currentPitch + " getHeresyPitch(hvArray[i], 5) % 12) " + (getHeresyPitch(hvArray[i], 5)));
+            if (currentPitch % 12 == (getHeresyPitch(hvArray[i], 5) % 12));
+                returnValue = true;
+        }
+        return returnValue;
+    }
+ */       
+    
+//-------------------------------------------------------------------------------------------------------------------------------           
+
+ /*    public boolean extensionNeeded(int extension){
+     boolean needed = false;
+         if (extension == 1 && no1s > 0) needed = true;
+         if (extension == 3 && no3s > 0) needed = true;
+         if (extension == 5 && no5s > 0) needed = true;
+         if (extension == 7 && no7s > 0) needed = true;
+         if (extension == 9 && no9s > 0) needed = true;
+         if (extension == 11 && no11s > 0) needed = true;
+         if (extension == 13 && no13s > 0) needed = true;
+         return needed;
+     }
+   */
+    
+
+//------------------------------------------------------------------------------------------------------------------------------- 
+
+  /*  public int extensionMatch(){
+        int returnValue = -1;
+        for (int i = 0; i < 16; i++){
+            if( hvArray[i] == 1 && no1s > 0){
+                returnValue =  hvArray[i];
+                break;
+            }
+            if( hvArray[i] == 3 && no3s > 0){
+                returnValue =  hvArray[i];
+                break;
+            }
+            if( hvArray[i] == 5 && no5s > 0){
+                returnValue = hvArray[i];
+                break;
+            }
+            if( hvArray[i] == 7 && no7s > 0){
+                returnValue = hvArray[i];
+                break;
+            }
+            if( hvArray[i] == 9 && no9s > 0){
+                returnValue = hvArray[i];
+                break;
+            }
+            if( hvArray[i] == 11 && no11s > 0){
+                returnValue = hvArray[i];
+                break;
+            }
+            if( hvArray[i] == 13 && no13s > 0){
+                returnValue = hvArray[i];
+                break;
+            }
+        }
+        return returnValue;
+    }
+    
+    */
+      
+
+    
+    
+//-------------------------------------------------------------------------------------------------------------------------------   
+
+/*    public boolean extensionPossible(int playingNotesi, int extentionNeeded){
+        Boolean returnValue = true;
+        if (extentionNeeded != 1 && playingNotesi < 2) returnValue =  false;
+        if ((extentionNeeded == 5 || extentionNeeded == 7 || extentionNeeded == 1) && playingNotesi == 3) returnValue = false;
+        if (!returnValue) println ("returning no on playingNotesi = " + playingNotesi + " and " + extentionNeeded);
+        return returnValue;
+    }
+ */   
+    
+//-------------------------------------------------------------------------------------------------------------------------------
+
+/*    public boolean disiredPitch(int pitch, int extension){  // returns a value for voice leading purposes.  If true then pitch is already in current chord
+        if (pitch % 12 == getExtentionPitch(extension) % 12)
+            return true;
+        else return false;
+    }
+  */ 
+    
+//-------------------------------------------------------------------------------------------------------------------------------
+
+  /*  public int getExtentionPitch(int extension){  //
+        if (!heresyMinor){
+            if (currentChord-tonic == 1)  return tritoneSystem[extension/2]+currentChord;
+            if (currentChord-tonic == 7)  return dom7System[extension/2]+currentChord;
+            if (currentChord-tonic != 1 || currentChord-tonic != 7) return major7System[extension/2]+currentChord;
+        }
+        if (heresyMinor)
+            return minorSystem[extension/2]+currentChord;
+        else
+            return -1;
+   }
+    */
+    
+    
+//-------------------------------------------------------------------------------------------------------------------------------
+
+ /*   public void extensionCounter(boolean positive, int currentDesiredExtention){
+        if (currentDesiredExtention == 1) if (positive) no1s++; else no1s--;
+        if (currentDesiredExtention == 3) if (positive) no3s++; else no3s--;
+        if (currentDesiredExtention == 5) if (positive) no5s++; else no5s--;
+        if (currentDesiredExtention == 7) if (positive) no7s++; else no7s--;
+        if (currentDesiredExtention == 9) if (positive) no9s++; else no9s--;
+        if (currentDesiredExtention == 11) if (positive) no11s++; else no11s--;
+        if (currentDesiredExtention == 13) if (positive) no13s++; else no13s--;
+    }
+ */                                   
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+    public void workOutExtensions(){  // calculates whether the performer wants chord extensions
+        if (tracks[0].sequence[3][currentPulse%(tracks[0].loopLength)] != null && tracks[0].sequence[3][currentPulse%(tracks[0].loopLength)].noteVelocity == 0  && trSelected == 0 && noteOnArray[3])
+            tracks[0].sequence[3][currentPulse%(tracks[0].loopLength)] = null;
+        if (tracks[0].sequence[2][currentPulse%(tracks[0].loopLength)] != null && tracks[0].sequence[2][currentPulse%(tracks[0].loopLength)].noteVelocity == 0  && trSelected == 0 && noteOnArray[2])
+            tracks[0].sequence[2][currentPulse%(tracks[0].loopLength)] = null;
+        if (tracks[0].sequence[1][currentPulse%(tracks[0].loopLength)] != null && tracks[0].sequence[1][currentPulse%(tracks[0].loopLength)].noteVelocity == 0  && trSelected == 0 && noteOnArray[1])
+            tracks[0].sequence[1][currentPulse%(tracks[0].loopLength)] = null;
+        if (tracks[0].sequence[0][currentPulse%(tracks[0].loopLength)] != null && tracks[0].sequence[0][currentPulse%(tracks[0].loopLength)].noteVelocity == 0  && trSelected == 0 && noteOnArray[0])
+            tracks[0].sequence[0][currentPulse%(tracks[0].loopLength)] = null;         
+
+        if (tracks[0].sequence[3][currentPulse%(tracks[0].loopLength)] != null && tracks[0].sequence[3][currentPulse%(tracks[0].loopLength)].noteVelocity > 0)
+            heresy7th = true;
+        if (tracks[0].sequence[3][currentPulse%(tracks[0].loopLength)] != null && tracks[0].sequence[3][currentPulse%(tracks[0].loopLength)].noteVelocity == 0)
+            heresy7th = false;
+        if (tracks[0].sequence[2][currentPulse%(tracks[0].loopLength)] != null && tracks[0].sequence[2][currentPulse%(tracks[0].loopLength)].noteVelocity > 0)
+            heresy9th = true;
+        if (tracks[0].sequence[2][currentPulse%(tracks[0].loopLength)] != null && tracks[0].sequence[2][currentPulse%(tracks[0].loopLength)].noteVelocity == 0)
+            heresy9th = false;    
+        if (tracks[0].sequence[1][currentPulse%(tracks[0].loopLength)] != null && tracks[0].sequence[1][currentPulse%(tracks[0].loopLength)].noteVelocity > 0)
+            heresy11th = true;
+        if (tracks[0].sequence[1][currentPulse%(tracks[0].loopLength)] != null && tracks[0].sequence[1][currentPulse%(tracks[0].loopLength)].noteVelocity == 0)
+            heresy11th = false;
+        if (tracks[0].sequence[0][currentPulse%(tracks[0].loopLength)] != null && tracks[0].sequence[0][currentPulse%(tracks[0].loopLength)].noteVelocity > 0)
+            heresy13th = true;
+        if (tracks[0].sequence[0][currentPulse%(tracks[0].loopLength)] != null && tracks[0].sequence[0][currentPulse%(tracks[0].loopLength)].noteVelocity == 0)
+            heresy13th = false;
+            //---
+        if (chordsTemp.sequence[3][currentPulse%(chordsTemp.loopLength)] != null && chordsTemp.sequence[3][currentPulse%(chordsTemp.loopLength)].noteVelocity == 0  && trSelected == 0 && noteOnArray[3])
+            chordsTemp.sequence[3][currentPulse%(chordsTemp.loopLength)] = null;
+        if (chordsTemp.sequence[2][currentPulse%(chordsTemp.loopLength)] != null && chordsTemp.sequence[2][currentPulse%(chordsTemp.loopLength)].noteVelocity == 0  && trSelected == 0 && noteOnArray[2])
+            chordsTemp.sequence[2][currentPulse%(chordsTemp.loopLength)] = null;
+        if (chordsTemp.sequence[1][currentPulse%(chordsTemp.loopLength)] != null && chordsTemp.sequence[1][currentPulse%(chordsTemp.loopLength)].noteVelocity == 0  && trSelected == 0 && noteOnArray[1])
+            chordsTemp.sequence[1][currentPulse%(chordsTemp.loopLength)] = null;
+        if (chordsTemp.sequence[0][currentPulse%(chordsTemp.loopLength)] != null && chordsTemp.sequence[0][currentPulse%(chordsTemp.loopLength)].noteVelocity == 0  && trSelected == 0 && noteOnArray[0])
+            chordsTemp.sequence[0][currentPulse%(chordsTemp.loopLength)] = null;         
+
+        if (chordsTemp.sequence[3][currentPulse%(chordsTemp.loopLength)] != null && chordsTemp.sequence[3][currentPulse%(chordsTemp.loopLength)].noteVelocity > 0)
+            heresy7th = true;
+        if (chordsTemp.sequence[3][currentPulse%(chordsTemp.loopLength)] != null && chordsTemp.sequence[3][currentPulse%(chordsTemp.loopLength)].noteVelocity == 0)
+            heresy7th = false;
+        if (chordsTemp.sequence[2][currentPulse%(chordsTemp.loopLength)] != null && chordsTemp.sequence[2][currentPulse%(chordsTemp.loopLength)].noteVelocity > 0)
+            heresy9th = true;
+        if (chordsTemp.sequence[2][currentPulse%(chordsTemp.loopLength)] != null && chordsTemp.sequence[2][currentPulse%(chordsTemp.loopLength)].noteVelocity == 0)
+            heresy9th = false;    
+        if (chordsTemp.sequence[1][currentPulse%(chordsTemp.loopLength)] != null && chordsTemp.sequence[1][currentPulse%(chordsTemp.loopLength)].noteVelocity > 0)
+            heresy11th = true;
+        if (chordsTemp.sequence[1][currentPulse%(chordsTemp.loopLength)] != null && chordsTemp.sequence[1][currentPulse%(chordsTemp.loopLength)].noteVelocity == 0)
+            heresy11th = false;
+        if (chordsTemp.sequence[0][currentPulse%(chordsTemp.loopLength)] != null && chordsTemp.sequence[0][currentPulse%(chordsTemp.loopLength)].noteVelocity > 0)
+            heresy13th = true;
+        if (chordsTemp.sequence[0][currentPulse%(chordsTemp.loopLength)] != null && chordsTemp.sequence[0][currentPulse%(chordsTemp.loopLength)].noteVelocity == 0)
+            heresy13th = false;
+            
+    }
+    
+    
+//-------------------------------------------------------------------------------------------------------------------------------
+    
+    public void workOutChord(){ // calculates current chord and major minor tonality
+        for (int i = 4; i < 16; i++) {
+            if (tracks[0] != null){
+                if ((tracks[0].sequence[i][currentPulse%(tracks[0].loopLength)] != null && tracks[0].sequence[i][currentPulse%(tracks[0].loopLength)].noteVelocity > 0 )||
+                   (chordsTemp.sequence[i][currentPulse%(tracks[0].loopLength)] != null && chordsTemp.sequence[i][currentPulse%(chordsTemp.loopLength)].noteVelocity > 0 )){
+                    currentChord = 15 - i;
+                    boolean iiDone = false;
+                    for (int ii = 0;; ii--){
+                        if (ii == 0 && iiDone)
+                            break;
+                        if (currentPulse%(tracks[0].loopLength)+ii  == 0)
+                            ii = tracks[0].loopLength+ii-1;
+                        if (i > 3){
+                            if ((tracks[0].sequence[i-1][currentPulse%(tracks[0].loopLength)+ii] != null && tracks[0].sequence[i-1][currentPulse%(tracks[0].loopLength)+ii].noteVelocity == 0 ) ||
+                                 (chordsTemp.sequence[i-1][currentPulse%(chordsTemp.loopLength)+ii] != null && chordsTemp.sequence[i-1][currentPulse%(chordsTemp.loopLength)+ii].noteVelocity == 0 ))
+                                 break;
+                            if ((tracks[0].sequence[i-1][currentPulse%(tracks[0].loopLength)+ii] != null && tracks[0].sequence[i-1][currentPulse%(tracks[0].loopLength)+ii].noteVelocity != 0 ) ||
+                                 (chordsTemp.sequence[i-1][currentPulse%(chordsTemp.loopLength)+ii] != null && chordsTemp.sequence[i-1][currentPulse%(chordsTemp.loopLength)+ii].noteVelocity != 0 )){
+                                heresyMinor = true;
+                                break;
+                            }else
+                                heresyMinor = false;
+                        }
+                        iiDone = true;
+                    }
+                }
+            }
+        }
+    }
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+    
+    public void heresyChangeHistory(){  // remembers whether the chords or extensions have changed
+        if (currentChord != lastChord){
+            heresyChordChanged = true;
+            lastChord = currentChord;
+            heresyChange = true; 
+        }
+        if (heresyMinor != oldHeresyMinor){
+            heresyMinorChanged = true;
+            oldHeresyMinor = heresyMinor;
+            heresyChange = true;
+        }
+        if (heresy7th != oldHeresy7th){
+            heresy7thChanged = true;
+            oldHeresy7th = heresy7th;
+            heresyChange = true;
+        }
+        if (heresy9th != oldHeresy9th){
+            heresy9thChanged = true;
+            oldHeresy9th = heresy9th;
+            heresyChange = true;
+        }
+        if (heresy11th != oldHeresy11th){
+            heresy11thChanged = true;
+            oldHeresy11th = heresy11th;
+            heresyChange = true;
+        }
+        if (heresy13th != oldHeresy13th){
+            heresy13thChanged = true;
+            oldHeresy13th = heresy13th;
+            heresyChange = true;
+        }
+    }
+
+
+      
+       
+    
+// the main voicing tables for chords requested
+
+// root position
+
+int[] hchoice135 = new int[]  {24,  36,  43,  48,  52,  55,  60,  64,  67,  72,  76,  79,  84,  88,  91,  96};
+int[] hchoice7 = new int[]    {24,  36,  43,  48,  52,  55,  59,  64,  67,  71,  72,  76,  79,  83,  88,  95};
+int[] hchoice9 = new int[]    {24,  36,  43,  48,  50,  52,  55,  60,  62,  64,  67,  74,  76,  79,  86,  91};
+int[] hchoice11 = new int[]   {24,  36,  43,  48,  53,  55,  60,  65,  67,  72,  77,  79,  84,  89,  91,  96};
+int[] hchoice13 = new int[]   {24,  36,  43,  48,  52,  55,  57,  60,  64,  69,  72,  76,  81,  84,  88,  93};
+int[] hchoice79 = new int[]   {24,  36,  43,  48,  52,  55,  57,  59,  62,  64,  69,  71,  74,  76,  83,  86};
+int[] hchoice711 = new int[]  {24,  36,  43,  48,  53,  55,  59,  60,  65,  67,  71,  72,  77,  83,  88,  95}; //nice
+int[] hchoice713 = new int[]  {24,  36,  43,  48,  52,  57,  59,  64,  69,  71,  76,  79,  81,  83,  88,  93};
+int[] hchoice911 = new int[]  {24,  36,  43,  48,  53,  55,  60,  62,  65,  67,  74,  77,  79,  86,  89,  96};
+int[] hchoice913 = new int[]  {24,  36,  43,  48,  50,  57,  60,  62,  69,  72,  74,  81,  84,  86,  93,  96};
+int[] hchoice1113 = new int[] {24,  36,  43,  48,  52,  53,  57,  60,  64,  65,  69,  72,  77,  81,  84,  93}; //nice
+int[] hchoice7911 = new int[] {24,  36,  43,  48,  55,  62,  65,  71,  77,  79,  83,  84,  86,  89,  91,  96};
+int[] hchoice7913 = new int[] {24,  36,  43,  48,  59,  62,  69,  71,  74,  81,  83,  84,  86,  93,  95,  96};
+int[] hchoice71113 = new int[]{24,  36,  43,  48,  55,  59,  65,  69,  76,  77,  79,  84,  88,  89,  93,  96};
+int[] hchoice91113 = new int[]{24,  36,  48,  50,  53,  57,  60,  62,  65,  69,  72,  74,  77,  81,  89,  96};
+int[] hchoice791113 = new int[]{24,  36,  50,  53,  58,  62,  65,  70,  74,  77,  82,  84,  86,  89,  94,  96}; //dom7th full sus chord
+
+int[] mhchoice135 = new int[]  {24,  36,  43,  48,  51,  55,  60,  63,  67,  72,  75,  79,  84,  87,  91,  96};//
+int[] mhchoice7 = new int[]    {24,  36,  43,  48,  51,  55,  58,  63,  67,  70,  72,  75,  79,  82,  87,  94};//
+int[] mhchoice9 = new int[]    {24,  36,  43,  48,  50,  51,  55,  60,  62,  63,  67,  72,  74,  79,  86,  91};//
+int[] mhchoice11 = new int[]   {24,  36,  43,  48,  51,  53,  55,  60,  63,  65,  67,  72,  77,  79,  84,  89};//
+int[] mhchoice13 = new int[]   {24,  36,  43,  48,  51,  55,  57,  60,  63,  67,  69,  72,  75,  81,  84,  91};//
+int[] mhchoice79 = new int[]   {24,  36,  43,  50,  51,  55,  57,  58,  62,  63,  69,  70,  74,  75,  82,  86};//
+int[] mhchoice711 = new int[]  {24,  36,  43,  51,  58,  63,  65,  69,  72,  75,  77,  79,  82,  84,  89,  96};// 
+int[] mhchoice713 = new int[]  {24,  36,  43,  48,  55,  58,  59,  63,  69,  75,  79,  81,  82,  84,  93,  96};//
+int[] mhchoice911 = new int[]  {24,  36,  43,  48,  51,  53,  62,  63,  65,  67,  74,  77,  79,  86,  89,  96};//
+int[] mhchoice913 = new int[]  {24,  36,  43,  51,  57,  62,  63,  69,  74,  75,  81,  84,  86,  87,  93,  96};//
+int[] mhchoice1113 = new int[] {24,  36,  43,  53,  57,  63,  67,  72,  75,  77,  79,  81,  84,  87,  93,  96};// 
+int[] mhchoice7911 = new int[] {24,  36,  43,  50,  51,  58,  65,  67,  70,  72,  74,  75,  77,  79,  82,  86};//
+int[] mhchoice7913 = new int[] {24,  36,  48,  55,  58,  62,  63,  69,  70,  74,  75,  79,  81,  84,  93,  96};//
+int[] mhchoice71113 = new int[]{24,  36,  43,  48,  53,  58,  63,  65,  69,  72,  75,  77,  81,  84,  91,  96};//
+int[] mhchoice91113 = new int[]{24,  36,  48,  50,  53,  57,  60,  62,  65,  69,  72,  74,  77,  81,  89,  96};//
+int[] mhchoice791113 = new int[]{24,  36,  50,  53,  58,  62,  65,  70,  74,  77,  82,  84,  86,  89,  94,  96}; //dom7th full sus chord
+
+// first inversion
+
+int[] h1choice135 = new int[]  {24,  36,  40,  43,  48,  52,  55,  60,  64,  67,  72,  76,  79,  84,  88,  91};
+int[] h1choice7 = new int[]    {24,  36,  40,  43,  48,  52,  55,  59,  64,  67,  71,  72,  76,  79,  83,  88};
+int[] h1choice9 = new int[]    {24,  36,  38,  43,  48,  50,  52,  55,  60,  62,  64,  67,  74,  76,  79,  86};
+int[] h1choice11 = new int[]   {24,  36,  41,  43,  48,  53,  55,  60,  65,  67,  72,  77,  79,  84,  89,  91};
+int[] h1choice13 = new int[]   {24,  36,  40,  43,  48,  52,  55,  57,  60,  64,  69,  72,  76,  81,  84,  88};
+int[] h1choice79 = new int[]   {24,  36,  40,  43,  48,  52,  55,  57,  59,  62,  64,  69,  71,  74,  76,  83};
+int[] h1choice711 = new int[]  {24,  36,  41,  43,  48,  53,  55,  59,  60,  65,  67,  71,  72,  77,  83,  88}; //nice
+int[] h1choice713 = new int[]  {24,  36,  40,  43,  48,  52,  57,  59,  64,  69,  71,  76,  79,  81,  83,  88};
+int[] h1choice911 = new int[]  {24,  36,  41,  43,  48,  53,  55,  60,  62,  65,  67,  74,  77,  79,  86,  89};
+int[] h1choice913 = new int[]  {24,  36,  43,  45,  48,  50,  57,  60,  62,  69,  72,  74,  81,  84,  86,  93};
+int[] h1choice1113 = new int[] {24,  36,  40,  43,  48,  52,  53,  57,  60,  64,  65,  69,  72,  77,  81,  84}; //nice
+int[] h1choice7911 = new int[] {24,  36,  43,  48,  50,  55,  62,  65,  71,  77,  79,  83,  84,  86,  89,  91};
+int[] h1choice7913 = new int[] {24,  36,  43,  48,  55,  59,  62,  69,  71,  74,  81,  83,  84,  86,  93,  95};
+int[] h1choice71113 = new int[]{24,  36,  43,  48,  53,  55,  59,  65,  69,  76,  77,  79,  84,  88,  89,  93};
+int[] h1choice91113 = new int[]{24,  36,  41,  48,  50,  53,  57,  60,  62,  65,  69,  72,  74,  77,  81,  89};
+int[] h1choice791113 = new int[]{24,  36,  43,  50,  53,  58,  62,  65,  70,  74,  77,  82,  84,  86,  89,  94}; //dom7th full sus chord
+
+int[] m1hchoice135 = new int[]  {24,  36,  39,  43,  48,  51,  55,  60,  63,  67,  72,  75,  79,  84,  87,  91};//
+int[] m1hchoice7 = new int[]    {24,  36,  39,  43,  48,  51,  55,  58,  63,  67,  70,  72,  75,  79,  82,  87};//
+int[] m1hchoice9 = new int[]    {24,  36,  38,  43,  48,  50,  51,  55,  60,  62,  63,  67,  72,  74,  79,  86};//
+int[] m1hchoice11 = new int[]   {24,  36,  39,  43,  48,  51,  53,  55,  60,  63,  65,  67,  72,  77,  79,  84};//
+int[] m1hchoice13 = new int[]   {24,  36,  39,  43,  48,  51,  55,  57,  60,  63,  67,  69,  72,  75,  81,  84};//
+int[] m1hchoice79 = new int[]   {24,  36,  39,  43,  50,  51,  55,  57,  58,  62,  63,  69,  70,  74,  75,  82};//
+int[] m1hchoice711 = new int[]  {24,  36,  43,  46,  51,  58,  63,  65,  69,  72,  75,  77,  79,  82,  84,  89};// 
+int[] m1hchoice713 = new int[]  {24,  36,  43,  46,  48,  55,  58,  59,  63,  69,  75,  79,  81,  82,  84,  93};//
+int[] m1hchoice911 = new int[]  {24,  36,  39,  43,  48,  51,  53,  62,  63,  65,  67,  74,  77,  79,  86,  89};//
+int[] m1hchoice913 = new int[]  {24,  36,  43,  48,  51,  57,  62,  63,  69,  74,  75,  81,  84,  86,  87,  93};//
+int[] m1hchoice1113 = new int[] {24,  36,  43,  45,  53,  57,  63,  67,  72,  75,  77,  79,  81,  84,  87,  93};// 
+int[] m1hchoice7911 = new int[] {24,  36,  39,  43,  50,  51,  58,  65,  67,  70,  72,  74,  75,  77,  79,  82};//
+int[] m1hchoice7913 = new int[] {24,  36,  43,  48,  55,  58,  62,  63,  69,  70,  74,  75,  79,  81,  84,  93};//
+int[] m1hchoice71113 = new int[]{24,  36,  43,  46,  48,  53,  58,  63,  65,  69,  72,  75,  77,  81,  84,  91};//
+int[] m1hchoice91113 = new int[]{24,  36,  41,  48,  50,  53,  57,  60,  62,  65,  69,  72,  74,  77,  81,  89};//
+int[] m1hchoice791113 = new int[]{24,  36,  46,  50,  53,  58,  62,  65,  70,  74,  77,  82,  84,  86,  89,  94}; //dom7th full sus chord
+
+// second inversion
+
+int[] h2choice135 = new int[]  {24,  31,  36,  40,  43,  48,  52,  55,  60,  64,  67,  72,  76,  79,  84,  88};
+int[] h2choice7 = new int[]    {24,  31,  36,  40,  43,  48,  52,  55,  59,  64,  67,  71,  72,  76,  79,  83};
+int[] h2choice9 = new int[]    {24,  31,  36,  38,  43,  48,  50,  52,  55,  60,  62,  64,  67,  74,  76,  79};
+int[] h2choice11 = new int[]   {24,  31,  36,  41,  43,  48,  53,  55,  60,  65,  67,  72,  77,  79,  84,  89};
+int[] h2choice13 = new int[]   {24,  31,  36,  40,  43,  48,  52,  55,  57,  60,  64,  69,  72,  76,  81,  84};
+int[] h2choice79 = new int[]   {24,  31,  36,  40,  43,  48,  52,  55,  57,  59,  62,  64,  69,  71,  74,  76};
+int[] h2choice711 = new int[]  {24,  31,  36,  41,  43,  48,  53,  55,  59,  60,  65,  67,  71,  72,  77,  83}; //nice
+int[] h2choice713 = new int[]  {24,  31,  36,  40,  43,  48,  52,  57,  59,  64,  69,  71,  76,  79,  81,  83};
+int[] h2choice911 = new int[]  {24,  31,  36,  41,  43,  48,  53,  55,  60,  62,  65,  67,  74,  77,  79,  86};
+int[] h2choice913 = new int[]  {24,  31,  36,  43,  45,  48,  50,  57,  60,  62,  69,  72,  74,  81,  84,  86};
+int[] h2choice1113 = new int[] {24,  31,  36,  40,  43,  48,  52,  53,  57,  60,  64,  65,  69,  72,  77,  81}; //nice
+int[] h2choice7911 = new int[] {24,  31,  36,  43,  48,  50,  55,  62,  65,  71,  77,  79,  83,  84,  86,  89};
+int[] h2choice7913 = new int[] {24,  31,  36,  43,  48,  55,  59,  62,  69,  71,  74,  81,  83,  84,  86,  93};
+int[] h2choice71113 = new int[]{24,  31,  36,  43,  48,  53,  55,  59,  65,  69,  76,  77,  79,  84,  88,  89};
+int[] h2choice91113 = new int[]{24,  31,  36,  41,  48,  50,  53,  57,  60,  62,  65,  69,  72,  74,  77,  81};
+int[] h2choice791113 = new int[]{24,  31,  36,  43,  50,  53,  58,  62,  65,  70,  74,  77,  82,  84,  86,  89}; //dom7th full sus chord
+
+int[] m2hchoice135 = new int[]  {24,  31,  36,  39,  43,  48,  51,  55,  60,  63,  67,  72,  75,  79,  84,  87};//
+int[] m2hchoice7 = new int[]    {24,  31,  36,  39,  43,  48,  51,  55,  58,  63,  67,  70,  72,  75,  79,  82};//
+int[] m2hchoice9 = new int[]    {24,  31,  36,  38,  43,  48,  50,  51,  55,  60,  62,  63,  67,  72,  74,  79};//
+int[] m2hchoice11 = new int[]   {24,  31,  36,  39,  43,  48,  51,  53,  55,  60,  63,  65,  67,  72,  77,  79};//
+int[] m2hchoice13 = new int[]   {24,  31,  36,  39,  43,  48,  51,  55,  57,  60,  63,  67,  69,  72,  75,  81};//
+int[] m2hchoice79 = new int[]   {24,  31,  36,  39,  43,  50,  51,  55,  57,  58,  62,  63,  69,  70,  74,  75};//
+int[] m2hchoice711 = new int[]  {24,  31,  36,  43,  46,  51,  58,  63,  65,  69,  72,  75,  77,  79,  82,  84};// 
+int[] m2hchoice713 = new int[]  {24,  31,  36,  43,  46,  48,  55,  58,  59,  63,  69,  75,  79,  81,  82,  84};//
+int[] m2hchoice911 = new int[]  {24,  31,  36,  39,  43,  48,  51,  53,  62,  63,  65,  67,  74,  77,  79,  86};//
+int[] m2hchoice913 = new int[]  {24,  31,  36,  43,  48,  51,  57,  62,  63,  69,  74,  75,  81,  84,  86,  87};//
+int[] m2hchoice1113 = new int[] {24,  31,  36,  43,  45,  53,  57,  63,  67,  72,  75,  77,  79,  81,  84,  87};// 
+int[] m2hchoice7911 = new int[] {24,  31,  36,  39,  43,  50,  51,  58,  65,  67,  70,  72,  74,  75,  77,  79};//
+int[] m2hchoice7913 = new int[] {24,  31,  36,  43,  48,  55,  58,  62,  63,  69,  70,  74,  75,  79,  81,  84};//
+int[] m2hchoice71113 = new int[]{24,  31,  36,  43,  46,  48,  53,  58,  63,  65,  69,  72,  75,  77,  81,  84};//
+int[] m2hchoice91113 = new int[]{24,  31,  36,  41,  48,  50,  53,  57,  60,  62,  65,  69,  72,  74,  77,  81};//
+int[] m2hchoice791113 = new int[]{24,  31,  36,  46,  50,  53,  58,  62,  65,  70,  74,  77,  82,  84,  86,  89}; //dom7th full sus chord
+
+int[] hvArray;
+int[] minorSystem = new int[] {0, 3, 7, 10, 14, 17, 21};
+int[] major7System = new int[] {0, 4, 7, 11, 14, 18, 21};
+int[] dom7System = new int[] {0, 4, 7, 10, 14, 17, 21};
+int[] tritoneSystem = new int[] {0, 4, 7, 10, 14, 18, 21};
+
+public int heresyPitch(int arrayPosition, int heresyChannel){  //  calculates the pitch value to be returned for playback.
+    boolean m = heresyMinor;
+    boolean e7 = heresy7th;
+    boolean e9 = heresy9th;
+    boolean e11 = heresy11th;
+    boolean e13 = heresy13th;
+    int returnInt = 0;
+    if ((currentChord % 12) > -1 && (currentChord % 12) < 4){
+        if (!m && !e7 && !e9 && !e11 && !e13) returnInt = hchoice135[15 - arrayPosition];
+        if (!m &&  e7 && !e9 && !e11 && !e13) returnInt = hchoice7[15 - arrayPosition];
+        if (!m && !e7 &&  e9 && !e11 && !e13) returnInt = hchoice9[15 - arrayPosition];
+        if (!m && !e7 && !e9 &&  e11 && !e13) returnInt = hchoice11[15 - arrayPosition];
+        if (!m && !e7 && !e9 && !e11 &&  e13) returnInt = hchoice13[15 - arrayPosition];
+        if (!m &&  e7 &&  e9 && !e11 && !e13) returnInt = hchoice79[15 - arrayPosition]; 
+        if (!m &&  e7 && !e9 &&  e11 && !e13) returnInt = hchoice711[15 - arrayPosition]; 
+        if (!m &&  e7 && !e9 && !e11 &&  e13) returnInt = hchoice713[15 - arrayPosition];
+        if (!m && !e7 &&  e9 &&  e11 && !e13) returnInt = hchoice911[15 - arrayPosition];
+        if (!m && !e7 &&  e9 && !e11 &&  e13) returnInt = hchoice913[15 - arrayPosition];
+        if (!m && !e7 && !e9 &&  e11 &&  e13) returnInt = hchoice1113[15 - arrayPosition];
+        if (!m &&  e7 &&  e9 &&  e11 && !e13) returnInt = hchoice7911[15 - arrayPosition];
+        if (!m &&  e7 &&  e9 && !e11 &&  e13) returnInt = hchoice7913[15 - arrayPosition];
+        if (!m &&  e7 && !e9 &&  e11 &&  e13) returnInt = hchoice71113[15 - arrayPosition];
+        if (!m && !e7 &&  e9 &&  e11 &&  e13) returnInt = hchoice91113[15 - arrayPosition];
+        if (!m &&  e7 &&  e9 &&  e11 &&  e13) returnInt = hchoice791113[15 - arrayPosition];
+    
+        if (m && !e7 && !e9 && !e11 && !e13) returnInt = mhchoice135[15 - arrayPosition];
+        if (m &&  e7 && !e9 && !e11 && !e13) returnInt = mhchoice7[15 - arrayPosition];
+        if (m && !e7 &&  e9 && !e11 && !e13) returnInt = mhchoice9[15 - arrayPosition];
+        if (m && !e7 && !e9 &&  e11 && !e13) returnInt = mhchoice11[15 - arrayPosition];
+        if (m && !e7 && !e9 && !e11 &&  e13) returnInt = mhchoice13[15 - arrayPosition];
+        if (m &&  e7 &&  e9 && !e11 && !e13) returnInt = mhchoice79[15 - arrayPosition]; 
+        if (m &&  e7 && !e9 &&  e11 && !e13) returnInt = mhchoice711[15 - arrayPosition]; 
+        if (m &&  e7 && !e9 && !e11 &&  e13) returnInt = mhchoice713[15 - arrayPosition];
+        if (m && !e7 &&  e9 &&  e11 && !e13) returnInt = mhchoice911[15 - arrayPosition];
+        if (m && !e7 &&  e9 && !e11 &&  e13) returnInt = mhchoice913[15 - arrayPosition];
+        if (m && !e7 && !e9 &&  e11 &&  e13) returnInt = mhchoice1113[15 - arrayPosition];
+        if (m &&  e7 &&  e9 &&  e11 && !e13) returnInt = mhchoice7911[15 - arrayPosition];
+        if (m &&  e7 &&  e9 && !e11 &&  e13) returnInt = mhchoice7913[15 - arrayPosition];
+        if (m &&  e7 && !e9 &&  e11 &&  e13) returnInt = mhchoice71113[15 - arrayPosition];
+        if (m && !e7 &&  e9 &&  e11 &&  e13) returnInt = mhchoice91113[15 - arrayPosition];
+        if (m &&  e7 &&  e9 &&  e11 &&  e13) returnInt = mhchoice791113[15 - arrayPosition];
+    }
+    
+        if ((currentChord % 12) > 3 && (currentChord % 12) < 8){
+        if (!m && !e7 && !e9 && !e11 && !e13) returnInt = h1choice135[15 - arrayPosition];
+        if (!m &&  e7 && !e9 && !e11 && !e13) returnInt = h1choice7[15 - arrayPosition];
+        if (!m && !e7 &&  e9 && !e11 && !e13) returnInt = h1choice9[15 - arrayPosition];
+        if (!m && !e7 && !e9 &&  e11 && !e13) returnInt = h1choice11[15 - arrayPosition];
+        if (!m && !e7 && !e9 && !e11 &&  e13) returnInt = h1choice13[15 - arrayPosition];
+        if (!m &&  e7 &&  e9 && !e11 && !e13) returnInt = h1choice79[15 - arrayPosition]; 
+        if (!m &&  e7 && !e9 &&  e11 && !e13) returnInt = h1choice711[15 - arrayPosition]; 
+        if (!m &&  e7 && !e9 && !e11 &&  e13) returnInt = h1choice713[15 - arrayPosition];
+        if (!m && !e7 &&  e9 &&  e11 && !e13) returnInt = h1choice911[15 - arrayPosition];
+        if (!m && !e7 &&  e9 && !e11 &&  e13) returnInt = h1choice913[15 - arrayPosition];
+        if (!m && !e7 && !e9 &&  e11 &&  e13) returnInt = h1choice1113[15 - arrayPosition];
+        if (!m &&  e7 &&  e9 &&  e11 && !e13) returnInt = h1choice7911[15 - arrayPosition];
+        if (!m &&  e7 &&  e9 && !e11 &&  e13) returnInt = h1choice7913[15 - arrayPosition];
+        if (!m &&  e7 && !e9 &&  e11 &&  e13) returnInt = h1choice71113[15 - arrayPosition];
+        if (!m && !e7 &&  e9 &&  e11 &&  e13) returnInt = h1choice91113[15 - arrayPosition];
+        if (!m &&  e7 &&  e9 &&  e11 &&  e13) returnInt = h1choice791113[15 - arrayPosition];
+    
+        if (m && !e7 && !e9 && !e11 && !e13) returnInt = m1hchoice135[15 - arrayPosition];
+        if (m &&  e7 && !e9 && !e11 && !e13) returnInt = m1hchoice7[15 - arrayPosition];
+        if (m && !e7 &&  e9 && !e11 && !e13) returnInt = m1hchoice9[15 - arrayPosition];
+        if (m && !e7 && !e9 &&  e11 && !e13) returnInt = m1hchoice11[15 - arrayPosition];
+        if (m && !e7 && !e9 && !e11 &&  e13) returnInt = m1hchoice13[15 - arrayPosition];
+        if (m &&  e7 &&  e9 && !e11 && !e13) returnInt = m1hchoice79[15 - arrayPosition]; 
+        if (m &&  e7 && !e9 &&  e11 && !e13) returnInt = m1hchoice711[15 - arrayPosition]; 
+        if (m &&  e7 && !e9 && !e11 &&  e13) returnInt = m1hchoice713[15 - arrayPosition];
+        if (m && !e7 &&  e9 &&  e11 && !e13) returnInt = m1hchoice911[15 - arrayPosition];
+        if (m && !e7 &&  e9 && !e11 &&  e13) returnInt = m1hchoice913[15 - arrayPosition];
+        if (m && !e7 && !e9 &&  e11 &&  e13) returnInt = m1hchoice1113[15 - arrayPosition];
+        if (m &&  e7 &&  e9 &&  e11 && !e13) returnInt = m1hchoice7911[15 - arrayPosition];
+        if (m &&  e7 &&  e9 && !e11 &&  e13) returnInt = m1hchoice7913[15 - arrayPosition];
+        if (m &&  e7 && !e9 &&  e11 &&  e13) returnInt = m1hchoice71113[15 - arrayPosition];
+        if (m && !e7 &&  e9 &&  e11 &&  e13) returnInt = m1hchoice91113[15 - arrayPosition];
+        if (m &&  e7 &&  e9 &&  e11 &&  e13) returnInt = m1hchoice791113[15 - arrayPosition];
+    }
+    
+        if ((currentChord % 12) > 7 && (currentChord % 12) < 12){
+        if (!m && !e7 && !e9 && !e11 && !e13) returnInt = h2choice135[15 - arrayPosition];
+        if (!m &&  e7 && !e9 && !e11 && !e13) returnInt = h2choice7[15 - arrayPosition];
+        if (!m && !e7 &&  e9 && !e11 && !e13) returnInt = h2choice9[15 - arrayPosition];
+        if (!m && !e7 && !e9 &&  e11 && !e13) returnInt = h2choice11[15 - arrayPosition];
+        if (!m && !e7 && !e9 && !e11 &&  e13) returnInt = h2choice13[15 - arrayPosition];
+        if (!m &&  e7 &&  e9 && !e11 && !e13) returnInt = h2choice79[15 - arrayPosition]; 
+        if (!m &&  e7 && !e9 &&  e11 && !e13) returnInt = h2choice711[15 - arrayPosition]; 
+        if (!m &&  e7 && !e9 && !e11 &&  e13) returnInt = h2choice713[15 - arrayPosition];
+        if (!m && !e7 &&  e9 &&  e11 && !e13) returnInt = h2choice911[15 - arrayPosition];
+        if (!m && !e7 &&  e9 && !e11 &&  e13) returnInt = h2choice913[15 - arrayPosition];
+        if (!m && !e7 && !e9 &&  e11 &&  e13) returnInt = h2choice1113[15 - arrayPosition];
+        if (!m &&  e7 &&  e9 &&  e11 && !e13) returnInt = h2choice7911[15 - arrayPosition];
+        if (!m &&  e7 &&  e9 && !e11 &&  e13) returnInt = h2choice7913[15 - arrayPosition];
+        if (!m &&  e7 && !e9 &&  e11 &&  e13) returnInt = h2choice71113[15 - arrayPosition];
+        if (!m && !e7 &&  e9 &&  e11 &&  e13) returnInt = h2choice91113[15 - arrayPosition];
+        if (!m &&  e7 &&  e9 &&  e11 &&  e13) returnInt = h2choice791113[15 - arrayPosition];
+    
+        if (m && !e7 && !e9 && !e11 && !e13) returnInt = m2hchoice135[15 - arrayPosition];
+        if (m &&  e7 && !e9 && !e11 && !e13) returnInt = m2hchoice7[15 - arrayPosition];
+        if (m && !e7 &&  e9 && !e11 && !e13) returnInt = m2hchoice9[15 - arrayPosition];
+        if (m && !e7 && !e9 &&  e11 && !e13) returnInt = m2hchoice11[15 - arrayPosition];
+        if (m && !e7 && !e9 && !e11 &&  e13) returnInt = m2hchoice13[15 - arrayPosition];
+        if (m &&  e7 &&  e9 && !e11 && !e13) returnInt = m2hchoice79[15 - arrayPosition]; 
+        if (m &&  e7 && !e9 &&  e11 && !e13) returnInt = m2hchoice711[15 - arrayPosition]; 
+        if (m &&  e7 && !e9 && !e11 &&  e13) returnInt = m2hchoice713[15 - arrayPosition];
+        if (m && !e7 &&  e9 &&  e11 && !e13) returnInt = m2hchoice911[15 - arrayPosition];
+        if (m && !e7 &&  e9 && !e11 &&  e13) returnInt = m2hchoice913[15 - arrayPosition];
+        if (m && !e7 && !e9 &&  e11 &&  e13) returnInt = m2hchoice1113[15 - arrayPosition];
+        if (m &&  e7 &&  e9 &&  e11 && !e13) returnInt = m2hchoice7911[15 - arrayPosition];
+        if (m &&  e7 &&  e9 && !e11 &&  e13) returnInt = m2hchoice7913[15 - arrayPosition];
+        if (m &&  e7 && !e9 &&  e11 &&  e13) returnInt = m2hchoice71113[15 - arrayPosition];
+        if (m && !e7 &&  e9 &&  e11 &&  e13) returnInt = m2hchoice91113[15 - arrayPosition];
+        if (m &&  e7 &&  e9 &&  e11 &&  e13) returnInt = m2hchoice791113[15 - arrayPosition];
+    }
+    
+    if (heresyDom && returnInt % 12 == 11)
+        returnInt--;
+    returnInt = currentChord + returnInt;
+    
+  //  if (heresyChannel == 1 || heresyChannel == 5)
+  //      returnInt = 15 - arrayPosition + 36;
+        
+
+        
+    return returnInt;
+}
+
+
+public void sendNote(VPNote note, int channel){ // send note function gathers info to output to max
+    outputToMax(note.VPNotePitch, note.VPNoteVelocity, channel);
+}
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+public void outputToMax(int note, int velocity, int channel){ // calculates the necessary note on and note offs depending on ducking and muting and sends them to max
+    String noteOut = "";
+    if (!tracks[channel].mute){
+        if (tracks[channel].ducking){
+            if (velocity != 0){
+                noteOut = ("" + note + " " + velocity + " " + (channel+8));
+            }
+            if (velocity == 0 && !tracks[channel].cycled){
+                noteOut = ("" + note + " " + velocity + " " + (channel+8));
+                  OscMessage message = new OscMessage("/pitch_vel_chan");
+                  message.add(noteOut);
+                  oscP5return.send(message, ableton);
+                link.output(noteOut);
+                noteOut = ("" + note + " " + velocity + " " + channel);
+            }
+            if (velocity == 0 && tracks[channel].cycled){
+                noteOut = ("" + note + " " + velocity + " " + (channel+8));      
+            }
+        }
+        if (!tracks[channel].ducking){
+            if (velocity != 0){
+                noteOut = ("" + note + " " + velocity + " " + channel);
+            }
+            if (velocity == 0 && !tracks[channel].cycled){
+                noteOut = ("" + note + " " + velocity + " " + (channel+8));
+                  OscMessage message = new OscMessage("/pitch_vel_chan");
+                  message.add(noteOut);
+                  oscP5return.send(message, ableton);
+                link.output(noteOut);
+                noteOut = ("" + note + " " + velocity + " " + channel);
+            }
+            if (velocity == 0 && tracks[channel].cycled){
+                noteOut = ("" + note + " " + velocity + " " + channel);  
+            }
+        }
+        link.output(noteOut);
+        OscMessage message = new OscMessage("/pitch_vel_chan");
+        message.add(noteOut);
+        oscP5return.send(message, ableton);
+        
+    }
+    if (tracks[channel].mute){
+        if (velocity == 0 && !tracks[channel].cycled){
+            noteOut = ("" + note + " " + velocity + " " + (channel+8));
+            link.output(noteOut);
+            OscMessage message = new OscMessage("/pitch_vel_chan");
+            message.add(noteOut);
+            oscP5return.send(message, ableton);
+            noteOut = ("" + note + " " + velocity + " " + channel);
+            OscMessage message2 = new OscMessage("/pitch_vel_chan");
+            message2.add(noteOut);
+            oscP5return.send(message, ableton);
+            link.output(noteOut);
+        }
+    }   
+}
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+public void mouseDragged(){ // not used
+}
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+public void mouseReleased(){ // not used
+}
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+public void mousePressed(){ // not used
+}
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+public void keyPressed() { // takes keyboard input
+    if (key == 'c' || key == 'C') {
+        chordSelecter = !chordSelecter;
+        if (!chordSelecter)
+            trSelected = lastTrack;
+        else{
+            lastTrack = trSelected;
+            trSelected = 0;
+            
+        }
+    }
+    
+    if (key == ' ') {
+        if (trSelected != 0){
+            for (int i = 0; i < 16; i++){
+                noteOnArray[i] = false;
+                finishNote(i);
+                displayNoteOnArray[i] = false;
+           }
+    
+           if (trSelected != 0){     
+              for (int i = 24; i < 109; i++)
+                outputToMax(i, 0, trSelected);
+           }
+           tracks[trSelected] = new Track(tracks[trSelected].name, true,  tracks[trSelected].loopLength, tracks[trSelected].quantize, false, false);
+           imgNotes = null;
+        }
+        
+        if (trSelected == 0){
+           for (int i = 0; i < 16; i++){
+               noteOnArray[i] = false;
+               finishNote(i);
+               displayNoteOnArray[i] = false;
+           }
+           heresyMinor = false;
+           heresy7th = false;
+           heresy9th = false;
+           heresy11th = false;
+           heresy13th = false;
+           chordsTemp = new Track(tracks[trSelected].name, true,  tracks[trSelected].loopLength, tracks[trSelected].quantize, false, false);
+           imgNotes = null;
+        }
+    }
+
+     if (key == 'p' || key == 'P') {
+         for (int i = 0; i < 16; i++){
+              for (int ii = 24; ii < 109; ii++)
+                outputToMax(ii, 0, trSelected);
+             noteOnArray[i] = false;
+             displayNoteOnArray[i] = false; 
+         }
+     }
+     
+     if (key == 'd' || key == 'D') {
+         if (trSelected != 0 && trSelected != 1){
+               tracks[trSelected].ducking = !tracks[trSelected].ducking;
+               tracks[trSelected].cycled = false;
+               tracks[trSelected].cycledPosition = currentPulse%tracks[trSelected].loopLength; 
+         }
+     }
+    
+     if (key == 'w' || key == 'W') {
+       
+        trSelected = 0;
+
+        for (int i = 0; i < 16; i++){
+            noteOnArray[i] = false;
+            finishNoteCutOff(i);
+            displayNoteOnArray[i] = false;
+        }
+        heresyMinor = false;
+        heresy7th = false;
+        heresy9th = false;
+        heresy11th = false;
+        heresy13th = false;
+        
+        tracks[trSelected] = new Track(tracks[trSelected].name, true,  tracks[trSelected].loopLength, tracks[trSelected].quantize, false, false);
+        chordsTemp = new Track(tracks[trSelected].name, true,  tracks[trSelected].loopLength, tracks[trSelected].quantize, false, false);
+        imgNotes = null;
+    }
+    
+    if (key == 'q' || key == 'Q'){
+        quantizeValueIn = true;
+        sendToScreen(tracks[trSelected].name + " quantize?");
+    }
+    
+    if (key == 'x' || key == 'X'){
+        clickTrackOn = !clickTrackOn;
+    }
+    
+    if (key == 'e' || key == 'E'){
+        eraseOn = !eraseOn;
+        if (!eraseOn) imgNotes = null;
+    }
+    
+    if (key == 'r' || key == 'R'){
+        imgNotes = null;
+    }
+    
+    if (key == 'l' || key == 'L'){
+        loopLengthValueIn = true;
+        sendToScreen(tracks[trSelected].name + " loop length?");
+    }
+    
+    if (key == 'm' || key == 'M'){
+        if (trSelected != 0){
+            muteValueIn = true;
+            if (!tracks[trSelected].mute)
+                sendToScreen(tracks[trSelected].name + " mute in?");
+            if (tracks[trSelected].mute)
+                sendToScreen(tracks[trSelected].name + " unmute in?");              
+        }
+    }
+
+   
+    if (key == '1') numberKey(1);
+    if (key == '2') numberKey(2);
+    if (key == '3') numberKey(3);
+    if (key == '4') numberKey(4);
+    if (key == '5') numberKey(5);
+    if (key == '6') numberKey(6);
+    if (key == '7') numberKey(7);
+    if (key == '8') numberKey(8);       
+    if (key == '9') numberKey(9);
+    if (key == '0') numberKey(0);
+
+    if (key == CODED) {
+        if (keyCode == UP && trSelected < Track.currentNumberOfTracks-1)
+            trSelected++;
+        if (keyCode == DOWN && trSelected > 1) {
+           trSelected--;
+        } 
+     }
+     
+     if (key == 's' || key == 'S'){
+          for (int i = 0; i < 16; i++){
+              for (int ii = 0; ii < tracks[0].loopLength; ii++){
+                  if (chordsTemp.sequence[i][ii] != null)
+                      tracks[0].sequence[i][ii] = chordsTemp.sequence[i][ii];
+              }
+          }
+     }
+     
+ 
+}
+
+
+//------------------------------------------------------------------------------------------------------------------------------- 
+
+public void numberKey(int input){ // if a number is enterd, this method works out what to do with it
+    if (quantizeValueIn == true)
+        if (input == 1 || input == 2 || input == 4 || input == 8 || input == 0){
+             tracks[trSelected].quantize = input;
+             quantizeValueIn = false;
+             aniOut = true;
+        }
+         
+    if (loopLengthValueIn == true){
+        if (input >= 1 && input <= 8 ){
+            Track tempTrack = new Track(tracks[trSelected].name, tracks[trSelected].polyphonic, (input * loopLength / 2), tracks[trSelected].quantize, false, false);
+            NoteEvent tempNote;
+            
+            for (int i = 0; i < 16; i++){
+                if (tempTrack.loopLength >= tracks[trSelected].loopLength){
+                    for (int ii = 0; ii < tracks[trSelected].loopLength; ii++){
+                        tempTrack.sequence[i][ii] = tracks[trSelected].sequence[i][ii];
+                    }
+                }else{
+                    for (int ii = 0; ii < tempTrack.loopLength; ii++){
+                        tempTrack.sequence[i][ii] = tracks[trSelected].sequence[i][ii];
+                    }
+                }
+            }
+            tracks[trSelected] = tempTrack;
+            for (int i = 0; i < 16; i++)
+            if (noteOnArray[i] = true){
+                noteOnArray[i] = false;
+                finishNoteCutOff(i);
+                displayNoteOnArray[i] = false;
+            }
+  
+             
+            loopLengthValueIn = false;
+            aniOut = true;
+            if (trSelected ==0){
+                Track tempTrack2 = new Track(chordsTemp.name, chordsTemp.polyphonic, (input * loopLength / 2), chordsTemp.quantize, false, false);
+                NoteEvent tempNote2;
+            
+                for (int i = 0; i < 16; i++){
+                    if (tempTrack2.loopLength >= chordsTemp.loopLength){
+                        for (int ii = 0; ii < chordsTemp.loopLength; ii++){
+                            tempTrack2.sequence[i][ii] = chordsTemp.sequence[i][ii];
+                        }
+                    }else{
+                        for (int ii = 0; ii < tempTrack2.loopLength; ii++){
+                            tempTrack2.sequence[i][ii] = chordsTemp.sequence[i][ii];
+                        }
+                    }  
+                }
+            chordsTemp = tempTrack2;
+            }
+            imgNotes = null;
+        }
+    }
+    
+    if (muteValueIn == true){
+        tracks[trSelected].muteIn = bar + input;
+        muteValueIn = false;
+        tracks[trSelected].muteDone = false;
+        aniOut = true;
+    }
+        
+         
+}
+
+
+//------------------------------------------------------------------------------------------------------------------------------- 
+
+public void sendToScreen(String name){ // prepares a question for asking the user and turns the question on
+
+      screenQuestion = name;
+      screenAni = 0;
+      haveQuestion = true;
+    
+}
+
+
+//------------------------------------------------------------------------------------------------------------------------------- 
+
+public void checkCycled(){  // checks whether after ducking or muting all note offs are played.
+    for (int i = 1; i < Track.currentNumberOfTracks; i++)
+        if (tracks[i].cycled == false)
+            if (tracks[i].cycledPosition-1 == currentPulse%tracks[trSelected].loopLength)
+                tracks[i].cycled = true;
+    
+}
+
+
+//------------------------------------------------------------------------------------------------------------------------------- 
+
+
+public void checkForMutes(){ // looks for mute / unmuted changes in tracks
+    for (int i = 1; i < Track.currentNumberOfTracks; i++)
+        if (tracks[i].muteIn == bar && !tracks[i].muteDone){
+            tracks[i].mute = !tracks[i].mute;
+            tracks[i].muteDone = true;
+            tracks[trSelected].cycled = false;
+            tracks[trSelected].cycledPosition = currentPulse%tracks[trSelected].loopLength; 
+        }
+}
+
+
+
+//------------------------------------------------------------------------------------------------------------------------------- 
+
+public void writeQuestion(){ // animates screen questions
+  
+  if (screenAni < 10 && !aniOut){
+      screenAni++;
+  }
+  
+  if (screenAni > 0 && aniOut){
+     screenAni--;
+  }
+  
+   if (screenAni == 0){
+      haveQuestion = false;
+      aniOut = false;
+   }
+  
+  fill(255,0,0, screenAni*12);
+  textSize((11-screenAni)*40);
+  text(screenQuestion, (screenAni*50)-200,(100-screenAni*10)+150);
+  
+    
+}
+
+
+//------------------------------------------------------------------------------------------------------------------------------- 
+
+public void oscEvent(OscMessage theOscMessage) { // recieves osc messages from openFrameworks
+    println("osc message : " + theOscMessage);
+    if(theOscMessage.checkAddrPattern("/test")==true) {
+        println("i1 : " + theOscMessage.get(1).intValue() + "  i2 : " + theOscMessage.get(2).intValue() + "  i3 : " + theOscMessage.get(3).intValue() + "  i4 : " + theOscMessage.get(4).intValue());
+        clickTrack = false;
+        String stringValue = theOscMessage.get(0).stringValue();
+        int firstValue = theOscMessage.get(1).intValue(); 
+        int secondValue = theOscMessage.get(2).intValue();
+        int thirdValue = theOscMessage.get(3).intValue(); //velocity
+        int fourthValue = theOscMessage.get(4).intValue(); //channel
+        if (secondValue == 1){
+            noteOnArray[firstValue] = true;
+            writeNote(firstValue, thirdValue, fourthValue);       
+        }
+        else{
+            noteOnArray[firstValue] = false;
+            writeNote(firstValue, 0, fourthValue); 
+        }
+    }
+    if(theOscMessage.checkAddrPattern("/chord")==true) {
+        chordCalc();
+  //      writeNote(15, 80, 6);
+        writeNote(14, 80, 6);
+        writeNote(13, 80, 6);
+        writeNote(12, 80, 6);
+        writeNote(11, 80, 6);
+        writeNote(10, 80, 6);
+        writeNote(9, 80, 6);
+    }
+}
+
+
+
+class VPArray{ // the virtual playing array for Heresy AI to play with
+  
+    VPNote[] VPArrayNotes;
+    
+    public VPArray(){
+        VPArrayNotes = new VPNote[16];
+        for (int i = 0; i < 16; i++)
+          VPArrayNotes[i] = new VPNote();
+    }
+}
+
+class VPNote{
+  
+    boolean played;
+    boolean VPNoteOn;
+    boolean done;
+    int extension;
+    int VPNotePitch;
+    int VPNoteVelocity;
+    
+    public VPNote(){
+       VPNoteOn = false;
+       played = true;
+        extension = 0;
+        VPNotePitch = 0;
+        VPNoteVelocity = 0;
+    }
+}
+
+ 
+    
+
+public void chordCalc(){
+    barCounter++;
+    if (barCounter % 4 == 0 || ((currentChord == 1 || currentChord == 5 || currentChord == 7) && barCounter % 4 == 3)){
+        tonicNeeded = true;
+        print(" tonic needed " + (barCounter % 4));
+     }
+     else tonicNeeded = false;
+     chooseChord();
+}
+
+public void chooseChord(){
+
+    int i = 0;
+    for (; i < crneeded; i++){
+        if (chordChoicesArray[i].chordNote == currentChord && chordChoicesArray[i].minor == heresyMinor)
+            break;
+    }
+    if (currentChord == 1 && heresyDom)
+        i = 16;
+    if (tonicNeeded && i != 24){
+        int gotOne = -1;
+        int gotTwo = -1;
+        if (chordChoicesArray[i].optionArray[0].chordOption == 0 && chordChoicesArray[i].optionArray[1].chordOption == 0 && PApplet.parseInt(random(2)) == 0)
+            chosenChord (i, chordChoicesArray[i].optionArray[1].chordOption);
+        else if 
+            (chordChoicesArray[i].optionArray[0].chordOption == 0 && chordChoicesArray[i].optionArray[1].chordOption != 0)
+            chosenChord (i, chordChoicesArray[i].optionArray[0].chordOption);
+        else
+            chosenChord (i, PApplet.parseInt(random(chordChoicesArray[i].slots)));
+    }
+    else if (i != 24){
+        chosenChord(i, PApplet.parseInt(random(chordChoicesArray[i].slots))); 
+    }else{
+        currentChord = lastChordChange;
+        heresyMinor = lastMinor;
+    }
+    println("   chord selected : " + currentChord + " minor:" + heresyMinor);
+}
+
+public void chosenChord(int p, int p2){
+    lastChordChange = currentChord;
+    lastMinor = heresyMinor;
+ //   println("p: " + p + "  p2 : " + p2);
+    currentChord = chordChoicesArray[p].optionArray[p2].chordOption;
+    heresyMinor = chordChoicesArray[p].optionArray[p2].minor;
+    if (PApplet.parseInt(random(4)) == 0)
+        heresy7th = true;
+    else
+        heresy7th = false;
+    if (PApplet.parseInt(random(4)) == 0)
+        heresy9th = true;
+    else
+        heresy9th = false;       
+    if (PApplet.parseInt(random(4)) == 0)
+        heresy11th = true;
+    else
+        heresy11th = false;
+
+
+}   
+
+
+
+class chordChoices{
+    int chordNote;
+    boolean minor;
+    ChordChoice[] optionArray;
+    int slots;
+    
+    public chordChoices(int chordNote, boolean minor, int slotsNeeded){
+        this.chordNote = chordNote;
+        this.minor = minor;
+        optionArray = new ChordChoice[slotsNeeded];
+        slots = slotsNeeded;
+    }
+}
+
+class ChordChoice{
+    int chordOption;
+    boolean minor, h7th, h9th, h11th, h13th, dom;
+    
+    public ChordChoice(int chordOption, boolean minor, boolean dom, boolean h7th, boolean h9th, boolean h11th, boolean h13th){
+        this.chordOption = chordOption;
+        this.minor = minor;
+        this.dom = dom;
+        this.h7th = h7th;
+        this.h9th = h9th;
+        this.h11th = h11th;
+        this.h13th = h13th;       
+    }
+}
+
+//void stuff(){
+chordChoices[] chordChoicesArray = new chordChoices[crneeded];
+
+public void markovStuff(){
+chordChoicesArray[0] = new chordChoices(0, false, 13);
+chordChoicesArray[0].optionArray[0] = new ChordChoice(2, true, false, true, true, true, true);
+chordChoicesArray[0].optionArray[1] = new ChordChoice(3, false, false, true, true, true, true);
+chordChoicesArray[0].optionArray[2] = new ChordChoice(4, true, false, true, true, true, true);
+chordChoicesArray[0].optionArray[3] = new ChordChoice(5, true, false, true, true, true, true);
+chordChoicesArray[0].optionArray[4] = new ChordChoice(5, false, false, true, true, true, true);
+chordChoicesArray[0].optionArray[5] = new ChordChoice(7, true, false, true, true, true, true);
+chordChoicesArray[0].optionArray[6] = new ChordChoice(7, false, false, true, true, true, true);
+chordChoicesArray[0].optionArray[7] = new ChordChoice(8, true, false, true, true, true, true);
+chordChoicesArray[0].optionArray[8] = new ChordChoice(8, false, false, true, true, true, true);
+chordChoicesArray[0].optionArray[9] = new ChordChoice(9, true, false, true, true, true, true);
+chordChoicesArray[0].optionArray[10] = new ChordChoice(9, false, false, true, true, true, true);
+chordChoicesArray[0].optionArray[11] = new ChordChoice(10, false, true, true, true, true, true);
+chordChoicesArray[0].optionArray[12] = new ChordChoice(10, true, false, true, true, true, true);
+
+chordChoicesArray[1] = new chordChoices(0, true, 14);
+chordChoicesArray[1].optionArray[0] = new ChordChoice(1, false, true, true, true, true, true);
+chordChoicesArray[1].optionArray[1] = new ChordChoice(3, false, false, true, true, true, true);
+chordChoicesArray[1].optionArray[2] = new ChordChoice(3, true, false, true, true, true, true);
+chordChoicesArray[1].optionArray[3] = new ChordChoice(4, true, false, true, true, true, true);
+chordChoicesArray[1].optionArray[4] = new ChordChoice(5, false, false, true, true, true, true);
+chordChoicesArray[1].optionArray[5] = new ChordChoice(5, true, false, true, true, true, true);
+chordChoicesArray[1].optionArray[6] = new ChordChoice(6, true, false, true, true, true, true);
+chordChoicesArray[1].optionArray[7] = new ChordChoice(7, false, false, true, true, true, true);
+chordChoicesArray[1].optionArray[8] = new ChordChoice(7, true, false, true, true, true, true);
+chordChoicesArray[1].optionArray[9] = new ChordChoice(8, false, false, true, true, true, true);
+chordChoicesArray[1].optionArray[10] = new ChordChoice(8, true, false, true, true, true, true);
+chordChoicesArray[1].optionArray[11] = new ChordChoice(10, false, false, true, true, true, true);
+chordChoicesArray[1].optionArray[12] = new ChordChoice(11, true, false, true, true, true, true);
+chordChoicesArray[1].optionArray[13] = new ChordChoice(11, false, false, true, true, true, true);
+
+chordChoicesArray[2] = new chordChoices(2, false, 9);
+chordChoicesArray[2].optionArray[0] = new ChordChoice(1, false, true, true, true, true, true);
+chordChoicesArray[2].optionArray[1] = new ChordChoice(2, true, false, true, true, true, true);
+chordChoicesArray[2].optionArray[2] = new ChordChoice(5, false, false, true, true, true, true);
+chordChoicesArray[2].optionArray[3] = new ChordChoice(5, true, false, true, true, true, true);
+chordChoicesArray[2].optionArray[4] = new ChordChoice(7, false, false, true, true, true, true);
+chordChoicesArray[2].optionArray[5] = new ChordChoice(8, false, false, true, true, true, true);
+chordChoicesArray[2].optionArray[6] = new ChordChoice(9, false, false, true, true, true, true);
+chordChoicesArray[2].optionArray[7] = new ChordChoice(9, true, false, true, true, true, true);
+chordChoicesArray[2].optionArray[8] = new ChordChoice(10, false, false, true, true, true, true);
+
+chordChoicesArray[3] = new chordChoices(2, true, 13);
+chordChoicesArray[3].optionArray[0] = new ChordChoice(0, false, false, true, true, true, true);
+chordChoicesArray[3].optionArray[1] = new ChordChoice(1, false, true, true, true, true, true);
+chordChoicesArray[3].optionArray[2] = new ChordChoice(3, true, false, true, true, true, true);
+chordChoicesArray[3].optionArray[3] = new ChordChoice(3, false, false, true, true, true, true);
+chordChoicesArray[3].optionArray[4] = new ChordChoice(4, true, false, true, true, true, true);
+chordChoicesArray[3].optionArray[5] = new ChordChoice(5, true, false, true, true, true, true);
+chordChoicesArray[3].optionArray[6] = new ChordChoice(5, false, false, true, true, true, true);
+chordChoicesArray[3].optionArray[7] = new ChordChoice(7, false, false, true, true, true, true);
+chordChoicesArray[3].optionArray[8] = new ChordChoice(7, true, false, true, true, true, true);
+chordChoicesArray[3].optionArray[9] = new ChordChoice(8, false, false, true, true, true, true);
+chordChoicesArray[3].optionArray[10] = new ChordChoice(9, true, false, true, true, true, true);
+chordChoicesArray[3].optionArray[11] = new ChordChoice(10, false, false, true, true, true, true);
+chordChoicesArray[3].optionArray[12] = new ChordChoice(10, true, false, true, true, true, true);
+
+chordChoicesArray[4] = new chordChoices(4, false, 4);
+chordChoicesArray[4].optionArray[0] = new ChordChoice(5, true, false, true, true, true, true);
+chordChoicesArray[4].optionArray[1] = new ChordChoice(9, false, false, true, true, true, true);
+chordChoicesArray[4].optionArray[2] = new ChordChoice(9, true, false, true, true, true, true);
+chordChoicesArray[4].optionArray[3] = new ChordChoice(11, true, false, true, true, true, true);
+
+chordChoicesArray[5] = new chordChoices(4, true, 13);
+chordChoicesArray[5].optionArray[0] = new ChordChoice(0, false, false, true, true, true, true);
+chordChoicesArray[5].optionArray[1] = new ChordChoice(0, true, false, true, true, true, true);
+chordChoicesArray[5].optionArray[2] = new ChordChoice(1, false, true, true, true, true, true);
+chordChoicesArray[5].optionArray[3] = new ChordChoice(2, true, false, true, true, true, true);
+chordChoicesArray[5].optionArray[4] = new ChordChoice(3, false, false, true, true, true, true);
+chordChoicesArray[5].optionArray[5] = new ChordChoice(3, true, false, true, true, true, true);
+chordChoicesArray[5].optionArray[6] = new ChordChoice(5, false, false, true, true, true, true);
+chordChoicesArray[5].optionArray[7] = new ChordChoice(5, true, false, true, true, true, true);
+chordChoicesArray[5].optionArray[8] = new ChordChoice(8, true, false, true, true, true, true);
+chordChoicesArray[5].optionArray[9] = new ChordChoice(8, false, false, true, true, true, true);
+chordChoicesArray[5].optionArray[10] = new ChordChoice(9, true, false, true, true, true, true);
+chordChoicesArray[5].optionArray[11] = new ChordChoice(11, false, false, true, true, true, true);
+chordChoicesArray[5].optionArray[12] = new ChordChoice(11, true, false, true, true, true, true);
+
+chordChoicesArray[6] = new chordChoices(5, false, 14);
+chordChoicesArray[6].optionArray[0] = new ChordChoice(0, false, false, true, true, true, true);
+chordChoicesArray[6].optionArray[1] = new ChordChoice(0, true, false, true, true, true, true);
+chordChoicesArray[6].optionArray[2] = new ChordChoice(2, true, false, true, true, true, true);
+chordChoicesArray[6].optionArray[3] = new ChordChoice(4, true, false, true, true, true, true);
+chordChoicesArray[6].optionArray[4] = new ChordChoice(4, false, false, true, true, true, true);
+chordChoicesArray[6].optionArray[5] = new ChordChoice(5, true, false, true, true, true, true);
+chordChoicesArray[6].optionArray[6] = new ChordChoice(6, true, false, true, true, true, true);
+chordChoicesArray[6].optionArray[7] = new ChordChoice(7, false, false, true, true, true, true);
+chordChoicesArray[6].optionArray[8] = new ChordChoice(8, true, false, true, true, true, true);
+chordChoicesArray[6].optionArray[9] = new ChordChoice(8, false, false, true, true, true, true);
+chordChoicesArray[6].optionArray[10] = new ChordChoice(9, true, false, true, true, true, true);
+chordChoicesArray[6].optionArray[11] = new ChordChoice(9, false, false, true, true, true, true);
+chordChoicesArray[6].optionArray[12] = new ChordChoice(10, true, false, true, true, true, true);
+chordChoicesArray[6].optionArray[13] = new ChordChoice(10, false, false, true, true, true, true);
+
+chordChoicesArray[7] = new chordChoices(5, true, 15);
+chordChoicesArray[7].optionArray[0] = new ChordChoice(0, false, false, true, true, true, true);
+chordChoicesArray[7].optionArray[1] = new ChordChoice(0, true, false, true, true, true, true);
+chordChoicesArray[7].optionArray[2] = new ChordChoice(1, false, true, true, true, true, true);
+chordChoicesArray[7].optionArray[3] = new ChordChoice(2, true, false, true, true, true, true);
+chordChoicesArray[7].optionArray[4] = new ChordChoice(2, false, false, true, true, true, true);
+chordChoicesArray[7].optionArray[5] = new ChordChoice(3, false, false, true, true, true, true);
+chordChoicesArray[7].optionArray[6] = new ChordChoice(4, false, false, true, true, true, true);
+chordChoicesArray[7].optionArray[7] = new ChordChoice(6, true, false, true, true, true, true);
+chordChoicesArray[7].optionArray[8] = new ChordChoice(7, true, false, true, true, true, true);
+chordChoicesArray[7].optionArray[9] = new ChordChoice(7, false, false, true, true, true, true);
+chordChoicesArray[7].optionArray[10] = new ChordChoice(8, true, false, true, true, true, true);
+chordChoicesArray[7].optionArray[11] = new ChordChoice(8, false, false, true, true, true, true);
+chordChoicesArray[7].optionArray[12] = new ChordChoice(10, false, false, true, true, true, true);
+chordChoicesArray[7].optionArray[13] = new ChordChoice(11, false, false, true, true, true, true);
+chordChoicesArray[7].optionArray[14] = new ChordChoice(11, true, false, true, true, true, true);
+
+chordChoicesArray[8] = new chordChoices(7, true, 14);
+chordChoicesArray[8].optionArray[0] = new ChordChoice(0, false, false, true, true, true, true);
+chordChoicesArray[8].optionArray[1] = new ChordChoice(0, true, false, true, true, true, true);
+chordChoicesArray[8].optionArray[2] = new ChordChoice(1, false, true, true, true, true, true);
+chordChoicesArray[8].optionArray[3] = new ChordChoice(2, false, false, true, true, true, true);
+chordChoicesArray[8].optionArray[4] = new ChordChoice(2, true, false, true, true, true, true);
+chordChoicesArray[8].optionArray[5] = new ChordChoice(3, false, false, true, true, true, true);
+chordChoicesArray[8].optionArray[6] = new ChordChoice(3, true, false, true, true, true, true);
+chordChoicesArray[8].optionArray[7] = new ChordChoice(5, false, false, true, true, true, true);
+chordChoicesArray[8].optionArray[8] = new ChordChoice(5, true, false, true, true, true, true);
+chordChoicesArray[8].optionArray[9] = new ChordChoice(6, false, false, true, true, true, true);
+chordChoicesArray[8].optionArray[10] = new ChordChoice(8, true, false, true, true, true, true);
+chordChoicesArray[8].optionArray[11] = new ChordChoice(8, false, false, true, true, true, true);
+chordChoicesArray[8].optionArray[12] = new ChordChoice(10, false, false, true, true, true, true);
+chordChoicesArray[8].optionArray[13] = new ChordChoice(10, true, false, true, true, true, true);
+
+chordChoicesArray[9] = new chordChoices(7, false, 10);
+chordChoicesArray[9].optionArray[0] = new ChordChoice(0, false, false, true, true, true, true);
+chordChoicesArray[9].optionArray[1] = new ChordChoice(0, true, false, true, true, true, true);
+chordChoicesArray[9].optionArray[2] = new ChordChoice(2, false, false, true, true, true, true);
+chordChoicesArray[9].optionArray[3] = new ChordChoice(2, true, false, true, true, true, true);
+chordChoicesArray[9].optionArray[4] = new ChordChoice(4, true, false, true, true, true, true);
+chordChoicesArray[9].optionArray[5] = new ChordChoice(5, false, false, true, true, true, true);
+chordChoicesArray[9].optionArray[6] = new ChordChoice(5, true, false, true, true, true, true);
+chordChoicesArray[9].optionArray[7] = new ChordChoice(8, false, false, true, true, true, true);
+chordChoicesArray[9].optionArray[8] = new ChordChoice(8, true, false, true, true, true, true);
+chordChoicesArray[9].optionArray[9] = new ChordChoice(9, true, false, true, true, true, true);
+
+chordChoicesArray[10] = new chordChoices(9, true, 13);
+chordChoicesArray[10].optionArray[0] = new ChordChoice(0, false, false, true, true, true, true);
+chordChoicesArray[10].optionArray[1] = new ChordChoice(0, true, false, true, true, true, true);
+chordChoicesArray[10].optionArray[2] = new ChordChoice(1, false, true, true, true, true, true);
+chordChoicesArray[10].optionArray[3] = new ChordChoice(2, true, false, true, true, true, true);
+chordChoicesArray[10].optionArray[4] = new ChordChoice(2, false, false, true, true, true, true);
+chordChoicesArray[10].optionArray[5] = new ChordChoice(3, false, false, true, true, true, true);
+chordChoicesArray[10].optionArray[6] = new ChordChoice(4, true, false, true, true, true, true);
+chordChoicesArray[10].optionArray[7] = new ChordChoice(5, false, false, true, true, true, true);
+chordChoicesArray[10].optionArray[8] = new ChordChoice(5, true, false, true, true, true, true);
+chordChoicesArray[10].optionArray[9] = new ChordChoice(7, true, false, true, true, true, true);
+chordChoicesArray[10].optionArray[10] = new ChordChoice(7, false, false, true, true, true, true);
+chordChoicesArray[10].optionArray[11] = new ChordChoice(8, false, false, true, true, true, true);
+chordChoicesArray[10].optionArray[12] = new ChordChoice(10, false, false, true, true, true, true);
+
+chordChoicesArray[11] = new chordChoices(11, false, 6);
+chordChoicesArray[11].optionArray[0] = new ChordChoice(0, true, false, true, true, true, true);
+chordChoicesArray[11].optionArray[1] = new ChordChoice(1, false, true, true, true, true, true);
+chordChoicesArray[11].optionArray[2] = new ChordChoice(1, true, false, true, true, true, true);
+chordChoicesArray[11].optionArray[3] = new ChordChoice(1, false, false, true, true, true, true);
+chordChoicesArray[11].optionArray[4] = new ChordChoice(7, false, false, true, true, true, true);
+chordChoicesArray[11].optionArray[5] = new ChordChoice(7, true, false, true, true, true, true);
+
+chordChoicesArray[12] = new chordChoices(11, true, 5);
+chordChoicesArray[12].optionArray[0] = new ChordChoice(1, false, true, true, true, true, true);
+chordChoicesArray[12].optionArray[1] = new ChordChoice(2, true, false, true, true, true, true);
+chordChoicesArray[12].optionArray[2] = new ChordChoice(5, false, true, true, true, true, true);
+chordChoicesArray[12].optionArray[3] = new ChordChoice(5, true, false, true, true, true, true);
+chordChoicesArray[12].optionArray[4] = new ChordChoice(8, false, false, true, true, true, true);
+
+chordChoicesArray[13] = new chordChoices(1, false, 2);
+chordChoicesArray[13].optionArray[0] = new ChordChoice(0, false, false, true, true, true, true);
+chordChoicesArray[13].optionArray[1] = new ChordChoice(0, true, false, true, true, true, true);
+
+chordChoicesArray[14] = new chordChoices(1, true, 2);
+chordChoicesArray[14].optionArray[0] = new ChordChoice(0, true, false, true, true, true, true);
+chordChoicesArray[14].optionArray[1] = new ChordChoice(0, true, false, true, true, true, true);
+
+chordChoicesArray[15] = new chordChoices(3, false, 12);
+chordChoicesArray[15].optionArray[0] = new ChordChoice(0, false, false, true, true, true, true);
+chordChoicesArray[15].optionArray[1] = new ChordChoice(0, true, false, true, true, true, true);
+chordChoicesArray[15].optionArray[2] = new ChordChoice(1, false, true, true, true, true, true);
+chordChoicesArray[15].optionArray[3] = new ChordChoice(5, false, false, true, true, true, true);
+chordChoicesArray[15].optionArray[4] = new ChordChoice(7, false, false, true, true, true, true);
+chordChoicesArray[15].optionArray[5] = new ChordChoice(7, true, false, true, true, true, true);
+chordChoicesArray[15].optionArray[6] = new ChordChoice(8, true, false, true, true, true, true);
+chordChoicesArray[15].optionArray[7] = new ChordChoice(8, false, false, true, true, true, true);
+chordChoicesArray[15].optionArray[8] = new ChordChoice(10, true, false, true, true, true, true);
+chordChoicesArray[15].optionArray[9] = new ChordChoice(10, false, false, true, true, true, true);
+chordChoicesArray[15].optionArray[10] = new ChordChoice(11, false, false, true, true, true, true);
+chordChoicesArray[15].optionArray[11] = new ChordChoice(11, true, false, true, true, true, true);
+
+chordChoicesArray[16] = new chordChoices(111, false, 2);
+chordChoicesArray[16].optionArray[0] = new ChordChoice(0, false, false, true, true, true, true);
+chordChoicesArray[16].optionArray[1] = new ChordChoice(0, true, false, true, true, true, true);
+
+chordChoicesArray[17] = new chordChoices(6, false, 10);
+chordChoicesArray[17].optionArray[0] = new ChordChoice(1, false, false, true, true, true, true);
+chordChoicesArray[17].optionArray[1] = new ChordChoice(1, true, false, true, true, true, true);
+chordChoicesArray[17].optionArray[2] = new ChordChoice(2, false, false, true, true, true, true);
+chordChoicesArray[17].optionArray[3] = new ChordChoice(3, false, false, true, true, true, true);
+chordChoicesArray[17].optionArray[4] = new ChordChoice(3, true, false, true, true, true, true);
+chordChoicesArray[17].optionArray[5] = new ChordChoice(8, false, false, true, true, true, true);
+chordChoicesArray[17].optionArray[6] = new ChordChoice(9, false, false, true, true, true, true);
+chordChoicesArray[17].optionArray[7] = new ChordChoice(9, true, false, true, true, true, true);
+chordChoicesArray[17].optionArray[8] = new ChordChoice(10, true, false, true, true, true, true);
+chordChoicesArray[17].optionArray[9] = new ChordChoice(10, false, false, true, true, true, true);
+
+chordChoicesArray[18] = new chordChoices(8, false, 17);
+chordChoicesArray[18].optionArray[0] = new ChordChoice(0, false, false, true, true, true, true);
+chordChoicesArray[18].optionArray[1] = new ChordChoice(0, true, false, true, true, true, true);
+chordChoicesArray[18].optionArray[2] = new ChordChoice(1, false, true, true, true, true, true);
+chordChoicesArray[18].optionArray[3] = new ChordChoice(1, true, false, true, true, true, true);
+chordChoicesArray[18].optionArray[4] = new ChordChoice(1, false, false, true, true, true, true);
+chordChoicesArray[18].optionArray[5] = new ChordChoice(3, false, false, true, true, true, true);
+chordChoicesArray[18].optionArray[6] = new ChordChoice(3, true, false, true, true, true, true);
+chordChoicesArray[18].optionArray[7] = new ChordChoice(4, false, false, true, true, true, true);
+chordChoicesArray[18].optionArray[8] = new ChordChoice(4, true, false, true, true, true, true);
+chordChoicesArray[18].optionArray[9] = new ChordChoice(5, true, false, true, true, true, true);
+chordChoicesArray[18].optionArray[10] = new ChordChoice(5, false, false, true, true, true, true);
+chordChoicesArray[18].optionArray[11] = new ChordChoice(7, false, false, true, true, true, true);
+chordChoicesArray[18].optionArray[12] = new ChordChoice(7, true, false, true, true, true, true);
+chordChoicesArray[18].optionArray[13] = new ChordChoice(9, true, false, true, true, true, true);
+chordChoicesArray[18].optionArray[14] = new ChordChoice(10, false, false, true, true, true, true);
+chordChoicesArray[18].optionArray[15] = new ChordChoice(11, false, false, true, true, true, true);
+chordChoicesArray[18].optionArray[16] = new ChordChoice(11, true, false, true, true, true, true);
+
+chordChoicesArray[19] = new chordChoices(8, true, 10);
+chordChoicesArray[19].optionArray[0] = new ChordChoice(0, false, false, true, true, true, true);
+chordChoicesArray[19].optionArray[1] = new ChordChoice(0, true, false, true, true, true, true);
+chordChoicesArray[19].optionArray[2] = new ChordChoice(1, false, true, true, true, true, true);
+chordChoicesArray[19].optionArray[3] = new ChordChoice(1, false, false, true, true, true, true);
+chordChoicesArray[19].optionArray[4] = new ChordChoice(3, false, false, true, true, true, true);
+chordChoicesArray[19].optionArray[5] = new ChordChoice(3, true, false, true, true, true, true);
+chordChoicesArray[19].optionArray[6] = new ChordChoice(4, false, false, true, true, true, true);
+chordChoicesArray[19].optionArray[7] = new ChordChoice(4, true, false, true, true, true, true);
+chordChoicesArray[19].optionArray[8] = new ChordChoice(5, true, false, true, true, true, true);
+chordChoicesArray[19].optionArray[9] = new ChordChoice(5, false, false, true, true, true, true);
+
+chordChoicesArray[20] = new chordChoices(3, true, 19);
+chordChoicesArray[20].optionArray[0] = new ChordChoice(0, false, false, true, true, true, true);
+chordChoicesArray[20].optionArray[1] = new ChordChoice(0, true, false, true, true, true, true);
+chordChoicesArray[20].optionArray[2] = new ChordChoice(1, false, true, true, true, true, true);
+chordChoicesArray[20].optionArray[3] = new ChordChoice(2, false, false, true, true, true, true);
+chordChoicesArray[20].optionArray[4] = new ChordChoice(4, false, false, true, true, true, true);
+chordChoicesArray[20].optionArray[5] = new ChordChoice(4, true, false, true, true, true, true);
+chordChoicesArray[20].optionArray[6] = new ChordChoice(5, true, false, true, true, true, true);
+chordChoicesArray[20].optionArray[7] = new ChordChoice(5, false, false, true, true, true, true);
+chordChoicesArray[20].optionArray[8] = new ChordChoice(6, true, false, true, true, true, true);
+chordChoicesArray[20].optionArray[9] = new ChordChoice(6, false, false, true, true, true, true);
+chordChoicesArray[20].optionArray[10] = new ChordChoice(7, true, false, true, true, true, true);
+chordChoicesArray[20].optionArray[11] = new ChordChoice(8, false, false, true, true, true, true);
+chordChoicesArray[20].optionArray[12] = new ChordChoice(8, true, false, true, true, true, true);
+chordChoicesArray[20].optionArray[13] = new ChordChoice(9, true, false, true, true, true, true);
+chordChoicesArray[20].optionArray[14] = new ChordChoice(9, false, false, true, true, true, true);
+chordChoicesArray[20].optionArray[15] = new ChordChoice(10, false, false, true, true, true, true);
+chordChoicesArray[20].optionArray[16] = new ChordChoice(10, true, false, true, true, true, true);
+chordChoicesArray[20].optionArray[17] = new ChordChoice(11, false, false, true, true, true, true);
+chordChoicesArray[20].optionArray[18] = new ChordChoice(11, true, false, true, true, true, true);
+
+chordChoicesArray[21] = new chordChoices(6, true, 9);
+chordChoicesArray[21].optionArray[0] = new ChordChoice(1, false, false, true, true, true, true);
+chordChoicesArray[21].optionArray[1] = new ChordChoice(1, true, false, true, true, true, true);
+chordChoicesArray[21].optionArray[2] = new ChordChoice(2, false, false, true, true, true, true);
+chordChoicesArray[21].optionArray[3] = new ChordChoice(3, false, false, true, true, true, true);
+chordChoicesArray[21].optionArray[4] = new ChordChoice(3, true, false, true, true, true, true);
+chordChoicesArray[21].optionArray[5] = new ChordChoice(4, false, false, true, true, true, true);
+chordChoicesArray[21].optionArray[6] = new ChordChoice(5, false, false, true, true, true, true);
+chordChoicesArray[21].optionArray[7] = new ChordChoice(8, false, false, true, true, true, true);
+chordChoicesArray[21].optionArray[8] = new ChordChoice(11, true, false, true, true, true, true);
+
+chordChoicesArray[22] = new chordChoices(10, false, 13);
+chordChoicesArray[22].optionArray[0] = new ChordChoice(0, false, false, true, true, true, true);
+chordChoicesArray[22].optionArray[1] = new ChordChoice(0, true, false, true, true, true, true);
+chordChoicesArray[22].optionArray[2] = new ChordChoice(1, false, true, true, true, true, true);
+chordChoicesArray[22].optionArray[3] = new ChordChoice(3, false, false, true, true, true, true);
+chordChoicesArray[22].optionArray[4] = new ChordChoice(3, true, false, true, true, true, true);
+chordChoicesArray[22].optionArray[5] = new ChordChoice(5, true, false, true, true, true, true);
+chordChoicesArray[22].optionArray[6] = new ChordChoice(5, false, false, true, true, true, true);
+chordChoicesArray[22].optionArray[7] = new ChordChoice(6, false, false, true, true, true, true);
+chordChoicesArray[22].optionArray[8] = new ChordChoice(7, true, false, true, true, true, true);
+chordChoicesArray[22].optionArray[9] = new ChordChoice(7, false, false, true, true, true, true);
+chordChoicesArray[22].optionArray[10] = new ChordChoice(8, true, false, true, true, true, true);
+chordChoicesArray[22].optionArray[11] = new ChordChoice(8, false, false, true, true, true, true);
+chordChoicesArray[22].optionArray[12] = new ChordChoice(11, true, false, true, true, true, true);
+
+chordChoicesArray[23] = new chordChoices(10, true, 12);
+chordChoicesArray[23].optionArray[0] = new ChordChoice(0, false, false, true, true, true, true);
+chordChoicesArray[23].optionArray[1] = new ChordChoice(1, false, true, true, true, true, true);
+chordChoicesArray[23].optionArray[2] = new ChordChoice(3, false, false, true, true, true, true);
+chordChoicesArray[23].optionArray[3] = new ChordChoice(3, true, false, true, true, true, true);
+chordChoicesArray[23].optionArray[4] = new ChordChoice(5, false, false, true, true, true, true);
+chordChoicesArray[23].optionArray[5] = new ChordChoice(6, true, false, true, true, true, true);
+chordChoicesArray[23].optionArray[6] = new ChordChoice(6, false, false, true, true, true, true);
+chordChoicesArray[23].optionArray[7] = new ChordChoice(7, false, false, true, true, true, true);
+chordChoicesArray[23].optionArray[8] = new ChordChoice(7, true, false, true, true, true, true);
+chordChoicesArray[23].optionArray[9] = new ChordChoice(9, false, false, true, true, true, true);
+chordChoicesArray[23].optionArray[10] = new ChordChoice(9, true, false, true, true, true, true);
+chordChoicesArray[23].optionArray[11] = new ChordChoice(11, true, false, true, true, true, true);
+
+
+}
+public void loadSequences(){
+  
+    ArrayList<NoteEvent> sequenceBass = new ArrayList<NoteEvent>();
+    sequenceBass.add(new NoteEvent(15, 2,   1,  1,  1,  1,    0,  3,  3,  0));
+ // sequenceBass.add(new NoteEvent(15, 2,   1,  1,  2,  1,    0,  0,  0,  5));
+ // sequenceBass.add(new NoteEvent(15, 2,   1,  2,  3,  1,    0,  0,  0,  5));
+ // sequenceBass.add(new NoteEvent(15, 2,   1,  2,  4,  1,    0,  0,  0,  5));
+ // sequenceBass.add(new NoteEvent(15, 2,   1,  3,  2,  1,    0,  0,  0,  5));
+ // sequenceBass.add(new NoteEvent(15, 2,   1,  3,  3,  1,    0,  0,  0,  5));
+ // sequenceBass.add(new NoteEvent(15, 2,   1,  4,  1,  1,    0,  0,  0,  5));
+ // sequenceBass.add(new NoteEvent(15, 2,   1,  4,  2,  1,    0,  0,  0,  5));
+    seedSequencer(sequenceBass, 2);
+    
+    ArrayList<NoteEvent> sequencePizz = new ArrayList<NoteEvent>();
+    sequencePizz.add(new NoteEvent(13, 2,   1,  1,  3,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(12, 2,   1,  1,  3,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(11, 2,   1,  1,  3,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(10, 2,   1,  1,  3,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(9,  2,   1,  1,  3,  1,    0,  0,  1,  0));
+//  sequencePizz.add(new NoteEvent(8,  2,   1,  1,  3,  1,    0,  0,  1,  0));
+//  sequencePizz.add(new NoteEvent(7,  2,   1,  1,  3,  1,    0,  0,  1,  0));
+//  sequencePizz.add(new NoteEvent(6,  2,   1,  1,  3,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(0,  2,   1,  2,  3,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(1,  2,   1,  2,  3,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(2,  2,   1,  2,  3,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(3,  2,   1,  2,  3,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(4,  2,   1,  2,  3,  1,    0,  0,  1,  0));
+//  sequencePizz.add(new NoteEvent(8,  2,   1,  2,  3,  1,    0,  0,  1,  0));
+//  sequencePizz.add(new NoteEvent(7,  2,   1,  2,  3,  1,    0,  0,  1,  0));
+//  sequencePizz.add(new NoteEvent(6,  2,   1,  2,  3,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(13, 2,   1,  3,  3,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(12, 2,   1,  3,  3,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(11, 2,   1,  3,  3,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(10, 2,   1,  3,  3,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(9,  2,   1,  3,  3,  1,    0,  0,  1,  0));
+//  sequencePizz.add(new NoteEvent(8,  2,   1,  3,  3,  1,    0,  0,  1,  0));
+//  sequencePizz.add(new NoteEvent(7,  2,   1,  3,  3,  1,    0,  0,  1,  0));
+//  sequencePizz.add(new NoteEvent(6,  2,   1,  3,  3,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(0,  2,   1,  4,  1,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(1,  2,   1,  4,  1,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(2,  2,   1,  4,  1,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(3,  2,   1,  4,  1,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(4,  2,   1,  4,  1,  1,    0,  0,  1,  0));
+//  sequencePizz.add(new NoteEvent(8,  2,   1,  4,  3,  1,    0,  0,  1,  0));
+//  sequencePizz.add(new NoteEvent(7,  2,   1,  4,  3,  1,    0,  0,  1,  0));
+//  sequencePizz.add(new NoteEvent(6,  2,   1,  4,  3,  1,    0,  0,  1,  0));
+    seedSequencer(sequencePizz, 3);
+/*    
+    ArrayList<NoteEvent> sequenceStrings = new ArrayList<NoteEvent>();
+    sequenceStrings.add(new NoteEvent(13, 2,   1,  1,  1,  1,    0,  1,  3,  0));
+    sequenceStrings.add(new NoteEvent(12, 2,   1,  1,  1,  1,    0,  1,  3,  0));
+    sequenceStrings.add(new NoteEvent(11, 2,   1,  1,  1,  1,    0,  1,  3,  0));
+    sequenceStrings.add(new NoteEvent(10, 2,   1,  1,  1,  1,    0,  1,  3,  0));
+    sequenceStrings.add(new NoteEvent(9,  2,   1,  1,  1,  1,    0,  1,  3,  0));
+    sequenceStrings.add(new NoteEvent(8,  2,   1,  1,  1,  1,    0,  1,  3,  0));
+    sequenceStrings.add(new NoteEvent(7,  2,   1,  1,  1,  1,    0,  1,  3,  0));
+    sequenceStrings.add(new NoteEvent(6,  2,   1,  1,  1,  1,    0,  1,  3,  0));
+    seedSequencer(sequenceStrings, 4);
+*/
+    
+}
+
+public void seedSequencer(ArrayList<NoteEvent> sIn, int track){
+    for (int i = 0; i < sIn.size(); i++){
+      NoteEvent s = sIn.get(i);
+  //  println("info stuff : " + s[i].notePitch);
+        tracks[track].sequence[s.notePitch][(s.notePosition[0]-1)*pulsesPerBar + (s.notePosition[1]-1)*grid + (s.notePosition[2]-1)*(grid/fractions) + s.notePosition[3]] = new NoteEvent (s.notePitch, s.channel, bar,beat,fraction,pulse);
+        tracks[track].sequence[s.notePitch][(s.notePosition[0]-1)*pulsesPerBar + (s.notePosition[1]-1)*grid + (s.notePosition[2]-1)*(grid/fractions) + s.notePosition[3] + s.noteLength[0]*pulsesPerBar + s.noteLength[1]*grid + s.noteLength[2]*grid/fractions + s.noteLength[3]] = new NoteEvent (s.notePitch, s.channel, bar,beat,fraction,pulse, true);
+    }
+}
+  static public void main(String args[]) {
+    PApplet.main(new String[] { "--bgcolor=#FFFFFF", "HeresyBigBangDone" });
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HeresyBigBangDone/application.macosx/source/HeresyBigBangDone.pde	Sat Oct 08 22:12:49 2011 +0100
@@ -0,0 +1,288 @@
+ 
+
+void setup(){
+    markovStuff();
+    for (int i = 0; i < 16; i++)
+        VPA[i] = new VPArray(); // creates the virtual playing array for Heresy AI.
+    for (int i = 0; i < noteOnArray.length; i++)   
+        noteOnArray[i] = false; // makes sure there are initial random inputs from openFrameworks
+        
+    oscP5return = new OscP5(this,12346); 
+ 
+    frameRate(tempo);
+    img = createGraphics(imageWidth,imageHeight,P2D);
+    size(800,imageHeight,P2D);
+    arial = createFont("Arial",32);
+    textFont(arial,15);
+    
+    // initialize the tracks
+    
+    tracks[0] = new Track("Chord track", true, grid * beatsPerBar, 8, true, true);
+    tracks[1] = new Track("Drums", true, grid * beatsPerBar, 8, false, true);
+    tracks[2] = new Track("Bass", true, grid * beatsPerBar, 8, false, true);
+    tracks[3] = new Track("Pizz Strings", true, grid * beatsPerBar, 8, false, true);
+    tracks[4] = new Track("Synth", true, grid * beatsPerBar, 8, false, true);
+    tracks[5] = new Track("Voice", true, grid * beatsPerBar, 8, false, true);
+    tracks[6] = new Track("Voice", true, grid * beatsPerBar, 8, false, true);
+    chordsTemp = new Track("Chord track", true, loopLength, 8, true, false);
+    trSelected = 1;
+    backgroundColour();
+    drawLines();
+    drawBarLines();
+    imgNoteFan = createGraphics(fanWidth,imageHeight,P2D);
+    lastTrack = trSelected;
+    clickTrackOn = true;
+ //   loadSequences();
+ //   tracks[2].sequence[15][16] = new NoteEvent (14, 2, bar,beat,fraction,pulse);
+ //   tracks[2].sequence[15][grid * beatsPerBar -20] = new NoteEvent (14, 2, bar,beat,fraction,pulse, true);
+  
+ //   tracks[3].sequence[13][16] = new NoteEvent (13, 3, bar,beat,fraction,pulse);
+ //   tracks[3].sequence[13][20] = new NoteEvent (13, 3, bar,beat,fraction,pulse, true); 
+ //   tracks[3].sequence[12][16] = new NoteEvent (12, 3, bar,beat,fraction,pulse);
+ //   tracks[3].sequence[12][20] = new NoteEvent (12, 3, bar,beat,fraction,pulse, true);     
+ //   tracks[3].sequence[11][16] = new NoteEvent (11, 3, bar,beat,fraction,pulse);
+ //   tracks[3].sequence[11][20] = new NoteEvent (11, 3, bar,beat,fraction,pulse, true);   
+ //   tracks[3].sequence[10][16] = new NoteEvent (10, 3, bar,beat,fraction,pulse);
+ //   tracks[3].sequence[10][20] = new NoteEvent (10, 3, bar,beat,fraction,pulse, true);  
+}
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+void draw(){
+ /*   if (currentPulse % (grid * beatsPerBar) == grid * beatsPerBar -1){
+        int tempTrackSelected = trSelected;
+        for (int j = 0; j < 16; j++){
+            trSelected = j; 
+            if (tracks[j] != null){
+                for (int i = 0; i < 16; i++){
+                    noteOnArray[i] = false;
+                    finishNote(i);
+                    displayNoteOnArray[i] = false;
+                    for (int z = 24; z < 109; z++)
+                        outputToMax(z, 0, j);
+                }
+                tracks[j] = new Track(tracks[j].name, true,  tracks[j].loopLength, tracks[j].quantize, false, false);
+                imgNotes = null;
+            }
+        }
+        trSelected = tempTrackSelected;
+    }
+    */
+  //  tracks[0] = new Track("Chord track", true, grid * beatsPerBar, 8, true, true);
+  //  tracks[1] = new Track("Drums", true, grid * beatsPerBar, 8, false, true);
+  //  tracks[2] = new Track("Bass", true, grid * beatsPerBar, 8, false, true);
+  //  tracks[3] = new Track("Pizz Strings", true, grid * beatsPerBar, 8, false, true);
+  //  tracks[4] = new Track("Synth", true, grid * beatsPerBar, 8, false, true);
+  //  tracks[5] = new Track("Voice", true, grid * beatsPerBar, 8, false, true);
+  //  }
+    workOutPosition(); // calculates current bar, beat and pulse position
+    //println(bar + " " + beat + " " + fraction + " " + pulse);
+//    if (chordAI && bar > 1)
+//        chordCalc();
+    if (eraseOn)
+        eraseNotes();
+    calcColours(); // calcs chord colours for background and grid
+    heresyChange = false;
+    heresyChordChanged = false;
+    if (trackStorer != trSelected){ // resets display when changing tracks
+        for (int i = 0; i < 16; i++)
+            if (noteOnArray[i] = true){
+                noteOnArray[i] = false;
+                displayNoteOnArray[i] = false;
+            }
+        trackStorer = trSelected;    
+        imgNotes = null;
+    }
+    if (imgNotes == null)
+        imgNotes = createGraphics(tracks[trSelected].loopLength,imageHeight,P2D);
+    background(0);
+    image (img,width-x2-playArea,0);
+    drawTempImageGrid();
+    createNoteFan(); 
+    drawNotes();
+    fill (0);
+    noStroke();
+    rect (width-playArea,0,playArea,height);
+    image (imgNoteFan, width-playArea+3,0);
+    pulseFrame(x); // Draws a pulsing white line at the left edge of the edit area
+    if (haveQuestion) writeQuestion(); // for input request messages
+    x++; // counter for grid movement
+    x2++; // counter for note image movement
+    if (x2 == width - playArea + grid * beatsPerBar)
+        x2 = width - playArea;
+    if (x == width - playArea + tracks[trSelected].loopLength)
+        x = width - playArea;
+
+    
+   /* if (clickTrackOn){ // click track
+        if (fraction == 1){
+            if (pulse == 1){
+                String noteOut = ("37 80 1");
+                link.output(noteOut);
+            }
+            if (pulse == 2){
+                String noteOut = ("37 0 1" );
+                link.output(noteOut); 
+            } 
+        }
+    }
+    */
+    checkForMutes();
+    checkCycled();
+    playTrackEvents();
+
+    fill(255,255,255);
+    textSize(15);
+    text(bar + " " + beat + " " + fraction + " " + pulse, 10,20); // draws current time position to screen
+
+    fill(200,0,0);
+    textSize(15);
+    // this section draws current track and track info to screen
+    if (tracks[trSelected].ducking) 
+        text(tracks[trSelected].name + " ducking", 100,20); 
+    else
+        text(tracks[trSelected].name, 100,20); 
+    if (tracks[trSelected].muteIn > bar)
+        if (!tracks[trSelected].mute)
+             text("mute in " + (tracks[trSelected].muteIn - bar), 200,20);
+         else 
+             text("unmute in " + (tracks[trSelected].muteIn - bar), 200,20);
+             
+    if (haveQuestion){ // asks input questions
+        writeQuestion();
+    }
+ //   println(currentPulse + " ");
+
+
+    currentPulse++; // advances the sequencer to next pulse
+}
+        
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+void eraseNotes(){ // erases notes in current track if selected
+    if (trSelected != 0){
+        for (int i = 0; i < 16; i++){
+           if (tracks[trSelected].sequence[i][(currentPulse%(tracks[trSelected].loopLength))] != null){
+               tracks[trSelected].sequence[i][(currentPulse%(tracks[trSelected].loopLength))] = null;
+           }
+        }
+    }
+    if (trSelected == 0){
+        for (int i = 0; i < 16; i++){
+           if (chordsTemp.sequence[i][(currentPulse%(tracks[trSelected].loopLength))] != null){
+               chordsTemp.sequence[i][(currentPulse%(tracks[trSelected].loopLength))] = null;
+           }
+        }
+    }     
+}  
+           
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+void workOutPosition(){ // works out current position
+  if (currentPulse%(grid*beatsPerBar) == 0)
+    ++bar;
+  if (currentPulse%grid == 0)
+    ++beat;
+  if (beat > beatsPerBar)
+    beat = 1;
+  if (currentPulse%(grid/fractions) == 0)
+    ++fraction;
+  if (fraction > fractions)
+    fraction = 1;
+    ++pulse;
+  if (pulse > (grid/fractions))
+    pulse = 1;
+}
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+public void finishNote(int noteArrayPosition){ // writes note offs into the sequencers
+  if (trSelected != 0)
+      tracks[trSelected].sequence[noteArrayPosition][(currentPulse%(tracks[trSelected].loopLength))] = new NoteEvent (noteArrayPosition, trSelected+1, bar,beat,fraction,pulse, true);
+  if (trSelected == 0)
+      chordsTemp.sequence[noteArrayPosition][(currentPulse%(chordsTemp.loopLength))] = new NoteEvent (noteArrayPosition, trSelected+1, bar,beat,fraction,pulse, true);
+  displayNoteOnArray[noteArrayPosition] = false;
+}
+
+public void finishNote(int noteArrayPosition, int channel){ // writes note offs into the sequencers
+  if (trSelected != 0)
+      tracks[trSelected].sequence[noteArrayPosition][(currentPulse%(tracks[trSelected].loopLength))] = new NoteEvent (noteArrayPosition, channel, bar,beat,fraction,pulse, true);
+  if (trSelected == 0)
+      chordsTemp.sequence[noteArrayPosition][(currentPulse%(chordsTemp.loopLength))] = new NoteEvent (noteArrayPosition, channel, bar,beat,fraction,pulse, true);
+  displayNoteOnArray[noteArrayPosition] = false;
+}
+
+
+//-----------------------------------------------------------------------------------------------------------------------------
+
+public void finishNoteCutOff(int noteArrayPosition){ // writes note offs for unfinished notes in to the last track if track is changed and note ons are active
+    tracks[lastTrack].sequence[noteArrayPosition][(currentPulse%(tracks[lastTrack].loopLength))] = new NoteEvent (noteArrayPosition, lastTrack+1, bar,beat,fraction,pulse, true);
+}
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+public void writeNote(int noteArrayPosition, int veloc){ // writes note ons into the sequencers
+    if (trSelected != 0){
+        int quantizeOffset = getQuantizeOffset();
+        if (quantizeOffset >= 0){
+            tracks[trSelected].sequence[noteArrayPosition][(currentPulse+quantizeOffset)%(tracks[trSelected].loopLength)] = new NoteEvent (noteArrayPosition, trSelected+1, bar,beat,fraction,pulse);
+        }
+        if (quantizeOffset < 0){
+            tracks[trSelected].sequence[noteArrayPosition][(currentPulse+quantizeOffset)%(tracks[trSelected].loopLength)] = new NoteEvent (noteArrayPosition, trSelected+1, bar,beat,fraction,pulse);  
+
+            VPA[trSelected].VPArrayNotes[noteArrayPosition].VPNoteOn = true;
+            if (trSelected !=1 && trSelected !=5)
+                VPA[trSelected].VPArrayNotes[noteArrayPosition].VPNotePitch = heresyPitch(noteArrayPosition, 3);
+            else
+                VPA[trSelected].VPArrayNotes[noteArrayPosition].VPNotePitch = heresyPitch(noteArrayPosition, 1);
+            VPA[trSelected].VPArrayNotes[noteArrayPosition].VPNoteVelocity = veloc;
+            sendNote(VPA[trSelected].VPArrayNotes[noteArrayPosition], trSelected);
+            displayNoteOnArray[noteArrayPosition] = true;
+            
+        }
+    }
+    if (trSelected == 0){
+        int quantizeOffset = getQuantizeOffset();
+        if (quantizeOffset >= 0){
+            chordsTemp.sequence[noteArrayPosition][(currentPulse+quantizeOffset)%(tracks[trSelected].loopLength)] = new NoteEvent (noteArrayPosition, trSelected+1, bar,beat,fraction,pulse);
+        }
+        if (quantizeOffset < 0){
+            chordsTemp.sequence[noteArrayPosition][(currentPulse+quantizeOffset)%(tracks[trSelected].loopLength)] = new NoteEvent (noteArrayPosition, trSelected+1, bar,beat,fraction,pulse);  
+
+            if (noteArrayPosition > 3)
+                currentChord = 15 - noteArrayPosition;
+             displayNoteOnArray[noteArrayPosition] = true;
+        }
+    }
+}
+
+public void writeNote(int noteArrayPosition, int veloc, int channel){ // writes note ons into the sequencers
+    VPA[channel].VPArrayNotes[noteArrayPosition].VPNoteOn = true;
+    VPA[channel].VPArrayNotes[noteArrayPosition].VPNotePitch = heresyPitch(noteArrayPosition, 1);
+    VPA[channel].VPArrayNotes[noteArrayPosition].VPNoteVelocity = veloc;
+    sendNote(VPA[channel].VPArrayNotes[noteArrayPosition], channel);
+}
+
+
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+public int getQuantizeOffset(){  // tells write note method the quantize offset.
+    int quantizeInPulses = pulsesPerBar/(tracks[trSelected].quantize);
+    int quantizeOffset = currentPulse % quantizeInPulses;
+    if (quantizeOffset > quantizeInPulses/2.0){
+        return ((quantizeOffset - quantizeInPulses) * -1) ;
+    }
+    else{
+        return quantizeOffset * -1;
+    }
+}
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HeresyBigBangDone/application.macosx/source/HeresyVoicingTables.pde	Sat Oct 08 22:12:49 2011 +0100
@@ -0,0 +1,244 @@
+// the main voicing tables for chords requested
+
+// root position
+
+int[] hchoice135 = new int[]  {24,  36,  43,  48,  52,  55,  60,  64,  67,  72,  76,  79,  84,  88,  91,  96};
+int[] hchoice7 = new int[]    {24,  36,  43,  48,  52,  55,  59,  64,  67,  71,  72,  76,  79,  83,  88,  95};
+int[] hchoice9 = new int[]    {24,  36,  43,  48,  50,  52,  55,  60,  62,  64,  67,  74,  76,  79,  86,  91};
+int[] hchoice11 = new int[]   {24,  36,  43,  48,  53,  55,  60,  65,  67,  72,  77,  79,  84,  89,  91,  96};
+int[] hchoice13 = new int[]   {24,  36,  43,  48,  52,  55,  57,  60,  64,  69,  72,  76,  81,  84,  88,  93};
+int[] hchoice79 = new int[]   {24,  36,  43,  48,  52,  55,  57,  59,  62,  64,  69,  71,  74,  76,  83,  86};
+int[] hchoice711 = new int[]  {24,  36,  43,  48,  53,  55,  59,  60,  65,  67,  71,  72,  77,  83,  88,  95}; //nice
+int[] hchoice713 = new int[]  {24,  36,  43,  48,  52,  57,  59,  64,  69,  71,  76,  79,  81,  83,  88,  93};
+int[] hchoice911 = new int[]  {24,  36,  43,  48,  53,  55,  60,  62,  65,  67,  74,  77,  79,  86,  89,  96};
+int[] hchoice913 = new int[]  {24,  36,  43,  48,  50,  57,  60,  62,  69,  72,  74,  81,  84,  86,  93,  96};
+int[] hchoice1113 = new int[] {24,  36,  43,  48,  52,  53,  57,  60,  64,  65,  69,  72,  77,  81,  84,  93}; //nice
+int[] hchoice7911 = new int[] {24,  36,  43,  48,  55,  62,  65,  71,  77,  79,  83,  84,  86,  89,  91,  96};
+int[] hchoice7913 = new int[] {24,  36,  43,  48,  59,  62,  69,  71,  74,  81,  83,  84,  86,  93,  95,  96};
+int[] hchoice71113 = new int[]{24,  36,  43,  48,  55,  59,  65,  69,  76,  77,  79,  84,  88,  89,  93,  96};
+int[] hchoice91113 = new int[]{24,  36,  48,  50,  53,  57,  60,  62,  65,  69,  72,  74,  77,  81,  89,  96};
+int[] hchoice791113 = new int[]{24,  36,  50,  53,  58,  62,  65,  70,  74,  77,  82,  84,  86,  89,  94,  96}; //dom7th full sus chord
+
+int[] mhchoice135 = new int[]  {24,  36,  43,  48,  51,  55,  60,  63,  67,  72,  75,  79,  84,  87,  91,  96};//
+int[] mhchoice7 = new int[]    {24,  36,  43,  48,  51,  55,  58,  63,  67,  70,  72,  75,  79,  82,  87,  94};//
+int[] mhchoice9 = new int[]    {24,  36,  43,  48,  50,  51,  55,  60,  62,  63,  67,  72,  74,  79,  86,  91};//
+int[] mhchoice11 = new int[]   {24,  36,  43,  48,  51,  53,  55,  60,  63,  65,  67,  72,  77,  79,  84,  89};//
+int[] mhchoice13 = new int[]   {24,  36,  43,  48,  51,  55,  57,  60,  63,  67,  69,  72,  75,  81,  84,  91};//
+int[] mhchoice79 = new int[]   {24,  36,  43,  50,  51,  55,  57,  58,  62,  63,  69,  70,  74,  75,  82,  86};//
+int[] mhchoice711 = new int[]  {24,  36,  43,  51,  58,  63,  65,  69,  72,  75,  77,  79,  82,  84,  89,  96};// 
+int[] mhchoice713 = new int[]  {24,  36,  43,  48,  55,  58,  59,  63,  69,  75,  79,  81,  82,  84,  93,  96};//
+int[] mhchoice911 = new int[]  {24,  36,  43,  48,  51,  53,  62,  63,  65,  67,  74,  77,  79,  86,  89,  96};//
+int[] mhchoice913 = new int[]  {24,  36,  43,  51,  57,  62,  63,  69,  74,  75,  81,  84,  86,  87,  93,  96};//
+int[] mhchoice1113 = new int[] {24,  36,  43,  53,  57,  63,  67,  72,  75,  77,  79,  81,  84,  87,  93,  96};// 
+int[] mhchoice7911 = new int[] {24,  36,  43,  50,  51,  58,  65,  67,  70,  72,  74,  75,  77,  79,  82,  86};//
+int[] mhchoice7913 = new int[] {24,  36,  48,  55,  58,  62,  63,  69,  70,  74,  75,  79,  81,  84,  93,  96};//
+int[] mhchoice71113 = new int[]{24,  36,  43,  48,  53,  58,  63,  65,  69,  72,  75,  77,  81,  84,  91,  96};//
+int[] mhchoice91113 = new int[]{24,  36,  48,  50,  53,  57,  60,  62,  65,  69,  72,  74,  77,  81,  89,  96};//
+int[] mhchoice791113 = new int[]{24,  36,  50,  53,  58,  62,  65,  70,  74,  77,  82,  84,  86,  89,  94,  96}; //dom7th full sus chord
+
+// first inversion
+
+int[] h1choice135 = new int[]  {24,  36,  40,  43,  48,  52,  55,  60,  64,  67,  72,  76,  79,  84,  88,  91};
+int[] h1choice7 = new int[]    {24,  36,  40,  43,  48,  52,  55,  59,  64,  67,  71,  72,  76,  79,  83,  88};
+int[] h1choice9 = new int[]    {24,  36,  38,  43,  48,  50,  52,  55,  60,  62,  64,  67,  74,  76,  79,  86};
+int[] h1choice11 = new int[]   {24,  36,  41,  43,  48,  53,  55,  60,  65,  67,  72,  77,  79,  84,  89,  91};
+int[] h1choice13 = new int[]   {24,  36,  40,  43,  48,  52,  55,  57,  60,  64,  69,  72,  76,  81,  84,  88};
+int[] h1choice79 = new int[]   {24,  36,  40,  43,  48,  52,  55,  57,  59,  62,  64,  69,  71,  74,  76,  83};
+int[] h1choice711 = new int[]  {24,  36,  41,  43,  48,  53,  55,  59,  60,  65,  67,  71,  72,  77,  83,  88}; //nice
+int[] h1choice713 = new int[]  {24,  36,  40,  43,  48,  52,  57,  59,  64,  69,  71,  76,  79,  81,  83,  88};
+int[] h1choice911 = new int[]  {24,  36,  41,  43,  48,  53,  55,  60,  62,  65,  67,  74,  77,  79,  86,  89};
+int[] h1choice913 = new int[]  {24,  36,  43,  45,  48,  50,  57,  60,  62,  69,  72,  74,  81,  84,  86,  93};
+int[] h1choice1113 = new int[] {24,  36,  40,  43,  48,  52,  53,  57,  60,  64,  65,  69,  72,  77,  81,  84}; //nice
+int[] h1choice7911 = new int[] {24,  36,  43,  48,  50,  55,  62,  65,  71,  77,  79,  83,  84,  86,  89,  91};
+int[] h1choice7913 = new int[] {24,  36,  43,  48,  55,  59,  62,  69,  71,  74,  81,  83,  84,  86,  93,  95};
+int[] h1choice71113 = new int[]{24,  36,  43,  48,  53,  55,  59,  65,  69,  76,  77,  79,  84,  88,  89,  93};
+int[] h1choice91113 = new int[]{24,  36,  41,  48,  50,  53,  57,  60,  62,  65,  69,  72,  74,  77,  81,  89};
+int[] h1choice791113 = new int[]{24,  36,  43,  50,  53,  58,  62,  65,  70,  74,  77,  82,  84,  86,  89,  94}; //dom7th full sus chord
+
+int[] m1hchoice135 = new int[]  {24,  36,  39,  43,  48,  51,  55,  60,  63,  67,  72,  75,  79,  84,  87,  91};//
+int[] m1hchoice7 = new int[]    {24,  36,  39,  43,  48,  51,  55,  58,  63,  67,  70,  72,  75,  79,  82,  87};//
+int[] m1hchoice9 = new int[]    {24,  36,  38,  43,  48,  50,  51,  55,  60,  62,  63,  67,  72,  74,  79,  86};//
+int[] m1hchoice11 = new int[]   {24,  36,  39,  43,  48,  51,  53,  55,  60,  63,  65,  67,  72,  77,  79,  84};//
+int[] m1hchoice13 = new int[]   {24,  36,  39,  43,  48,  51,  55,  57,  60,  63,  67,  69,  72,  75,  81,  84};//
+int[] m1hchoice79 = new int[]   {24,  36,  39,  43,  50,  51,  55,  57,  58,  62,  63,  69,  70,  74,  75,  82};//
+int[] m1hchoice711 = new int[]  {24,  36,  43,  46,  51,  58,  63,  65,  69,  72,  75,  77,  79,  82,  84,  89};// 
+int[] m1hchoice713 = new int[]  {24,  36,  43,  46,  48,  55,  58,  59,  63,  69,  75,  79,  81,  82,  84,  93};//
+int[] m1hchoice911 = new int[]  {24,  36,  39,  43,  48,  51,  53,  62,  63,  65,  67,  74,  77,  79,  86,  89};//
+int[] m1hchoice913 = new int[]  {24,  36,  43,  48,  51,  57,  62,  63,  69,  74,  75,  81,  84,  86,  87,  93};//
+int[] m1hchoice1113 = new int[] {24,  36,  43,  45,  53,  57,  63,  67,  72,  75,  77,  79,  81,  84,  87,  93};// 
+int[] m1hchoice7911 = new int[] {24,  36,  39,  43,  50,  51,  58,  65,  67,  70,  72,  74,  75,  77,  79,  82};//
+int[] m1hchoice7913 = new int[] {24,  36,  43,  48,  55,  58,  62,  63,  69,  70,  74,  75,  79,  81,  84,  93};//
+int[] m1hchoice71113 = new int[]{24,  36,  43,  46,  48,  53,  58,  63,  65,  69,  72,  75,  77,  81,  84,  91};//
+int[] m1hchoice91113 = new int[]{24,  36,  41,  48,  50,  53,  57,  60,  62,  65,  69,  72,  74,  77,  81,  89};//
+int[] m1hchoice791113 = new int[]{24,  36,  46,  50,  53,  58,  62,  65,  70,  74,  77,  82,  84,  86,  89,  94}; //dom7th full sus chord
+
+// second inversion
+
+int[] h2choice135 = new int[]  {24,  31,  36,  40,  43,  48,  52,  55,  60,  64,  67,  72,  76,  79,  84,  88};
+int[] h2choice7 = new int[]    {24,  31,  36,  40,  43,  48,  52,  55,  59,  64,  67,  71,  72,  76,  79,  83};
+int[] h2choice9 = new int[]    {24,  31,  36,  38,  43,  48,  50,  52,  55,  60,  62,  64,  67,  74,  76,  79};
+int[] h2choice11 = new int[]   {24,  31,  36,  41,  43,  48,  53,  55,  60,  65,  67,  72,  77,  79,  84,  89};
+int[] h2choice13 = new int[]   {24,  31,  36,  40,  43,  48,  52,  55,  57,  60,  64,  69,  72,  76,  81,  84};
+int[] h2choice79 = new int[]   {24,  31,  36,  40,  43,  48,  52,  55,  57,  59,  62,  64,  69,  71,  74,  76};
+int[] h2choice711 = new int[]  {24,  31,  36,  41,  43,  48,  53,  55,  59,  60,  65,  67,  71,  72,  77,  83}; //nice
+int[] h2choice713 = new int[]  {24,  31,  36,  40,  43,  48,  52,  57,  59,  64,  69,  71,  76,  79,  81,  83};
+int[] h2choice911 = new int[]  {24,  31,  36,  41,  43,  48,  53,  55,  60,  62,  65,  67,  74,  77,  79,  86};
+int[] h2choice913 = new int[]  {24,  31,  36,  43,  45,  48,  50,  57,  60,  62,  69,  72,  74,  81,  84,  86};
+int[] h2choice1113 = new int[] {24,  31,  36,  40,  43,  48,  52,  53,  57,  60,  64,  65,  69,  72,  77,  81}; //nice
+int[] h2choice7911 = new int[] {24,  31,  36,  43,  48,  50,  55,  62,  65,  71,  77,  79,  83,  84,  86,  89};
+int[] h2choice7913 = new int[] {24,  31,  36,  43,  48,  55,  59,  62,  69,  71,  74,  81,  83,  84,  86,  93};
+int[] h2choice71113 = new int[]{24,  31,  36,  43,  48,  53,  55,  59,  65,  69,  76,  77,  79,  84,  88,  89};
+int[] h2choice91113 = new int[]{24,  31,  36,  41,  48,  50,  53,  57,  60,  62,  65,  69,  72,  74,  77,  81};
+int[] h2choice791113 = new int[]{24,  31,  36,  43,  50,  53,  58,  62,  65,  70,  74,  77,  82,  84,  86,  89}; //dom7th full sus chord
+
+int[] m2hchoice135 = new int[]  {24,  31,  36,  39,  43,  48,  51,  55,  60,  63,  67,  72,  75,  79,  84,  87};//
+int[] m2hchoice7 = new int[]    {24,  31,  36,  39,  43,  48,  51,  55,  58,  63,  67,  70,  72,  75,  79,  82};//
+int[] m2hchoice9 = new int[]    {24,  31,  36,  38,  43,  48,  50,  51,  55,  60,  62,  63,  67,  72,  74,  79};//
+int[] m2hchoice11 = new int[]   {24,  31,  36,  39,  43,  48,  51,  53,  55,  60,  63,  65,  67,  72,  77,  79};//
+int[] m2hchoice13 = new int[]   {24,  31,  36,  39,  43,  48,  51,  55,  57,  60,  63,  67,  69,  72,  75,  81};//
+int[] m2hchoice79 = new int[]   {24,  31,  36,  39,  43,  50,  51,  55,  57,  58,  62,  63,  69,  70,  74,  75};//
+int[] m2hchoice711 = new int[]  {24,  31,  36,  43,  46,  51,  58,  63,  65,  69,  72,  75,  77,  79,  82,  84};// 
+int[] m2hchoice713 = new int[]  {24,  31,  36,  43,  46,  48,  55,  58,  59,  63,  69,  75,  79,  81,  82,  84};//
+int[] m2hchoice911 = new int[]  {24,  31,  36,  39,  43,  48,  51,  53,  62,  63,  65,  67,  74,  77,  79,  86};//
+int[] m2hchoice913 = new int[]  {24,  31,  36,  43,  48,  51,  57,  62,  63,  69,  74,  75,  81,  84,  86,  87};//
+int[] m2hchoice1113 = new int[] {24,  31,  36,  43,  45,  53,  57,  63,  67,  72,  75,  77,  79,  81,  84,  87};// 
+int[] m2hchoice7911 = new int[] {24,  31,  36,  39,  43,  50,  51,  58,  65,  67,  70,  72,  74,  75,  77,  79};//
+int[] m2hchoice7913 = new int[] {24,  31,  36,  43,  48,  55,  58,  62,  63,  69,  70,  74,  75,  79,  81,  84};//
+int[] m2hchoice71113 = new int[]{24,  31,  36,  43,  46,  48,  53,  58,  63,  65,  69,  72,  75,  77,  81,  84};//
+int[] m2hchoice91113 = new int[]{24,  31,  36,  41,  48,  50,  53,  57,  60,  62,  65,  69,  72,  74,  77,  81};//
+int[] m2hchoice791113 = new int[]{24,  31,  36,  46,  50,  53,  58,  62,  65,  70,  74,  77,  82,  84,  86,  89}; //dom7th full sus chord
+
+int[] hvArray;
+int[] minorSystem = new int[] {0, 3, 7, 10, 14, 17, 21};
+int[] major7System = new int[] {0, 4, 7, 11, 14, 18, 21};
+int[] dom7System = new int[] {0, 4, 7, 10, 14, 17, 21};
+int[] tritoneSystem = new int[] {0, 4, 7, 10, 14, 18, 21};
+
+public int heresyPitch(int arrayPosition, int heresyChannel){  //  calculates the pitch value to be returned for playback.
+    boolean m = heresyMinor;
+    boolean e7 = heresy7th;
+    boolean e9 = heresy9th;
+    boolean e11 = heresy11th;
+    boolean e13 = heresy13th;
+    int returnInt = 0;
+    if ((currentChord % 12) > -1 && (currentChord % 12) < 4){
+        if (!m && !e7 && !e9 && !e11 && !e13) returnInt = hchoice135[15 - arrayPosition];
+        if (!m &&  e7 && !e9 && !e11 && !e13) returnInt = hchoice7[15 - arrayPosition];
+        if (!m && !e7 &&  e9 && !e11 && !e13) returnInt = hchoice9[15 - arrayPosition];
+        if (!m && !e7 && !e9 &&  e11 && !e13) returnInt = hchoice11[15 - arrayPosition];
+        if (!m && !e7 && !e9 && !e11 &&  e13) returnInt = hchoice13[15 - arrayPosition];
+        if (!m &&  e7 &&  e9 && !e11 && !e13) returnInt = hchoice79[15 - arrayPosition]; 
+        if (!m &&  e7 && !e9 &&  e11 && !e13) returnInt = hchoice711[15 - arrayPosition]; 
+        if (!m &&  e7 && !e9 && !e11 &&  e13) returnInt = hchoice713[15 - arrayPosition];
+        if (!m && !e7 &&  e9 &&  e11 && !e13) returnInt = hchoice911[15 - arrayPosition];
+        if (!m && !e7 &&  e9 && !e11 &&  e13) returnInt = hchoice913[15 - arrayPosition];
+        if (!m && !e7 && !e9 &&  e11 &&  e13) returnInt = hchoice1113[15 - arrayPosition];
+        if (!m &&  e7 &&  e9 &&  e11 && !e13) returnInt = hchoice7911[15 - arrayPosition];
+        if (!m &&  e7 &&  e9 && !e11 &&  e13) returnInt = hchoice7913[15 - arrayPosition];
+        if (!m &&  e7 && !e9 &&  e11 &&  e13) returnInt = hchoice71113[15 - arrayPosition];
+        if (!m && !e7 &&  e9 &&  e11 &&  e13) returnInt = hchoice91113[15 - arrayPosition];
+        if (!m &&  e7 &&  e9 &&  e11 &&  e13) returnInt = hchoice791113[15 - arrayPosition];
+    
+        if (m && !e7 && !e9 && !e11 && !e13) returnInt = mhchoice135[15 - arrayPosition];
+        if (m &&  e7 && !e9 && !e11 && !e13) returnInt = mhchoice7[15 - arrayPosition];
+        if (m && !e7 &&  e9 && !e11 && !e13) returnInt = mhchoice9[15 - arrayPosition];
+        if (m && !e7 && !e9 &&  e11 && !e13) returnInt = mhchoice11[15 - arrayPosition];
+        if (m && !e7 && !e9 && !e11 &&  e13) returnInt = mhchoice13[15 - arrayPosition];
+        if (m &&  e7 &&  e9 && !e11 && !e13) returnInt = mhchoice79[15 - arrayPosition]; 
+        if (m &&  e7 && !e9 &&  e11 && !e13) returnInt = mhchoice711[15 - arrayPosition]; 
+        if (m &&  e7 && !e9 && !e11 &&  e13) returnInt = mhchoice713[15 - arrayPosition];
+        if (m && !e7 &&  e9 &&  e11 && !e13) returnInt = mhchoice911[15 - arrayPosition];
+        if (m && !e7 &&  e9 && !e11 &&  e13) returnInt = mhchoice913[15 - arrayPosition];
+        if (m && !e7 && !e9 &&  e11 &&  e13) returnInt = mhchoice1113[15 - arrayPosition];
+        if (m &&  e7 &&  e9 &&  e11 && !e13) returnInt = mhchoice7911[15 - arrayPosition];
+        if (m &&  e7 &&  e9 && !e11 &&  e13) returnInt = mhchoice7913[15 - arrayPosition];
+        if (m &&  e7 && !e9 &&  e11 &&  e13) returnInt = mhchoice71113[15 - arrayPosition];
+        if (m && !e7 &&  e9 &&  e11 &&  e13) returnInt = mhchoice91113[15 - arrayPosition];
+        if (m &&  e7 &&  e9 &&  e11 &&  e13) returnInt = mhchoice791113[15 - arrayPosition];
+    }
+    
+        if ((currentChord % 12) > 3 && (currentChord % 12) < 8){
+        if (!m && !e7 && !e9 && !e11 && !e13) returnInt = h1choice135[15 - arrayPosition];
+        if (!m &&  e7 && !e9 && !e11 && !e13) returnInt = h1choice7[15 - arrayPosition];
+        if (!m && !e7 &&  e9 && !e11 && !e13) returnInt = h1choice9[15 - arrayPosition];
+        if (!m && !e7 && !e9 &&  e11 && !e13) returnInt = h1choice11[15 - arrayPosition];
+        if (!m && !e7 && !e9 && !e11 &&  e13) returnInt = h1choice13[15 - arrayPosition];
+        if (!m &&  e7 &&  e9 && !e11 && !e13) returnInt = h1choice79[15 - arrayPosition]; 
+        if (!m &&  e7 && !e9 &&  e11 && !e13) returnInt = h1choice711[15 - arrayPosition]; 
+        if (!m &&  e7 && !e9 && !e11 &&  e13) returnInt = h1choice713[15 - arrayPosition];
+        if (!m && !e7 &&  e9 &&  e11 && !e13) returnInt = h1choice911[15 - arrayPosition];
+        if (!m && !e7 &&  e9 && !e11 &&  e13) returnInt = h1choice913[15 - arrayPosition];
+        if (!m && !e7 && !e9 &&  e11 &&  e13) returnInt = h1choice1113[15 - arrayPosition];
+        if (!m &&  e7 &&  e9 &&  e11 && !e13) returnInt = h1choice7911[15 - arrayPosition];
+        if (!m &&  e7 &&  e9 && !e11 &&  e13) returnInt = h1choice7913[15 - arrayPosition];
+        if (!m &&  e7 && !e9 &&  e11 &&  e13) returnInt = h1choice71113[15 - arrayPosition];
+        if (!m && !e7 &&  e9 &&  e11 &&  e13) returnInt = h1choice91113[15 - arrayPosition];
+        if (!m &&  e7 &&  e9 &&  e11 &&  e13) returnInt = h1choice791113[15 - arrayPosition];
+    
+        if (m && !e7 && !e9 && !e11 && !e13) returnInt = m1hchoice135[15 - arrayPosition];
+        if (m &&  e7 && !e9 && !e11 && !e13) returnInt = m1hchoice7[15 - arrayPosition];
+        if (m && !e7 &&  e9 && !e11 && !e13) returnInt = m1hchoice9[15 - arrayPosition];
+        if (m && !e7 && !e9 &&  e11 && !e13) returnInt = m1hchoice11[15 - arrayPosition];
+        if (m && !e7 && !e9 && !e11 &&  e13) returnInt = m1hchoice13[15 - arrayPosition];
+        if (m &&  e7 &&  e9 && !e11 && !e13) returnInt = m1hchoice79[15 - arrayPosition]; 
+        if (m &&  e7 && !e9 &&  e11 && !e13) returnInt = m1hchoice711[15 - arrayPosition]; 
+        if (m &&  e7 && !e9 && !e11 &&  e13) returnInt = m1hchoice713[15 - arrayPosition];
+        if (m && !e7 &&  e9 &&  e11 && !e13) returnInt = m1hchoice911[15 - arrayPosition];
+        if (m && !e7 &&  e9 && !e11 &&  e13) returnInt = m1hchoice913[15 - arrayPosition];
+        if (m && !e7 && !e9 &&  e11 &&  e13) returnInt = m1hchoice1113[15 - arrayPosition];
+        if (m &&  e7 &&  e9 &&  e11 && !e13) returnInt = m1hchoice7911[15 - arrayPosition];
+        if (m &&  e7 &&  e9 && !e11 &&  e13) returnInt = m1hchoice7913[15 - arrayPosition];
+        if (m &&  e7 && !e9 &&  e11 &&  e13) returnInt = m1hchoice71113[15 - arrayPosition];
+        if (m && !e7 &&  e9 &&  e11 &&  e13) returnInt = m1hchoice91113[15 - arrayPosition];
+        if (m &&  e7 &&  e9 &&  e11 &&  e13) returnInt = m1hchoice791113[15 - arrayPosition];
+    }
+    
+        if ((currentChord % 12) > 7 && (currentChord % 12) < 12){
+        if (!m && !e7 && !e9 && !e11 && !e13) returnInt = h2choice135[15 - arrayPosition];
+        if (!m &&  e7 && !e9 && !e11 && !e13) returnInt = h2choice7[15 - arrayPosition];
+        if (!m && !e7 &&  e9 && !e11 && !e13) returnInt = h2choice9[15 - arrayPosition];
+        if (!m && !e7 && !e9 &&  e11 && !e13) returnInt = h2choice11[15 - arrayPosition];
+        if (!m && !e7 && !e9 && !e11 &&  e13) returnInt = h2choice13[15 - arrayPosition];
+        if (!m &&  e7 &&  e9 && !e11 && !e13) returnInt = h2choice79[15 - arrayPosition]; 
+        if (!m &&  e7 && !e9 &&  e11 && !e13) returnInt = h2choice711[15 - arrayPosition]; 
+        if (!m &&  e7 && !e9 && !e11 &&  e13) returnInt = h2choice713[15 - arrayPosition];
+        if (!m && !e7 &&  e9 &&  e11 && !e13) returnInt = h2choice911[15 - arrayPosition];
+        if (!m && !e7 &&  e9 && !e11 &&  e13) returnInt = h2choice913[15 - arrayPosition];
+        if (!m && !e7 && !e9 &&  e11 &&  e13) returnInt = h2choice1113[15 - arrayPosition];
+        if (!m &&  e7 &&  e9 &&  e11 && !e13) returnInt = h2choice7911[15 - arrayPosition];
+        if (!m &&  e7 &&  e9 && !e11 &&  e13) returnInt = h2choice7913[15 - arrayPosition];
+        if (!m &&  e7 && !e9 &&  e11 &&  e13) returnInt = h2choice71113[15 - arrayPosition];
+        if (!m && !e7 &&  e9 &&  e11 &&  e13) returnInt = h2choice91113[15 - arrayPosition];
+        if (!m &&  e7 &&  e9 &&  e11 &&  e13) returnInt = h2choice791113[15 - arrayPosition];
+    
+        if (m && !e7 && !e9 && !e11 && !e13) returnInt = m2hchoice135[15 - arrayPosition];
+        if (m &&  e7 && !e9 && !e11 && !e13) returnInt = m2hchoice7[15 - arrayPosition];
+        if (m && !e7 &&  e9 && !e11 && !e13) returnInt = m2hchoice9[15 - arrayPosition];
+        if (m && !e7 && !e9 &&  e11 && !e13) returnInt = m2hchoice11[15 - arrayPosition];
+        if (m && !e7 && !e9 && !e11 &&  e13) returnInt = m2hchoice13[15 - arrayPosition];
+        if (m &&  e7 &&  e9 && !e11 && !e13) returnInt = m2hchoice79[15 - arrayPosition]; 
+        if (m &&  e7 && !e9 &&  e11 && !e13) returnInt = m2hchoice711[15 - arrayPosition]; 
+        if (m &&  e7 && !e9 && !e11 &&  e13) returnInt = m2hchoice713[15 - arrayPosition];
+        if (m && !e7 &&  e9 &&  e11 && !e13) returnInt = m2hchoice911[15 - arrayPosition];
+        if (m && !e7 &&  e9 && !e11 &&  e13) returnInt = m2hchoice913[15 - arrayPosition];
+        if (m && !e7 && !e9 &&  e11 &&  e13) returnInt = m2hchoice1113[15 - arrayPosition];
+        if (m &&  e7 &&  e9 &&  e11 && !e13) returnInt = m2hchoice7911[15 - arrayPosition];
+        if (m &&  e7 &&  e9 && !e11 &&  e13) returnInt = m2hchoice7913[15 - arrayPosition];
+        if (m &&  e7 && !e9 &&  e11 &&  e13) returnInt = m2hchoice71113[15 - arrayPosition];
+        if (m && !e7 &&  e9 &&  e11 &&  e13) returnInt = m2hchoice91113[15 - arrayPosition];
+        if (m &&  e7 &&  e9 &&  e11 &&  e13) returnInt = m2hchoice791113[15 - arrayPosition];
+    }
+    
+    if (heresyDom && returnInt % 12 == 11)
+        returnInt--;
+    returnInt = currentChord + returnInt;
+    
+  //  if (heresyChannel == 1 || heresyChannel == 5)
+  //      returnInt = 15 - arrayPosition + 36;
+        
+
+        
+    return returnInt;
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HeresyBigBangDone/application.macosx/source/IO.pde	Sat Oct 08 22:12:49 2011 +0100
@@ -0,0 +1,398 @@
+void sendNote(VPNote note, int channel){ // send note function gathers info to output to max
+    outputToMax(note.VPNotePitch, note.VPNoteVelocity, channel);
+}
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+void outputToMax(int note, int velocity, int channel){ // calculates the necessary note on and note offs depending on ducking and muting and sends them to max
+    String noteOut = "";
+    if (!tracks[channel].mute){
+        if (tracks[channel].ducking){
+            if (velocity != 0){
+                noteOut = ("" + note + " " + velocity + " " + (channel+8));
+            }
+            if (velocity == 0 && !tracks[channel].cycled){
+                noteOut = ("" + note + " " + velocity + " " + (channel+8));
+                  OscMessage message = new OscMessage("/pitch_vel_chan");
+                  message.add(noteOut);
+                  oscP5return.send(message, ableton);
+                link.output(noteOut);
+                noteOut = ("" + note + " " + velocity + " " + channel);
+            }
+            if (velocity == 0 && tracks[channel].cycled){
+                noteOut = ("" + note + " " + velocity + " " + (channel+8));      
+            }
+        }
+        if (!tracks[channel].ducking){
+            if (velocity != 0){
+                noteOut = ("" + note + " " + velocity + " " + channel);
+            }
+            if (velocity == 0 && !tracks[channel].cycled){
+                noteOut = ("" + note + " " + velocity + " " + (channel+8));
+                  OscMessage message = new OscMessage("/pitch_vel_chan");
+                  message.add(noteOut);
+                  oscP5return.send(message, ableton);
+                link.output(noteOut);
+                noteOut = ("" + note + " " + velocity + " " + channel);
+            }
+            if (velocity == 0 && tracks[channel].cycled){
+                noteOut = ("" + note + " " + velocity + " " + channel);  
+            }
+        }
+        link.output(noteOut);
+        OscMessage message = new OscMessage("/pitch_vel_chan");
+        message.add(noteOut);
+        oscP5return.send(message, ableton);
+        
+    }
+    if (tracks[channel].mute){
+        if (velocity == 0 && !tracks[channel].cycled){
+            noteOut = ("" + note + " " + velocity + " " + (channel+8));
+            link.output(noteOut);
+            OscMessage message = new OscMessage("/pitch_vel_chan");
+            message.add(noteOut);
+            oscP5return.send(message, ableton);
+            noteOut = ("" + note + " " + velocity + " " + channel);
+            OscMessage message2 = new OscMessage("/pitch_vel_chan");
+            message2.add(noteOut);
+            oscP5return.send(message, ableton);
+            link.output(noteOut);
+        }
+    }   
+}
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+void mouseDragged(){ // not used
+}
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+void mouseReleased(){ // not used
+}
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+void mousePressed(){ // not used
+}
+
+
+//-------------------------------------------------------------------------------------------------------------------------------
+
+void keyPressed() { // takes keyboard input
+    if (key == 'c' || key == 'C') {
+        chordSelecter = !chordSelecter;
+        if (!chordSelecter)
+            trSelected = lastTrack;
+        else{
+            lastTrack = trSelected;
+            trSelected = 0;
+            
+        }
+    }
+    
+    if (key == ' ') {
+        if (trSelected != 0){
+            for (int i = 0; i < 16; i++){
+                noteOnArray[i] = false;
+                finishNote(i);
+                displayNoteOnArray[i] = false;
+           }
+    
+           if (trSelected != 0){     
+              for (int i = 24; i < 109; i++)
+                outputToMax(i, 0, trSelected);
+           }
+           tracks[trSelected] = new Track(tracks[trSelected].name, true,  tracks[trSelected].loopLength, tracks[trSelected].quantize, false, false);
+           imgNotes = null;
+        }
+        
+        if (trSelected == 0){
+           for (int i = 0; i < 16; i++){
+               noteOnArray[i] = false;
+               finishNote(i);
+               displayNoteOnArray[i] = false;
+           }
+           heresyMinor = false;
+           heresy7th = false;
+           heresy9th = false;
+           heresy11th = false;
+           heresy13th = false;
+           chordsTemp = new Track(tracks[trSelected].name, true,  tracks[trSelected].loopLength, tracks[trSelected].quantize, false, false);
+           imgNotes = null;
+        }
+    }
+
+     if (key == 'p' || key == 'P') {
+         for (int i = 0; i < 16; i++){
+              for (int ii = 24; ii < 109; ii++)
+                outputToMax(ii, 0, trSelected);
+             noteOnArray[i] = false;
+             displayNoteOnArray[i] = false; 
+         }
+     }
+     
+     if (key == 'd' || key == 'D') {
+         if (trSelected != 0 && trSelected != 1){
+               tracks[trSelected].ducking = !tracks[trSelected].ducking;
+               tracks[trSelected].cycled = false;
+               tracks[trSelected].cycledPosition = currentPulse%tracks[trSelected].loopLength; 
+         }
+     }
+    
+     if (key == 'w' || key == 'W') {
+       
+        trSelected = 0;
+
+        for (int i = 0; i < 16; i++){
+            noteOnArray[i] = false;
+            finishNoteCutOff(i);
+            displayNoteOnArray[i] = false;
+        }
+        heresyMinor = false;
+        heresy7th = false;
+        heresy9th = false;
+        heresy11th = false;
+        heresy13th = false;
+        
+        tracks[trSelected] = new Track(tracks[trSelected].name, true,  tracks[trSelected].loopLength, tracks[trSelected].quantize, false, false);
+        chordsTemp = new Track(tracks[trSelected].name, true,  tracks[trSelected].loopLength, tracks[trSelected].quantize, false, false);
+        imgNotes = null;
+    }
+    
+    if (key == 'q' || key == 'Q'){
+        quantizeValueIn = true;
+        sendToScreen(tracks[trSelected].name + " quantize?");
+    }
+    
+    if (key == 'x' || key == 'X'){
+        clickTrackOn = !clickTrackOn;
+    }
+    
+    if (key == 'e' || key == 'E'){
+        eraseOn = !eraseOn;
+        if (!eraseOn) imgNotes = null;
+    }
+    
+    if (key == 'r' || key == 'R'){
+        imgNotes = null;
+    }
+    
+    if (key == 'l' || key == 'L'){
+        loopLengthValueIn = true;
+        sendToScreen(tracks[trSelected].name + " loop length?");
+    }
+    
+    if (key == 'm' || key == 'M'){
+        if (trSelected != 0){
+            muteValueIn = true;
+            if (!tracks[trSelected].mute)
+                sendToScreen(tracks[trSelected].name + " mute in?");
+            if (tracks[trSelected].mute)
+                sendToScreen(tracks[trSelected].name + " unmute in?");              
+        }
+    }
+
+   
+    if (key == '1') numberKey(1);
+    if (key == '2') numberKey(2);
+    if (key == '3') numberKey(3);
+    if (key == '4') numberKey(4);
+    if (key == '5') numberKey(5);
+    if (key == '6') numberKey(6);
+    if (key == '7') numberKey(7);
+    if (key == '8') numberKey(8);       
+    if (key == '9') numberKey(9);
+    if (key == '0') numberKey(0);
+
+    if (key == CODED) {
+        if (keyCode == UP && trSelected < Track.currentNumberOfTracks-1)
+            trSelected++;
+        if (keyCode == DOWN && trSelected > 1) {
+           trSelected--;
+        } 
+     }
+     
+     if (key == 's' || key == 'S'){
+          for (int i = 0; i < 16; i++){
+              for (int ii = 0; ii < tracks[0].loopLength; ii++){
+                  if (chordsTemp.sequence[i][ii] != null)
+                      tracks[0].sequence[i][ii] = chordsTemp.sequence[i][ii];
+              }
+          }
+     }
+     
+ 
+}
+
+
+//------------------------------------------------------------------------------------------------------------------------------- 
+
+void numberKey(int input){ // if a number is enterd, this method works out what to do with it
+    if (quantizeValueIn == true)
+        if (input == 1 || input == 2 || input == 4 || input == 8 || input == 0){
+             tracks[trSelected].quantize = input;
+             quantizeValueIn = false;
+             aniOut = true;
+        }
+         
+    if (loopLengthValueIn == true){
+        if (input >= 1 && input <= 8 ){
+            Track tempTrack = new Track(tracks[trSelected].name, tracks[trSelected].polyphonic, (input * loopLength / 2), tracks[trSelected].quantize, false, false);
+            NoteEvent tempNote;
+            
+            for (int i = 0; i < 16; i++){
+                if (tempTrack.loopLength >= tracks[trSelected].loopLength){
+                    for (int ii = 0; ii < tracks[trSelected].loopLength; ii++){
+                        tempTrack.sequence[i][ii] = tracks[trSelected].sequence[i][ii];
+                    }
+                }else{
+                    for (int ii = 0; ii < tempTrack.loopLength; ii++){
+                        tempTrack.sequence[i][ii] = tracks[trSelected].sequence[i][ii];
+                    }
+                }
+            }
+            tracks[trSelected] = tempTrack;
+            for (int i = 0; i < 16; i++)
+            if (noteOnArray[i] = true){
+                noteOnArray[i] = false;
+                finishNoteCutOff(i);
+                displayNoteOnArray[i] = false;
+            }
+  
+             
+            loopLengthValueIn = false;
+            aniOut = true;
+            if (trSelected ==0){
+                Track tempTrack2 = new Track(chordsTemp.name, chordsTemp.polyphonic, (input * loopLength / 2), chordsTemp.quantize, false, false);
+                NoteEvent tempNote2;
+            
+                for (int i = 0; i < 16; i++){
+                    if (tempTrack2.loopLength >= chordsTemp.loopLength){
+                        for (int ii = 0; ii < chordsTemp.loopLength; ii++){
+                            tempTrack2.sequence[i][ii] = chordsTemp.sequence[i][ii];
+                        }
+                    }else{
+                        for (int ii = 0; ii < tempTrack2.loopLength; ii++){
+                            tempTrack2.sequence[i][ii] = chordsTemp.sequence[i][ii];
+                        }
+                    }  
+                }
+            chordsTemp = tempTrack2;
+            }
+            imgNotes = null;
+        }
+    }
+    
+    if (muteValueIn == true){
+        tracks[trSelected].muteIn = bar + input;
+        muteValueIn = false;
+        tracks[trSelected].muteDone = false;
+        aniOut = true;
+    }
+        
+         
+}
+
+
+//------------------------------------------------------------------------------------------------------------------------------- 
+
+void sendToScreen(String name){ // prepares a question for asking the user and turns the question on
+
+      screenQuestion = name;
+      screenAni = 0;
+      haveQuestion = true;
+    
+}
+
+
+//------------------------------------------------------------------------------------------------------------------------------- 
+
+void checkCycled(){  // checks whether after ducking or muting all note offs are played.
+    for (int i = 1; i < Track.currentNumberOfTracks; i++)
+        if (tracks[i].cycled == false)
+            if (tracks[i].cycledPosition-1 == currentPulse%tracks[trSelected].loopLength)
+                tracks[i].cycled = true;
+    
+}
+
+
+//------------------------------------------------------------------------------------------------------------------------------- 
+
+
+void checkForMutes(){ // looks for mute / unmuted changes in tracks
+    for (int i = 1; i < Track.currentNumberOfTracks; i++)
+        if (tracks[i].muteIn == bar && !tracks[i].muteDone){
+            tracks[i].mute = !tracks[i].mute;
+            tracks[i].muteDone = true;
+            tracks[trSelected].cycled = false;
+            tracks[trSelected].cycledPosition = currentPulse%tracks[trSelected].loopLength; 
+        }
+}
+
+
+
+//------------------------------------------------------------------------------------------------------------------------------- 
+
+void writeQuestion(){ // animates screen questions
+  
+  if (screenAni < 10 && !aniOut){
+      screenAni++;
+  }
+  
+  if (screenAni > 0 && aniOut){
+     screenAni--;
+  }
+  
+   if (screenAni == 0){
+      haveQuestion = false;
+      aniOut = false;
+   }
+  
+  fill(255,0,0, screenAni*12);
+  textSize((11-screenAni)*40);
+  text(screenQuestion, (screenAni*50)-200,(100-screenAni*10)+150);
+  
+    
+}
+
+
+//------------------------------------------------------------------------------------------------------------------------------- 
+
+void oscEvent(OscMessage theOscMessage) { // recieves osc messages from openFrameworks
+    println("osc message : " + theOscMessage);
+    if(theOscMessage.checkAddrPattern("/test")==true) {
+        println("i1 : " + theOscMessage.get(1).intValue() + "  i2 : " + theOscMessage.get(2).intValue() + "  i3 : " + theOscMessage.get(3).intValue() + "  i4 : " + theOscMessage.get(4).intValue());
+        clickTrack = false;
+        String stringValue = theOscMessage.get(0).stringValue();
+        int firstValue = theOscMessage.get(1).intValue(); 
+        int secondValue = theOscMessage.get(2).intValue();
+        int thirdValue = theOscMessage.get(3).intValue(); //velocity
+        int fourthValue = theOscMessage.get(4).intValue(); //channel
+        if (secondValue == 1){
+            noteOnArray[firstValue] = true;
+            writeNote(firstValue, thirdValue, fourthValue);       
+        }
+        else{
+            noteOnArray[firstValue] = false;
+            writeNote(firstValue, 0, fourthValue); 
+        }
+    }
+    if(theOscMessage.checkAddrPattern("/chord")==true) {
+        chordCalc();
+  //      writeNote(15, 80, 6);
+        writeNote(14, 80, 6);
+        writeNote(13, 80, 6);
+        writeNote(12, 80, 6);
+        writeNote(11, 80, 6);
+        writeNote(10, 80, 6);
+        writeNote(9, 80, 6);
+    }
+}
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HeresyBigBangDone/application.macosx/source/NoteEvent.java	Sat Oct 08 22:12:49 2011 +0100
@@ -0,0 +1,61 @@
+ class MidiEvent { // the basic super class for all midi events
+  
+    int firstDataByte;
+    int secondDataByte;
+    int channel;
+
+}
+
+//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+
+ class NoteEvent extends MidiEvent{ //  the note event class
+  
+    int notePitch = 60;
+    int[] notePosition = new int[4];
+    int[] noteLength = new int[4];
+    int noteVelocity;  
+    boolean noteIgnore;
+    boolean noteOn;
+    
+    
+    public NoteEvent(int notePitch, int channel, int bar, int beat, int fraction, int pulse, boolean noteOff) {
+        this.notePitch = notePitch;
+        this.channel = channel;
+        this.noteVelocity = 80;     
+        if (noteOff)
+        this.noteVelocity = 0;
+        boolean noteIgnore = false;
+        this.noteOn = true;
+    }
+  
+    public NoteEvent(int notePitch, int channel, int bar, int beat, int fraction, int pulse) {
+        this(notePitch, channel, bar, beat, fraction, pulse, false);
+    }
+    
+    public NoteEvent(int notePitch, int channel, int veloc, int bar, int beat, int fraction, int pulse) {
+        this.notePitch = notePitch;
+        this.channel = channel;
+        this.noteVelocity = veloc;     
+        boolean noteIgnore = false;
+        this.noteOn = true;
+    }
+
+    
+    public NoteEvent(int notePitch, int channel, int bar, int beat, int fraction, int pulse, int lengthBar, int lengthBeat, int lengthFraction, int lengthPulse) {
+        this.notePitch = notePitch;
+        this.channel = channel;
+        this.noteVelocity = 80;     
+        boolean noteIgnore = false;
+        this.noteOn = true;
+        notePosition[0] = bar;
+        notePosition[1] = beat;
+        notePosition[2] = fraction;
+        notePosition[3] = pulse;
+        noteLength[0] = lengthBar;
+        noteLength[1] = lengthBeat;
+        noteLength[2] = lengthFraction;
+        noteLength[3] = lengthPulse;
+    }
+        
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HeresyBigBangDone/application.macosx/source/Track.java	Sat Oct 08 22:12:49 2011 +0100
@@ -0,0 +1,41 @@
+class Track{ // the track class
+  
+    boolean polyphonic;
+    int loopLength;
+    int trackNumber;
+    static int currentNumberOfTracks;
+    boolean selected;
+    NoteEvent[][] sequence;
+    int quantize;
+    boolean forceLegato;
+    String name;
+    boolean ducking;
+    boolean cycled;
+    int cycledPosition;
+    boolean mute;
+    boolean muteDone;
+    int muteIn;
+
+
+    
+    public Track(String name, boolean polyphonic, int loopLength, int quantize, boolean forceLegato, boolean increment){
+      
+        if (polyphonic)
+            this.polyphonic = true;
+        else
+            this.polyphonic = false;
+        this.name = name;
+        this.ducking = false;
+        this.cycled = true;
+        this.forceLegato = forceLegato;
+        this.quantize = quantize;
+        this.loopLength = loopLength;
+        if (increment) this.trackNumber = currentNumberOfTracks++;
+        this.selected = false;
+        this.mute = false;
+        this.muteIn = 0;
+        sequence = new NoteEvent[16][loopLength];
+     
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HeresyBigBangDone/application.macosx/source/VirtualPlayingArray.pde	Sat Oct 08 22:12:49 2011 +0100
@@ -0,0 +1,31 @@
+class VPArray{ // the virtual playing array for Heresy AI to play with
+  
+    VPNote[] VPArrayNotes;
+    
+    public VPArray(){
+        VPArrayNotes = new VPNote[16];
+        for (int i = 0; i < 16; i++)
+          VPArrayNotes[i] = new VPNote();
+    }
+}
+
+class VPNote{
+  
+    boolean played;
+    boolean VPNoteOn;
+    boolean done;
+    int extension;
+    int VPNotePitch;
+    int VPNoteVelocity;
+    
+    public VPNote(){
+       VPNoteOn = false;
+       played = true;
+        extension = 0;
+        VPNotePitch = 0;
+        VPNoteVelocity = 0;
+    }
+}
+
+ 
+    
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HeresyBigBangDone/application.macosx/source/chord_changer.pde	Sat Oct 08 22:12:49 2011 +0100
@@ -0,0 +1,398 @@
+
+void chordCalc(){
+    barCounter++;
+    if (barCounter % 4 == 0 || ((currentChord == 1 || currentChord == 5 || currentChord == 7) && barCounter % 4 == 3)){
+        tonicNeeded = true;
+        print(" tonic needed " + (barCounter % 4));
+     }
+     else tonicNeeded = false;
+     chooseChord();
+}
+
+void chooseChord(){
+
+    int i = 0;
+    for (; i < crneeded; i++){
+        if (chordChoicesArray[i].chordNote == currentChord && chordChoicesArray[i].minor == heresyMinor)
+            break;
+    }
+    if (currentChord == 1 && heresyDom)
+        i = 16;
+    if (tonicNeeded && i != 24){
+        int gotOne = -1;
+        int gotTwo = -1;
+        if (chordChoicesArray[i].optionArray[0].chordOption == 0 && chordChoicesArray[i].optionArray[1].chordOption == 0 && int(random(2)) == 0)
+            chosenChord (i, chordChoicesArray[i].optionArray[1].chordOption);
+        else if 
+            (chordChoicesArray[i].optionArray[0].chordOption == 0 && chordChoicesArray[i].optionArray[1].chordOption != 0)
+            chosenChord (i, chordChoicesArray[i].optionArray[0].chordOption);
+        else
+            chosenChord (i, int(random(chordChoicesArray[i].slots)));
+    }
+    else if (i != 24){
+        chosenChord(i, int(random(chordChoicesArray[i].slots))); 
+    }else{
+        currentChord = lastChordChange;
+        heresyMinor = lastMinor;
+    }
+    println("   chord selected : " + currentChord + " minor:" + heresyMinor);
+}
+
+void chosenChord(int p, int p2){
+    lastChordChange = currentChord;
+    lastMinor = heresyMinor;
+ //   println("p: " + p + "  p2 : " + p2);
+    currentChord = chordChoicesArray[p].optionArray[p2].chordOption;
+    heresyMinor = chordChoicesArray[p].optionArray[p2].minor;
+    if (int(random(4)) == 0)
+        heresy7th = true;
+    else
+        heresy7th = false;
+    if (int(random(4)) == 0)
+        heresy9th = true;
+    else
+        heresy9th = false;       
+    if (int(random(4)) == 0)
+        heresy11th = true;
+    else
+        heresy11th = false;
+
+
+}   
+
+
+
+class chordChoices{
+    int chordNote;
+    boolean minor;
+    ChordChoice[] optionArray;
+    int slots;
+    
+    public chordChoices(int chordNote, boolean minor, int slotsNeeded){
+        this.chordNote = chordNote;
+        this.minor = minor;
+        optionArray = new ChordChoice[slotsNeeded];
+        slots = slotsNeeded;
+    }
+}
+
+class ChordChoice{
+    int chordOption;
+    boolean minor, h7th, h9th, h11th, h13th, dom;
+    
+    public ChordChoice(int chordOption, boolean minor, boolean dom, boolean h7th, boolean h9th, boolean h11th, boolean h13th){
+        this.chordOption = chordOption;
+        this.minor = minor;
+        this.dom = dom;
+        this.h7th = h7th;
+        this.h9th = h9th;
+        this.h11th = h11th;
+        this.h13th = h13th;       
+    }
+}
+
+//void stuff(){
+chordChoices[] chordChoicesArray = new chordChoices[crneeded];
+
+void markovStuff(){
+chordChoicesArray[0] = new chordChoices(0, false, 13);
+chordChoicesArray[0].optionArray[0] = new ChordChoice(2, true, false, true, true, true, true);
+chordChoicesArray[0].optionArray[1] = new ChordChoice(3, false, false, true, true, true, true);
+chordChoicesArray[0].optionArray[2] = new ChordChoice(4, true, false, true, true, true, true);
+chordChoicesArray[0].optionArray[3] = new ChordChoice(5, true, false, true, true, true, true);
+chordChoicesArray[0].optionArray[4] = new ChordChoice(5, false, false, true, true, true, true);
+chordChoicesArray[0].optionArray[5] = new ChordChoice(7, true, false, true, true, true, true);
+chordChoicesArray[0].optionArray[6] = new ChordChoice(7, false, false, true, true, true, true);
+chordChoicesArray[0].optionArray[7] = new ChordChoice(8, true, false, true, true, true, true);
+chordChoicesArray[0].optionArray[8] = new ChordChoice(8, false, false, true, true, true, true);
+chordChoicesArray[0].optionArray[9] = new ChordChoice(9, true, false, true, true, true, true);
+chordChoicesArray[0].optionArray[10] = new ChordChoice(9, false, false, true, true, true, true);
+chordChoicesArray[0].optionArray[11] = new ChordChoice(10, false, true, true, true, true, true);
+chordChoicesArray[0].optionArray[12] = new ChordChoice(10, true, false, true, true, true, true);
+
+chordChoicesArray[1] = new chordChoices(0, true, 14);
+chordChoicesArray[1].optionArray[0] = new ChordChoice(1, false, true, true, true, true, true);
+chordChoicesArray[1].optionArray[1] = new ChordChoice(3, false, false, true, true, true, true);
+chordChoicesArray[1].optionArray[2] = new ChordChoice(3, true, false, true, true, true, true);
+chordChoicesArray[1].optionArray[3] = new ChordChoice(4, true, false, true, true, true, true);
+chordChoicesArray[1].optionArray[4] = new ChordChoice(5, false, false, true, true, true, true);
+chordChoicesArray[1].optionArray[5] = new ChordChoice(5, true, false, true, true, true, true);
+chordChoicesArray[1].optionArray[6] = new ChordChoice(6, true, false, true, true, true, true);
+chordChoicesArray[1].optionArray[7] = new ChordChoice(7, false, false, true, true, true, true);
+chordChoicesArray[1].optionArray[8] = new ChordChoice(7, true, false, true, true, true, true);
+chordChoicesArray[1].optionArray[9] = new ChordChoice(8, false, false, true, true, true, true);
+chordChoicesArray[1].optionArray[10] = new ChordChoice(8, true, false, true, true, true, true);
+chordChoicesArray[1].optionArray[11] = new ChordChoice(10, false, false, true, true, true, true);
+chordChoicesArray[1].optionArray[12] = new ChordChoice(11, true, false, true, true, true, true);
+chordChoicesArray[1].optionArray[13] = new ChordChoice(11, false, false, true, true, true, true);
+
+chordChoicesArray[2] = new chordChoices(2, false, 9);
+chordChoicesArray[2].optionArray[0] = new ChordChoice(1, false, true, true, true, true, true);
+chordChoicesArray[2].optionArray[1] = new ChordChoice(2, true, false, true, true, true, true);
+chordChoicesArray[2].optionArray[2] = new ChordChoice(5, false, false, true, true, true, true);
+chordChoicesArray[2].optionArray[3] = new ChordChoice(5, true, false, true, true, true, true);
+chordChoicesArray[2].optionArray[4] = new ChordChoice(7, false, false, true, true, true, true);
+chordChoicesArray[2].optionArray[5] = new ChordChoice(8, false, false, true, true, true, true);
+chordChoicesArray[2].optionArray[6] = new ChordChoice(9, false, false, true, true, true, true);
+chordChoicesArray[2].optionArray[7] = new ChordChoice(9, true, false, true, true, true, true);
+chordChoicesArray[2].optionArray[8] = new ChordChoice(10, false, false, true, true, true, true);
+
+chordChoicesArray[3] = new chordChoices(2, true, 13);
+chordChoicesArray[3].optionArray[0] = new ChordChoice(0, false, false, true, true, true, true);
+chordChoicesArray[3].optionArray[1] = new ChordChoice(1, false, true, true, true, true, true);
+chordChoicesArray[3].optionArray[2] = new ChordChoice(3, true, false, true, true, true, true);
+chordChoicesArray[3].optionArray[3] = new ChordChoice(3, false, false, true, true, true, true);
+chordChoicesArray[3].optionArray[4] = new ChordChoice(4, true, false, true, true, true, true);
+chordChoicesArray[3].optionArray[5] = new ChordChoice(5, true, false, true, true, true, true);
+chordChoicesArray[3].optionArray[6] = new ChordChoice(5, false, false, true, true, true, true);
+chordChoicesArray[3].optionArray[7] = new ChordChoice(7, false, false, true, true, true, true);
+chordChoicesArray[3].optionArray[8] = new ChordChoice(7, true, false, true, true, true, true);
+chordChoicesArray[3].optionArray[9] = new ChordChoice(8, false, false, true, true, true, true);
+chordChoicesArray[3].optionArray[10] = new ChordChoice(9, true, false, true, true, true, true);
+chordChoicesArray[3].optionArray[11] = new ChordChoice(10, false, false, true, true, true, true);
+chordChoicesArray[3].optionArray[12] = new ChordChoice(10, true, false, true, true, true, true);
+
+chordChoicesArray[4] = new chordChoices(4, false, 4);
+chordChoicesArray[4].optionArray[0] = new ChordChoice(5, true, false, true, true, true, true);
+chordChoicesArray[4].optionArray[1] = new ChordChoice(9, false, false, true, true, true, true);
+chordChoicesArray[4].optionArray[2] = new ChordChoice(9, true, false, true, true, true, true);
+chordChoicesArray[4].optionArray[3] = new ChordChoice(11, true, false, true, true, true, true);
+
+chordChoicesArray[5] = new chordChoices(4, true, 13);
+chordChoicesArray[5].optionArray[0] = new ChordChoice(0, false, false, true, true, true, true);
+chordChoicesArray[5].optionArray[1] = new ChordChoice(0, true, false, true, true, true, true);
+chordChoicesArray[5].optionArray[2] = new ChordChoice(1, false, true, true, true, true, true);
+chordChoicesArray[5].optionArray[3] = new ChordChoice(2, true, false, true, true, true, true);
+chordChoicesArray[5].optionArray[4] = new ChordChoice(3, false, false, true, true, true, true);
+chordChoicesArray[5].optionArray[5] = new ChordChoice(3, true, false, true, true, true, true);
+chordChoicesArray[5].optionArray[6] = new ChordChoice(5, false, false, true, true, true, true);
+chordChoicesArray[5].optionArray[7] = new ChordChoice(5, true, false, true, true, true, true);
+chordChoicesArray[5].optionArray[8] = new ChordChoice(8, true, false, true, true, true, true);
+chordChoicesArray[5].optionArray[9] = new ChordChoice(8, false, false, true, true, true, true);
+chordChoicesArray[5].optionArray[10] = new ChordChoice(9, true, false, true, true, true, true);
+chordChoicesArray[5].optionArray[11] = new ChordChoice(11, false, false, true, true, true, true);
+chordChoicesArray[5].optionArray[12] = new ChordChoice(11, true, false, true, true, true, true);
+
+chordChoicesArray[6] = new chordChoices(5, false, 14);
+chordChoicesArray[6].optionArray[0] = new ChordChoice(0, false, false, true, true, true, true);
+chordChoicesArray[6].optionArray[1] = new ChordChoice(0, true, false, true, true, true, true);
+chordChoicesArray[6].optionArray[2] = new ChordChoice(2, true, false, true, true, true, true);
+chordChoicesArray[6].optionArray[3] = new ChordChoice(4, true, false, true, true, true, true);
+chordChoicesArray[6].optionArray[4] = new ChordChoice(4, false, false, true, true, true, true);
+chordChoicesArray[6].optionArray[5] = new ChordChoice(5, true, false, true, true, true, true);
+chordChoicesArray[6].optionArray[6] = new ChordChoice(6, true, false, true, true, true, true);
+chordChoicesArray[6].optionArray[7] = new ChordChoice(7, false, false, true, true, true, true);
+chordChoicesArray[6].optionArray[8] = new ChordChoice(8, true, false, true, true, true, true);
+chordChoicesArray[6].optionArray[9] = new ChordChoice(8, false, false, true, true, true, true);
+chordChoicesArray[6].optionArray[10] = new ChordChoice(9, true, false, true, true, true, true);
+chordChoicesArray[6].optionArray[11] = new ChordChoice(9, false, false, true, true, true, true);
+chordChoicesArray[6].optionArray[12] = new ChordChoice(10, true, false, true, true, true, true);
+chordChoicesArray[6].optionArray[13] = new ChordChoice(10, false, false, true, true, true, true);
+
+chordChoicesArray[7] = new chordChoices(5, true, 15);
+chordChoicesArray[7].optionArray[0] = new ChordChoice(0, false, false, true, true, true, true);
+chordChoicesArray[7].optionArray[1] = new ChordChoice(0, true, false, true, true, true, true);
+chordChoicesArray[7].optionArray[2] = new ChordChoice(1, false, true, true, true, true, true);
+chordChoicesArray[7].optionArray[3] = new ChordChoice(2, true, false, true, true, true, true);
+chordChoicesArray[7].optionArray[4] = new ChordChoice(2, false, false, true, true, true, true);
+chordChoicesArray[7].optionArray[5] = new ChordChoice(3, false, false, true, true, true, true);
+chordChoicesArray[7].optionArray[6] = new ChordChoice(4, false, false, true, true, true, true);
+chordChoicesArray[7].optionArray[7] = new ChordChoice(6, true, false, true, true, true, true);
+chordChoicesArray[7].optionArray[8] = new ChordChoice(7, true, false, true, true, true, true);
+chordChoicesArray[7].optionArray[9] = new ChordChoice(7, false, false, true, true, true, true);
+chordChoicesArray[7].optionArray[10] = new ChordChoice(8, true, false, true, true, true, true);
+chordChoicesArray[7].optionArray[11] = new ChordChoice(8, false, false, true, true, true, true);
+chordChoicesArray[7].optionArray[12] = new ChordChoice(10, false, false, true, true, true, true);
+chordChoicesArray[7].optionArray[13] = new ChordChoice(11, false, false, true, true, true, true);
+chordChoicesArray[7].optionArray[14] = new ChordChoice(11, true, false, true, true, true, true);
+
+chordChoicesArray[8] = new chordChoices(7, true, 14);
+chordChoicesArray[8].optionArray[0] = new ChordChoice(0, false, false, true, true, true, true);
+chordChoicesArray[8].optionArray[1] = new ChordChoice(0, true, false, true, true, true, true);
+chordChoicesArray[8].optionArray[2] = new ChordChoice(1, false, true, true, true, true, true);
+chordChoicesArray[8].optionArray[3] = new ChordChoice(2, false, false, true, true, true, true);
+chordChoicesArray[8].optionArray[4] = new ChordChoice(2, true, false, true, true, true, true);
+chordChoicesArray[8].optionArray[5] = new ChordChoice(3, false, false, true, true, true, true);
+chordChoicesArray[8].optionArray[6] = new ChordChoice(3, true, false, true, true, true, true);
+chordChoicesArray[8].optionArray[7] = new ChordChoice(5, false, false, true, true, true, true);
+chordChoicesArray[8].optionArray[8] = new ChordChoice(5, true, false, true, true, true, true);
+chordChoicesArray[8].optionArray[9] = new ChordChoice(6, false, false, true, true, true, true);
+chordChoicesArray[8].optionArray[10] = new ChordChoice(8, true, false, true, true, true, true);
+chordChoicesArray[8].optionArray[11] = new ChordChoice(8, false, false, true, true, true, true);
+chordChoicesArray[8].optionArray[12] = new ChordChoice(10, false, false, true, true, true, true);
+chordChoicesArray[8].optionArray[13] = new ChordChoice(10, true, false, true, true, true, true);
+
+chordChoicesArray[9] = new chordChoices(7, false, 10);
+chordChoicesArray[9].optionArray[0] = new ChordChoice(0, false, false, true, true, true, true);
+chordChoicesArray[9].optionArray[1] = new ChordChoice(0, true, false, true, true, true, true);
+chordChoicesArray[9].optionArray[2] = new ChordChoice(2, false, false, true, true, true, true);
+chordChoicesArray[9].optionArray[3] = new ChordChoice(2, true, false, true, true, true, true);
+chordChoicesArray[9].optionArray[4] = new ChordChoice(4, true, false, true, true, true, true);
+chordChoicesArray[9].optionArray[5] = new ChordChoice(5, false, false, true, true, true, true);
+chordChoicesArray[9].optionArray[6] = new ChordChoice(5, true, false, true, true, true, true);
+chordChoicesArray[9].optionArray[7] = new ChordChoice(8, false, false, true, true, true, true);
+chordChoicesArray[9].optionArray[8] = new ChordChoice(8, true, false, true, true, true, true);
+chordChoicesArray[9].optionArray[9] = new ChordChoice(9, true, false, true, true, true, true);
+
+chordChoicesArray[10] = new chordChoices(9, true, 13);
+chordChoicesArray[10].optionArray[0] = new ChordChoice(0, false, false, true, true, true, true);
+chordChoicesArray[10].optionArray[1] = new ChordChoice(0, true, false, true, true, true, true);
+chordChoicesArray[10].optionArray[2] = new ChordChoice(1, false, true, true, true, true, true);
+chordChoicesArray[10].optionArray[3] = new ChordChoice(2, true, false, true, true, true, true);
+chordChoicesArray[10].optionArray[4] = new ChordChoice(2, false, false, true, true, true, true);
+chordChoicesArray[10].optionArray[5] = new ChordChoice(3, false, false, true, true, true, true);
+chordChoicesArray[10].optionArray[6] = new ChordChoice(4, true, false, true, true, true, true);
+chordChoicesArray[10].optionArray[7] = new ChordChoice(5, false, false, true, true, true, true);
+chordChoicesArray[10].optionArray[8] = new ChordChoice(5, true, false, true, true, true, true);
+chordChoicesArray[10].optionArray[9] = new ChordChoice(7, true, false, true, true, true, true);
+chordChoicesArray[10].optionArray[10] = new ChordChoice(7, false, false, true, true, true, true);
+chordChoicesArray[10].optionArray[11] = new ChordChoice(8, false, false, true, true, true, true);
+chordChoicesArray[10].optionArray[12] = new ChordChoice(10, false, false, true, true, true, true);
+
+chordChoicesArray[11] = new chordChoices(11, false, 6);
+chordChoicesArray[11].optionArray[0] = new ChordChoice(0, true, false, true, true, true, true);
+chordChoicesArray[11].optionArray[1] = new ChordChoice(1, false, true, true, true, true, true);
+chordChoicesArray[11].optionArray[2] = new ChordChoice(1, true, false, true, true, true, true);
+chordChoicesArray[11].optionArray[3] = new ChordChoice(1, false, false, true, true, true, true);
+chordChoicesArray[11].optionArray[4] = new ChordChoice(7, false, false, true, true, true, true);
+chordChoicesArray[11].optionArray[5] = new ChordChoice(7, true, false, true, true, true, true);
+
+chordChoicesArray[12] = new chordChoices(11, true, 5);
+chordChoicesArray[12].optionArray[0] = new ChordChoice(1, false, true, true, true, true, true);
+chordChoicesArray[12].optionArray[1] = new ChordChoice(2, true, false, true, true, true, true);
+chordChoicesArray[12].optionArray[2] = new ChordChoice(5, false, true, true, true, true, true);
+chordChoicesArray[12].optionArray[3] = new ChordChoice(5, true, false, true, true, true, true);
+chordChoicesArray[12].optionArray[4] = new ChordChoice(8, false, false, true, true, true, true);
+
+chordChoicesArray[13] = new chordChoices(1, false, 2);
+chordChoicesArray[13].optionArray[0] = new ChordChoice(0, false, false, true, true, true, true);
+chordChoicesArray[13].optionArray[1] = new ChordChoice(0, true, false, true, true, true, true);
+
+chordChoicesArray[14] = new chordChoices(1, true, 2);
+chordChoicesArray[14].optionArray[0] = new ChordChoice(0, true, false, true, true, true, true);
+chordChoicesArray[14].optionArray[1] = new ChordChoice(0, true, false, true, true, true, true);
+
+chordChoicesArray[15] = new chordChoices(3, false, 12);
+chordChoicesArray[15].optionArray[0] = new ChordChoice(0, false, false, true, true, true, true);
+chordChoicesArray[15].optionArray[1] = new ChordChoice(0, true, false, true, true, true, true);
+chordChoicesArray[15].optionArray[2] = new ChordChoice(1, false, true, true, true, true, true);
+chordChoicesArray[15].optionArray[3] = new ChordChoice(5, false, false, true, true, true, true);
+chordChoicesArray[15].optionArray[4] = new ChordChoice(7, false, false, true, true, true, true);
+chordChoicesArray[15].optionArray[5] = new ChordChoice(7, true, false, true, true, true, true);
+chordChoicesArray[15].optionArray[6] = new ChordChoice(8, true, false, true, true, true, true);
+chordChoicesArray[15].optionArray[7] = new ChordChoice(8, false, false, true, true, true, true);
+chordChoicesArray[15].optionArray[8] = new ChordChoice(10, true, false, true, true, true, true);
+chordChoicesArray[15].optionArray[9] = new ChordChoice(10, false, false, true, true, true, true);
+chordChoicesArray[15].optionArray[10] = new ChordChoice(11, false, false, true, true, true, true);
+chordChoicesArray[15].optionArray[11] = new ChordChoice(11, true, false, true, true, true, true);
+
+chordChoicesArray[16] = new chordChoices(111, false, 2);
+chordChoicesArray[16].optionArray[0] = new ChordChoice(0, false, false, true, true, true, true);
+chordChoicesArray[16].optionArray[1] = new ChordChoice(0, true, false, true, true, true, true);
+
+chordChoicesArray[17] = new chordChoices(6, false, 10);
+chordChoicesArray[17].optionArray[0] = new ChordChoice(1, false, false, true, true, true, true);
+chordChoicesArray[17].optionArray[1] = new ChordChoice(1, true, false, true, true, true, true);
+chordChoicesArray[17].optionArray[2] = new ChordChoice(2, false, false, true, true, true, true);
+chordChoicesArray[17].optionArray[3] = new ChordChoice(3, false, false, true, true, true, true);
+chordChoicesArray[17].optionArray[4] = new ChordChoice(3, true, false, true, true, true, true);
+chordChoicesArray[17].optionArray[5] = new ChordChoice(8, false, false, true, true, true, true);
+chordChoicesArray[17].optionArray[6] = new ChordChoice(9, false, false, true, true, true, true);
+chordChoicesArray[17].optionArray[7] = new ChordChoice(9, true, false, true, true, true, true);
+chordChoicesArray[17].optionArray[8] = new ChordChoice(10, true, false, true, true, true, true);
+chordChoicesArray[17].optionArray[9] = new ChordChoice(10, false, false, true, true, true, true);
+
+chordChoicesArray[18] = new chordChoices(8, false, 17);
+chordChoicesArray[18].optionArray[0] = new ChordChoice(0, false, false, true, true, true, true);
+chordChoicesArray[18].optionArray[1] = new ChordChoice(0, true, false, true, true, true, true);
+chordChoicesArray[18].optionArray[2] = new ChordChoice(1, false, true, true, true, true, true);
+chordChoicesArray[18].optionArray[3] = new ChordChoice(1, true, false, true, true, true, true);
+chordChoicesArray[18].optionArray[4] = new ChordChoice(1, false, false, true, true, true, true);
+chordChoicesArray[18].optionArray[5] = new ChordChoice(3, false, false, true, true, true, true);
+chordChoicesArray[18].optionArray[6] = new ChordChoice(3, true, false, true, true, true, true);
+chordChoicesArray[18].optionArray[7] = new ChordChoice(4, false, false, true, true, true, true);
+chordChoicesArray[18].optionArray[8] = new ChordChoice(4, true, false, true, true, true, true);
+chordChoicesArray[18].optionArray[9] = new ChordChoice(5, true, false, true, true, true, true);
+chordChoicesArray[18].optionArray[10] = new ChordChoice(5, false, false, true, true, true, true);
+chordChoicesArray[18].optionArray[11] = new ChordChoice(7, false, false, true, true, true, true);
+chordChoicesArray[18].optionArray[12] = new ChordChoice(7, true, false, true, true, true, true);
+chordChoicesArray[18].optionArray[13] = new ChordChoice(9, true, false, true, true, true, true);
+chordChoicesArray[18].optionArray[14] = new ChordChoice(10, false, false, true, true, true, true);
+chordChoicesArray[18].optionArray[15] = new ChordChoice(11, false, false, true, true, true, true);
+chordChoicesArray[18].optionArray[16] = new ChordChoice(11, true, false, true, true, true, true);
+
+chordChoicesArray[19] = new chordChoices(8, true, 10);
+chordChoicesArray[19].optionArray[0] = new ChordChoice(0, false, false, true, true, true, true);
+chordChoicesArray[19].optionArray[1] = new ChordChoice(0, true, false, true, true, true, true);
+chordChoicesArray[19].optionArray[2] = new ChordChoice(1, false, true, true, true, true, true);
+chordChoicesArray[19].optionArray[3] = new ChordChoice(1, false, false, true, true, true, true);
+chordChoicesArray[19].optionArray[4] = new ChordChoice(3, false, false, true, true, true, true);
+chordChoicesArray[19].optionArray[5] = new ChordChoice(3, true, false, true, true, true, true);
+chordChoicesArray[19].optionArray[6] = new ChordChoice(4, false, false, true, true, true, true);
+chordChoicesArray[19].optionArray[7] = new ChordChoice(4, true, false, true, true, true, true);
+chordChoicesArray[19].optionArray[8] = new ChordChoice(5, true, false, true, true, true, true);
+chordChoicesArray[19].optionArray[9] = new ChordChoice(5, false, false, true, true, true, true);
+
+chordChoicesArray[20] = new chordChoices(3, true, 19);
+chordChoicesArray[20].optionArray[0] = new ChordChoice(0, false, false, true, true, true, true);
+chordChoicesArray[20].optionArray[1] = new ChordChoice(0, true, false, true, true, true, true);
+chordChoicesArray[20].optionArray[2] = new ChordChoice(1, false, true, true, true, true, true);
+chordChoicesArray[20].optionArray[3] = new ChordChoice(2, false, false, true, true, true, true);
+chordChoicesArray[20].optionArray[4] = new ChordChoice(4, false, false, true, true, true, true);
+chordChoicesArray[20].optionArray[5] = new ChordChoice(4, true, false, true, true, true, true);
+chordChoicesArray[20].optionArray[6] = new ChordChoice(5, true, false, true, true, true, true);
+chordChoicesArray[20].optionArray[7] = new ChordChoice(5, false, false, true, true, true, true);
+chordChoicesArray[20].optionArray[8] = new ChordChoice(6, true, false, true, true, true, true);
+chordChoicesArray[20].optionArray[9] = new ChordChoice(6, false, false, true, true, true, true);
+chordChoicesArray[20].optionArray[10] = new ChordChoice(7, true, false, true, true, true, true);
+chordChoicesArray[20].optionArray[11] = new ChordChoice(8, false, false, true, true, true, true);
+chordChoicesArray[20].optionArray[12] = new ChordChoice(8, true, false, true, true, true, true);
+chordChoicesArray[20].optionArray[13] = new ChordChoice(9, true, false, true, true, true, true);
+chordChoicesArray[20].optionArray[14] = new ChordChoice(9, false, false, true, true, true, true);
+chordChoicesArray[20].optionArray[15] = new ChordChoice(10, false, false, true, true, true, true);
+chordChoicesArray[20].optionArray[16] = new ChordChoice(10, true, false, true, true, true, true);
+chordChoicesArray[20].optionArray[17] = new ChordChoice(11, false, false, true, true, true, true);
+chordChoicesArray[20].optionArray[18] = new ChordChoice(11, true, false, true, true, true, true);
+
+chordChoicesArray[21] = new chordChoices(6, true, 9);
+chordChoicesArray[21].optionArray[0] = new ChordChoice(1, false, false, true, true, true, true);
+chordChoicesArray[21].optionArray[1] = new ChordChoice(1, true, false, true, true, true, true);
+chordChoicesArray[21].optionArray[2] = new ChordChoice(2, false, false, true, true, true, true);
+chordChoicesArray[21].optionArray[3] = new ChordChoice(3, false, false, true, true, true, true);
+chordChoicesArray[21].optionArray[4] = new ChordChoice(3, true, false, true, true, true, true);
+chordChoicesArray[21].optionArray[5] = new ChordChoice(4, false, false, true, true, true, true);
+chordChoicesArray[21].optionArray[6] = new ChordChoice(5, false, false, true, true, true, true);
+chordChoicesArray[21].optionArray[7] = new ChordChoice(8, false, false, true, true, true, true);
+chordChoicesArray[21].optionArray[8] = new ChordChoice(11, true, false, true, true, true, true);
+
+chordChoicesArray[22] = new chordChoices(10, false, 13);
+chordChoicesArray[22].optionArray[0] = new ChordChoice(0, false, false, true, true, true, true);
+chordChoicesArray[22].optionArray[1] = new ChordChoice(0, true, false, true, true, true, true);
+chordChoicesArray[22].optionArray[2] = new ChordChoice(1, false, true, true, true, true, true);
+chordChoicesArray[22].optionArray[3] = new ChordChoice(3, false, false, true, true, true, true);
+chordChoicesArray[22].optionArray[4] = new ChordChoice(3, true, false, true, true, true, true);
+chordChoicesArray[22].optionArray[5] = new ChordChoice(5, true, false, true, true, true, true);
+chordChoicesArray[22].optionArray[6] = new ChordChoice(5, false, false, true, true, true, true);
+chordChoicesArray[22].optionArray[7] = new ChordChoice(6, false, false, true, true, true, true);
+chordChoicesArray[22].optionArray[8] = new ChordChoice(7, true, false, true, true, true, true);
+chordChoicesArray[22].optionArray[9] = new ChordChoice(7, false, false, true, true, true, true);
+chordChoicesArray[22].optionArray[10] = new ChordChoice(8, true, false, true, true, true, true);
+chordChoicesArray[22].optionArray[11] = new ChordChoice(8, false, false, true, true, true, true);
+chordChoicesArray[22].optionArray[12] = new ChordChoice(11, true, false, true, true, true, true);
+
+chordChoicesArray[23] = new chordChoices(10, true, 12);
+chordChoicesArray[23].optionArray[0] = new ChordChoice(0, false, false, true, true, true, true);
+chordChoicesArray[23].optionArray[1] = new ChordChoice(1, false, true, true, true, true, true);
+chordChoicesArray[23].optionArray[2] = new ChordChoice(3, false, false, true, true, true, true);
+chordChoicesArray[23].optionArray[3] = new ChordChoice(3, true, false, true, true, true, true);
+chordChoicesArray[23].optionArray[4] = new ChordChoice(5, false, false, true, true, true, true);
+chordChoicesArray[23].optionArray[5] = new ChordChoice(6, true, false, true, true, true, true);
+chordChoicesArray[23].optionArray[6] = new ChordChoice(6, false, false, true, true, true, true);
+chordChoicesArray[23].optionArray[7] = new ChordChoice(7, false, false, true, true, true, true);
+chordChoicesArray[23].optionArray[8] = new ChordChoice(7, true, false, true, true, true, true);
+chordChoicesArray[23].optionArray[9] = new ChordChoice(9, false, false, true, true, true, true);
+chordChoicesArray[23].optionArray[10] = new ChordChoice(9, true, false, true, true, true, true);
+chordChoicesArray[23].optionArray[11] = new ChordChoice(11, true, false, true, true, true, true);
+
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HeresyBigBangDone/application.macosx/source/sequences.pde	Sat Oct 08 22:12:49 2011 +0100
@@ -0,0 +1,70 @@
+void loadSequences(){
+  
+    ArrayList<NoteEvent> sequenceBass = new ArrayList<NoteEvent>();
+    sequenceBass.add(new NoteEvent(15, 2,   1,  1,  1,  1,    0,  3,  3,  0));
+ // sequenceBass.add(new NoteEvent(15, 2,   1,  1,  2,  1,    0,  0,  0,  5));
+ // sequenceBass.add(new NoteEvent(15, 2,   1,  2,  3,  1,    0,  0,  0,  5));
+ // sequenceBass.add(new NoteEvent(15, 2,   1,  2,  4,  1,    0,  0,  0,  5));
+ // sequenceBass.add(new NoteEvent(15, 2,   1,  3,  2,  1,    0,  0,  0,  5));
+ // sequenceBass.add(new NoteEvent(15, 2,   1,  3,  3,  1,    0,  0,  0,  5));
+ // sequenceBass.add(new NoteEvent(15, 2,   1,  4,  1,  1,    0,  0,  0,  5));
+ // sequenceBass.add(new NoteEvent(15, 2,   1,  4,  2,  1,    0,  0,  0,  5));
+    seedSequencer(sequenceBass, 2);
+    
+    ArrayList<NoteEvent> sequencePizz = new ArrayList<NoteEvent>();
+    sequencePizz.add(new NoteEvent(13, 2,   1,  1,  3,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(12, 2,   1,  1,  3,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(11, 2,   1,  1,  3,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(10, 2,   1,  1,  3,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(9,  2,   1,  1,  3,  1,    0,  0,  1,  0));
+//  sequencePizz.add(new NoteEvent(8,  2,   1,  1,  3,  1,    0,  0,  1,  0));
+//  sequencePizz.add(new NoteEvent(7,  2,   1,  1,  3,  1,    0,  0,  1,  0));
+//  sequencePizz.add(new NoteEvent(6,  2,   1,  1,  3,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(0,  2,   1,  2,  3,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(1,  2,   1,  2,  3,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(2,  2,   1,  2,  3,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(3,  2,   1,  2,  3,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(4,  2,   1,  2,  3,  1,    0,  0,  1,  0));
+//  sequencePizz.add(new NoteEvent(8,  2,   1,  2,  3,  1,    0,  0,  1,  0));
+//  sequencePizz.add(new NoteEvent(7,  2,   1,  2,  3,  1,    0,  0,  1,  0));
+//  sequencePizz.add(new NoteEvent(6,  2,   1,  2,  3,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(13, 2,   1,  3,  3,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(12, 2,   1,  3,  3,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(11, 2,   1,  3,  3,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(10, 2,   1,  3,  3,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(9,  2,   1,  3,  3,  1,    0,  0,  1,  0));
+//  sequencePizz.add(new NoteEvent(8,  2,   1,  3,  3,  1,    0,  0,  1,  0));
+//  sequencePizz.add(new NoteEvent(7,  2,   1,  3,  3,  1,    0,  0,  1,  0));
+//  sequencePizz.add(new NoteEvent(6,  2,   1,  3,  3,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(0,  2,   1,  4,  1,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(1,  2,   1,  4,  1,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(2,  2,   1,  4,  1,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(3,  2,   1,  4,  1,  1,    0,  0,  1,  0));
+    sequencePizz.add(new NoteEvent(4,  2,   1,  4,  1,  1,    0,  0,  1,  0));
+//  sequencePizz.add(new NoteEvent(8,  2,   1,  4,  3,  1,    0,  0,  1,  0));
+//  sequencePizz.add(new NoteEvent(7,  2,   1,  4,  3,  1,    0,  0,  1,  0));
+//  sequencePizz.add(new NoteEvent(6,  2,   1,  4,  3,  1,    0,  0,  1,  0));
+    seedSequencer(sequencePizz, 3);
+/*    
+    ArrayList<NoteEvent> sequenceStrings = new ArrayList<NoteEvent>();
+    sequenceStrings.add(new NoteEvent(13, 2,   1,  1,  1,  1,    0,  1,  3,  0));
+    sequenceStrings.add(new NoteEvent(12, 2,   1,  1,  1,  1,    0,  1,  3,  0));
+    sequenceStrings.add(new NoteEvent(11, 2,   1,  1,  1,  1,    0,  1,  3,  0));
+    sequenceStrings.add(new NoteEvent(10, 2,   1,  1,  1,  1,    0,  1,  3,  0));
+    sequenceStrings.add(new NoteEvent(9,  2,   1,  1,  1,  1,    0,  1,  3,  0));
+    sequenceStrings.add(new NoteEvent(8,  2,   1,  1,  1,  1,    0,  1,  3,  0));
+    sequenceStrings.add(new NoteEvent(7,  2,   1,  1,  1,  1,    0,  1,  3,  0));
+    sequenceStrings.add(new NoteEvent(6,  2,   1,  1,  1,  1,    0,  1,  3,  0));
+    seedSequencer(sequenceStrings, 4);
+*/
+    
+}
+
+void seedSequencer(ArrayList<NoteEvent> sIn, int track){
+    for (int i = 0; i < sIn.size(); i++){
+      NoteEvent s = sIn.get(i);
+  //  println("info stuff : " + s[i].notePitch);
+        tracks[track].sequence[s.notePitch][(s.notePosition[0]-1)*pulsesPerBar + (s.notePosition[1]-1)*grid + (s.notePosition[2]-1)*(grid/fractions) + s.notePosition[3]] = new NoteEvent (s.notePitch, s.channel, bar,beat,fraction,pulse);
+        tracks[track].sequence[s.notePitch][(s.notePosition[0]-1)*pulsesPerBar + (s.notePosition[1]-1)*grid + (s.notePosition[2]-1)*(grid/fractions) + s.notePosition[3] + s.noteLength[0]*pulsesPerBar + s.noteLength[1]*grid + s.noteLength[2]*grid/fractions + s.noteLength[3]] = new NoteEvent (s.notePitch, s.channel, bar,beat,fraction,pulse, true);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mophoControl.maxpat	Sat Oct 08 22:12:49 2011 +0100
@@ -0,0 +1,297 @@
+{
+	"patcher" : 	{
+		"fileversion" : 1,
+		"rect" : [ 25.0, 69.0, 640.0, 480.0 ],
+		"bglocked" : 0,
+		"defrect" : [ 25.0, 69.0, 640.0, 480.0 ],
+		"openrect" : [ 0.0, 0.0, 0.0, 0.0 ],
+		"openinpresentation" : 0,
+		"default_fontsize" : 12.0,
+		"default_fontface" : 0,
+		"default_fontname" : "Arial",
+		"gridonopen" : 0,
+		"gridsize" : [ 15.0, 15.0 ],
+		"gridsnaponopen" : 0,
+		"toolbarvisible" : 1,
+		"boxanimatetime" : 200,
+		"imprint" : 0,
+		"enablehscroll" : 1,
+		"enablevscroll" : 1,
+		"devicewidth" : 0.0,
+		"boxes" : [ 			{
+				"box" : 				{
+					"maxclass" : "newobj",
+					"text" : "prepend set",
+					"outlettype" : [ "" ],
+					"fontsize" : 12.0,
+					"patching_rect" : [ 311.0, 253.0, 74.0, 20.0 ],
+					"numinlets" : 1,
+					"id" : "obj-15",
+					"numoutlets" : 1,
+					"fontname" : "Arial"
+				}
+
+			}
+, 			{
+				"box" : 				{
+					"maxclass" : "newobj",
+					"text" : "prepend 102",
+					"outlettype" : [ "" ],
+					"fontsize" : 12.0,
+					"patching_rect" : [ 310.0, 284.0, 78.0, 20.0 ],
+					"numinlets" : 1,
+					"id" : "obj-14",
+					"numoutlets" : 1,
+					"fontname" : "Arial"
+				}
+
+			}
+, 			{
+				"box" : 				{
+					"maxclass" : "umenu",
+					"outlettype" : [ "int", "", "" ],
+					"fontsize" : 12.0,
+					"pattrmode" : 1,
+					"items" : [ "filter", "frequency", ",", "resonance", ",", "filter", "key", "amount", ",", "filter", "audio", "mod", ",", "filter", "env", "amount", ",", "filt", "env", "vel", "amt", ",", "filter", "deay", ",", "filter", "attack", ",", "filter", "decay", ",", "filter", "sustain", ",", "filter", "release", ",", "vca", "level", ",", "amp", "env", "amt", ",", "amp", "vel", "amt", ",", "amp", "decay", ",", "amp", "sustain", ",", "amp", "release" ],
+					"types" : [  ],
+					"patching_rect" : [ 200.0, 99.0, 159.0, 20.0 ],
+					"numinlets" : 1,
+					"id" : "obj-13",
+					"numoutlets" : 3,
+					"fontname" : "Arial"
+				}
+
+			}
+, 			{
+				"box" : 				{
+					"maxclass" : "newobj",
+					"text" : "prepend set",
+					"outlettype" : [ "" ],
+					"fontsize" : 12.0,
+					"patching_rect" : [ 372.0, 199.0, 74.0, 20.0 ],
+					"numinlets" : 1,
+					"id" : "obj-12",
+					"numoutlets" : 1,
+					"fontname" : "Arial"
+				}
+
+			}
+, 			{
+				"box" : 				{
+					"maxclass" : "newobj",
+					"text" : "+ 20",
+					"outlettype" : [ "int" ],
+					"fontsize" : 12.0,
+					"patching_rect" : [ 372.0, 173.0, 34.0, 20.0 ],
+					"numinlets" : 2,
+					"id" : "obj-11",
+					"numoutlets" : 1,
+					"fontname" : "Arial"
+				}
+
+			}
+, 			{
+				"box" : 				{
+					"maxclass" : "umenu",
+					"outlettype" : [ "int", "", "" ],
+					"fontsize" : 12.0,
+					"pattrmode" : 1,
+					"items" : [ "osc1freq", ",", "osc1frew", "fine", ",", "osc1", "shape", ",", "glide", 1, ",", "osc2", "freq", ",", "osc2", "freq", "fine", ",", "osc2", "shape", ",", "glide", 2, ",", "osc", "mix", ",", "noise", "level", ",", "sub", "osc", 1, ",", "sub", "osc", 2 ],
+					"types" : [  ],
+					"patching_rect" : [ 372.0, 138.0, 100.0, 20.0 ],
+					"numinlets" : 1,
+					"id" : "obj-8",
+					"numoutlets" : 3,
+					"fontname" : "Arial"
+				}
+
+			}
+, 			{
+				"box" : 				{
+					"maxclass" : "newobj",
+					"text" : "+ 102",
+					"outlettype" : [ "int" ],
+					"fontsize" : 12.0,
+					"patching_rect" : [ 311.0, 227.0, 41.0, 20.0 ],
+					"numinlets" : 2,
+					"id" : "obj-6",
+					"numoutlets" : 1,
+					"fontname" : "Arial"
+				}
+
+			}
+, 			{
+				"box" : 				{
+					"maxclass" : "number",
+					"outlettype" : [ "int", "bang" ],
+					"fontsize" : 12.0,
+					"patching_rect" : [ 243.0, 191.0, 50.0, 20.0 ],
+					"numinlets" : 1,
+					"maximum" : 127,
+					"id" : "obj-7",
+					"numoutlets" : 2,
+					"fontname" : "Arial",
+					"minimum" : 0
+				}
+
+			}
+, 			{
+				"box" : 				{
+					"maxclass" : "newobj",
+					"text" : "midiout b",
+					"fontsize" : 12.0,
+					"patching_rect" : [ 201.0, 334.0, 59.0, 20.0 ],
+					"numinlets" : 1,
+					"id" : "obj-5",
+					"numoutlets" : 0,
+					"fontname" : "Arial"
+				}
+
+			}
+, 			{
+				"box" : 				{
+					"maxclass" : "newobj",
+					"text" : "midiformat 1",
+					"outlettype" : [ "int" ],
+					"fontsize" : 12.0,
+					"patching_rect" : [ 161.0, 285.0, 100.0, 20.0 ],
+					"numinlets" : 7,
+					"id" : "obj-4",
+					"numoutlets" : 1,
+					"fontname" : "Arial"
+				}
+
+			}
+, 			{
+				"box" : 				{
+					"maxclass" : "newobj",
+					"text" : "prepend 30",
+					"outlettype" : [ "" ],
+					"fontsize" : 12.0,
+					"patching_rect" : [ 146.0, 253.0, 71.0, 20.0 ],
+					"numinlets" : 1,
+					"id" : "obj-3",
+					"numoutlets" : 1,
+					"fontname" : "Arial"
+				}
+
+			}
+, 			{
+				"box" : 				{
+					"maxclass" : "number",
+					"outlettype" : [ "int", "bang" ],
+					"fontsize" : 12.0,
+					"patching_rect" : [ 151.0, 197.0, 50.0, 20.0 ],
+					"numinlets" : 1,
+					"maximum" : 127,
+					"id" : "obj-2",
+					"numoutlets" : 2,
+					"fontname" : "Arial",
+					"minimum" : 0
+				}
+
+			}
+ ],
+		"lines" : [ 			{
+				"patchline" : 				{
+					"source" : [ "obj-7", 0 ],
+					"destination" : [ "obj-14", 0 ],
+					"hidden" : 0,
+					"midpoints" : [  ]
+				}
+
+			}
+, 			{
+				"patchline" : 				{
+					"source" : [ "obj-14", 0 ],
+					"destination" : [ "obj-4", 2 ],
+					"hidden" : 0,
+					"midpoints" : [  ]
+				}
+
+			}
+, 			{
+				"patchline" : 				{
+					"source" : [ "obj-15", 0 ],
+					"destination" : [ "obj-14", 0 ],
+					"hidden" : 0,
+					"midpoints" : [  ]
+				}
+
+			}
+, 			{
+				"patchline" : 				{
+					"source" : [ "obj-13", 0 ],
+					"destination" : [ "obj-6", 0 ],
+					"hidden" : 0,
+					"midpoints" : [  ]
+				}
+
+			}
+, 			{
+				"patchline" : 				{
+					"source" : [ "obj-6", 0 ],
+					"destination" : [ "obj-15", 0 ],
+					"hidden" : 0,
+					"midpoints" : [  ]
+				}
+
+			}
+, 			{
+				"patchline" : 				{
+					"source" : [ "obj-12", 0 ],
+					"destination" : [ "obj-3", 0 ],
+					"hidden" : 0,
+					"midpoints" : [  ]
+				}
+
+			}
+, 			{
+				"patchline" : 				{
+					"source" : [ "obj-11", 0 ],
+					"destination" : [ "obj-12", 0 ],
+					"hidden" : 0,
+					"midpoints" : [  ]
+				}
+
+			}
+, 			{
+				"patchline" : 				{
+					"source" : [ "obj-8", 0 ],
+					"destination" : [ "obj-11", 0 ],
+					"hidden" : 0,
+					"midpoints" : [  ]
+				}
+
+			}
+, 			{
+				"patchline" : 				{
+					"source" : [ "obj-4", 0 ],
+					"destination" : [ "obj-5", 0 ],
+					"hidden" : 0,
+					"midpoints" : [  ]
+				}
+
+			}
+, 			{
+				"patchline" : 				{
+					"source" : [ "obj-3", 0 ],
+					"destination" : [ "obj-4", 2 ],
+					"hidden" : 0,
+					"midpoints" : [  ]
+				}
+
+			}
+, 			{
+				"patchline" : 				{
+					"source" : [ "obj-2", 0 ],
+					"destination" : [ "obj-3", 0 ],
+					"hidden" : 0,
+					"midpoints" : [  ]
+				}
+
+			}
+ ]
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/of/testApp.cpp.orig	Sat Oct 08 22:12:49 2011 +0100
@@ -0,0 +1,288 @@
+#include "testApp.h"
+
+//--------------------------------------------------------------
+void testApp::setup(){
+	drawIt=false;
+	// load the default ofxOpenNI config settings
+	// see bin/data/openni/config/ofxopenni_config.xml
+	context.setupUsingXMLFile();
+	
+	// uncomment this to see what open ni is doing inside
+	//context.enableLogging(OF_LOG_VERBOSE);
+	
+	// setup resources
+	depth.setup(&context);
+	image.setup(&context);
+	user.setup(&context, &depth);
+//	Davy.loadImage("images/davy.jpg");
+   ofEnableSmoothing();
+   ofSetBackgroundAuto(false);
+   	ofBackground(238,238,224);
+  // 	ofEnableAlphaBlending();
+   	ofSetLineWidth(12);
+
+
+	
+	anubis.loadImage("images/anubis-wall-mask.gif");
+	
+	franklinBook.loadFont("frabk.ttf", 32);
+
+	sender.setup( HOST, PORT );
+	stopSender.setup( HOST, STOPPORT );
+	
+	maxTorsoValues[0] = 0;
+	maxTorsoValues[1] = 0;
+	maxTorsoValues[2] = 0;
+	double timeNow = ofGetElapsedTimeMillis();
+	for (int user = 0;user < NUMBER_OF_USERS;user++)
+	lastRecordedTime[user] = timeNow;
+}
+
+//--------------------------------------------------------------
+void testApp::update(){
+	
+	// update the open ni context and user tracker
+	context.update();
+	user.update();
+
+	
+}
+
+
+void testApp::getCoordinates(int userID){
+	//tracked = user.getTrackedUser(i);
+	ofxTrackedUser* tracked = user.getTrackedUser(userID);
+	
+
+	double timeNow = ofGetElapsedTimeMillis();
+
+		
+		
+		
+		if ((fabs(torso[userID][0] - tracked->left_upper_torso.end.x) + fabs(torso[userID][1] - tracked->left_upper_torso.end.y) > 0.1 && tracked->left_upper_torso.end.x > 0 )){
+			//printf("tracking time %d and last recorded %d\n", timeNow, lastRecordedTime[userID]);
+		userPresent[userID] = true;
+		lastRecordedTime[userID] = timeNow ;
+		torso[userID][0] = tracked->left_upper_torso.end.x;
+		torso[userID][1] = tracked->left_upper_torso.end.y;
+		torso[userID][2] = tracked->left_upper_torso.end.z;
+		
+		checkTorsoMaxima(userID);
+		
+		//recent track, low distance but do nothing yet
+	}
+	else if(userPresent[userID] && 	(timeNow - lastRecordedTime[userID]) > 500 ){
+		//not recent track => stopped
+		userPresent[userID] = false;
+		printf("user %i has STOPPED!\n", userID);
+		torso[userID][0] = tracked->left_upper_torso.end.x;
+		torso[userID][1] = tracked->left_upper_torso.end.y;
+		torso[userID][2] = tracked->left_upper_torso.end.z;
+		
+		sendStopMessageForUser(userID);
+
+	}
+	ofSetColor(0x00FF00);
+	outputString = "HeadX : ";
+	outputString += ofToString(torso[0][0]);
+	franklinBook.drawString(outputString, 100,600);
+
+}
+
+void testApp::checkTorsoMaxima(int id){
+	for (int h = 0; h < 3;h++){
+	if (torso[id][h] > maxTorsoValues[h])
+		maxTorsoValues[h] = torso[id][h];
+	}
+}
+
+void testApp::sendDataViaOSC(int userID){
+
+	ofxOscMessage m;
+	m.setAddress( "/person" );
+	m.addIntArg( userID );
+	m.addFloatArg( torso[userID][0]/maxTorsoValues[0] );
+	m.addFloatArg( torso[userID][1] /maxTorsoValues[1]);
+	m.addFloatArg( torso[userID][2] /maxTorsoValues[2]);
+	sender.sendMessage( m );
+
+}
+
+void testApp::sendStopMessageForUser(int userID){
+	ofxOscMessage m;
+	m.setAddress( "/stoppedperson" );
+	m.addIntArg( userID );
+	m.addFloatArg( torso[userID][0]/maxTorsoValues[0] );
+	m.addFloatArg( torso[userID][1] /maxTorsoValues[1]);
+	m.addFloatArg( torso[userID][2] /maxTorsoValues[2]);
+	stopSender.sendMessage( m );
+}
+
+//--------------------------------------------------------------
+void testApp::draw(){
+		ofBackground(238,238,224);
+	
+	// draw depth and rgb images
+	//depth.draw();
+if (drawIt != true)	{
+image.draw();
+user.draw();	
+}
+	// draw all the users automatically?
+
+	
+	
+	
+	stringstream info;
+	info << "number of tracked users: " << user.getNumTrackedUsers() << endl;
+	
+	// draw the neck positions of each user
+	for(int i = 0; i < user.getNumTrackedUsers(); ++i) {
+		ofxTrackedUser* tracked = user.getTrackedUser(i);
+		if(tracked != NULL) {
+
+			
+		
+		//andrews code
+			int userID = i;
+
+			if (userID < 6){
+			
+				getCoordinates(userID);
+				
+
+				if (userPresent[userID]){
+				sendDataViaOSC(userID);
+				
+				ofSetColor(0x000000);
+				outputString = "Us ";
+				outputString += ofToString(userID);
+				outputString += "  ";	
+				outputString += ofToString(userPresent[userID]);	
+				outputString += "HeadX : ";
+				outputString += ofToString(torso[userID][0], 2);
+				outputString += "  HeadY : ";
+				outputString += ofToString(torso[userID][1], 2);
+				outputString += "  HeadZ : ";
+				outputString += ofToString(torso[userID][2], 2);
+				
+				franklinBook.drawString(outputString, 100,600+userID*40);
+				
+				ofSetColor(0,0,255);
+				ofCircle(tracked->neck.begin.x, tracked->neck.begin.y , 40);
+	
+
+					
+				}
+				
+				ofSetColor(255,255,255);
+				anubis.draw(tracked->neck.begin.x- anubis.width/2,tracked->neck.begin.y - anubis.height/2);
+				
+			}
+			
+			//end andrew
+
+			info << i << " neck pos: "
+				 << tracked->left_lower_arm.end.x << " " 
+				 << tracked->left_lower_arm.end.y << " "
+				 << tracked->neck.begin.z << endl; 
+
+			
+			if (tracked->neck.begin.x != 0)
+
+
+			ofSetColor(139,0,0,100);
+			ofNoFill();
+			float w = ofGetWidth();
+			float h = ofGetHeight();
+
+//		ofBezier(tracked->neck.begin.x,tracked->neck.begin.y,tracked->neck.end.x,tracked->neck.end.y,tracked->left_lower_arm.begin.x,tracked->left_lower_arm.begin.y,tracked->left_lower_arm.end.x,/*tracked->left_lower_arm.end.y*/ w);
+//		ofBezier(tracked->neck.begin.x,tracked->neck.begin.y,tracked->neck.end.x,tracked->neck.end.y,tracked->right_lower_arm.begin.x,tracked->right_lower_arm.begin.y,tracked->right_lower_arm.end.x,/*tracked->right_lower_arm.end.y*/ w);
+//		ofBezier(tracked->neck.begin.x,tracked->neck.begin.y,tracked->neck.end.x,tracked->neck.end.y,tracked->left_lower_leg.begin.x,tracked->left_lower_leg.begin.y,tracked->left_lower_leg.end.x,/*tracked->left_lower_leg.end.y*/ h);
+//		ofBezier(tracked->neck.begin.x,tracked->neck.begin.y,tracked->neck.end.x,tracked->neck.end.y,tracked->right_lower_leg.begin.x,tracked->right_lower_leg.begin.y,tracked->right_lower_leg.end.x,/*tracked->right_lower_leg.end.y*/ h);
+
+		//acid smiley	
+	/*	ofFill();
+		ofSetColor(255,255,100);
+		ofCircle(tracked->neck.begin.x,tracked->neck.begin.y,30);
+		ofSetColor(0);
+		ofCircle(tracked->neck.begin.x,tracked->neck.begin.y,35);
+		ofSetColor(255,255,100);
+		ofCircle(tracked->neck.begin.x,tracked->neck.begin.y,30);
+		ofSetColor(0);
+		ofCircle(tracked->neck.begin.x+10.0f,tracked->neck.begin.y,6);
+		ofCircle(tracked->neck.begin.x-10.0f,tracked->neck.begin.y,6);
+			*/
+//		anubis.draw(tracked->neck.begin.x,tracked->neck.begin.y);	
+		
+
+
+ofBezier(tracked->neck.begin.x,tracked->neck.begin.y,tracked->neck.end.x,tracked->neck.end.y,tracked->left_lower_arm.begin.x,tracked->left_lower_arm.begin.y,tracked->left_lower_arm.end.x,/*tracked->left_lower_arm.end.y*/ w);
+ofBezier(tracked->neck.begin.x,tracked->neck.begin.y,tracked->neck.end.x,tracked->neck.end.y,tracked->right_lower_arm.begin.x,tracked->right_lower_arm.begin.y,tracked->right_lower_arm.end.x,/*tracked->right_lower_arm.end.y*/ w);
+ofBezier(tracked->neck.begin.x,tracked->neck.begin.y,tracked->neck.end.x,tracked->neck.end.y,tracked->left_lower_leg.begin.x,tracked->left_lower_leg.begin.y,tracked->left_lower_leg.end.x,/*tracked->left_lower_leg.end.y*/ h);
+ofBezier(tracked->neck.begin.x,tracked->neck.begin.y,tracked->neck.end.x,tracked->neck.end.y,tracked->right_lower_leg.begin.x,tracked->right_lower_leg.begin.y,tracked->right_lower_leg.end.x,/*tracked->right_lower_leg.end.y*/ h);
+ofFill();
+ofSetColor(255,255,100);
+	ofCircle(tracked->neck.begin.x,tracked->neck.begin.y,30);
+ofSetColor(0);
+ofCircle(tracked->neck.begin.x,tracked->neck.begin.y,35);
+ofSetColor(255,255,100);
+	ofCircle(tracked->neck.begin.x,tracked->neck.begin.y,30);
+	ofSetColor(0);
+ofCircle(tracked->neck.begin.x+10.0f,tracked->neck.begin.y,6);
+ofCircle(tracked->neck.begin.x-10.0f,tracked->neck.begin.y,6);
+
+		}
+	}
+	
+	//faint rectangle?
+	ofFill();
+	ofSetColor(238,238,224,20);
+//	ofRect(0,0,ofGetWidth(),ofGetHeight()); blurring
+	ofDrawBitmapString(info.str(), 10, 500);
+		
+}
+
+//--------------------------------------------------------------
+void testApp::keyPressed(int key){
+	ofSetColor(238,238,224);
+	ofRect(0,0,ofGetWidth(),ofGetHeight());
+//	drawIt =!drawIt;
+  ofToggleFullscreen();
+	
+	sendDataViaOSC(0);
+}
+
+//--------------------------------------------------------------
+void testApp::keyReleased(int key){
+
+}
+
+//--------------------------------------------------------------
+void testApp::mouseMoved(int x, int y ){
+
+}
+
+//--------------------------------------------------------------
+void testApp::mouseDragged(int x, int y, int button){
+
+}
+
+//--------------------------------------------------------------
+void testApp::mousePressed(int x, int y, int button){
+	ofSetColor(238,238,224);
+	ofFill();
+	ofRect(0,0,ofGetWidth(),ofGetHeight());
+
+}
+
+//--------------------------------------------------------------
+void testApp::mouseReleased(int x, int y, int button){
+
+}
+
+//--------------------------------------------------------------
+void testApp::windowResized(int w, int h){
+
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/of/testApp.h.orig	Sat Oct 08 22:12:49 2011 +0100
@@ -0,0 +1,49 @@
+#ifndef _TEST_APP
+#define _TEST_APP
+
+// uncomment this for OF 007 compatibility
+//#define OFX_OPENNI_BETA
+
+#include "ofMain.h"
+#include "ofxOpenNI.h"
+#include "ofxOsc.h"
+
+#define HOST "localhost"
+#define PORT 12346
+
+class testApp : public ofBaseApp{
+
+	public:
+		void setup();
+		void update();
+		void draw();
+
+	void getCoordinates(int userID);
+	void sendDataViaOSC(int userID);
+
+		void keyPressed  (int key);
+		void keyReleased(int key);
+		void mouseMoved(int x, int y );
+		void mouseDragged(int x, int y, int button);
+		void mousePressed(int x, int y, int button);
+		void mouseReleased(int x, int y, int button);
+		void windowResized(int w, int h);
+		ofxOpenNIContext context;
+		ofxDepthGenerator depth;
+		ofxUserGenerator user;
+		ofxImageGenerator image;
+		//ofImage Davy;
+	
+		ofImage anubis;
+		bool drawIt;
+
+
+	float torso[6][3];//x,y,and z of the head
+	bool userPresent[6];
+	
+	ofTrueTypeFont franklinBook;
+	string outputString;
+	ofxOscSender sender;
+	
+};
+#endif
Binary file tim_grid_mapper/OSC.pyc has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tim_grid_mapper/grid_mapper.app/Contents/Info.plist	Sat Oct 08 22:12:49 2011 +0100
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>CFBundleDevelopmentRegion</key>
+	<string>English</string>
+	<key>CFBundleDocumentTypes</key>
+	<array>
+		<dict>
+			<key>CFBundleTypeOSTypes</key>
+			<array>
+				<string>****</string>
+				<string>fold</string>
+				<string>disk</string>
+			</array>
+			<key>CFBundleTypeRole</key>
+			<string>Viewer</string>
+		</dict>
+	</array>
+	<key>CFBundleExecutable</key>
+	<string>grid_mapper</string>
+	<key>CFBundleIconFile</key>
+	<string>PythonApplet.icns</string>
+	<key>CFBundleIdentifier</key>
+	<string>grid_mapper</string>
+	<key>CFBundleInfoDictionaryVersion</key>
+	<string>6.0</string>
+	<key>CFBundleName</key>
+	<string>grid_mapper</string>
+	<key>CFBundlePackageType</key>
+	<string>APPL</string>
+	<key>CFBundleSignature</key>
+	<string>????</string>
+</dict>
+</plist>
Binary file tim_grid_mapper/grid_mapper.app/Contents/MacOS/Python has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tim_grid_mapper/grid_mapper.app/Contents/MacOS/grid_mapper	Sat Oct 08 22:12:49 2011 +0100
@@ -0,0 +1,23 @@
+#!/System/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python
+
+import sys, os
+execdir = os.path.dirname(sys.argv[0])
+executable = os.path.join(execdir, "Python")
+resdir = os.path.join(os.path.dirname(execdir), "Resources")
+libdir = os.path.join(os.path.dirname(execdir), "Frameworks")
+mainprogram = os.path.join(resdir, "__argvemulator_grid_mapper.py")
+
+sys.argv.insert(1, mainprogram)
+if 0 or 0:
+    os.environ["PYTHONPATH"] = resdir
+    if 0:
+        os.environ["PYTHONHOME"] = resdir
+else:
+    pypath = os.getenv("PYTHONPATH", "")
+    if pypath:
+        pypath = ":" + pypath
+    os.environ["PYTHONPATH"] = resdir + pypath
+os.environ["PYTHONEXECUTABLE"] = executable
+os.environ["DYLD_LIBRARY_PATH"] = libdir
+os.environ["DYLD_FRAMEWORK_PATH"] = libdir
+os.execve(executable, sys.argv, os.environ)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tim_grid_mapper/grid_mapper.app/Contents/PkgInfo	Sat Oct 08 22:12:49 2011 +0100
@@ -0,0 +1,1 @@
+APPL????
\ No newline at end of file
Binary file tim_grid_mapper/grid_mapper.app/Contents/Resources/PythonApplet.icns has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tim_grid_mapper/grid_mapper.app/Contents/Resources/__argvemulator_grid_mapper.py	Sat Oct 08 22:12:49 2011 +0100
@@ -0,0 +1,4 @@
+import argvemulator, os
+
+argvemulator.ArgvCollector().mainloop()
+execfile(os.path.join(os.path.split(__file__)[0], "grid_mapper.py"))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tim_grid_mapper/grid_mapper.app/Contents/Resources/grid_mapper.py	Sat Oct 08 22:12:49 2011 +0100
@@ -0,0 +1,262 @@
+#! /usr/bin/python
+'''
+grid_mapper.py - maintained by Tim.
+
+This module implements a mapping from person positions (id,x,y,z) to generate 
+pitch, velocities and channels for Joe's synthesiser and controller data for
+Ableton.
+
+'''
+
+from OSC import ThreadingOSCServer, OSCClient, OSCMessage, OSCClientError
+from threading import Thread
+from time import sleep
+import pdb
+
+#### PUBLIC OPTIONS ####
+num_channels = 3 # number of instruments (and max number of people who can 
+                 # make noise).
+
+#### OSC OPTIONS - THESE NEED TO BE SET MANUALLY ####
+my_port = 12344 # to receive OSC messages
+joe     = ('localhost', 12345)
+ableton = ('localhost', 12346)
+
+### Constants for grid mapping:
+# The range of values that the input coordinates and output values may take:
+# (ranges are inclusive)
+MIN = {
+	'x'		: 0.,
+	'y'		: 0.,
+	'z'		: 0.,
+	'pitch'	: 0,
+	'cc1'   : 0,
+	'cc2'   : 0,
+	'velocity' : 0,
+}
+MAX = {
+	'x'     : 1.,
+	'y'     : 1.,
+	'z'     : 1.,
+	'pitch' : 15,
+	'cc1'   : 127,
+	'cc2'   : 127,
+	'velocity' : 127,
+}
+
+
+
+#### PRIVATE VARIABLES ####
+
+# mapping from channel to the currently playing note (pitch values) or None
+# initialize each channel to None:
+currently_playing = [None] * num_channels
+
+# mapping from personId to time of last update
+# ((not yet implemented))
+#last_update_times = {}
+
+# mapping from (channel, CC_number) to last CC value sent:
+last_value_sent = {
+	(1, 1) : 0,
+	(1, 2) : 0,
+	(2, 1) : 0,
+	(2, 2) : 0,
+	(3, 1) : 0,
+	(3, 2) : 0,
+}
+	
+
+# OSC OBJECTS
+server = None # Initialised when start() is run
+client = OSCClient()
+
+
+
+
+
+### MAPPING
+
+def send_to_joe(data, address='/test'):
+	'''Sends `data` to Joe directly as an OSC message.
+	'''
+	message = OSCMessage(address)
+	message.extend(data)
+	client.sendto(message, joe)
+	print_d('\n==OSC Output "%s" to Joe %s:==\n    %s' % (address, joe, data))
+
+
+def send_to_ableton(data, address='/cc'):
+	'''Sends `data` to Ableton (via Max) as an OSC message.
+	'''
+	#pdb.set_trace()
+	message = OSCMessage(address)
+	message.extend(data)
+	client.sendto(message, ableton)
+	print('\n==OSC Output "%s" to Ableton %s:==\n    %s' % (address, ableton, data))
+	
+
+
+def flush(channel):
+	'''Sends note off messages for whatever note is currently playing on 
+	`channel`.
+	'''
+	pitch = currently_playing[channel]
+	if pitch:
+		#print_d('Sending note-off for note %i on channel %i.' % (pitch, channel))
+		send_to_joe([
+			'Turn off note %i on channel %i' % (pitch, channel), 
+			    # first string is ignored
+			int(pitch),       # pitch to turn off
+			0,                # 0 to turn note off
+			127,              # doesn't matter for note-off (but never send 0)
+			int(channel),
+		])
+	currently_playing[channel] = None
+
+
+def person_handler(address, tags, data, client_address):
+	''' Handles OSC input matching the 'person' tag.
+	
+	`data` should be in form [person_id, x, y, z]
+	'''
+	pitch, velocity, channel, cc1, cc2 = grid_map(*data)
+	
+	cc1, cc2 = int(round(cc1)), int(round(cc2))
+	if cc1 != last_value_sent[(channel, 1)]:
+		send_to_ableton([channel, 1, cc1], '/cc')
+		last_value_sent[(channel, 1)] = cc1
+	if cc2 != last_value_sent[(channel, 2)]:
+		send_to_ableton([channel, 2, cc2], '/cc')
+		last_value_sent[(channel, 2)] = cc2		
+
+	
+	## Format data for Joe - done using Specification.txt on 2011-02-15
+	
+	# constrain and round off pitch and velocity
+	pitch = max(min(round(pitch), MAX['pitch']), MIN['pitch'])
+	velocity = max(min(round(velocity), MAX['velocity']), MIN['velocity'])
+	
+	if velocity and pitch == currently_playing[channel]:
+		return # keep playing current note
+	
+	# otherwise turn note off:
+	flush(channel)
+	
+	if velocity: # if there is a new note to play
+		send_to_joe([
+			'Turn on note %i on channel %i' % (pitch, channel),
+				# first value is string which is ignored
+			int(pitch),    
+			1,               # 1 to turn note on
+			int(velocity), 
+			int(channel)
+		])
+		currently_playing[channel] = pitch
+
+
+
+
+
+def grid_map(person_id, x, y, z):
+	'''This function maps from a person's location to MIDI data
+	returning a tuple (pitch, velocity, channel, cc1, cc2).
+	
+	The current mapping creates higher pitch values as the person moves
+	closer to the Kinect (i.e. z decreases). x and y values are mapped to cc1 
+	and cc2 (to be sent straight to Ableton and determined by a particular
+	synth)
+	
+	NB. channel == person_id and velocity==0 when note is off.
+	Midi-Velocity is currently unimplemented but will use Person-velocity data
+	when that becomes available.
+	This function does not guarantee that the output will be in range if the 
+	input goes out of range.
+	'''
+	pitch = round(interpolate(z, 
+	                          MIN['z'],     MAX['z'],
+	                          MIN['pitch'], MAX['pitch'])
+	        )
+	cc1 = round(interpolate(x, 
+	                          MIN['x'],     MAX['x'],
+	                          MIN['cc1'], MAX['cc1'])
+	        )
+	cc2 = round(interpolate(y, 
+	                          MIN['y'],     MAX['y'],
+	                          MIN['cc2'], MAX['cc2'])
+	        )
+	velocity = 127
+	return (pitch, velocity, person_id, cc1, cc2)
+	
+
+
+
+def interpolate(x, a, b, A, B):
+	''' Interpolates x from the range [a, b] to the range [A, B].
+	
+	
+	Interpolation is linear. From [a,b] to [A,B] this would be:
+	(B-A)*(x-a)/(b-a) + A
+	'''
+	return (B-A)*(x-a)/(b-a) + A
+
+
+def print_d(string):
+	'''Function to print out debug method. Disable if processing power is in
+	demand.
+	'''
+	print(string)
+
+
+
+
+
+
+#### CONTROL
+
+def start():
+	'''Set up OSC servers and start the program running.
+	'''
+	global joe, ableton, server
+	if joe[1] == "THIS_MUST_BE_SET":
+		joe_port = input("Enter port number on %s for Joe's synth software: " % joe[0])
+		joe = (joe[0], joe_port)
+	
+	if ableton[1] == "THIS_MUST_BE_SET":
+		ableton_port = input("Enter port number on %s for Ableton: " % ableton[0])
+		ableton = (ableton[0], ableton_port)
+
+	server = ThreadingOSCServer(('localhost', my_port))
+	# Register OSC callbacks:
+	server.addMsgHandler('/person', person_handler)
+	t = Thread(target=server.serve_forever)
+	t.start()
+	if server.running and t.is_alive():
+		print('OSC Server running on port %i.' % my_port)
+		print("Use 'stop()' to close it.")
+	else:
+		print('Error: Either server thread died or server is not reported as running.')
+
+
+def stop():
+	'''Close the OSC server.
+	'''
+	if server:
+		server.close()
+		sleep(0.3)
+		if not server.running:
+			print("\n\nSuccessfully closed the OSC server. Ignore a 'Bad file descriptor' Exception - there's nothing I can do about that.")
+			print("Type 'quit()' to exit.")
+		else:
+			print('Error: server has been told to close but is still running.')
+
+if __name__=='__main__':
+	start()
+	while True:
+		try:
+			print(repr(input()))
+		except Exception as e:
+			print('Caught %s:' % repr(e))
+			exception = e
+			trace = traceback.format_exc()
+			print('Exception saved as `exception`. Stack trace saved as `trace`.')
Binary file tim_grid_mapper/grid_mapper.pyc has changed