package com.domemusictechnologies.smolrat;


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 static java.lang.Math.round; // Round double to nearest integer value
import static java.lang.Math.pow;   // Raise to power method, used for V/oct calc
import static java.lang.Math.exp;   // e to the power x method, used for RC time constant calc

//[/user-imports]


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

public SmolRat( long moduleID, VoltageObjects voltageObjects )
{
   super( moduleID, voltageObjects, "Smol Rat", ModuleType.ModuleType_CVProcessors, 2.0 );

   InitializeControls();


   canBeBypassed = false;
   SetSkin( "0c14ebb227b64d9bb42848013ff105c8" );
}

void InitializeControls()
{

   gateInSocket = new VoltageAudioJack( "Gate Input", "Gate In", this, JackType.JackType_AudioInput );
   AddComponent( gateInSocket );
   gateInSocket.SetWantsMouseNotifications( false );
   gateInSocket.SetPosition( 14, 36 );
   gateInSocket.SetSize( 25, 25 );
   gateInSocket.SetSkin( "Jack Round 25px" );

   gatePolaritySwitch = new VoltageSwitch( "Gate Polarity", "Gate Polarity", this, 1 );
   AddComponent( gatePolaritySwitch );
   gatePolaritySwitch.SetWantsMouseNotifications( false );
   gatePolaritySwitch.SetPosition( 64, 35 );
   gatePolaritySwitch.SetSize( 15, 27 );
   gatePolaritySwitch.SetSkin( "2-State Slide Vertical" );

   riseTimeKnob = new VoltageKnob( "Attack", "Rise Time", this, 0.1, 10.0, 1.0 );
   AddComponent( riseTimeKnob );
   riseTimeKnob.SetWantsMouseNotifications( false );
   riseTimeKnob.SetPosition( 30, 93 );
   riseTimeKnob.SetSize( 25, 25 );
   riseTimeKnob.SetSkin( "ARP2500 Sm Gold" );
   riseTimeKnob.SetRange( 0.1, 10.0, 1.0, false, 0 );
   riseTimeKnob.SetKnobParams( 215, 145 );
   riseTimeKnob.DisplayValueInPercent( false );
   riseTimeKnob.SetKnobAdjustsRing( true );
   riseTimeKnob.SetMidpointValue( 1.0 );

   riseLimitKnob = new VoltageKnob( "Rise Vr Limit", "Rise Vr Limit", this, 0.0, 20.0, 20.0 );
   AddComponent( riseLimitKnob );
   riseLimitKnob.SetWantsMouseNotifications( false );
   riseLimitKnob.SetPosition( 88, 93 );
   riseLimitKnob.SetSize( 25, 25 );
   riseLimitKnob.SetSkin( "ARP2500 Sm Orange" );
   riseLimitKnob.SetRange( 0.0, 20.0, 20.0, false, 0 );
   riseLimitKnob.SetKnobParams( 215, 145 );
   riseLimitKnob.DisplayValueInPercent( false );
   riseLimitKnob.SetKnobAdjustsRing( true );
   riseLimitKnob.SetMidpointValue( 1.0 );

   fallTimeKnob = new VoltageKnob( "Decay", "Fall Time", this, 0.1, 10.0, 1.0 );
   AddComponent( fallTimeKnob );
   fallTimeKnob.SetWantsMouseNotifications( false );
   fallTimeKnob.SetPosition( 30, 211 );
   fallTimeKnob.SetSize( 25, 25 );
   fallTimeKnob.SetSkin( "ARP2500 Sm Gold" );
   fallTimeKnob.SetRange( 0.1, 10.0, 1.0, false, 0 );
   fallTimeKnob.SetKnobParams( 215, 145 );
   fallTimeKnob.DisplayValueInPercent( false );
   fallTimeKnob.SetKnobAdjustsRing( true );
   fallTimeKnob.SetMidpointValue( 1.0 );

   fallLimitKnob = new VoltageKnob( "Fall Vr Limit", "Fall Vr Limit", this, 0.0, 20.0, 20.0 );
   AddComponent( fallLimitKnob );
   fallLimitKnob.SetWantsMouseNotifications( false );
   fallLimitKnob.SetPosition( 88, 211 );
   fallLimitKnob.SetSize( 25, 25 );
   fallLimitKnob.SetSkin( "ARP2500 Sm Orange" );
   fallLimitKnob.SetRange( 0.0, 20.0, 20.0, false, 0 );
   fallLimitKnob.SetKnobParams( 215, 145 );
   fallLimitKnob.DisplayValueInPercent( false );
   fallLimitKnob.SetKnobAdjustsRing( true );
   fallLimitKnob.SetMidpointValue( 1.0 );

   riseTimeCV = new VoltageAudioJack( "Rise Time CV In", "Rise Time CV In", this, JackType.JackType_AudioInput );
   AddComponent( riseTimeCV );
   riseTimeCV.SetWantsMouseNotifications( false );
   riseTimeCV.SetPosition( 30, 122 );
   riseTimeCV.SetSize( 25, 25 );
   riseTimeCV.SetSkin( "Jack Round Yellow Ring" );

   riseLimitCV = new VoltageAudioJack( "Rise Limit CV In", "Rise Limit CV In", this, JackType.JackType_AudioInput );
   AddComponent( riseLimitCV );
   riseLimitCV.SetWantsMouseNotifications( false );
   riseLimitCV.SetPosition( 88, 122 );
   riseLimitCV.SetSize( 25, 25 );
   riseLimitCV.SetSkin( "Jack Round Orange Ring" );

   fallTimeCV = new VoltageAudioJack( "Fall Time CV", "Fall Time CV In", this, JackType.JackType_AudioInput );
   AddComponent( fallTimeCV );
   fallTimeCV.SetWantsMouseNotifications( false );
   fallTimeCV.SetPosition( 30, 240 );
   fallTimeCV.SetSize( 25, 25 );
   fallTimeCV.SetSkin( "Jack Round Yellow Ring" );

   fallLimitCV = new VoltageAudioJack( "Fall Limit CV In", "Fall Limit CV In", this, JackType.JackType_AudioInput );
   AddComponent( fallLimitCV );
   fallLimitCV.SetWantsMouseNotifications( false );
   fallLimitCV.SetPosition( 88, 240 );
   fallLimitCV.SetSize( 25, 25 );
   fallLimitCV.SetSkin( "Jack Round Orange Ring" );

   outputCapacitor = new VoltageAudioJack( "Low Pass Output", "Low Pass Output", this, JackType.JackType_AudioOutput );
   AddComponent( outputCapacitor );
   outputCapacitor.SetWantsMouseNotifications( false );
   outputCapacitor.SetPosition( 102, 289 );
   outputCapacitor.SetSize( 25, 25 );
   outputCapacitor.SetSkin( "Jack Round Orange Ring" );

   textLabel1 = new VoltageLabel( "textLabel1", "textLabel1", this, "S.M.O.L.R.A.T." );
   AddComponent( textLabel1 );
   textLabel1.SetWantsMouseNotifications( false );
   textLabel1.SetPosition( 22, 0 );
   textLabel1.SetSize( 98, 17 );
   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", 14, true, false );

   textLabel2 = new VoltageLabel( "textLabel2", "textLabel2", this, "Rise Time" );
   AddComponent( textLabel2 );
   textLabel2.SetWantsMouseNotifications( false );
   textLabel2.SetPosition( 15, 78 );
   textLabel2.SetSize( 53, 13 );
   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( "<Sans-Serif>", 12, false, false );

   textLabel3 = new VoltageLabel( "textLabel3", "textLabel3", this, "Vr Limit" );
   AddComponent( textLabel3 );
   textLabel3.SetWantsMouseNotifications( false );
   textLabel3.SetPosition( 77, 78 );
   textLabel3.SetSize( 44, 14 );
   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( "<Sans-Serif>", 12, false, false );

   textLabel4 = new VoltageLabel( "textLabel4", "textLabel4", this, "CV In" );
   AddComponent( textLabel4 );
   textLabel4.SetWantsMouseNotifications( false );
   textLabel4.SetPosition( 53, 240 );
   textLabel4.SetSize( 36, 26 );
   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( "<Sans-Serif>", 12, false, false );

   textLabel5 = new VoltageLabel( "textLabel5", "textLabel5", this, "Fall Time" );
   AddComponent( textLabel5 );
   textLabel5.SetWantsMouseNotifications( false );
   textLabel5.SetPosition( 17, 193 );
   textLabel5.SetSize( 53, 17 );
   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( "<Sans-Serif>", 12, false, false );

   textLabel6 = new VoltageLabel( "textLabel6", "textLabel6", this, "Vr Limit" );
   AddComponent( textLabel6 );
   textLabel6.SetWantsMouseNotifications( false );
   textLabel6.SetPosition( 76, 192 );
   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( "<Sans-Serif>", 12, false, false );

   textLabel9 = new VoltageLabel( "textLabel9", "textLabel9", this, "Gate In" );
   AddComponent( textLabel9 );
   textLabel9.SetWantsMouseNotifications( false );
   textLabel9.SetPosition( 0, 20 );
   textLabel9.SetSize( 51, 15 );
   textLabel9.SetEditable( false, false );
   textLabel9.SetJustificationFlags( VoltageLabel.Justification.HorizCentered );
   textLabel9.SetJustificationFlags( VoltageLabel.Justification.VertCentered );
   textLabel9.SetColor( new Color( 255, 255, 255, 255 ) );
   textLabel9.SetBkColor( new Color( 65, 65, 65, 0 ) );
   textLabel9.SetBorderColor( new Color( 0, 0, 0, 0 ) );
   textLabel9.SetBorderSize( 1 );
   textLabel9.SetMultiLineEdit( false );
   textLabel9.SetIsNumberEditor( false );
   textLabel9.SetNumberEditorRange( 0, 100 );
   textLabel9.SetNumberEditorInterval( 1 );
   textLabel9.SetNumberEditorUsesMouseWheel( false );
   textLabel9.SetHasCustomTextHoverColor( false );
   textLabel9.SetTextHoverColor( new Color( 0, 0, 0, 255 ) );
   textLabel9.SetFont( "<Sans-Serif>", 12, false, false );

   textLabel11 = new VoltageLabel( "textLabel11", "textLabel11", this, "High" );
   AddComponent( textLabel11 );
   textLabel11.SetWantsMouseNotifications( false );
   textLabel11.SetPosition( 57, 19 );
   textLabel11.SetSize( 29, 17 );
   textLabel11.SetEditable( false, false );
   textLabel11.SetJustificationFlags( VoltageLabel.Justification.HorizCentered );
   textLabel11.SetJustificationFlags( VoltageLabel.Justification.VertCentered );
   textLabel11.SetColor( new Color( 255, 255, 255, 255 ) );
   textLabel11.SetBkColor( new Color( 65, 65, 65, 0 ) );
   textLabel11.SetBorderColor( new Color( 0, 0, 0, 0 ) );
   textLabel11.SetBorderSize( 1 );
   textLabel11.SetMultiLineEdit( false );
   textLabel11.SetIsNumberEditor( false );
   textLabel11.SetNumberEditorRange( 0, 100 );
   textLabel11.SetNumberEditorInterval( 1 );
   textLabel11.SetNumberEditorUsesMouseWheel( false );
   textLabel11.SetHasCustomTextHoverColor( false );
   textLabel11.SetTextHoverColor( new Color( 0, 0, 0, 255 ) );
   textLabel11.SetFont( "<Sans-Serif>", 12, false, false );

   textLabel13 = new VoltageLabel( "textLabel13", "textLabel13", this, "Outputs" );
   AddComponent( textLabel13 );
   textLabel13.SetWantsMouseNotifications( false );
   textLabel13.SetPosition( 71, 271 );
   textLabel13.SetSize( 44, 19 );
   textLabel13.SetEditable( false, false );
   textLabel13.SetJustificationFlags( VoltageLabel.Justification.HorizCentered );
   textLabel13.SetJustificationFlags( VoltageLabel.Justification.VertCentered );
   textLabel13.SetColor( new Color( 255, 255, 255, 255 ) );
   textLabel13.SetBkColor( new Color( 65, 65, 65, 0 ) );
   textLabel13.SetBorderColor( new Color( 0, 0, 0, 0 ) );
   textLabel13.SetBorderSize( 1 );
   textLabel13.SetMultiLineEdit( false );
   textLabel13.SetIsNumberEditor( false );
   textLabel13.SetNumberEditorRange( 0, 100 );
   textLabel13.SetNumberEditorInterval( 1 );
   textLabel13.SetNumberEditorUsesMouseWheel( false );
   textLabel13.SetHasCustomTextHoverColor( false );
   textLabel13.SetTextHoverColor( new Color( 0, 0, 0, 255 ) );
   textLabel13.SetFont( "<Sans-Serif>", 12, false, false );

   textLabel14 = new VoltageLabel( "textLabel14", "textLabel14", this, "CV In" );
   AddComponent( textLabel14 );
   textLabel14.SetWantsMouseNotifications( false );
   textLabel14.SetPosition( 55, 125 );
   textLabel14.SetSize( 33, 20 );
   textLabel14.SetEditable( false, false );
   textLabel14.SetJustificationFlags( VoltageLabel.Justification.HorizCentered );
   textLabel14.SetJustificationFlags( VoltageLabel.Justification.VertCentered );
   textLabel14.SetColor( new Color( 255, 255, 255, 255 ) );
   textLabel14.SetBkColor( new Color( 65, 65, 65, 0 ) );
   textLabel14.SetBorderColor( new Color( 0, 0, 0, 0 ) );
   textLabel14.SetBorderSize( 1 );
   textLabel14.SetMultiLineEdit( false );
   textLabel14.SetIsNumberEditor( false );
   textLabel14.SetNumberEditorRange( 0, 100 );
   textLabel14.SetNumberEditorInterval( 1 );
   textLabel14.SetNumberEditorUsesMouseWheel( false );
   textLabel14.SetHasCustomTextHoverColor( false );
   textLabel14.SetTextHoverColor( new Color( 0, 0, 0, 255 ) );
   textLabel14.SetFont( "<Sans-Serif>", 12, false, false );

   textLabel15 = new VoltageLabel( "textLabel15", "textLabel15", this, "Dome Music Technologies" );
   AddComponent( textLabel15 );
   textLabel15.SetWantsMouseNotifications( false );
   textLabel15.SetPosition( 18, 342 );
   textLabel15.SetSize( 108, 18 );
   textLabel15.SetEditable( false, false );
   textLabel15.SetJustificationFlags( VoltageLabel.Justification.HorizCentered );
   textLabel15.SetJustificationFlags( VoltageLabel.Justification.VertCentered );
   textLabel15.SetColor( new Color( 255, 232, 49, 255 ) );
   textLabel15.SetBkColor( new Color( 65, 65, 65, 0 ) );
   textLabel15.SetBorderColor( new Color( 0, 0, 0, 0 ) );
   textLabel15.SetBorderSize( 1 );
   textLabel15.SetMultiLineEdit( false );
   textLabel15.SetIsNumberEditor( false );
   textLabel15.SetNumberEditorRange( 0, 100 );
   textLabel15.SetNumberEditorInterval( 1 );
   textLabel15.SetNumberEditorUsesMouseWheel( false );
   textLabel15.SetHasCustomTextHoverColor( false );
   textLabel15.SetTextHoverColor( new Color( 0, 0, 0, 255 ) );
   textLabel15.SetFont( "<Sans-Serif>", 10, false, false );

   outputResistor = new VoltageAudioJack( "High Pass Output", "High Pass Output", this, JackType.JackType_AudioOutput );
   AddComponent( outputResistor );
   outputResistor.SetWantsMouseNotifications( false );
   outputResistor.SetPosition( 59, 289 );
   outputResistor.SetSize( 25, 25 );
   outputResistor.SetSkin( "Jack Round Orange Ring" );

   textLabel16 = new VoltageLabel( "textLabel16", "textLabel16", this, "Vr" );
   AddComponent( textLabel16 );
   textLabel16.SetWantsMouseNotifications( false );
   textLabel16.SetPosition( 61, 312 );
   textLabel16.SetSize( 19, 16 );
   textLabel16.SetEditable( false, false );
   textLabel16.SetJustificationFlags( VoltageLabel.Justification.HorizCentered );
   textLabel16.SetJustificationFlags( VoltageLabel.Justification.VertCentered );
   textLabel16.SetColor( new Color( 255, 255, 255, 255 ) );
   textLabel16.SetBkColor( new Color( 65, 65, 65, 0 ) );
   textLabel16.SetBorderColor( new Color( 0, 0, 0, 0 ) );
   textLabel16.SetBorderSize( 1 );
   textLabel16.SetMultiLineEdit( false );
   textLabel16.SetIsNumberEditor( false );
   textLabel16.SetNumberEditorRange( 0, 100 );
   textLabel16.SetNumberEditorInterval( 1 );
   textLabel16.SetNumberEditorUsesMouseWheel( false );
   textLabel16.SetHasCustomTextHoverColor( false );
   textLabel16.SetTextHoverColor( new Color( 0, 0, 0, 255 ) );
   textLabel16.SetFont( "<Sans-Serif>", 12, false, false );

   textLabel17 = new VoltageLabel( "textLabel17", "textLabel17", this, "Vc" );
   AddComponent( textLabel17 );
   textLabel17.SetWantsMouseNotifications( false );
   textLabel17.SetPosition( 104, 313 );
   textLabel17.SetSize( 22, 14 );
   textLabel17.SetEditable( false, false );
   textLabel17.SetJustificationFlags( VoltageLabel.Justification.HorizCentered );
   textLabel17.SetJustificationFlags( VoltageLabel.Justification.VertCentered );
   textLabel17.SetColor( new Color( 255, 255, 255, 255 ) );
   textLabel17.SetBkColor( new Color( 65, 65, 65, 0 ) );
   textLabel17.SetBorderColor( new Color( 0, 0, 0, 0 ) );
   textLabel17.SetBorderSize( 1 );
   textLabel17.SetMultiLineEdit( false );
   textLabel17.SetIsNumberEditor( false );
   textLabel17.SetNumberEditorRange( 0, 100 );
   textLabel17.SetNumberEditorInterval( 1 );
   textLabel17.SetNumberEditorUsesMouseWheel( false );
   textLabel17.SetHasCustomTextHoverColor( false );
   textLabel17.SetTextHoverColor( new Color( 0, 0, 0, 255 ) );
   textLabel17.SetFont( "<Sans-Serif>", 12, false, false );

   rateSwitch = new VoltageSwitch( "Time Factor", "Rate Switch", this, 0 );
   AddComponent( rateSwitch );
   rateSwitch.SetWantsMouseNotifications( false );
   rateSwitch.SetPosition( 52, 169 );
   rateSwitch.SetSize( 39, 15 );
   rateSwitch.SetSkin( "3-State Slide Horizontal" );

   textLabel18 = new VoltageLabel( "textLabel18", "textLabel18", this, "Slow" );
   AddComponent( textLabel18 );
   textLabel18.SetWantsMouseNotifications( false );
   textLabel18.SetPosition( 17, 169 );
   textLabel18.SetSize( 39, 15 );
   textLabel18.SetEditable( false, false );
   textLabel18.SetJustificationFlags( VoltageLabel.Justification.HorizCentered );
   textLabel18.SetJustificationFlags( VoltageLabel.Justification.VertCentered );
   textLabel18.SetColor( new Color( 255, 255, 255, 255 ) );
   textLabel18.SetBkColor( new Color( 65, 65, 65, 0 ) );
   textLabel18.SetBorderColor( new Color( 0, 0, 0, 0 ) );
   textLabel18.SetBorderSize( 1 );
   textLabel18.SetMultiLineEdit( false );
   textLabel18.SetIsNumberEditor( false );
   textLabel18.SetNumberEditorRange( 0, 100 );
   textLabel18.SetNumberEditorInterval( 1 );
   textLabel18.SetNumberEditorUsesMouseWheel( false );
   textLabel18.SetHasCustomTextHoverColor( false );
   textLabel18.SetTextHoverColor( new Color( 0, 0, 0, 255 ) );
   textLabel18.SetFont( "<Sans-Serif>", 12, false, false );

   textLabel19 = new VoltageLabel( "textLabel19", "textLabel19", this, "Fast" );
   AddComponent( textLabel19 );
   textLabel19.SetWantsMouseNotifications( false );
   textLabel19.SetPosition( 52, 154 );
   textLabel19.SetSize( 37, 17 );
   textLabel19.SetEditable( false, false );
   textLabel19.SetJustificationFlags( VoltageLabel.Justification.HorizCentered );
   textLabel19.SetJustificationFlags( VoltageLabel.Justification.VertCentered );
   textLabel19.SetColor( new Color( 255, 255, 255, 255 ) );
   textLabel19.SetBkColor( new Color( 65, 65, 65, 0 ) );
   textLabel19.SetBorderColor( new Color( 0, 0, 0, 0 ) );
   textLabel19.SetBorderSize( 1 );
   textLabel19.SetMultiLineEdit( false );
   textLabel19.SetIsNumberEditor( false );
   textLabel19.SetNumberEditorRange( 0, 100 );
   textLabel19.SetNumberEditorInterval( 1 );
   textLabel19.SetNumberEditorUsesMouseWheel( false );
   textLabel19.SetHasCustomTextHoverColor( false );
   textLabel19.SetTextHoverColor( new Color( 0, 0, 0, 255 ) );
   textLabel19.SetFont( "<Sans-Serif>", 12, false, false );

   textLabel20 = new VoltageLabel( "textLabel20", "textLabel20", this, "Audio" );
   AddComponent( textLabel20 );
   textLabel20.SetWantsMouseNotifications( false );
   textLabel20.SetPosition( 92, 169 );
   textLabel20.SetSize( 32, 15 );
   textLabel20.SetEditable( false, false );
   textLabel20.SetJustificationFlags( VoltageLabel.Justification.HorizCentered );
   textLabel20.SetJustificationFlags( VoltageLabel.Justification.VertCentered );
   textLabel20.SetColor( new Color( 255, 255, 255, 255 ) );
   textLabel20.SetBkColor( new Color( 65, 65, 65, 0 ) );
   textLabel20.SetBorderColor( new Color( 0, 0, 0, 0 ) );
   textLabel20.SetBorderSize( 1 );
   textLabel20.SetMultiLineEdit( false );
   textLabel20.SetIsNumberEditor( false );
   textLabel20.SetNumberEditorRange( 0, 100 );
   textLabel20.SetNumberEditorInterval( 1 );
   textLabel20.SetNumberEditorUsesMouseWheel( false );
   textLabel20.SetHasCustomTextHoverColor( false );
   textLabel20.SetTextHoverColor( new Color( 0, 0, 0, 255 ) );
   textLabel20.SetFont( "<Sans-Serif>", 12, false, false );

   textLabel21 = new VoltageLabel( "textLabel21", "textLabel21", this, "Low" );
   AddComponent( textLabel21 );
   textLabel21.SetWantsMouseNotifications( false );
   textLabel21.SetPosition( 57, 60 );
   textLabel21.SetSize( 28, 14 );
   textLabel21.SetEditable( false, false );
   textLabel21.SetJustificationFlags( VoltageLabel.Justification.HorizCentered );
   textLabel21.SetJustificationFlags( VoltageLabel.Justification.VertCentered );
   textLabel21.SetColor( new Color( 255, 255, 255, 255 ) );
   textLabel21.SetBkColor( new Color( 65, 65, 65, 0 ) );
   textLabel21.SetBorderColor( new Color( 0, 0, 0, 0 ) );
   textLabel21.SetBorderSize( 1 );
   textLabel21.SetMultiLineEdit( false );
   textLabel21.SetIsNumberEditor( false );
   textLabel21.SetNumberEditorRange( 0, 100 );
   textLabel21.SetNumberEditorInterval( 1 );
   textLabel21.SetNumberEditorUsesMouseWheel( false );
   textLabel21.SetHasCustomTextHoverColor( false );
   textLabel21.SetTextHoverColor( new Color( 0, 0, 0, 255 ) );
   textLabel21.SetFont( "Verdana", 12, false, false );

   gateFunctionSwitch = new VoltageSwitch( "Gate Function", "Gate Function", this, 0 );
   AddComponent( gateFunctionSwitch );
   gateFunctionSwitch.SetWantsMouseNotifications( false );
   gateFunctionSwitch.SetPosition( 109, 35 );
   gateFunctionSwitch.SetSize( 15, 27 );
   gateFunctionSwitch.SetSkin( "2-State Slide Vertical" );

   textLabel22 = new VoltageLabel( "textLabel22", "textLabel22", this, "Hold" );
   AddComponent( textLabel22 );
   textLabel22.SetWantsMouseNotifications( false );
   textLabel22.SetPosition( 99, 19 );
   textLabel22.SetSize( 34, 16 );
   textLabel22.SetEditable( false, false );
   textLabel22.SetJustificationFlags( VoltageLabel.Justification.HorizCentered );
   textLabel22.SetJustificationFlags( VoltageLabel.Justification.VertCentered );
   textLabel22.SetColor( new Color( 255, 255, 255, 255 ) );
   textLabel22.SetBkColor( new Color( 65, 65, 65, 0 ) );
   textLabel22.SetBorderColor( new Color( 0, 0, 0, 0 ) );
   textLabel22.SetBorderSize( 1 );
   textLabel22.SetMultiLineEdit( false );
   textLabel22.SetIsNumberEditor( false );
   textLabel22.SetNumberEditorRange( 0, 100 );
   textLabel22.SetNumberEditorInterval( 1 );
   textLabel22.SetNumberEditorUsesMouseWheel( false );
   textLabel22.SetHasCustomTextHoverColor( false );
   textLabel22.SetTextHoverColor( new Color( 0, 0, 0, 255 ) );
   textLabel22.SetFont( "Verdana", 12, false, false );

   textLabel23 = new VoltageLabel( "textLabel23", "textLabel23", this, "Track" );
   AddComponent( textLabel23 );
   textLabel23.SetWantsMouseNotifications( false );
   textLabel23.SetPosition( 95, 60 );
   textLabel23.SetSize( 42, 14 );
   textLabel23.SetEditable( false, false );
   textLabel23.SetJustificationFlags( VoltageLabel.Justification.HorizCentered );
   textLabel23.SetJustificationFlags( VoltageLabel.Justification.VertCentered );
   textLabel23.SetColor( new Color( 255, 255, 255, 255 ) );
   textLabel23.SetBkColor( new Color( 65, 65, 65, 0 ) );
   textLabel23.SetBorderColor( new Color( 0, 0, 0, 0 ) );
   textLabel23.SetBorderSize( 1 );
   textLabel23.SetMultiLineEdit( false );
   textLabel23.SetIsNumberEditor( false );
   textLabel23.SetNumberEditorRange( 0, 100 );
   textLabel23.SetNumberEditorInterval( 1 );
   textLabel23.SetNumberEditorUsesMouseWheel( false );
   textLabel23.SetHasCustomTextHoverColor( false );
   textLabel23.SetTextHoverColor( new Color( 0, 0, 0, 255 ) );
   textLabel23.SetFont( "Verdana", 12, false, false );

   textLabel24 = new VoltageLabel( "textLabel24", "textLabel24", this, "(LPF)" );
   AddComponent( textLabel24 );
   textLabel24.SetWantsMouseNotifications( false );
   textLabel24.SetPosition( 96, 321 );
   textLabel24.SetSize( 40, 21 );
   textLabel24.SetEditable( false, false );
   textLabel24.SetJustificationFlags( VoltageLabel.Justification.HorizCentered );
   textLabel24.SetJustificationFlags( VoltageLabel.Justification.VertCentered );
   textLabel24.SetColor( new Color( 255, 255, 255, 255 ) );
   textLabel24.SetBkColor( new Color( 65, 65, 65, 0 ) );
   textLabel24.SetBorderColor( new Color( 0, 0, 0, 0 ) );
   textLabel24.SetBorderSize( 1 );
   textLabel24.SetMultiLineEdit( false );
   textLabel24.SetIsNumberEditor( false );
   textLabel24.SetNumberEditorRange( 0, 100 );
   textLabel24.SetNumberEditorInterval( 1 );
   textLabel24.SetNumberEditorUsesMouseWheel( false );
   textLabel24.SetHasCustomTextHoverColor( false );
   textLabel24.SetTextHoverColor( new Color( 0, 0, 0, 255 ) );
   textLabel24.SetFont( "Verdana", 12, false, false );

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

   voltsInSocket = new VoltageAudioJack( "Input Voltage", "Input Voltage", this, JackType.JackType_AudioInput );
   AddComponent( voltsInSocket );
   voltsInSocket.SetWantsMouseNotifications( false );
   voltsInSocket.SetPosition( 16, 289 );
   voltsInSocket.SetSize( 25, 25 );
   voltsInSocket.SetSkin( "Jack Round Yellow Ring" );

   textLabel26 = new VoltageLabel( "textLabel26", "textLabel26", this, "Input" );
   AddComponent( textLabel26 );
   textLabel26.SetWantsMouseNotifications( false );
   textLabel26.SetPosition( 8, 272 );
   textLabel26.SetSize( 42, 17 );
   textLabel26.SetEditable( false, false );
   textLabel26.SetJustificationFlags( VoltageLabel.Justification.HorizCentered );
   textLabel26.SetJustificationFlags( VoltageLabel.Justification.VertCentered );
   textLabel26.SetColor( new Color( 255, 255, 255, 255 ) );
   textLabel26.SetBkColor( new Color( 65, 65, 65, 0 ) );
   textLabel26.SetBorderColor( new Color( 0, 0, 0, 0 ) );
   textLabel26.SetBorderSize( 1 );
   textLabel26.SetMultiLineEdit( false );
   textLabel26.SetIsNumberEditor( false );
   textLabel26.SetNumberEditorRange( 0, 100 );
   textLabel26.SetNumberEditorInterval( 1 );
   textLabel26.SetNumberEditorUsesMouseWheel( false );
   textLabel26.SetHasCustomTextHoverColor( false );
   textLabel26.SetTextHoverColor( new Color( 0, 0, 0, 255 ) );
   textLabel26.SetFont( "Verdana", 12, false, false );

   textLabel27 = new VoltageLabel( "textLabel27", "textLabel27", this, "Vin" );
   AddComponent( textLabel27 );
   textLabel27.SetWantsMouseNotifications( false );
   textLabel27.SetPosition( 18, 313 );
   textLabel27.SetSize( 24, 13 );
   textLabel27.SetEditable( false, false );
   textLabel27.SetJustificationFlags( VoltageLabel.Justification.HorizCentered );
   textLabel27.SetJustificationFlags( VoltageLabel.Justification.VertCentered );
   textLabel27.SetColor( new Color( 255, 255, 255, 255 ) );
   textLabel27.SetBkColor( new Color( 65, 65, 65, 0 ) );
   textLabel27.SetBorderColor( new Color( 0, 0, 0, 0 ) );
   textLabel27.SetBorderSize( 1 );
   textLabel27.SetMultiLineEdit( false );
   textLabel27.SetIsNumberEditor( false );
   textLabel27.SetNumberEditorRange( 0, 100 );
   textLabel27.SetNumberEditorInterval( 1 );
   textLabel27.SetNumberEditorUsesMouseWheel( false );
   textLabel27.SetHasCustomTextHoverColor( false );
   textLabel27.SetTextHoverColor( new Color( 0, 0, 0, 255 ) );
   textLabel27.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

   // Read and store input voltage
   inputValue = voltsInSocket.GetValue();
   currentValue = inputValue;

   // Set output voltages to zero
   outputCapacitor.SetValue(0.0);
   outputResistor.SetValue(0.0);
   
   // Read and store switch positions
   gateOn = (gateInSocket.GetValue() > 0.0);
   previousGateOn = gateOn;
   gateActiveHigh = (gatePolaritySwitch.GetValue() > 0.0);
   holdSelected = (gateFunctionSwitch.GetValue() > 0.0);
   
   // Read all current knob positions
   currentRiseTimeKnob = smoothRiseTime.GetSmoothValue();
   previousRiseTimeKnob = currentRiseTimeKnob;
   
   currentFallTimeKnob = smoothFallTime.GetSmoothValue();
   previousFallTimeKnob = currentFallTimeKnob;
   
   currentRiseLimitKnob = smoothRiseLimit.GetSmoothValue();
   previousRiseLimitKnob = currentRiseLimitKnob;
   
   currentFallLimitKnob = smoothFallLimit.GetSmoothValue();
   previousFallLimitKnob = currentFallLimitKnob;
   
   // Read all current CV input voltages
   currentRiseTimeCV = riseTimeCV.GetValue();
   previousRiseTimeCV = currentRiseTimeCV;
   
   currentFallTimeCV = fallTimeCV.GetValue();
   previousFallTimeCV = currentFallTimeCV;
   
   currentRiseLimitCV = riseLimitCV.GetValue();
   previousRiseLimitCV = currentRiseLimitCV;
   
   currentFallLimitCV = fallLimitCV.GetValue();
   previousFallLimitCV = currentFallLimitCV;
   
   // Use current settings and CVs to calculate parameters
   SetTimeBaseMultiplier();
   CalculateRiseTime();
   CalculateFallTime();
   CalculateRiseLimit();
   CalculateFallLimit();

   //[/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 == riseTimeKnob)
         {
            smoothRiseTime.SetValue(doubleValue);
         }
         else if (component == fallTimeKnob)
         {
            smoothFallTime.SetValue(doubleValue);
         }
         else if (component == riseLimitKnob)
         {
            smoothRiseLimit.SetValue(doubleValue);
         }
         else if (component == fallLimitKnob)
         {
            smoothFallLimit.SetValue(doubleValue);
         }         
         
      }
      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
      {
         // Only check for change in Rate Selector or Polarity as Gate Hold is checked every sample
         if (component == rateSwitch)
         {
            SetTimeBaseMultiplier();
         }
         else if (component == gatePolaritySwitch)
         {
            gateActiveHigh = (doubleValue > 0.0);            
         }
         else if (component == gateFunctionSwitch)
         {
            holdSelected = (doubleValue > 0.0);            
         }

      }
      break;
   
      case Jack_Connected:   // longValue is the new cable ID
      {
         if (component == gateInSocket)
         {
            gateInConnected = true;
         }
         else if (component == riseTimeCV)
         {
            riseTimeCVConnected = true;
         }
         else if (component == riseLimitCV)
         {
            riseLimitCVConnected = true;
         }
         else if (component == fallTimeCV)
         {
            fallTimeCVConnected = true;
         }
         else if (component == fallLimitCV)
         {
            fallLimitCVConnected = true;
         }
         else if (component == voltsInSocket)
         {
            vInConnected = true;
         }
         else if (component == outputResistor)
         {
            vResistorOutConnected = true;
         }
         else if (component == outputCapacitor)
         {
            vCapacitorOutConnected = true;
         }
         
      }
      break;
   
      case Jack_Disconnected:   // All cables have been disconnected from this jack
      {
         if (component == gateInSocket)
         {
            gateInConnected = false;
         }
         else if (component == riseTimeCV)
         {
            riseTimeCVConnected = false;
            currentRiseTimeCV = 0.0;
            previousRiseTimeCV = 0.0;
            CalculateRiseTime();
         }
         else if (component == riseLimitCV)
         {
            riseLimitCVConnected = false;
            currentRiseLimitCV = 0.0;
            previousRiseLimitCV = 0.0;
            CalculateRiseLimit();            
         }
         else if (component == fallTimeCV)
         {
            fallTimeCVConnected = false;
            currentFallTimeCV = 0.0;
            previousFallTimeCV = 0.0;
            CalculateFallTime();
         }
         else if (component == fallLimitCV)
         {
            fallLimitCVConnected = false;
            currentFallLimitCV = 0.0;
            previousFallLimitCV = 0.0;
            CalculateFallLimit();
         }
         else if (component == voltsInSocket)
         {
            vInConnected = false;
         }
         else if (component == outputResistor)
         {
            vResistorOutConnected = false;
         }
         else if (component == outputCapacitor)
         {
            vCapacitorOutConnected = false;
         }
         
      }
      break;
   
      case GUI_Update_Timer:   // Called every 50ms (by default) if turned on
      {
      }
      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 processChange;
   double diff;

   // If no output socket is connected, immediately exit this function
   if (vResistorOutConnected || vCapacitorOutConnected)
   {
      // Unconditionally read voltage from input
      inputValue = voltsInSocket.GetValue();
      
      // Check for changes in knob positions and CV inputs
      // Initially, check all knobs and CVs every iteration.
      // If sockets are disconnected, CVs are unchanged and
      // knobs are stationary, then don't recalculate time constants.
      
      // Check for Rise Time value changes
      processChange = false;
      currentRiseTimeKnob = smoothRiseTime.GetSmoothValue();
      if (currentRiseTimeKnob != previousRiseTimeKnob)
      {
         processChange = true;
         previousRiseTimeKnob = currentRiseTimeKnob;
      }
      if (riseTimeCVConnected)
      {
         currentRiseTimeCV = riseTimeCV.GetValue();
         if (currentRiseTimeCV != previousRiseTimeCV)
         {
            processChange = true;
            previousRiseTimeCV = currentRiseTimeCV;
         }
      }
      if (processChange)
      {
         CalculateRiseTime();
      }

      // Check for Fall Time value changes
      processChange = false;
      currentFallTimeKnob = smoothFallTime.GetSmoothValue();
      if (currentFallTimeKnob != previousFallTimeKnob)
      {
         processChange = true;
         previousFallTimeKnob = currentFallTimeKnob;
      }
      if (fallTimeCVConnected)
      {
         currentFallTimeCV = fallTimeCV.GetValue();
         if (currentFallTimeCV != previousFallTimeCV)
         {
            processChange = true;
            previousFallTimeCV = currentFallTimeCV;
         }
      }
      if (processChange)
      {
         CalculateFallTime();
      }

      // Check for Rise Limit value changes
      processChange = false;
      currentRiseLimitKnob = smoothRiseLimit.GetSmoothValue();
      if (currentRiseLimitKnob != previousRiseLimitKnob)
      {
         processChange = true;
         previousRiseLimitKnob = currentRiseLimitKnob;
      }
      if (riseLimitCVConnected)
      {
         currentRiseLimitCV = riseLimitCV.GetValue();
         if (currentRiseLimitCV != previousRiseLimitCV)
         {
            processChange = true;
            previousRiseLimitCV = currentRiseLimitCV;
         }
      }
      if (processChange)
      {
         CalculateRiseLimit();
      }

      // Check for Fall Limit value changes
      processChange = false;
      currentFallLimitKnob = smoothFallLimit.GetSmoothValue();
      if (currentFallLimitKnob != previousFallLimitKnob)
      {
         processChange = true;
         previousFallLimitKnob = currentFallLimitKnob;
      }
      if (fallLimitCVConnected)
      {
         currentFallLimitCV = fallLimitCV.GetValue();
         if (currentFallLimitCV != previousFallLimitCV)
         {
            processChange = true;
            previousFallLimitCV = currentFallLimitCV;
         }
      }
      if (processChange)
      {
         CalculateFallLimit();
      }

      // Always need to know if gate is on or off
      gateOn = (gateInSocket.GetValue() > 0.0); // Any +ve value
      
      // Calculate which mode we're in from positions of switches
      specialFunctionSelected = ((previousGateOn) && (gateActiveHigh)) ||
                                ((!previousGateOn) && (!gateActiveHigh));
                                 
      if (specialFunctionSelected)
      {
         // Special function processing
         
         if (holdSelected)
         {
            // HOLD State Processing
            
            // Don't update capacitor value

         }
         else
         {
            // TRACK State Processing
            
            // Directly assign input value to capacitor value without slew
            currentValue = inputValue;
            
         }
      }
      else
      {
         // Normal RC slew processing
         
         diff = inputValue - currentValue;
         
         // Decide if we are in a RISE or FALL state
         
         if (diff > 0.0)
         {
            // RISE state processing
            
            // Perform limiting test first
            if (diff >= riseLimitDifference)
            {
               // Immediately jump to (input - limit)
               currentValue = inputValue - riseLimitDifference;
               
               // Calculate post-limiting diff value
               diff = inputValue - currentValue;
            }
            
            // Perform slewing
            currentValue = inputValue - (diff * riseTimeFactor);
            
         }
         else
         {
            // FALL state processing
            
            // Remember that diff will be 0 or negative, so limit test
            // willl be sign inverted
            
            // Perform limiting test first
            if ((-diff) >= fallLimitDifference)
            {
               // Immediately jump to (input + limit)
               currentValue = inputValue + fallLimitDifference;
               
               // Calculate post-limiting diff value
               diff = inputValue - currentValue;
            }
            
            // Perform slewing
            currentValue = inputValue - (diff * fallTimeFactor);
            
         }
         
      }
      
      // Now we've processed the capacitor voltage, calculate resistor voltage
      resistorValue = inputValue - currentValue;
      
      // Output both values unconditionally to save checking
      outputCapacitor.SetValue(currentValue);
      outputResistor.SetValue(resistorValue);
      
      // Assign current gate value to 'previous' one for next sample period
      previousGateOn = gateOn;
      
   }  // End of if (outputConnected)

   //[/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 textLabel27;
