/*****************************************************************************/

/*
 *      handlecdda.c -- REALmagic disc (CDDA) playing primitives
 *
 *      Copyright (C) 2001 Sigma Designs
 *                    written by Pascal Cannenterre <pascal_cannenterre@sdesigns.com>
 *
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *
 *      This program 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 General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/*****************************************************************************/
#include "define.h"
#include "handlecdda.h"
#include "gtk_callbacks.h"
#include "fmpcontrol.h"




void handle_Stop_Close_cdda(INFO *pInfo)
{
  
  FMPStop();
  FMPClose();
  pInfo->playing = CLOSED;
  displayMsg(MSG_BOTH, MSG_CLOSE, NULL);
  //Before showing splash screen we return to 720x480 resolution
  if(pInfo->IHdtv_c)
    IHdtv_SetMode(pInfo->pIHdtv, &(Hdtv_Params_Init), g_OutputMode);
}

void handle_FForward_cdda(INFO *pInfo)
{
  switch(pInfo->playing)
    {
    case PLAYING:
      CDDAFastForward(4);
      pInfo->playing = TRICK_MODE;
      displayMsg(MSG_BOTH, MSG_FF, "4X");
      break;
    case TRICK_MODE:
      CDDAFastForward(0);
      pInfo->playing = PLAYING;
      displayMsg(MSG_BOTH, MSG_PLAY, NULL);
      break;
    default:
      break;
    }  
}


void handle_FRewind_cdda(INFO *pInfo)
{
  switch(pInfo->playing)
    {
    case PLAYING:
      CDDARewind(4);
      pInfo->playing = TRICK_MODE;
      displayMsg(MSG_BOTH, MSG_FR,"4X");
      break;
    case TRICK_MODE:
      CDDARewind(0);
      pInfo->playing = PLAYING;
      displayMsg(MSG_BOTH, MSG_PLAY, NULL);
      break;
    default:
      break;
    }
}


void handle_Prev_Track_cdda(INFO *pInfo)
{
  int pl_tmp = pInfo->playing;
  
  pInfo->playing = PLAYING;
  if(CDDAPrevTrack() == S_OK) 
    {
      displayMsg(MSG_OSD_ONLY, MSG_BACK, NULL);  
    }
  else 
    {
      pInfo->playing = pl_tmp;
      displayMsg(MSG_STATUS_ONLY, 0, "Error - Probably no Previous Track...");
    }
}

void handle_Next_Track_cdda(INFO *pInfo)
{
  int pl_tmp = pInfo->playing;
  
  pInfo->playing = PLAYING;
  if(CDDANextTrack() == S_OK) 
    {
      displayMsg(MSG_OSD_ONLY, MSG_NEXT, NULL);
    }
  else 
    {
      pInfo->playing = pl_tmp;
      displayMsg(MSG_STATUS_ONLY, 0, "Error - Probably no Next Track..."); 
    }   
}



void retrieveInfo_cdda(INFO* pInfo) 
{
  BYTE i=0;
  DWORD somme = 0, sect =0;

  if(CDDAGetNumberOfTracks(&(pInfo->CDDAtracknumber)) != FMPE_OK)
    pInfo->CDDAtracknumber = 0;
	  
  pInfo->CDDATrackDuration = Malloc(DWORD, pInfo->CDDAtracknumber);

  for(i=0;i<pInfo->CDDAtracknumber;i++)
    {
      CDDAGetTrackDuration(i+1, &sect);
      pInfo->CDDATrackDuration[i] = sect;
      G_PRINT("\nCDDA track %d duration : %ld",
	      i+1,
	      sect);
      somme = somme + pInfo->CDDATrackDuration[i];
    }
  G_PRINT("\n\nTotal time : %ld", somme);

  pInfo->totalTime = somme;
  
  if(pInfo->CDDAtracknumber != 0)
    pInfo->previous_trackTime = pInfo->CDDATrackDuration[0];
}




void handle_Search_cdda(INFO *pInfo)
{
  /* int pl_tmp = pInfo->playing; */

  if(pInfo->bSearch == 3 
     && pInfo->dwSearch) 
    {
      
    }
  else if(pInfo->bSearch == 2) 
    {
      
    }
  else 
    {
     
    }
  pInfo->bSearch = 0;
}

