/*
    GDAM - Geoff & Dave's Audio Mixer
    Copyright (C) 1999    Dave Benson, Geoff Matters.

    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 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

    Contact:
        daveb@ffem.org <Dave Benson>
        geoff@ugcs.caltech.edu <Geoff Matters>
*/
#ifndef __GDAMCROSSFADESKIN__H_
#define __GDAMCROSSFADESKIN__H_

#include "gdamskin.h"
#include <gdam/component/gdamgain.h>
#include <gtk/gtkdrawingarea.h>


typedef struct _GdamCrossfadeSkinClass GdamCrossfadeSkinClass;
typedef struct _GdamCrossfadeSkin GdamCrossfadeSkin;
typedef struct _GdamCrossfadeGainInfo GdamCrossfadeGainInfo;


GtkType gdam_crossfade_skin_get_type();
#define GDAM_TYPE_CROSSFADE_SKIN              (gdam_crossfade_skin_get_type ())
#define GDAM_CROSSFADE_SKIN(obj)              (GTK_CHECK_CAST ((obj), GDAM_TYPE_CROSSFADE_SKIN, GdamCrossfadeSkin))
#define GDAM_CROSSFADE_SKIN_CLASS(klass)      (GTK_CHECK_CLASS_CAST ((klass), GDAM_TYPE_CROSSFADE_SKIN, GdamCrossfadeSkinClass))
#define GDAM_IS_CROSSFADE_SKIN(obj)           (GTK_CHECK_TYPE ((obj), GDAM_TYPE_CROSSFADE_SKIN))
#define GDAM_IS_CROSSFADE_SKIN_CLASS(klass)   (GTK_CHECK_CLASS_TYPE ((klass), GDAM_TYPE_CROSSFADE_SKIN))


#define GDAM_CROSSFADE_LOOKUP_RESOLUTION 100

struct _GdamCrossfadeSkinClass {
	GdamSkinClass		skin_class;
};

struct _GdamCrossfadeGainInfo {
	int			index;
	guint			update_volume_handler;
	guint                   destroy_handler;
	GdamGain*		gain;
	GdamCrossfadeSkin*	crossfade;
	gboolean		locked;
	gdouble			scale;
};

struct _GdamCrossfadeSkin {
	GdamSkin		base;
	GSList*			gains;
	GSList*			adjustment_changes;
	gdouble			max_gain;
	gdouble			current_crossfade;
	gdouble			shelf_width;
	int 			curve_mode;

	/* Used to stop recursing... */
	gboolean		resetting_gains;

	GdkGC*			left_gc;
	GdkGC*			right_gc;
	GdkGC*			background;
	GdkPixmap*		backing_pixmap;
	GtkWidget*		drawing_area;
	int			draw_width, draw_height;
	gdouble	                ideal_ratios[GDAM_CROSSFADE_LOOKUP_RESOLUTION];
};

/* If gain index is passed in, it is treated as `fixed',
 * you may pass in -1 if you just want to renormalize. */
void     gdam_crossfade_gain_changed   (GdamCrossfadeSkin* crossfade,
                                        int                gain_index);

//void     gdam_crossfade_set_max_gain   (GdamCrossfadeSkin* crossfade,
				        //gdouble            max_gain);

void     gdam_crossfade_set_crossfade  (GdamCrossfadeSkin* crossfade,
                                        int                index1,
				        int                index2,
				        gdouble            fade_amt);

void     gdam_crossfade_nudge_crossfade(GdamCrossfadeSkin* crossfade,
				        gdouble            fade_amt);

gboolean gdam_crossfade_skin_set_child (GdamCrossfadeSkin* skin,
				        int 		   child_num,
				        GdamGain*	   gain);

#endif