private VoltageLabel textLabel26;
private VoltageAudioJack voltsInSocket;
private VoltageLabel textLabel25;
private VoltageLabel textLabel24;
private VoltageLabel textLabel23;
private VoltageLabel textLabel22;
private VoltageSwitch gateFunctionSwitch;
private VoltageLabel textLabel21;
private VoltageLabel textLabel20;
private VoltageLabel textLabel19;
private VoltageLabel textLabel18;
private VoltageSwitch rateSwitch;
private VoltageLabel textLabel17;
private VoltageLabel textLabel16;
private VoltageAudioJack outputResistor;
private VoltageLabel textLabel15;
private VoltageLabel textLabel14;
private VoltageLabel textLabel13;
private VoltageLabel textLabel11;
private VoltageLabel textLabel9;
private VoltageLabel textLabel6;
private VoltageLabel textLabel5;
private VoltageLabel textLabel4;
private VoltageLabel textLabel3;
private VoltageLabel textLabel2;
private VoltageLabel textLabel1;
private VoltageAudioJack outputCapacitor;
private VoltageAudioJack fallLimitCV;
private VoltageAudioJack fallTimeCV;
private VoltageAudioJack riseLimitCV;
private VoltageAudioJack riseTimeCV;
private VoltageKnob fallLimitKnob;
private VoltageKnob fallTimeKnob;
private VoltageKnob riseLimitKnob;
private VoltageKnob riseTimeKnob;
private VoltageSwitch gatePolaritySwitch;
private VoltageAudioJack gateInSocket;


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

