///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// File:           reaper_cc121.cpp                                          //
//                                                                           //
// Functionality:  Common functions for this extension.                      //
//                                                                           //
// 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.              //
///////////////////////////////////////////////////////////////////////////////

// This define will remove the extern modifier from the function pointer
// declarations in the reaper headers and thus implement storage space for the
// functions loaded by ReaperPluginEntry() below:
#define REAPERAPI_DECL
#include "reaper_cc121.h"

// The control surface registration data:
static reaper_csurf_reg_t csurf_cc121_reg =
{
  "CC121",
  "Steinberg CC121",
  CC121::CreateInstance,
  CreateConfigDialog
};

///////////////////////////////////////////////////////////////////////////////
// ReaperPluginEntry()
///////////////////////////////////////////////////////////////////////////////
// Description:  Exported entry/exit point for this extension.
// Parameters:   [in] hInstance: Instance handle, used for resource handling
//                               and related actions.
//               [in] rec:       Informations to enable communication to the
//                               host. May be NULL.
// Return value: Returns TRUE if successfull or FALSE on error.
// Remarks:      If the rec parameter is NULL the plugin is unloaded (usually
//               because of REAPER exiting). The hInstance parameter is equal
//               to the hModule parameter of the windows DllMain() entry point.
///////////////////////////////////////////////////////////////////////////////
extern "C" REAPER_PLUGIN_DLL_EXPORT int REAPER_PLUGIN_ENTRYPOINT(REAPER_PLUGIN_HINSTANCE hInstance, reaper_plugin_info_t *rec)
{
  // Parameter check:
  if (!rec || rec->caller_version != REAPER_PLUGIN_VERSION || !rec->GetFunc)
      return 0;

  // Store globals:
  hResourceInst = hInstance;
  hReaperWnd    = rec->hwnd_main;

  // Load REAPER api functions:
  #define IMPAPI(x) if (!((*((void**)&(x)) = (void *)rec->GetFunc(#x)))) return 0;
  IMPAPI(DB2SLIDER)
  IMPAPI(SLIDER2DB)
  IMPAPI(GetNumMIDIInputs)
  IMPAPI(GetNumMIDIOutputs)
  IMPAPI(CreateMIDIInput)
  IMPAPI(CreateMIDIOutput)
  IMPAPI(GetMIDIOutputName)
  IMPAPI(GetMIDIInputName)
  IMPAPI(CSurf_TrackToID)
  IMPAPI(CSurf_TrackFromID)
  IMPAPI(CSurf_NumTracks)
  IMPAPI(CSurf_SetSurfaceVolume)
  IMPAPI(CSurf_SetSurfacePan)
  IMPAPI(CSurf_OnVolumeChange)
  IMPAPI(CSurf_OnPanChange)
  IMPAPI(CSurf_OnMuteChange)
  IMPAPI(CSurf_OnRecArmChange)
  IMPAPI(CSurf_OnPlay)
  IMPAPI(CSurf_OnStop)
  IMPAPI(CSurf_OnFwd)
  IMPAPI(CSurf_OnRew)
  IMPAPI(CSurf_OnRecord)
  IMPAPI(CSurf_GoStart)
  IMPAPI(CSurf_GoEnd)
  IMPAPI(CSurf_OnSoloChange)
  IMPAPI(CSurf_SetAutoMode)
  IMPAPI(CSurf_ScrubAmt)
  IMPAPI(CSurf_SetSurfaceSelected)
  IMPAPI(CSurf_OnSelectedChange)

  IMPAPI(TrackList_UpdateAllExternalSurfaces)
  IMPAPI(SetTrackAutomationMode)
  IMPAPI(GetTrackAutomationMode)
  IMPAPI(SetTrackSelected)
  IMPAPI(TrackFX_GetCount)
  IMPAPI(TrackFX_GetNumParams)
  IMPAPI(TrackFX_GetParam)
  IMPAPI(TrackFX_SetParam)
  IMPAPI(TrackFX_GetParamName)
  IMPAPI(TrackFX_GetFXName)
  IMPAPI(GetSetMediaTrackInfo)
  IMPAPI(GetTrackInfo)
  IMPAPI(GetLastTouchedTrack)
  IMPAPI(Main_OnCommand)
  IMPAPI(GetSetTrackSendInfo)
  IMPAPI(GetCursorPosition)
  IMPAPI(SetEditCurPos)
  IMPAPI(GetPlayPosition)
  IMPAPI(KBD_OnMainActionEx)
  IMPAPI(NamedCommandLookup)
  IMPAPI(GetExePath)

  // Register the control surface:
  rec->Register("csurf", &csurf_cc121_reg);

  // Return success:
  return 1;
}

///////////////////////////////// End of File /////////////////////////////////
