package net.mkonrad.synes.data;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;

import net.mkonrad.synes.gui.elements.instruments.InstrumentShape;
import net.mkonrad.synes.util.DbgTools;

/**
 * Takes care of the layers
 * @todo remove.
 * @author mako
 *
 */
public class LayerSet
{
  private ArrayList<Layer> _layers;
  private int _currLayerLevel = 0;
  
  public LayerSet()
  {
    _layers = new ArrayList<Layer>();
  }
  
  public void setCurrLayerLevel(int l)
  {
    _currLayerLevel = l;
  }
  
  public int getCurrLayerLevel()
  {
    return _currLayerLevel;
  }

  public void addLayer(Layer l)
  {
    _layers.add(l);
  }
  
  public void removeLayer(int index)
  {
    _layers.remove(index);
  }
  
  public Layer getLayer(int index)
  {
    return _layers.get(index);
  }
  
  public Layer[] getLayers()
  {
    return _layers.toArray(new Layer[0]);
  }

  public Layer getCurrLayer()
  {
    return getLayer(_currLayerLevel);
  }

  public int getLayerNum()
  {
    return _layers.size();
  }
  
  /**
   * Method for recursive enabling/disabling of picking capabilities of
   * GraphLines and their Elements as well as setting their transparency values
   * 
   * @param layer layer-id. If this is less than 0, take the current layer id
   * @param enabled Set enabled true or false
   */
  public void setEnabled(int layer, boolean enabled)
  {
    if (layer < 0)
      layer = _currLayerLevel;
   
    Collection<AbstractGraph> graphs = getLayer(layer).getGraphs();
    
    AbstractGraph graph;
    InstrumentShape instrShape;
    
    for (Iterator<AbstractGraph> it = graphs.iterator(); it.hasNext(); )
    {
      graph = it.next();
      for (int iSynth = 0; iSynth < graph.size(); iSynth++)
      {
        instrShape = ((SynthObj)graph.get(iSynth)).getInstrumentShape();
        instrShape.setEnabled(enabled);
      }
      
      graph.getGraphLine().setEnabled(enabled);
    }
  }
  
  /*
  public ArrayList<Note> getAllNotes()
  {
    ArrayList<Note> allNotes = new ArrayList<Note>();
    Layer[] layers = getLayers();
    
    for (int iL = 0; iL < layers.length; iL++)
    {
      Note[] notes = layers[iL].getNotes();
      
      for (int iN = 0; iN < notes.length; iN++)
      {
        allNotes.add(notes[iN]);
      }
    }
    
    return allNotes;
  }*/
}