private enum State
{
   TRACK,      // Gate active, function = Track
   HOLD,       // Gate active, function = Hold
   RISE,       // Gate inactive, Vin >  CurrentValue
   FALL,       // Gate inactive, Vin <= CurrentValue
}

private enum Range
{
   SLOW,       // Time base multiplier = x1.00 seconds
   FAST,       // Time base multiplier = x0.10 seconds
   AUDIO       // Time base multiplier = x0.01 seconds
}

private State currentState;               // TRACK, HOLD, RISE, FALL
private Range currentRange;               // SLOW / FAST / AUDIO

private double inputValue;                // Voltage at input socket
private double currentValue;              // Capacitor voltage
private double resistorValue;             // Resistor voltage

private double timeBaseMultiplier;        // Slow / Fast / Audio ranges
private double riseTimeFactor;            // Exponential rise factor
private double fallTimeFactor;            // Exponential fall factor
private double riseLimitDifference;       // Rise Limit max step size
private double fallLimitDifference;       // Fall Limit max step size

private boolean gateOn;                   // Gate input socket is High
private boolean previousGateOn;           // Gate value from previous sample period
private boolean gateActiveHigh;           // True if Active High, false if Active Low
private boolean specialFunctionSelected;  // True when Hold or Track is engaged
private boolean holdSelected;             // True if Hold selected, false if Track selected

