#include <lib/std.mi>

Global Layout eqg;
Global Group thisGroup;

Global Layer lPre, eq1, eq2, eq3, eq4, eq5, eq6, eq7, eq8, eq9, eq10;
Global Map eqMap;

System.onScriptLoaded() {
  eqg = getScriptGroup();

  thisGroup = eqg.getObject("eq2");
  
  lPre = thisGroup.getObject("l.pre");
  eq1 = thisGroup.getObject("l.eq1");
  eq2 = thisGroup.getObject("l.eq2");
  eq3 = thisGroup.getObject("l.eq3");
  eq4 = thisGroup.getObject("l.eq4");
  eq5 = thisGroup.getObject("l.eq5");
  eq6 = thisGroup.getObject("l.eq6");
  eq7 = thisGroup.getObject("l.eq7");
  eq8 = thisGroup.getObject("l.eq8");
  eq9 = thisGroup.getObject("l.eq9");
  eq10 = thisGroup.getObject("l.eq10");

  eqMap = new map;
  eqMap.loadMap("eq.map");

  onEqPreampChanged(getEQPreamp());
  int x;
  for(x=0; x<10; x++) {
    onEqBandChanged(x, getEQBand(x));
  }
}

System.onEqPreampChanged(int newvalue) {
  newvalue += 127;
  lPre.setRegionFromMap(eqMap, newvalue, 1);
}

System.onEqBandChanged(int band, int newvalue) {
  newvalue += 127;
  if(band == 0) {
    eq1.setRegionFromMap(eqMap, newvalue, 1);
  } else if(band == 1) {
    eq2.setRegionFromMap(eqMap, newvalue, 1);
  } else if(band == 2) {
    eq3.setRegionFromMap(eqMap, newvalue, 1);
  } else if(band == 3) {
    eq4.setRegionFromMap(eqMap, newvalue, 1);
  } else if(band == 4) {
    eq5.setRegionFromMap(eqMap, newvalue, 1);
  } else if(band == 5) {
    eq6.setRegionFromMap(eqMap, newvalue, 1);
  } else if(band == 6) {
    eq7.setRegionFromMap(eqMap, newvalue, 1);
  } else if(band == 7) {
    eq8.setRegionFromMap(eqMap, newvalue, 1);
  } else if(band == 8) {
    eq9.setRegionFromMap(eqMap, newvalue, 1);
  } else if(band == 9) {
    eq10.setRegionFromMap(eqMap, newvalue, 1);
  }
}