package com.domemusictechnology.babaolowrey;


import voltage.controllers.*;
import voltage.core.*;
import voltage.core.Jack.JackType;
import voltage.sources.*;
import voltage.utility.*;
import voltage.processors.*;
import voltage.effects.*;
import java.awt.*;

//[user-imports]   Add your own imports here

import javax.sound.midi.ShortMessage;
import java.util.ArrayList;
import javax.sound.midi.InvalidMidiDataException;

//[/user-imports]


public class BabaOLowrey extends VoltageModule
//[user-inheritance]
//[/user-inheritance]
{

public BabaOLowrey( long moduleID, VoltageObjects voltageObjects )
{
   super( moduleID, voltageObjects, "Baba O'Lowrey", ModuleType.ModuleType_MIDI, 2.0 );

   InitializeControls();


   canBeBypassed = false;
   SetSkin( "505d0957c4f74d0893152520630dbe4b" );
}

void InitializeControls()
{

   switch01CSharp = new VoltageSwitch( "C# Bank Select", "C# Bank Select", this, 0 );
   AddComponent( switch01CSharp );
   switch01CSharp.SetWantsMouseNotifications( false );
   switch01CSharp.SetPosition( 74, 288 );
   switch01CSharp.SetSize( 37, 15 );
   switch01CSharp.SetSkin( "Rocker Switch Plastic Black Hor" );

   switch03EFlat = new VoltageSwitch( "Eb Bank Select", "Eb Bank Select", this, 1 );
   AddComponent( switch03EFlat );
   switch03EFlat.SetWantsMouseNotifications( false );
   switch03EFlat.SetPosition( 74, 248 );
   switch03EFlat.SetSize( 37, 15 );
   switch03EFlat.SetSkin( "Rocker Switch Plastic Black Hor" );

   switch00C = new VoltageSwitch( "C Bank Select", "C Bank Select", this, 0 );
   AddComponent( switch00C );
   switch00C.SetWantsMouseNotifications( false );
   switch00C.SetPosition( 83, 308 );
   switch00C.SetSize( 37, 15 );
   switch00C.SetSkin( "Rocker Switch Plastic Cream Hor" );

   switch02D = new VoltageSwitch( "D Bank Select", "D Bank Select", this, 1 );
   AddComponent( switch02D );
   switch02D.SetWantsMouseNotifications( false );
   switch02D.SetPosition( 83, 268 );
   switch02D.SetSize( 37, 15 );
   switch02D.SetSkin( "Rocker Switch Plastic Cream Hor" );

   switch04E = new VoltageSwitch( "E Bank Select", "E Bank Select", this, 1 );
   AddComponent( switch04E );
   switch04E.SetWantsMouseNotifications( false );
   switch04E.SetPosition( 83, 229 );
   switch04E.SetSize( 37, 15 );
   switch04E.SetSkin( "Rocker Switch Plastic Cream Hor" );

   switch05F = new VoltageSwitch( "F Bank Select", "F Bank Select", this, 0 );
   AddComponent( switch05F );
   switch05F.SetWantsMouseNotifications( false );
   switch05F.SetPosition( 83, 208 );
   switch05F.SetSize( 37, 15 );
   switch05F.SetSkin( "Rocker Switch Plastic Cream Hor" );

   switch07G = new VoltageSwitch( "G Bank Select", "G Bank Select", this, 0 );
   AddComponent( switch07G );
   switch07G.SetWantsMouseNotifications( false );
   switch07G.SetPosition( 83, 168 );
   switch07G.SetSize( 37, 15 );
   switch07G.SetSkin( "Rocker Switch Plastic Cream Hor" );

   switch06FSharp = new VoltageSwitch( "F# Bank Select", "F# Bank Select", this, 0 );
   AddComponent( switch06FSharp );
   switch06FSharp.SetWantsMouseNotifications( false );
   switch06FSharp.SetPosition( 74, 188 );
   switch06FSharp.SetSize( 37, 15 );
   switch06FSharp.SetSkin( "Rocker Switch Plastic Black Hor" );

   switch08AFlat = new VoltageSwitch( "Ab Bank Select", "Ab Bank Select", this, 1 );
   AddComponent( switch08AFlat );
   switch08AFlat.SetWantsMouseNotifications( false );
   switch08AFlat.SetPosition( 74, 148 );
   switch08AFlat.SetSize( 37, 15 );
   switch08AFlat.SetSkin( "Rocker Switch Plastic Black Hor" );

   switch09A = new VoltageSwitch( "A Bank Select", "A Bank Select", this, 1 );
   AddComponent( switch09A );
   switch09A.SetWantsMouseNotifications( false );
   switch09A.SetPosition( 83, 128 );
   switch09A.SetSize( 37, 15 );
   switch09A.SetSkin( "Rocker Switch Plastic Cream Hor" );

   switch10BFlat = new VoltageSwitch( "Bb Bank Select", "Bb Bank Select", this, 1 );
   AddComponent( switch10BFlat );
   switch10BFlat.SetWantsMouseNotifications( false );
   switch10BFlat.SetPosition( 74, 108 );
   switch10BFlat.SetSize( 37, 15 );
   switch10BFlat.SetSkin( "Rocker Switch Plastic Black Hor" );

   switch11B = new VoltageSwitch( "B Bank Select", "B Bank Select", this, 0 );
   AddComponent( switch11B );
   switch11B.SetWantsMouseNotifications( false );
   switch11B.SetPosition( 83, 88 );
   switch11B.SetSize( 37, 15 );
   switch11B.SetSkin( "Rocker Switch Plastic Cream Hor" );

   midiInputJack = new VoltageMidiJack( "MIDI In", "MIDI In", this, JackType.JackType_MidiInput );
   AddComponent( midiInputJack );
   midiInputJack.SetWantsMouseNotifications( false );
   midiInputJack.SetPosition( 12, 24 );
   midiInputJack.SetSize( 37, 37 );
   midiInputJack.SetSkin( "Mini MIDI Jack" );

   midiOutputJack = new VoltageMidiJack( "Marimba Out", "Marimba Out", this, JackType.JackType_MidiOutput );
   AddComponent( midiOutputJack );
   midiOutputJack.SetWantsMouseNotifications( false );
   midiOutputJack.SetPosition( 81, 24 );
   midiOutputJack.SetSize( 37, 37 );
   midiOutputJack.SetSkin( "Mini MIDI Jack" );

   inputJackClock = new VoltageAudioJack( "Clock In", "Clock In", this, JackType.JackType_AudioInput );
   AddComponent( inputJackClock );
   inputJackClock.SetWantsMouseNotifications( false );
   inputJackClock.SetPosition( 18, 158 );
   inputJackClock.SetSize( 25, 25 );
   inputJackClock.SetSkin( "Jack Round Plum Ring" );

   textLabel1 = new VoltageLabel( "textLabel1", "textLabel1", this, "Dome Music Technologies" );
   AddComponent( textLabel1 );
   textLabel1.SetWantsMouseNotifications( false );
   textLabel1.SetPosition( 9, 343 );
   textLabel1.SetSize( 127, 16 );
   textLabel1.SetEditable( false, false );
   textLabel1.SetJustificationFlags( VoltageLabel.Justification.HorizCentered );
   textLabel1.SetJustificationFlags( VoltageLabel.Justification.VertCentered );
   textLabel1.SetColor( new Color( 255, 255, 255, 255 ) );
   textLabel1.SetBkColor( new Color( 65, 65, 65, 0 ) );
   textLabel1.SetBorderColor( new Color( 0, 0, 0, 0 ) );
   textLabel1.SetBorderSize( 1 );
   textLabel1.SetMultiLineEdit( false );
   textLabel1.SetIsNumberEditor( false );
   textLabel1.SetNumberEditorRange( 0, 100 );
   textLabel1.SetNumberEditorInterval( 1 );
   textLabel1.SetNumberEditorUsesMouseWheel( false );
   textLabel1.SetHasCustomTextHoverColor( false );
   textLabel1.SetTextHoverColor( new Color( 0, 0, 0, 255 ) );
   textLabel1.SetFont( "Verdana", 10, false, false );

   LEDA11 = new VoltageLED( "LED A B", "LED A B", this );
   AddComponent( LEDA11 );
   LEDA11.SetWantsMouseNotifications( false );
   LEDA11.SetPosition( 60, 90 );
   LEDA11.SetSize( 11, 11 );
   LEDA11.SetSkin( "Green" );

   LEDA10 = new VoltageLED( "LED A Bb", "LED A Bb", this );
   AddComponent( LEDA10 );
   LEDA10.SetWantsMouseNotifications( false );
   LEDA10.SetPosition( 60, 110 );
   LEDA10.SetSize( 11, 11 );
   LEDA10.SetSkin( "Green" );

   LEDA09 = new VoltageLED( "LED A A", "LED A A", this );
   AddComponent( LEDA09 );
   LEDA09.SetWantsMouseNotifications( false );
   LEDA09.SetPosition( 60, 130 );
   LEDA09.SetSize( 11, 11 );
   LEDA09.SetSkin( "Green" );

   LEDA08 = new VoltageLED( "LED A Ab", "LED A Ab", this );
   AddComponent( LEDA08 );
   LEDA08.SetWantsMouseNotifications( false );
   LEDA08.SetPosition( 60, 150 );
   LEDA08.SetSize( 11, 11 );
   LEDA08.SetSkin( "Green" );

   LEDA07 = new VoltageLED( "LED A G", "LED A G", this );
   AddComponent( LEDA07 );
   LEDA07.SetWantsMouseNotifications( false );
   LEDA07.SetPosition( 60, 170 );
   LEDA07.SetSize( 11, 11 );
   LEDA07.SetSkin( "Green" );

   LEDA06 = new VoltageLED( "LED A F#", "LED A F#", this );
   AddComponent( LEDA06 );
   LEDA06.SetWantsMouseNotifications( false );
   LEDA06.SetPosition( 60, 190 );
   LEDA06.SetSize( 11, 11 );
   LEDA06.SetSkin( "Green" );

   LEDA05 = new VoltageLED( "LED A F", "LED A F", this );
   AddComponent( LEDA05 );
   LEDA05.SetWantsMouseNotifications( false );
   LEDA05.SetPosition( 60, 210 );
   LEDA05.SetSize( 11, 11 );
   LEDA05.SetSkin( "Green" );

   LEDA04 = new VoltageLED( "LED A E", "LED A E", this );
   AddComponent( LEDA04 );
   LEDA04.SetWantsMouseNotifications( false );
   LEDA04.SetPosition( 60, 230 );
   LEDA04.SetSize( 11, 11 );
   LEDA04.SetSkin( "Green" );

   LEDA03 = new VoltageLED( "LED A Eb", "LED A Eb", this );
   AddComponent( LEDA03 );
   LEDA03.SetWantsMouseNotifications( false );
   LEDA03.SetPosition( 60, 250 );
   LEDA03.SetSize( 11, 11 );
   LEDA03.SetSkin( "Green" );

   LEDA02 = new VoltageLED( "LED A D", "LED A D", this );
   AddComponent( LEDA02 );
   LEDA02.SetWantsMouseNotifications( false );
   LEDA02.SetPosition( 60, 270 );
   LEDA02.SetSize( 11, 11 );
   LEDA02.SetSkin( "Green" );

   LEDA01 = new VoltageLED( "LED A C#", "LED A C#", this );
   AddComponent( LEDA01 );
   LEDA01.SetWantsMouseNotifications( false );
   LEDA01.SetPosition( 60, 290 );
   LEDA01.SetSize( 11, 11 );
   LEDA01.SetSkin( "Green" );

   LEDA00 = new VoltageLED( "LED A C", "LED A C", this );
   AddComponent( LEDA00 );
   LEDA00.SetWantsMouseNotifications( false );
   LEDA00.SetPosition( 60, 310 );
   LEDA00.SetSize( 11, 11 );
   LEDA00.SetSkin( "Green" );

   LEDB11 = new VoltageLED( "LED B B", "LED B B", this );
   AddComponent( LEDB11 );
   LEDB11.SetWantsMouseNotifications( false );
   LEDB11.SetPosition( 123, 90 );
   LEDB11.SetSize( 11, 11 );
   LEDB11.SetSkin( "Red" );

   LEDB10 = new VoltageLED( "LED B Bb", "LED B Bb", this );
   AddComponent( LEDB10 );
   LEDB10.SetWantsMouseNotifications( false );
   LEDB10.SetPosition( 123, 110 );
   LEDB10.SetSize( 11, 11 );
   LEDB10.SetSkin( "Red" );

   LEDB09 = new VoltageLED( " LED B A", " LED B A", this );
   AddComponent( LEDB09 );
   LEDB09.SetWantsMouseNotifications( false );
   LEDB09.SetPosition( 123, 130 );
   LEDB09.SetSize( 11, 11 );
   LEDB09.SetSkin( "Red" );

   LEDB08 = new VoltageLED( "LED B Ab", "LED B Ab", this );
   AddComponent( LEDB08 );
   LEDB08.SetWantsMouseNotifications( false );
   LEDB08.SetPosition( 123, 150 );
   LEDB08.SetSize( 11, 11 );
   LEDB08.SetSkin( "Red" );

   LEDB07 = new VoltageLED( "LED B G", "LED B G", this );
   AddComponent( LEDB07 );
   LEDB07.SetWantsMouseNotifications( false );
   LEDB07.SetPosition( 123, 170 );
   LEDB07.SetSize( 11, 11 );
   LEDB07.SetSkin( "Red" );

   LEDB06 = new VoltageLED( "LED B F#", "LED B F#", this );
   AddComponent( LEDB06 );
   LEDB06.SetWantsMouseNotifications( false );
   LEDB06.SetPosition( 123, 190 );
   LEDB06.SetSize( 11, 11 );
   LEDB06.SetSkin( "Red" );

   LEDB05 = new VoltageLED( "LED B F", "LED B F", this );
   AddComponent( LEDB05 );
   LEDB05.SetWantsMouseNotifications( false );
   LEDB05.SetPosition( 123, 210 );
   LEDB05.SetSize( 11, 11 );
   LEDB05.SetSkin( "Red" );

   LEDB04 = new VoltageLED( "LED B E", "LED B E", this );
   AddComponent( LEDB04 );
   LEDB04.SetWantsMouseNotifications( false );
   LEDB04.SetPosition( 123, 230 );
   LEDB04.SetSize( 11, 11 );
   LEDB04.SetSkin( "Red" );

   LEDB03 = new VoltageLED( "LED B Eb", "LED B Eb", this );
   AddComponent( LEDB03 );
   LEDB03.SetWantsMouseNotifications( false );
   LEDB03.SetPosition( 123, 250 );
   LEDB03.SetSize( 11, 11 );
   LEDB03.SetSkin( "Red" );

   LEDB02 = new VoltageLED( "LED B D", "LED B D", this );
   AddComponent( LEDB02 );
   LEDB02.SetWantsMouseNotifications( false );
   LEDB02.SetPosition( 123, 270 );
   LEDB02.SetSize( 11, 11 );
   LEDB02.SetSkin( "Red" );

   LEDB01 = new VoltageLED( "LED B C#", "LED B C#", this );
   AddComponent( LEDB01 );
   LEDB01.SetWantsMouseNotifications( false );
   LEDB01.SetPosition( 123, 290 );
   LEDB01.SetSize( 11, 11 );
   LEDB01.SetSkin( "Red" );

   LEDB00 = new VoltageLED( "LED B C", "LED B C", this );
   AddComponent( LEDB00 );
   LEDB00.SetWantsMouseNotifications( false );
   LEDB00.SetPosition( 123, 310 );
   LEDB00.SetSize( 11, 11 );
   LEDB00.SetSkin( "Red" );

   inputJackSetA = new VoltageAudioJack( "Set A In", "Set A In", this, JackType.JackType_AudioInput );
   AddComponent( inputJackSetA );
   inputJackSetA.SetWantsMouseNotifications( false );
   inputJackSetA.SetPosition( 17, 218 );
   inputJackSetA.SetSize( 25, 25 );
   inputJackSetA.SetSkin( "Jack Round Green Ring" );

   inputJackSetB = new VoltageAudioJack( "Set B In", "Set B In", this, JackType.JackType_AudioInput );
   AddComponent( inputJackSetB );
   inputJackSetB.SetWantsMouseNotifications( false );
   inputJackSetB.SetPosition( 17, 277 );
   inputJackSetB.SetSize( 25, 25 );
   inputJackSetB.SetSkin( "Jack Round Red Ring" );

   textLabel2 = new VoltageLabel( "textLabel2", "textLabel2", this, "Baba O'Lowrey" );
   AddComponent( textLabel2 );
   textLabel2.SetWantsMouseNotifications( false );
   textLabel2.SetPosition( 6, -4 );
   textLabel2.SetSize( 132, 24 );
   textLabel2.SetEditable( false, false );
   textLabel2.SetJustificationFlags( VoltageLabel.Justification.HorizCentered );
   textLabel2.SetJustificationFlags( VoltageLabel.Justification.VertCentered );
   textLabel2.SetColor( new Color( 255, 255, 255, 255 ) );
   textLabel2.SetBkColor( new Color( 65, 65, 65, 0 ) );
   textLabel2.SetBorderColor( new Color( 0, 0, 0, 0 ) );
   textLabel2.SetBorderSize( 1 );
   textLabel2.SetMultiLineEdit( false );
   textLabel2.SetIsNumberEditor( false );
   textLabel2.SetNumberEditorRange( 0, 100 );
   textLabel2.SetNumberEditorInterval( 1 );
   textLabel2.SetNumberEditorUsesMouseWheel( false );
   textLabel2.SetHasCustomTextHoverColor( false );
   textLabel2.SetTextHoverColor( new Color( 0, 0, 0, 255 ) );
   textLabel2.SetFont( "Verdana", 14, true, false );

   textLabel3 = new VoltageLabel( "textLabel3", "textLabel3", this, "KEYS IN" );
   AddComponent( textLabel3 );
   textLabel3.SetWantsMouseNotifications( false );
   textLabel3.SetPosition( 1, 59 );
   textLabel3.SetSize( 56, 18 );
   textLabel3.SetEditable( false, false );
   textLabel3.SetJustificationFlags( VoltageLabel.Justification.HorizCentered );
   textLabel3.SetJustificationFlags( VoltageLabel.Justification.VertCentered );
   textLabel3.SetColor( new Color( 255, 255, 255, 255 ) );
   textLabel3.SetBkColor( new Color( 65, 65, 65, 0 ) );
   textLabel3.SetBorderColor( new Color( 0, 0, 0, 0 ) );
   textLabel3.SetBorderSize( 1 );
   textLabel3.SetMultiLineEdit( false );
   textLabel3.SetIsNumberEditor( false );
   textLabel3.SetNumberEditorRange( 0, 100 );
   textLabel3.SetNumberEditorInterval( 1 );
   textLabel3.SetNumberEditorUsesMouseWheel( false );
   textLabel3.SetHasCustomTextHoverColor( false );
   textLabel3.SetTextHoverColor( new Color( 0, 0, 0, 255 ) );
   textLabel3.SetFont( "Verdana", 12, false, false );

   textLabel4 = new VoltageLabel( "textLabel4", "textLabel4", this, "REPEAT OUT" );
   AddComponent( textLabel4 );
   textLabel4.SetWantsMouseNotifications( false );
   textLabel4.SetPosition( 64, 59 );
   textLabel4.SetSize( 72, 18 );
   textLabel4.SetEditable( false, false );
   textLabel4.SetJustificationFlags( VoltageLabel.Justification.HorizCentered );
   textLabel4.SetJustificationFlags( VoltageLabel.Justification.VertCentered );
   textLabel4.SetColor( new Color( 255, 255, 255, 255 ) );
   textLabel4.SetBkColor( new Color( 65, 65, 65, 0 ) );
   textLabel4.SetBorderColor( new Color( 0, 0, 0, 0 ) );
   textLabel4.SetBorderSize( 1 );
   textLabel4.SetMultiLineEdit( false );
   textLabel4.SetIsNumberEditor( false );
   textLabel4.SetNumberEditorRange( 0, 100 );
   textLabel4.SetNumberEditorInterval( 1 );
   textLabel4.SetNumberEditorUsesMouseWheel( false );
   textLabel4.SetHasCustomTextHoverColor( false );
   textLabel4.SetTextHoverColor( new Color( 0, 0, 0, 255 ) );
   textLabel4.SetFont( "Verdana", 12, false, false );

   textLabel5 = new VoltageLabel( "textLabel5", "textLabel5", this, "EXT CLK" );
   AddComponent( textLabel5 );
   textLabel5.SetWantsMouseNotifications( false );
   textLabel5.SetPosition( 3, 179 );
   textLabel5.SetSize( 54, 20 );
   textLabel5.SetEditable( false, false );
   textLabel5.SetJustificationFlags( VoltageLabel.Justification.HorizCentered );
   textLabel5.SetJustificationFlags( VoltageLabel.Justification.VertCentered );
   textLabel5.SetColor( new Color( 255, 255, 255, 255 ) );
   textLabel5.SetBkColor( new Color( 65, 65, 65, 0 ) );
   textLabel5.SetBorderColor( new Color( 0, 0, 0, 0 ) );
   textLabel5.SetBorderSize( 1 );
   textLabel5.SetMultiLineEdit( false );
   textLabel5.SetIsNumberEditor( false );
   textLabel5.SetNumberEditorRange( 0, 100 );
   textLabel5.SetNumberEditorInterval( 1 );
   textLabel5.SetNumberEditorUsesMouseWheel( false );
   textLabel5.SetHasCustomTextHoverColor( false );
   textLabel5.SetTextHoverColor( new Color( 0, 0, 0, 255 ) );
   textLabel5.SetFont( "Verdana", 12, false, false );

   LEDclockA = new VoltageLED( "Clock A LED", "Clock A LED", this );
   AddComponent( LEDclockA );
   LEDclockA.SetWantsMouseNotifications( false );
   LEDclockA.SetPosition( 15, 139 );
   LEDclockA.SetSize( 11, 11 );
   LEDclockA.SetSkin( "Green" );

   LEDclockB = new VoltageLED( "Clock B LED", "Clock B LED", this );
   AddComponent( LEDclockB );
   LEDclockB.SetWantsMouseNotifications( false );
   LEDclockB.SetPosition( 35, 139 );
   LEDclockB.SetSize( 11, 11 );
   LEDclockB.SetSkin( "Red" );

   textLabel6 = new VoltageLabel( "textLabel6", "textLabel6", this, "SET A" );
   AddComponent( textLabel6 );
   textLabel6.SetWantsMouseNotifications( false );
   textLabel6.SetPosition( 7, 241 );
   textLabel6.SetSize( 46, 19 );
   textLabel6.SetEditable( false, false );
   textLabel6.SetJustificationFlags( VoltageLabel.Justification.HorizCentered );
   textLabel6.SetJustificationFlags( VoltageLabel.Justification.VertCentered );
   textLabel6.SetColor( new Color( 255, 255, 255, 255 ) );
   textLabel6.SetBkColor( new Color( 65, 65, 65, 0 ) );
   textLabel6.SetBorderColor( new Color( 0, 0, 0, 0 ) );
   textLabel6.SetBorderSize( 1 );
   textLabel6.SetMultiLineEdit( false );
   textLabel6.SetIsNumberEditor( false );
   textLabel6.SetNumberEditorRange( 0, 100 );
   textLabel6.SetNumberEditorInterval( 1 );
   textLabel6.SetNumberEditorUsesMouseWheel( false );
   textLabel6.SetHasCustomTextHoverColor( false );
   textLabel6.SetTextHoverColor( new Color( 0, 0, 0, 255 ) );
   textLabel6.SetFont( "Verdana", 12, false, false );

   textLabel7 = new VoltageLabel( "textLabel7", "textLabel7", this, "SET B" );
   AddComponent( textLabel7 );
   textLabel7.SetWantsMouseNotifications( false );
   textLabel7.SetPosition( 7, 299 );
   textLabel7.SetSize( 47, 23 );
   textLabel7.SetEditable( false, false );
   textLabel7.SetJustificationFlags( VoltageLabel.Justification.HorizCentered );
   textLabel7.SetJustificationFlags( VoltageLabel.Justification.VertCentered );
   textLabel7.SetColor( new Color( 255, 255, 255, 255 ) );
   textLabel7.SetBkColor( new Color( 65, 65, 65, 0 ) );
   textLabel7.SetBorderColor( new Color( 0, 0, 0, 0 ) );
   textLabel7.SetBorderSize( 1 );
   textLabel7.SetMultiLineEdit( false );
   textLabel7.SetIsNumberEditor( false );
   textLabel7.SetNumberEditorRange( 0, 100 );
   textLabel7.SetNumberEditorInterval( 1 );
   textLabel7.SetNumberEditorUsesMouseWheel( false );
   textLabel7.SetHasCustomTextHoverColor( false );
   textLabel7.SetTextHoverColor( new Color( 0, 0, 0, 255 ) );
   textLabel7.SetFont( "Verdana", 12, false, false );

   rateKnob = new VoltageKnob( "Repeat Rate", "Repeat Rate", this, 30, 160, 120 );
   AddComponent( rateKnob );
   rateKnob.SetWantsMouseNotifications( false );
   rateKnob.SetPosition( 17, 89 );
   rateKnob.SetSize( 27, 27 );
   rateKnob.SetSkin( "Plastic White" );
   rateKnob.SetRange( 30, 160, 120, false, 0 );
   rateKnob.SetKnobParams( 215, 145 );
   rateKnob.DisplayValueInPercent( false );
   rateKnob.SetKnobAdjustsRing( true );
   rateKnob.SetMidpointValue( 120 );

   textLabel8 = new VoltageLabel( "textLabel8", "textLabel8", this, "RATE" );
   AddComponent( textLabel8 );
   textLabel8.SetWantsMouseNotifications( false );
   textLabel8.SetPosition( 6, 113 );
   textLabel8.SetSize( 47, 19 );
   textLabel8.SetEditable( false, false );
   textLabel8.SetJustificationFlags( VoltageLabel.Justification.HorizCentered );
   textLabel8.SetJustificationFlags( VoltageLabel.Justification.VertCentered );
   textLabel8.SetColor( new Color( 255, 255, 255, 255 ) );
   textLabel8.SetBkColor( new Color( 65, 65, 65, 0 ) );
   textLabel8.SetBorderColor( new Color( 0, 0, 0, 0 ) );
   textLabel8.SetBorderSize( 1 );
   textLabel8.SetMultiLineEdit( false );
   textLabel8.SetIsNumberEditor( false );
   textLabel8.SetNumberEditorRange( 0, 100 );
   textLabel8.SetNumberEditorInterval( 1 );
   textLabel8.SetNumberEditorUsesMouseWheel( false );
   textLabel8.SetHasCustomTextHoverColor( false );
   textLabel8.SetTextHoverColor( new Color( 0, 0, 0, 255 ) );
   textLabel8.SetFont( "Verdana", 12, false, false );
}



//-------------------------------------------------------------------------------
//  public void Initialize()

//  Initialize will get called shortly after your module's constructor runs. You can use it to
//  do any initialization that the auto-generated code doesn't handle.
//-------------------------------------------------------------------------------
@Override
public void Initialize()
{
   //[user-Initialize]   Add your own initialization code here

   int key;
   int semitone;
   
   for (semitone = 0; semitone < SEMITONES_PER_OCTAVE; semitone++)
   {
      heldNotes[semitone] = false;
   }
   
   for (key = 0; key < NUMBER_OF_KEYS; key++)
   {
      keyVelocities[key] = 0;
      playingNotes[key] = false;
   }
      
   currentExtClockHigh = (inputJackClock.GetValue() > 2.5);
   previousExtClockHigh = currentExtClockHigh;

   currentClockState = ClockState.BANK_B_OFF;
   clockCounter = 1;    // Decrememnt to zero on first call of ProcessSample
   intClockHigh = false;
   currentRunMode = RunMode.BANK_TOGGLE;
   
   CalculateRate();
   CheckConnections();
   CheckBankSelections();
   
   keysChanged = false;

   StartGuiUpdateTimer(10);   // 10ms
   
   //[/user-Initialize]
}


//-------------------------------------------------------------------------------
//  public void Destroy()

//  Destroy will get called just before your module gets deleted. You can use it to perform any
//  cleanup that's not handled automatically by Java.
//-------------------------------------------------------------------------------
@Override
public void Destroy()
{
   super.Destroy();
   //[user-Destroy]   Add your own module-getting-deleted code here



   //[/user-Destroy]
}


//-------------------------------------------------------------------------------
//  public boolean Notify( VoltageComponent component, ModuleNotifications notification, double doubleValue, long longValue, int x, int y, Object object )

//  Notify will get called when various events occur - control values changing, timers firing, etc.
//-------------------------------------------------------------------------------
@Override
public boolean Notify( VoltageComponent component, ModuleNotifications notification, double doubleValue, long longValue, int x, int y, Object object )
{
   //[user-Notify]   Add your own notification handling code between this line and the notify-close comment
   switch( notification )
   {
      case Knob_Changed:   // doubleValue is the new VoltageKnob value
      {
         if (component == rateKnob)
         {
            CalculateRate();
         }
      }
      break;
   
      case Slider_Changed:   // doubleValue is the new slider value
      {
      }
      break;
   
      case Button_Changed:   // doubleValue is the new button/toggle button value
      {
      }
      break;
   
      case Switch_Changed:   // doubleValue is the new switch value
      {
         CheckBankSelections();
         keysChanged = true;  // Force LED redraw on next GUI Update
      }
      break;
   
      case Jack_Connected:   // longValue is the new cable ID
      {
         CheckConnections();
      }
      break;
   
      case Jack_Disconnected:   // All cables have been disconnected from this jack
      {
         CheckConnections();
      }
      break;
   
      case GUI_Update_Timer:   // Called every 50ms (by default) if turned on
      {
         switch (currentClockState)
         {
            case BANK_A_ON:
            {
               LEDclockA.SetValue(1.0);
               LEDclockB.SetValue(0.0);
            }
            break;
         
            case BANK_A_OFF:
            {
               LEDclockA.SetValue(0.0);
               LEDclockB.SetValue(0.0);
            }
            break;
         
            case BANK_B_ON:
            {
               LEDclockA.SetValue(0.0);
               LEDclockB.SetValue(1.0);
            }
            break;
         
            case BANK_B_OFF:
            {
               LEDclockA.SetValue(0.0);
               LEDclockB.SetValue(0.0);
            }
            break;
                        
         }
         
         if (keysChanged)
         {
            CheckHeldKeys();
            RedrawBankLEDs();
            
            keysChanged = false;
         }
      }
      break;
   
      case Object_MouseMove:   // called when mouse is over an object that receives mouse notifications. 'object' parameter is a VoltageMouseKeyFlags object.
      {
      }
      break;
   
      case Object_MouseLeave:  // called when mouse leaves an object that receives mouse notifications. 'object' parameter is a VoltageMouseKeyFlags object.
      {
      }
      break;
   
      case Object_LeftButtonDown:   // called when user left-clicks on an object that receives mouse notifications. 'object' parameter is a VoltageMouseKeyFlags object.
      {
      }
      break;
   
      case Object_LeftButtonUp:   // called when user releases left mouse button on an object that receives mouse notifications. 'object' parameter is a VoltageMouseKeyFlags object.
      {
      }
      break;
   
      case Object_RightButtonDown:   // called when user releases right mouse button on an object that receives mouse notifications. 'object' parameter is a VoltageMouseKeyFlags object.
      {
      }
      break;
   
      case Object_RightButtonUp:   // called when user right-clicks on an object that receives mouse notifications
      {
      }
      break;
   
      case Object_LeftButtonDoubleClick: // called when user left-button double-clicks on an object that receives mouse notifications
      {
      }
      break;
   
      // Less common notifications:
   
      case Named_Timer:   // object contains a String with the name of the timer that has fired
      {
      }
      break;
   
      case Canvas_Painting:   // About to paint canvas.  object is a java.awt.Rectangle with painting boundaries
      {
      }
      break;
   
      case Canvas_Painted:   // Canvas painting is complete
      {
      }
      break;
   
      case Control_DragStart:    // A user has started dragging on a control that has been marked as draggable
      {
      }
      break;
   
      case Control_DragOn:       // This control has been dragged over during a drag operation. object contains the dragged object
      {
      }
      break;
   
      case Control_DragOff:      // This control has been dragged over during a drag operation. object contains the dragged object
      {
      }
      break;
   
      case Control_DragEnd:      // A user has ended their drag on a control that has been marked as draggable
      {
      }
      break;
   
      case Label_Changed:        // The text of an editable text control has changed
      {
      }
      break;
   
      case SoundPlayback_Start:   // A sound has begun playback
      {
      }
      break;
   
      case SoundPlayback_End:     // A sound has ended playback
      {
      }
      break;
   
      case Scrollbar_Position:    // longValue is the new scrollbar position
      {
      }
      break;
   
      case PolyVoices_Changed:    // longValue is the new number of poly voices
      {
      }
      break;
   
      case File_Dropped:     // 'object' is a String containing the file path
      {
      }
      break;
   
      case Preset_Loading_Start:   // called when preset loading begins
      {
      }
      break;
   
      case Preset_Loading_Finish:  // called when preset loading finishes
      {
      }
      break;
   
      case Variation_Loading_Start:    // sent when a variation is about to load
      {
      }
      break;
   
      case Variation_Loading_Finish:   // sent when a variation has just finished loading
      {
      }
      break;
   
      case Tempo_Changed:     // doubleValue is the new tempo
      {
      }
      break;
   
      case Randomized:     // called when the module's controls get randomized
      {
      }
      break;
   
      case VariationListChanged:   // sent when a variation gets added, deleted, or renamed, or the variations list gets reordered
      {
      }
      break;
   
      case Key_Press:     // sent when module has keyboard focus and a key is pressed; object is a VoltageKeyPressInfo object
      {
      }
      break;
   
      case Reset:    // sent when the module has been reset to default settings
      {
      }
      break;
   
      case Keyboard_NoteOn:   // sent when a note has been pressed on a VoltageKeyboard object. longValue is the note value ( 0-127 )
      {
      }
      break;
   
      case Keyboard_NoteOff:   // sent when a note has been released on a VoltageKeyboard object. longValue is the note value ( 0-127 )
      {
      }
      break;
   
      case Curve_Changed:   // sent when user has edited a curve's value. 'object' will be a VoltageCurve.CurveChangeNotification object.
      {
      }
      break;
   }



   return false;
   //[/user-Notify]
}


//-------------------------------------------------------------------------------
//  public void ProcessSample()

//  ProcessSample is called once per sample. Usually it's where you read
//  from input jacks, process audio, and write it to your output jacks.
//  Since ProcesssSample gets called 48,000 times per second, offload CPU-intensive operations
//  to other threads when possible and avoid calling native functions.
//-------------------------------------------------------------------------------
@Override
public void ProcessSample()
{
   //[user-ProcessSample]   Add your own process-sampling code here

   boolean changedPhase = false;
   boolean risingEdge = false;
   boolean fallingEdge = false;
   
   // Work out current run mode from Set A and Set B inputs
   
   boolean setAhigh = (inputJackSetA.GetValue() >= 2.5);
   boolean setBhigh = (inputJackSetB.GetValue() >= 2.5);
   
   if (setAhigh)
   {
      if (setBhigh)
      {
         currentRunMode = RunMode.BANK_HOLD;
      }
      else
      {
         currentRunMode = RunMode.BANK_A_SET;
      }
   }
   else
   {
      if (setBhigh)
      {
         currentRunMode = RunMode.BANK_B_SET;
      }
      else
      {
         currentRunMode = RunMode.BANK_TOGGLE;
      }
   }
   
   // Update clock phase depnding on whether internal or external   
   if (extClockConnected)
   {
      currentExtClockHigh = (inputJackClock.GetValue() > 2.5);
      
      // Check for edge transition in EXT CLK signal
      if (currentExtClockHigh != previousExtClockHigh)
      {
         if (currentExtClockHigh)
         {
            risingEdge = true;
         }
         else
         {
            fallingEdge = true;
         }
         changedPhase = true;
         
      }
            
      previousExtClockHigh = currentExtClockHigh;
      
   }
   else
   {
      // Ext Clk not connected, so process internal clock
      clockCounter--;
   
      if (clockCounter <= 0)  // Use inequality to be safer
      {
         changedPhase = true;
         clockCounter = clockPeriod;
      
         if (intClockHigh)
         {
            // Falling edge
            intClockHigh = false;
            fallingEdge = true;
         }
         else
         {
            // Rising edge
            intClockHigh = true;
            risingEdge = true;
         }
      }
   }
   
   // Now use edge detection to trigger on / off of held keys
   if (fallingEdge || risingEdge)
   {
      // Advance to next phase in clock cycle
      switch (currentClockState)
      {
         case BANK_A_ON:
         {
            if (fallingEdge)
            {
               SendAllHeldNoteOff ();
               currentClockState = ClockState.BANK_A_OFF;
            }
         }
         break;
         
         case BANK_A_OFF:
         {
            if (risingEdge)
            {
               switch (currentRunMode)
               {
                  case BANK_B_SET:
                  case BANK_TOGGLE:
                  {
                     currentClockState = ClockState.BANK_B_ON;
                     SendAllHeldNoteOn ();
                  }
                  break;
                  
                  case BANK_A_SET:
                  case BANK_HOLD:
                  {
                     currentClockState = ClockState.BANK_A_ON;
                     SendAllHeldNoteOn ();
                  }
                  break;
               }
            }
                  
         }
         break;
         
         case BANK_B_ON:
         {
            if (fallingEdge)
            {
               SendAllHeldNoteOff ();
               currentClockState = ClockState.BANK_B_OFF;
            }
         }
         break;
         
         case BANK_B_OFF:
         {
            if (risingEdge)
            {
               switch (currentRunMode)
               {
                  case BANK_A_SET:
                  case BANK_TOGGLE:
                  {
                     currentClockState = ClockState.BANK_A_ON;
                     SendAllHeldNoteOn ();
                  }
                  break;
                  
                  case BANK_B_SET:
                  case BANK_HOLD:
                  {
                     currentClockState = ClockState.BANK_B_ON;
                     SendAllHeldNoteOn ();
                  }
                  break;
               }
            }
                  
         }
         break;
         
      }
      
   }
         
   // Process any pending MIDI input stream messages
   ArrayList<ShortMessage> events = midiInputJack.GetMessages();
   
   // events will be non-null if there are
   // MIDI events to process
   if (events != null)
   {
      int numEvents = events.size();   
      for (int ix = 0; ix < numEvents; ix++)
      {
         ShortMessage event = events.get(ix);
         
         int command = event.getCommand();
         
         switch (command)
         {
         
            case ShortMessage.NOTE_ON:
            {
               int noteValue = event.getData1();
               int velocityValue = event.getData2();
            
               // Set the appropriate note's velocity value
               keyVelocities[noteValue] = velocityValue;
            
               // Set flag to be picked up by GUI Notify
               keysChanged = true;
               
               // Immediately pass through note on if in the right cycle phase
               if (NoteIsOn(noteValue))
               {
                  SendNoteOn (noteValue);
               }
               
            }
            break;
            
            case ShortMessage.NOTE_OFF:
            {
               int noteValue = event.getData1();
               int velocityValue = event.getData2();
            
               // Set the appropriate note's velocity value
               keyVelocities[noteValue] = 0;
            
               // Set flag to be picked up by GUI Notify
               keysChanged = true;
               
               // Immediately pass through note off unconditionally            
               SendNoteOff (noteValue);
            
            }
            break;
            
            default:
            {
            }
            break;
            
         }
      }
      
   }
   


   //[/user-ProcessSample]
}


//-------------------------------------------------------------------------------
//  public String GetTooltipText( VoltageComponent component )

//  Gets called when a tooltip is about to display for a control. Override it if
//  you want to change what the tooltip displays - if you want a knob to work in logarithmic fashion,
//  for instance, you can translate the knob's current value to a log-based string and display it here.
//-------------------------------------------------------------------------------
@Override
public String GetTooltipText( VoltageComponent component )
{
   //[user-GetTooltipText]   Add your own code here



   return super.GetTooltipText( component );
   //[/user-GetTooltipText]
}


//-------------------------------------------------------------------------------
//  public void EditComponentValue( VoltageComponent component, double newValue, String newText )

//  Gets called after a user clicks on a tooltip and types in a new value for a control. Override this if
//  you've changed the default tooltip display (translating a linear value to logarithmic, for instance)
//  in GetTooltipText().
//-------------------------------------------------------------------------------
@Override
public void EditComponentValue( VoltageComponent component, double newValue, String newText )
{
   //[user-EditComponentValue]   Add your own code here



   //[/user-EditComponentValue]
   super.EditComponentValue( component, newValue, newText );
}


//-------------------------------------------------------------------------------
//  public void OnUndoRedo( String undoType, double newValue, Object optionalObject )

//  If you've created custom undo events via calls to CreateUndoEvent, you'll need to
//  process them in this function when they get triggered by undo/redo actions.
//-------------------------------------------------------------------------------
@Override
public void OnUndoRedo( String undoType, double newValue, Object optionalObject )
{
   //[user-OnUndoRedo]   Add your own code here



   //[/user-OnUndoRedo]
}


//-------------------------------------------------------------------------------
//  public byte[] GetStateInformation()

//  Gets called when the module's state gets saved, typically when the user saves a preset with
//  this module in it. Voltage Modular will automatically save the states of knobs, sliders, etc.,
//  but if you have any custom state information you need to save, return it from this function.
//-------------------------------------------------------------------------------
@Override
public byte[] GetStateInformation()
{
   //[user-GetStateInformation]   Add your own code here



   return null;
   //[/user-GetStateInformation]
}


//-------------------------------------------------------------------------------
//  public void SetStateInformation(byte[] stateInfo)

//  Gets called when this module's state is getting restored, typically when a user opens a preset with
//  this module in it. The stateInfo parameter will contain whatever custom data you stored in GetStateInformation().
//-------------------------------------------------------------------------------
@Override
public void SetStateInformation(byte[] stateInfo)
{
   //[user-SetStateInformation]   Add your own code here



   //[/user-SetStateInformation]
}


//-------------------------------------------------------------------------------
//  public byte[] GetStateInformationForVariations()

//  Gets called when a user saves a variation with this module in it.
//  Voltage Modular will automatically save the states of knobs, sliders, etc.,
//  but if you have any custom state information you need to save, return it from this function.
//-------------------------------------------------------------------------------
@Override
public byte[] GetStateInformationForVariations()
{
   //[user-GetStateInformationForVariations]   Add your own code here



   return GetStateInformation();
   //[/user-GetStateInformationForVariations]
}


//-------------------------------------------------------------------------------
//  public void SetStateInformationForVariations(byte[] stateInfo)

//  Gets called when a user loads a variation with this module in it.
//  The stateInfo parameter will contain whatever custom data you stored in GetStateInformationForVariations().
//-------------------------------------------------------------------------------
@Override
public void SetStateInformationForVariations(byte[] stateInfo)
{
   //[user-SetStateInformationForVariations]   Add your own code here
   SetStateInformation(stateInfo);



   //[/user-SetStateInformationForVariations]
}


// Auto-generated variables
private VoltageLabel textLabel8;
private VoltageKnob rateKnob;
private VoltageLabel textLabel7;
private VoltageLabel textLabel6;
private VoltageLED LEDclockB;
private VoltageLED LEDclockA;
private VoltageLabel textLabel5;
private VoltageLabel textLabel4;
private VoltageLabel textLabel3;
private VoltageLabel textLabel2;
private VoltageAudioJack inputJackSetB;
private VoltageAudioJack inputJackSetA;
private VoltageLED LEDB00;
private VoltageLED LEDB01;
private VoltageLED LEDB02;
private VoltageLED LEDB03;
private VoltageLED LEDB04;
private VoltageLED LEDB05;
private VoltageLED LEDB06;
private VoltageLED LEDB07;
private VoltageLED LEDB08;
private VoltageLED LEDB09;
private VoltageLED LEDB10;
private VoltageLED LEDB11;
private VoltageLED LEDA00;
private VoltageLED LEDA01;
private VoltageLED LEDA02;
private VoltageLED LEDA03;
private VoltageLED LEDA04;
private VoltageLED LEDA05;
private VoltageLED LEDA06;
private VoltageLED LEDA07;
private VoltageLED LEDA08;
private VoltageLED LEDA09;
private VoltageLED LEDA10;
private VoltageLED LEDA11;
private VoltageLabel textLabel1;
private VoltageAudioJack inputJackClock;
private VoltageMidiJack midiOutputJack;
private VoltageMidiJack midiInputJack;
private VoltageSwitch switch11B;
private VoltageSwitch switch10BFlat;
private VoltageSwitch switch09A;
private VoltageSwitch switch08AFlat;
private VoltageSwitch switch06FSharp;
private VoltageSwitch switch07G;
private VoltageSwitch switch05F;
private VoltageSwitch switch04E;
private VoltageSwitch switch02D;
private VoltageSwitch switch00C;
private VoltageSwitch switch03EFlat;
private VoltageSwitch switch01CSharp;


//[user-code-and-variables]    Add your own variables and functions here

// Constants
public final int NUMBER_OF_KEYS = 128;
public final int SEMITONES_PER_OCTAVE = 12;
public final int TEMPO_DIVIDER = 180000;  // 1500 samples @ 120 BPM

// Enums
public enum ClockState
{
   BANK_A_ON,
   BANK_A_OFF,
   BANK_B_ON,
   BANK_B_OFF
}

public enum RunMode
{
   BANK_TOGGLE,
   BANK_A_SET,
   BANK_B_SET,
   BANK_HOLD
}

// Variables
public int keyVelocities[] = new int [NUMBER_OF_KEYS];
public boolean bankSelect[] = new boolean [SEMITONES_PER_OCTAVE]; // True = A, False = B
public boolean heldNotes[] = new boolean [SEMITONES_PER_OCTAVE]; // OR of each note in octave over entire range of keys
public boolean playingNotes[] = new boolean [NUMBER_OF_KEYS]; // match NOTE_ON and NOTE_OFF events


public int clockPeriod;
public int clockCounter;
public boolean intClockHigh;

public ClockState currentClockState;
public RunMode currentRunMode;

public boolean extClockConnected;
public boolean setAConnected;
public boolean setBConnected;
public boolean MIDIInConnected;
public boolean MIDIOutConnected;

public boolean previousExtClockHigh;
public boolean currentExtClockHigh;

public boolean keysChanged;

public void CalculateRate()
{
   int BPM = (int) rateKnob.GetValue();
   clockPeriod = TEMPO_DIVIDER / BPM;
}

public void CheckConnections()
{
   extClockConnected = inputJackClock.IsConnected();
   setAConnected = inputJackSetA.IsConnected();
   setBConnected = inputJackSetB.IsConnected();
   MIDIInConnected = midiInputJack.IsConnected();
   MIDIOutConnected = midiOutputJack.IsConnected();
   
}

public void CheckBankSelections()
{
   bankSelect[0]  = (switch00C.GetValue() < 0.5);
   bankSelect[1]  = (switch01CSharp.GetValue() < 0.5);
   bankSelect[2]  = (switch02D.GetValue() < 0.5);
   bankSelect[3]  = (switch03EFlat.GetValue() < 0.5);
   bankSelect[4]  = (switch04E.GetValue() < 0.5);
   bankSelect[5]  = (switch05F.GetValue() < 0.5);
   bankSelect[6]  = (switch06FSharp.GetValue() < 0.5);
   bankSelect[7]  = (switch07G.GetValue() < 0.5);
   bankSelect[8]  = (switch08AFlat.GetValue() < 0.5);
   bankSelect[9]  = (switch09A.GetValue() < 0.5);
   bankSelect[10] = (switch10BFlat.GetValue() < 0.5);
   bankSelect[11] = (switch11B.GetValue() < 0.5);
}

public void CheckHeldKeys()
{
   int key;
   int semitone;
   
   for (semitone = 0; semitone < SEMITONES_PER_OCTAVE; semitone++)
   {
      heldNotes[semitone] = false;
   }
   
   for (key = 0; key < NUMBER_OF_KEYS; key++)
   {
      semitone = key % SEMITONES_PER_OCTAVE;
      
      if (keyVelocities[key] > 0)
      {
         heldNotes[semitone] = true;
      }
   }
}

public void RedrawBankLEDs()
{
   // C LEDs
   if (heldNotes[0])
   {
      if (bankSelect[0])
      {
         // Only light LED A
         LEDA00.SetValue(1.0);
         LEDB00.SetValue(0.0);
      }
      else
      {
         // Only light LED B
         LEDA00.SetValue(0.0);
         LEDB00.SetValue(1.0);
      }
   }
   else
   {
      // Switch both LEDs off
      LEDA00.SetValue(0.0);
      LEDB00.SetValue(0.0);
   }
   
   // C# LEDs
   if (heldNotes[1])
   {
      if (bankSelect[1])
      {
         // Only light LED A
         LEDA01.SetValue(1.0);
         LEDB01.SetValue(0.0);
      }
      else
      {
         // Only light LED B
         LEDA01.SetValue(0.0);
         LEDB01.SetValue(1.0);
      }
   }
   else
   {
      // Switch both LEDs off
      LEDA01.SetValue(0.0);
      LEDB01.SetValue(0.0);
   }
   
   // D LEDs
   if (heldNotes[2])
   {
      if (bankSelect[2])
      {
         // Only light LED A
         LEDA02.SetValue(1.0);
         LEDB02.SetValue(0.0);
      }
      else
      {
         // Only light LED B
         LEDA02.SetValue(0.0);
         LEDB02.SetValue(1.0);
      }
   }
   else
   {
      // Switch both LEDs off
      LEDA02.SetValue(0.0);
      LEDB02.SetValue(0.0);
   }
   
   // Eb LEDs
   if (heldNotes[3])
   {
      if (bankSelect[3])
      {
         // Only light LED A
         LEDA03.SetValue(1.0);
         LEDB03.SetValue(0.0);
      }
      else
      {
         // Only light LED B
         LEDA03.SetValue(0.0);
         LEDB03.SetValue(1.0);
      }
   }
   else
   {
      // Switch both LEDs off
      LEDA03.SetValue(0.0);
      LEDB03.SetValue(0.0);
   }
   
   // E LEDs
   if (heldNotes[4])
   {
      if (bankSelect[4])
      {
         // Only light LED A
         LEDA04.SetValue(1.0);
         LEDB04.SetValue(0.0);
      }
      else
      {
         // Only light LED B
         LEDA04.SetValue(0.0);
         LEDB04.SetValue(1.0);
      }
   }
   else
   {
      // Switch both LEDs off
      LEDA04.SetValue(0.0);
      LEDB04.SetValue(0.0);
   }
   
   // F LEDs
   if (heldNotes[5])
   {
      if (bankSelect[5])
      {
         // Only light LED A
         LEDA05.SetValue(1.0);
         LEDB05.SetValue(0.0);
      }
      else
      {
         // Only light LED B
         LEDA05.SetValue(0.0);
         LEDB05.SetValue(1.0);
      }
   }
   else
   {
      // Switch both LEDs off
      LEDA05.SetValue(0.0);
      LEDB05.SetValue(0.0);
   }
   
   // F# LEDs
   if (heldNotes[6])
   {
      if (bankSelect[6])
      {
         // Only light LED A
         LEDA06.SetValue(1.0);
         LEDB06.SetValue(0.0);
      }
      else
      {
         // Only light LED B
         LEDA06.SetValue(0.0);
         LEDB06.SetValue(1.0);
      }
   }
   else
   {
      // Switch both LEDs off
      LEDA06.SetValue(0.0);
      LEDB06.SetValue(0.0);
   }
   
   // G LEDs
   if (heldNotes[7])
   {
      if (bankSelect[7])
      {
         // Only light LED A
         LEDA07.SetValue(1.0);
         LEDB07.SetValue(0.0);
      }
      else
      {
         // Only light LED B
         LEDA07.SetValue(0.0);
         LEDB07.SetValue(1.0);
      }
   }
   else
   {
      // Switch both LEDs off
      LEDA07.SetValue(0.0);
      LEDB07.SetValue(0.0);
   }
   
   // Ab LEDs
   if (heldNotes[8])
   {
      if (bankSelect[8])
      {
         // Only light LED A
         LEDA08.SetValue(1.0);
         LEDB08.SetValue(0.0);
      }
      else
      {
         // Only light LED B
         LEDA08.SetValue(0.0);
         LEDB08.SetValue(1.0);
      }
   }
   else
   {
      // Switch both LEDs off
      LEDA08.SetValue(0.0);
      LEDB08.SetValue(0.0);
   }
   
   // A LEDs
   if (heldNotes[9])
   {
      if (bankSelect[9])
      {
         // Only light LED A
         LEDA09.SetValue(1.0);
         LEDB09.SetValue(0.0);
      }
      else
      {
         // Only light LED B
         LEDA09.SetValue(0.0);
         LEDB09.SetValue(1.0);
      }
   }
   else
   {
      // Switch both LEDs off
      LEDA09.SetValue(0.0);
      LEDB09.SetValue(0.0);
   }
   
   // Bb LEDs
   if (heldNotes[10])
   {
      if (bankSelect[10])
      {
         // Only light LED A
         LEDA10.SetValue(1.0);
         LEDB10.SetValue(0.0);
      }
      else
      {
         // Only light LED B
         LEDA10.SetValue(0.0);
         LEDB10.SetValue(1.0);
      }
   }
   else
   {
      // Switch both LEDs off
      LEDA10.SetValue(0.0);
      LEDB10.SetValue(0.0);
   }
   
   // B LEDs
   if (heldNotes[11])
   {
      if (bankSelect[11])
      {
         // Only light LED A
         LEDA11.SetValue(1.0);
         LEDB11.SetValue(0.0);
      }
      else
      {
         // Only light LED B
         LEDA11.SetValue(0.0);
         LEDB11.SetValue(1.0);
      }
   }
   else
   {
      // Switch both LEDs off
      LEDA11.SetValue(0.0);
      LEDB11.SetValue(0.0);
   }
   
}

public boolean NoteEnabled (int noteNumber)
{
   int semitone;
   boolean result = false;
   boolean noteIsBankA;
   
   if (keyVelocities[noteNumber] > 0)
   {
      semitone = noteNumber % SEMITONES_PER_OCTAVE;
      
      noteIsBankA = bankSelect[semitone];
      
      if (noteIsBankA)
      {
         switch (currentClockState)
         {
            case BANK_A_ON:
            case BANK_A_OFF:
            {
               result = true;
            }
            break;
            
         }
      }
      else
      {
         switch (currentClockState)
         {
            case BANK_B_ON:
            case BANK_B_OFF:
            {
               result = true;
            }
            break;
            
         }
      }
   }
   
   return result;
}

public boolean NoteIsOn (int noteNumber)
{
   int semitone;
   boolean result = false;
   boolean noteIsBankA;
   
   if (keyVelocities[noteNumber] > 0)
   {
      semitone = noteNumber % SEMITONES_PER_OCTAVE;
      
      noteIsBankA = bankSelect[semitone];
      
      if (noteIsBankA)
      {
         if (currentClockState == ClockState.BANK_A_ON)
         {
            result = true;
         }
      }
      else
      {
         if (currentClockState == ClockState.BANK_B_ON)
         {
            result = true;
         }
      }
   }
   
   return result;
}

public void SendAllHeldNoteOn ()
{
   int noteNumber;
   
   for (noteNumber = 0; noteNumber < NUMBER_OF_KEYS; noteNumber++)
   {
      if (NoteEnabled(noteNumber))
      {
         SendNoteOn(noteNumber);
      }
   }           

}

public void SendAllHeldNoteOff ()
{
   int noteNumber;
   
   for (noteNumber = 0; noteNumber < NUMBER_OF_KEYS; noteNumber++)
   {
      if (NoteEnabled(noteNumber))
      {
         SendNoteOff(noteNumber);
      }
   }           

}

public void SendNoteOn (int noteNumber)
{
   int velocityValue;
   
   if (!playingNotes[noteNumber])
   {
      ShortMessage noteOnEvent = new ShortMessage();
      
      velocityValue = keyVelocities[noteNumber];
         
      try
      {
         noteOnEvent.setMessage(ShortMessage.NOTE_ON, 0, noteNumber, velocityValue);
      }
      catch (InvalidMidiDataException e)
      {
         // Do nothing for time being
      }
               
      midiOutputJack.AddMessage(noteOnEvent);
   
      playingNotes[noteNumber] = true;
   }
   
}

public void SendNoteOff (int noteNumber)
{
   int velocityValue;
   
   if (playingNotes[noteNumber])
   {
      ShortMessage noteOffEvent = new ShortMessage();
      
      velocityValue = keyVelocities[noteNumber];
         
      try
      {
         noteOffEvent.setMessage(ShortMessage.NOTE_OFF, 0, noteNumber, velocityValue);
      }
      catch (InvalidMidiDataException e)
      {
         // Do nothing for time being
      }
               
      midiOutputJack.AddMessage(noteOffEvent);
   
      playingNotes[noteNumber] = false;
   }
   
}


//[/user-code-and-variables]
}

 