// Input socket connection flags
private boolean gateInConnected;          // Gate socket connected
private boolean riseTimeCVConnected;      // Rise Time CV connected
private boolean riseLimitCVConnected;     // Rise Vr Limit CV connected
private boolean fallTimeCVConnected;      // Fall Time CV connected
private boolean fallLimitCVConnected;     // Fall Vr Limit CV connected
private boolean vInConnected;             // Voltage In connected

// Output socket connection flags
private boolean vResistorOutConnected;    // Resistor Voltage output connected
private boolean vCapacitorOutConnected;   // Capacitor Voltage output connected

// Knob and input smoothing and change detection for improved efficiency
private SmoothValue smoothRiseTime = new SmoothValue();
private double currentRiseTimeKnob;       // Current value return from SmoothValue
private double previousRiseTimeKnob;      // Previous value to check if changes need processed

private SmoothValue smoothFallTime = new SmoothValue();
private double currentFallTimeKnob;       // Current value return from SmoothValue
private double previousFallTimeKnob;      // Previous value to check if changes need processed

private SmoothValue smoothRiseLimit = new SmoothValue();
private double currentRiseLimitKnob;      // Current value return from SmoothValue
private double previousRiseLimitKnob;     // Previous value to check if changes need processed

private SmoothValue smoothFallLimit = new SmoothValue();
private double currentFallLimitKnob;      // Current value return from SmoothValue
private double previousFallLimitKnob;     // Previous value to check if changes need processed

