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

GRAOUMF TRACKER 2

Copyright (c) 1996 - 2002 Laurent de Soras

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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

Contact the author : laurent@ohmforce.com
More information about this license : http://www.gnu.org/licenses/gpl.html

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



/*\\\ FICHIERS INCLUDE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/

#include	<stdio.h>

#include	"base_ct.h"
#include	"gtracker.h"
#include	"intrface.h"
#include	"mpannel.h"
#include	"SplEdCurrentSample.h"
#include	"resource.h"
#include	"rsc01.h"
#include	"samp.h"
#include	"Sample.h"
#include	"EditString.h"
#include	"edstring.h"



/*\\\ CONSTANTES PUBLIQUES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/



/*\\\ CONSTANTES PRIVEES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/



/*\\\ TYPES & STRUCTURES PRIVEES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/



/*\\\ DEFINITION DES VARIABLES DE CLASSE PUBLIQUES \\\\\\\\\\\\\\\\\\\\\\\\\*/



/*\\\ DEFINITION DES VARIABLES DE CLASSE PRIVEES \\\\\\\\\\\\\\\\\\\\\\\\\\\*/



/*\\\ METHODES PUBLIQUES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/



/*==========================================================================*/
/*      Nom: redraw                                                         */
/*      Description: Affiche la composante d'interface.                     */
/*==========================================================================*/

void	SplEdCurrentSample::redraw (void)
{
	RSC_display_object (RSC_OBJ_SE_CURSPL);
	refresh ();
}



/*==========================================================================*/
/*      Nom: refresh                                                        */
/*      Description: Rafraichit l'affichage des donnees.                    */
/*==========================================================================*/

void	SplEdCurrentSample::refresh (void)
{
	char	nbr3_0 [3+1];
	char	text_0 [Sample_NAME_LEN+1];
	long		freq;
	int		nbr_tracks;
	int		nbr_bytes;

	freq = SAMP_get_sample_freq (GTK_sample_nbr);
	nbr_tracks = SAMP_get_sample_stereo (GTK_sample_nbr);
	nbr_bytes = SAMP_get_sample_resolution (GTK_sample_nbr) >> 3;

	/* Numero du sample */
	sprintf (nbr3_0, INTR_base_song_3, GTK_sample_nbr);
	RSC_set_string (RSC_OBJ_SE_CURSPL_SPL_VAL, nbr3_0);
	RSC_display_object (RSC_OBJ_SE_CURSPL_SPL_VAL);
	
	/* Length */
	INTR_splpos_2_string (text_0, SAMP_get_sample_length (GTK_sample_nbr),
								 freq, nbr_tracks, nbr_bytes);
	RSC_set_string (RSC_OBJ_SE_CURSPL_LEN_VAL, text_0);
	RSC_display_object (RSC_OBJ_SE_CURSPL_LEN_VAL);

	/* Name */
	SAMP_get_sample_name (GTK_sample_nbr, text_0);
	RSC_set_string (RSC_OBJ_SE_CURSPL_NAME_VAL, text_0);
	RSC_display_object (RSC_OBJ_SE_CURSPL_NAME_VAL);

	refresh_dynamic (TRUE);
}



/*==========================================================================*/
/*      Nom: manage                                                         */
/*      Description: Gere la composante d'interface                         */
/*      Parametres en entree:                                               */
/*        - sel_object: objet detecte par le gestionnaire d'interface       */
/*        - sel_elder: aine de sel_object                                   */
/*==========================================================================*/

void	SplEdCurrentSample::manage (int sel_object, int sel_elder)
{
	char	text_0 [Sample_NAME_LEN+1]; 

	switch (sel_object)
	{

	/* Numero du sample */
	case	RSC_OBJ_SE_CURSPL_SPL:
		if (RSC_mouse_key == 2)
		{
			MPAN_set_sample_number (INTR_CHGTYPE_POP, 0, RSC_OBJ_SE_CURSPL_SPL_VAL);
		}
		else
		{
			MPAN_set_sample_number (INTR_CHGTYPE_KBD, 0, RSC_OBJ_SE_CURSPL_SPL_VAL);
		}
		break;

	/* Sample + */
	case	RSC_OBJ_SE_CURSPL_UP:
		MPAN_set_sample_number (INTR_CHGTYPE_REL,
										INTR_inc_speed [0] [RSC_mouse_key],
										RSC_OBJ_SE_CURSPL_SPL_VAL);
		break;

	/* Sample - */
	case	RSC_OBJ_SE_CURSPL_DOWN:
		MPAN_set_sample_number (INTR_CHGTYPE_REL,
										-INTR_inc_speed [0] [RSC_mouse_key],
										RSC_OBJ_SE_CURSPL_SPL_VAL);
		break;

	/* Length */
	case	RSC_OBJ_SE_CURSPL_LEN:
		INTR_dialog_box ("", "Not implemented", "Cancel", 0, 0);
		/*** A faire ***/
		break;

	/* Name */
	case	RSC_OBJ_SE_CURSPL_NAME:
		SAMP_get_sample_name (GTK_sample_nbr, text_0);
		if (EDIT_edit_string (text_0, RSC_OBJ_SE_CURSPL_NAME_VAL,
									 Sample_NAME_LEN, EditString_TYPE_ALPHA) == 0)
		{
			SAMP_set_sample_name (GTK_sample_nbr, text_0);
		}
		refresh ();
		break;
	}
}



int	SplEdCurrentSample::get_width (void)
{
	return (RSC_get_width (RSC_OBJ_SE_CURSPL));
}



int	SplEdCurrentSample::get_height (void)
{
	return (RSC_get_height (RSC_OBJ_SE_CURSPL));
}



void	SplEdCurrentSample::get_coordinates (int &pix_x, int &pix_y)
{
	pix_x = RSC_absolute_object_pixxpos [RSC_OBJ_SE_CURSPL];
	pix_y = RSC_absolute_object_pixypos [RSC_OBJ_SE_CURSPL];
}



void	SplEdCurrentSample::move_to (int pix_x, int pix_y)
{
	RSC_set_absolute_object_position (RSC_OBJ_SE_CURSPL, pix_x, pix_y);
}



/*\\\ METHODES PRIVEES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/



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



/*==========================================================================*/
/*      Nom:                                                                */
/*      Description:                                                        */
/*      Parametres en entree:                                               */
/*      Parametres en sortie:                                               */
/*      Parametres en entree/sortie:                                        */
/*      Retour:                                                             */
/*==========================================================================*/
