///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// File:           CC121EqMap.h                                              //
//                                                                           //
// Functionality:  EQ parameter map class definition.                        //
//                                                                           //
// Author:         Rolf Meyerhoff (rm@matrix44.de)                           //
//                                                                           //
// Copyright:      (C) 2009 by Rolf Meyerhoff. All rights reserved.          //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// License:                                                                  //
//                                                                           //
// This library is free software;  you can redistribute it  and/or modify it //
// under the terms of the GNU Lesser  General Public License as published by //
// the Free Software Foundation;  either version 2.1 of the License,  or (at //
// your option) any later version.                                           //
//                                                                           //
// This  library is  distributed in  the hope that  it will  be useful,  but //
// WITHOUT   ANY   WARRANTY;   without   even   the   implied  warranty   of //
// MERCHANTABILITY or FITNESS FOR A  PARTICULAR PURPOSE.  See the GNU Lesser //
// General Public License for more details.                                  //
//                                                                           //
// You should have received a copy of  the GNU Lesser General Public License //
// along with this library;  if not,  write to the Free Software Foundation, //
// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.              //
///////////////////////////////////////////////////////////////////////////////
#ifndef __CC121EQMAP_H_INCLUDED__
#define __CC121EQMAP_H_INCLUDED__

///////////////////////////////////////////////////////////////////////////////
// class CC121EqMap
///////////////////////////////////////////////////////////////////////////////
// REAPER uses numbers from zero up the total number of parameters to identify
// the parameters of a plugin. This class maps these linear values to the knobs
// on the CC121.
//
// The file format has a simple structure. It is a text file with one map entry
// per line. Every consists of an 'ID = value' pair. The followings IDs are
// currently defined:
//
// ID:             Name of the plugin as displayed by REAPER's FX window.
// Q1, Q2, Q3, Q4: Mappings for the Q knobs of the surface.
// F1, F2, F3, F4: Mappings for the Frequency knobs of the surface.
// G1, G2, G3, G4: Mappings for the Gain knobs of the surface.
// T1, T2, T3, T4: Mappings for the Type knobs of the surface.
// B1, B2, B3, B4: Mappings for the Bypass buttons of the surface.
// BP:             Mappings for the All Bypass button.
// MX:             Mix parameter assignment (currently unused).
// QS, FS, GS, TS: Scaling factors for the individual parameters.
///////////////////////////////////////////////////////////////////////////////
class CC121EqMap
{
public:
  /////////////////////////////////////////////////////////////////////////////
  // CC121EqMap::CC121EqMap()
  /////////////////////////////////////////////////////////////////////////////
  // Description:  Default constructor of this class.
  // Parameters:   None.
  // Return value: No return value.
  // Remarks:      Just initializes the members of this class.
  /////////////////////////////////////////////////////////////////////////////
  CC121EqMap();
  
  /////////////////////////////////////////////////////////////////////////////
  // CC121EqMap::CC121EqMap()
  /////////////////////////////////////////////////////////////////////////////
  // Description:  Copy constructor of this class.
  // Parameters:   [in] other: The source class to copy.
  // Return value: No return value.
  // Remarks:      Just copies the members of the source class.
  /////////////////////////////////////////////////////////////////////////////
  CC121EqMap(const CC121EqMap& other);

  /////////////////////////////////////////////////////////////////////////////
  // CC121EqMap::~CC121EqMap()
  /////////////////////////////////////////////////////////////////////////////
  // Description:  Destructor of this class.
  // Parameters:   None.
  // Return value: No return value.
  // Remarks:      Clears up all allocated resources.
  /////////////////////////////////////////////////////////////////////////////
  ~CC121EqMap();

  /////////////////////////////////////////////////////////////////////////////
  // CC121EqMap::()
  /////////////////////////////////////////////////////////////////////////////
  // Description:  .
  // Parameters:   None.
  // Return value: No return value.
  // Remarks:      .
  /////////////////////////////////////////////////////////////////////////////
  const std::string& getMapName() const;

  /////////////////////////////////////////////////////////////////////////////
  // All eq related encoders and buttons of the surface:
  /////////////////////////////////////////////////////////////////////////////
  typedef enum EqParam
  {
    Q          = 0, // Bandwidth knob.
    Frequency  = 1, // Frequency knob.
    Gain       = 2, // Gain knob.
    Type       = 3, // Gain knob in Type Select Mode.
    BandBypass = 4, // EQ on button.
    EqBypass   = 5, // All Bypass button.
    EqMix      = 6  // EQ mix (currently unused).
  } EqParam;

  /////////////////////////////////////////////////////////////////////////////
  // CC121EqMap::MapParameter()
  /////////////////////////////////////////////////////////////////////////////
  // Description:  Map EQ control to EQ parameter number.
  // Parameters:   [in]  param:   Parameter type, see enum above.
  //               [in]  channel: Channel / column of the parameter (1 - 4).
  //               [out] scale:   Scaling of the parameter, may be NULL.
  // Return value: Returns the ID of the parameter or -1 if unassigned.
  // Remarks:      The channel is ignored for the Bypass/Mix parameters.
  /////////////////////////////////////////////////////////////////////////////
  int MapParameter(const EqParam param, const int channel, double* scale = 0) const;

  ///////////////////////////////////////////////////////////////////////////////
  // CC121EqMap::LoadMap()
  ///////////////////////////////////////////////////////////////////////////////
  // Description:  Load a single EQ map from file.
  // Parameters:   [in] fileName: Name of the file to load.
  // Return value: Returns true on success or false otherwise.
  // Remarks:      EQ maps have a *.eqmap extension.
  ///////////////////////////////////////////////////////////////////////////////
  bool LoadMap(const char* fileName);

private:

  /////////////////////////////////////////////////////////////////////////////
  // Member
  /////////////////////////////////////////////////////////////////////////////

  // Name of the map as displayed by REAPER:
  std::string mapName;

  // Storage: Q1, Q2, Q3, Q4, F1, F2 etc. The last two entries are overall
  // bypass and mix:
  int eq_map[22];

  // Scaling of the Q parameter:
  double qScaling;

  // Scaling of the Frequency parameter:
  double fScaling;

  // Scaling of the Gain parameter:
  double gScaling;

  // Scaling of the Type parameter:
  double tScaling;
};

#endif // #ifndef __CC121EQMAP_H_INCLUDED__
///////////////////////////////// End of File /////////////////////////////////