private double currentRiseTimeCV;         // Current value direct from socket
private double previousRiseTimeCV;        // Previous value to check if changes need processed

private double currentFallTimeCV;         // Current value direct from socket
private double previousFallTimeCV;        // Previous value to check if changes need processed

private double currentRiseLimitCV;        // Current value direct from socket
private double previousRiseLimitCV;       // Previous value to check if changes need processed

private double currentFallLimitCV;        // Current value direct from socket
private double previousFallLimitCV;       // Previous value to check if changes need processed


// Private functions

private void SetTimeBaseMultiplier ()
{
   int switchPos;
   
   switchPos = (int) round(rateSwitch.GetValue());
   
   // All values for timeBaseMultiplier are negative for use in exp function
   
   switch (switchPos)
   {
      case 0:
      {
         currentRange = Range.SLOW;
         timeBaseMultiplier = -5.0 / Values.SampleRate;     // 5x base rate
      }
      break;
      
      case 1:
      {
         currentRange = Range.FAST;
         timeBaseMultiplier = -50.0 / Values.SampleRate;    // 50x base rate
      }
      break;
      
      case 2:
      {
         currentRange = Range.AUDIO;
         timeBaseMultiplier = -4500.0 / Values.SampleRate;  // 4500x base rate
      }
      break;
      
   }
   
   CalculateRiseTime();
   CalculateFallTime();
      
}

