#include <vdr/plugin.h>
#include <vdr/status.h>
#include <vdr/interface.h>
#include <alsa/asoundlib.h>
#include "i18n.h"

// --- linked list for setup values ---
class setupvalues
{
 public:
  class elem
  {
   public:
    elem(){next=NULL;}
    ~elem(){delete next;}
    char	name[128],value[128];
    elem	*next;
  };
  
  elem	*head,*p;
  
  setupvalues(){head=new elem;p=head;}
  ~setupvalues(){delete head;}
  
  char* getName(){return p->name;}
  char* getValue(){return p->value;}

  void setName(const char* name){strcpy(p->name,name);}
  void setValue(const char* value){strcpy(p->value,value);}
  
  void addElem(){p->next=new elem;p=p->next;}
  
  void resetp(){p=head;}
  bool isNext()
  {
   if(p->next!=NULL)return true;
   else return false;
  }
  void goNext(){p=p->next;}
};

// --- linked list for mixers ---
class mixerlist
{
 public:
  class elem
  {
   public:
    elem(){next=NULL;offset=0;volume=false;_switch=false;}
    ~elem(){delete next;}
    char	name[128],extname[128];
    bool	volume,_switch;
    long	vmin,vmax;
    int		setup,offset;
    elem	*next;
  };
  
  elem	*head,*p;

  mixerlist(){head=new elem;p=head;}
  ~mixerlist(){delete head;}

  char* getName(){return p->name;}
  char* extName()
  {
   if(p->volume)sprintf(p->extname,"%s",p->name);
   else sprintf(p->extname,"[S] %s",p->name);
   return p->extname;
  }
  long getVmin(){return p->vmin;}
  long getVmax(){return p->vmax;}
  int getOffset(){return p->offset;}
  bool isVolume(){return p->volume;}
  bool isSwitch(){return p->_switch;}
  int getSetup(){return p->setup;}
  
  void setName(const char* name){strcpy(p->name,name);}
  void setVmin(long vmin){p->vmin=vmin;}
  void setVmax(long vmax){p->vmax=vmax;}
  void setOffset(int offset){p->offset=offset;}
  void setVolume(bool volume){p->volume=volume;}
  void setSwitch(bool _switch){p->_switch=_switch;}
  void setSetup(int setup){p->setup=setup;}
  
  void addElem(){p->next=new elem;p=p->next;}
  
  void resetp(){p=head;}
  bool isNext()
  {
   if(p->next!=NULL)return true;
   else return false;
  }
  void goNext(){p=p->next;}
};


// --- class for handling the alsa-lib ---
class alsa
{
 private:
  int			err;
  snd_mixer_t		*handle;
  snd_mixer_selem_id_t	*sid;
  snd_mixer_elem_t	*elem;

 public:
  mixerlist		*list;

  alsa();
  ~alsa();
  mixerlist* List(); // gives back a linked list with info's about mixers
  void setVolume(char* name,long vol);  // sets the volume of a given mixer
  void setSwitch(char* name,int value); // sets the value of a given switch
};

// --- sets the volume while changing the offset value ---
class editoffset:public cMenuEditItem
{
 protected:
  char name[128];
  int *value;
  bool _controlable;
  virtual void Set();
 public:
  editoffset(const char *Name,int *Value,bool controlable);
  virtual eOSState ProcessKey(eKeys Key);
};

class editselect:public cMenuEditItem
{
 protected:
  char name[128];
  int *value;
  bool isSwitch;
  virtual void Set();
 public:
  editselect(const char *Name,int *Value,bool Switch);
  virtual eOSState ProcessKey(eKeys Key);
};

class editswitch:public cMenuEditItem
{
 protected:
  char name[128];
  int *value;
  virtual void Set();
 public:
  editswitch(const char *Name,int *Value);
  virtual eOSState ProcessKey(eKeys Key);
};
