view HeresyBigBangDone/application.macosx/source/HeresyAl.pde @ 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
children
line wrap: on
line source
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;
        }
    }