private void CalculateRiseTime ()
{
   double timePeriod;   // Base time period (knob * time base multiplier
   double temp;
   double voltsPerOctaveMultiplier;
   
   // Get base period / freq as set by front panel knob
   
   temp = timeBaseMultiplier / currentRiseTimeKnob;  // Basic RC time period
   
   // Modify base period by V/Oct CV input
   
   voltsPerOctaveMultiplier = pow (2.0, currentRiseTimeCV);  // Shorten period with increasing CV
   
   temp *= voltsPerOctaveMultiplier;
   
   riseTimeFactor = exp (temp);
   
}

private void CalculateFallTime ()
{
   double timePeriod;   // Base time period (knob * time base multiplier
   double temp;
   double voltsPerOctaveMultiplier;
   
   // Get base period / freq as set by front panel knob
   
   temp = timeBaseMultiplier / currentFallTimeKnob;  // Basic RC time period
   
   // Modify base period by V/Oct CV input
   
   voltsPerOctaveMultiplier = pow (2.0, currentFallTimeCV);  // Shorten period with increasing CV
   
   temp *= voltsPerOctaveMultiplier;
   
   fallTimeFactor = exp (temp);
   
}

private void CalculateRiseLimit ()
{
   double clampedValue;
   double linearOvershoot;
   
   clampedValue = currentRiseLimitKnob;
   clampedValue += currentRiseLimitCV;
   
   if (clampedValue > 20.0) clampedValue = 20.0;
   if (clampedValue <  0.0) clampedValue =  0.0;
   
   riseLimitDifference = clampedValue;
   
}

private void CalculateFallLimit ()
{
   double clampedValue;
   double linearOvershoot;
   
   clampedValue = currentFallLimitKnob;
   clampedValue += currentFallLimitCV;
   
   if (clampedValue > 20.0) clampedValue = 20.0;
   if (clampedValue <  0.0) clampedValue =  0.0;
      
   fallLimitDifference = clampedValue;

}

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

 