// Devay - Eq slider/button temp text

#include "../../../lib/std.mi"

Function setTempText(String txt);
Function emptyTempText();

Global int onoff, autonoff;
Global slider eqPreamp, eq1, eq2, eq3, eq4, eq5, eq6, eq7, eq8, eq9, eq10;
Global button Eqonoff, Eqauto, EqPresets;
Global Text SongTicker, ShadeSongTicker;
Global Timer EqTimer;

System.onScriptLoaded() {
  Layout eqnorm = System.getContainer("eq").getLayout("normal");
  Group displaygroup = getContainer("main").getLayout("normal").getObject("display-group");
  SongTicker = displaygroup.getObject("Songticker");
  Layout mainslim = System.getContainer("main").getLayout("slim");
  ShadeSongTicker = mainslim.getObject("Songticker");

  EqTimer = new Timer;
  EqTimer.setDelay(750);

  eqPreamp = eqnorm.getObject("preamp");
  eq1 = eqnorm.getObject("eq1");
  eq2 = eqnorm.getObject("eq2");
  eq3 = eqnorm.getObject("eq3");
  eq4 = eqnorm.getObject("eq4");
  eq5 = eqnorm.getObject("eq5");
  eq6 = eqnorm.getObject("eq6");
  eq7 = eqnorm.getObject("eq7");
  eq8 = eqnorm.getObject("eq8");
  eq9 = eqnorm.getObject("eq9");
  eq10 = eqnorm.getObject("eq10");
  Eqonoff = eqnorm.getObject("eqtoggle");
  Eqauto = eqnorm.getObject("eqauto");
  EqPresets = eqnorm.getObject("presets");
}

System.onScriptUnloading() {
  delete EqTimer;
}  
  
// The eq sliders are treated like ordinary slider with a range of
// 0 to 255 instead of eq-sliders which are -127 to 127, the "-20" offsets this
eqPreamp.onSetPosition(int p) {
  Float f;   
  f = p;
  f = ((f / 6.35)-20); 
  if (f >= 0) setTempText("Preamp: " + "+" + integerToString(f));
  if (f  < 0) setTempText("Preamp: " + integerToString(f));	
} 

eq1.onSetPosition(int p) {
  Float f;   
  f = p;
  f = ((f / 6.35)-20);
  if (f >= 0) setTempText("60 Hz: " + "+" + integerToString(f));
  if (f  < 0) setTempText("60 Hz: " + integerToString(f));	
} 

eq2.onSetPosition(int p) {
  Float f;   
  f = p;
  f = ((f / 6.35)-20);
  if (f >= 0) setTempText("170Hz: " + "+" + integerToString(f));
  if (f  < 0) setTempText("170Hz: " + integerToString(f));	
} 

eq3.onSetPosition(int p) {
  Float f;   
  f = p;
  f = ((f / 6.35)-20);
  if (f >= 0) setTempText("310Hz: " + "+" + integerToString(f));
  if (f  < 0) setTempText("310Hz: " + integerToString(f));	
} 

eq4.onSetPosition(int p) {
  Float f;   
  f = p;
  f = ((f / 6.35)-20);
  if (f >= 0) setTempText("600Hz: " + "+" + integerToString(f));
  if (f  < 0) setTempText("600Hz: " + integerToString(f));	
} 

eq5.onSetPosition(int p) {
  Float f;   
  f = p;
  f = ((f / 6.35)-20);
  if (f >= 0) setTempText("1 kHz: " + "+" + integerToString(f));
  if (f  < 0) setTempText("1 kHz: " + integerToString(f));	
} 

eq6.onSetPosition(int p) {
  Float f;   
  f = p;
  f = ((f / 6.35)-20);
  if (f >= 0) setTempText("3 kHz: " + "+" + integerToString(f));
  if (f  < 0) setTempText("3 kHz: " + integerToString(f));	
} 

eq7.onSetPosition(int p) {
  Float f;   
  f = p;
  f = ((f / 6.35)-20);
  if (f >= 0) setTempText("6 kHz: " + "+" + integerToString(f));
  if (f  < 0) setTempText("6 kHz: " + integerToString(f));	
} 

eq8.onSetPosition(int p) {
  Float f;   
  f = p;
  f = ((f / 6.35)-20);
  if (f >= 0) setTempText("12kHz: " + "+" + integerToString(f));
  if (f  < 0) setTempText("12kHz: " + integerToString(f));	
} 

eq9.onSetPosition(int p) {
  Float f;   
  f = p;
  f = ((f / 6.35)-20);
  if (f >= 0) setTempText("14kHz: " + "+" + integerToString(f));
  if (f  < 0) setTempText("14kHz: " + integerToString(f));	
} 

eq10.onSetPosition(int p) {
  Float f;   
  f = p;
  f = ((f / 6.35)-20);
  if (f >= 0) setTempText("16kHz: " + "+" + integerToString(f));
  if (f  < 0) setTempText("16kHz: " + integerToString(f));	
} 

System.onEqChanged(int onoff) {
  if (onoff) {
    setTempText("Eq now on");
  } else {
    setTempText("Eq now off");
  }
}  

Eqauto.onActivate(int autonoff) {
  if (autonoff == 1) {
    setTempText("Auto now on");
  } else {
    setTempText("Auto now off");
  }
}  

EqPresets.onLeftButtonDown(int x, int y) {
   setTempText("Eq Presets");
}  

// Temp text functions
EqTimer.onTimer() {
  SongTicker.setText("");
  ShadeSongTicker.setText("");
  stop();
}

setTempText(String txt) {
    EqTimer.stop();
    SongTicker.setText(txt);
    ShadeSongTicker.setText(txt);
    EqTimer.start();
}

emptyTempText() {
    SongTicker.setText("");
    ShadeSongTicker.setText("");
    EqTimer.stop();

}

