/*
    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 __GDAS_MIX_H_
#define __GDAS_MIX_H_


typedef struct _GdasMix GdasMix;
typedef struct _GdasMixClass GdasMixClass;

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

#include "gdassource.h"
typedef struct _GdasMixElement GdasMixElement;

GtkType gdas_mix_get_type();
#define GDAS_TYPE_MIX			(gdas_mix_get_type ())
#define GDAS_MIX(obj)              (GTK_CHECK_CAST ((obj), GDAS_TYPE_MIX, GdasMix))
#define GDAS_MIX_CLASS(klass)      (GTK_CHECK_CLASS_CAST ((klass), GDAS_TYPE_MIX, GdasMixClass))
#define GDAS_IS_MIX(obj)           (GTK_CHECK_TYPE ((obj), GDAS_TYPE_MIX))
#define GDAS_IS_MIX_CLASS(klass)   (GTK_CHECK_CLASS_TYPE ((klass), GDAS_TYPE_MIX))



typedef enum _GdasMixMode GdasMixMode;
enum _GdasMixMode {
	GDAS_MIX_ETERNAL,
	GDAS_MIX_FIRST_ENDED,
	GDAS_MIX_ALL_ENDED,
	GDAS_MIX_LOOPS
};

struct _GdasMixElement {
	GdasSource*		source;
	GdasMix*		mix;
	gint64			position;
	gint64			start_offset;
	gboolean		ended;
	gboolean		may_miss_data;
	gboolean		remove_when_ended;
	char*			name;
};

typedef void (*GdasMixSampleFunc) (GdasMix          *mix,
                                   GdamSample       *dest,
                                   const GdamSample *source,
				   int               num_samples);

struct _GdasMixClass {
	GdasSourceClass		source_class;

	GdasMixSampleFunc       init_samples;
	GdasMixSampleFunc       add_samples;
};
struct _GdasMix {
	GdasSource		source;

	/* All members are private. */

	/* List of playing elements. */
	GSList*			playing;

	/* List of elements that are to be played in the future. */
	GSList*			waiting;

	/* List of elements that have ended, perhaps to be revitalized
	 * on seek. */
	GSList*			ended;

	gint64			position;

	gint64			loop_length;
	GdasMixMode		mode;

	int			freeze_count;

	gboolean		mix_should_end;

	GdamSample*		tmp_buffer;
	guint			tmp_buffer_size;
};

GdasMix        *gdas_mix_new           (GdasMixMode    mode);
void            gdas_mix_freeze        (GdasMix       *mix);
void            gdas_mix_thaw          (GdasMix       *mix);
void            gdas_mix_clear         (GdasMix       *mix);
GdasMixElement *gdas_mix_add           (GdasMix       *mix,
                                        GdasSource    *source,
                                        gint64         time);
GdasMixElement *gdas_mix_add_now       (GdasMix       *mix,
                                        GdasSource    *source);
GdasMixElement *gdas_mix_add_named     (GdasMix       *mix,
                                        GdasSource    *source,
                                        gint64         time,
                                        const char    *name);
GdasSource     *gdas_mix_get_named     (GdasMix       *mix,
                                        const char    *name);

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif
