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

typedef struct _GdamProducerQueueClass GdamProducerQueueClass;
typedef struct _GdamProducerQueue GdamProducerQueue;

#include "gdamsongdatabase.h"
#include <gdam/component/gdamproducer.h>

GtkType gdam_producer_queue_get_type();
#define GDAM_TYPE_PRODUCER_QUEUE              (gdam_producer_queue_get_type ())
#define GDAM_PRODUCER_QUEUE(obj)              (GTK_CHECK_CAST ((obj), GDAM_TYPE_PRODUCER_QUEUE, GdamProducerQueue))
#define GDAM_PRODUCER_QUEUE_CLASS(klass)      (GTK_CHECK_CLASS_CAST ((klass), GDAM_TYPE_PRODUCER_QUEUE, GdamProducerQueueClass))
#define GDAM_IS_PRODUCER_QUEUE(obj)           (GTK_CHECK_TYPE ((obj), GDAM_TYPE_PRODUCER_QUEUE))
#define GDAM_IS_PRODUCER_QUEUE_CLASS(klass)   (GTK_CHECK_CLASS_TYPE ((klass), GDAM_TYPE_PRODUCER_QUEUE))

/* TODO: freeze, thaw? . */

struct _GdamProducerQueueClass
{
  GdamProducerClass  producer_class;
  void              (*skip_songs)    (GdamProducerQueue   *queue,
				      int                  songs);
  void              (*skip_to)       (GdamProducerQueue   *queue,
				      int                  song);
  void              (*add_filename)  (GdamProducerQueue   *queue,
				      const char          *filename);
  void              (*set_queue_list)(GdamProducerQueue   *queue,
				      GList               *songinfo_list);
  void              (*set_filename)  (GdamProducerQueue     *queue,
				      const char          *filename);
};

struct _GdamProducerQueue
{
  GdamProducer            producer;
  GdamSongDatabase       *song_database;
  GList                  *songinfo_list;
  int                     eof_sub_id;
  int                     queued_eof_sub_id;
  GdamSongInfo           *current_song;
  GdamSongInfo           *queued_song;
  int                     current_id;
  int                     queued_id;
  int                     current_idx;
  char                   *filename;   /* TODO: get rid of this? */
  int                     fade_envelope;
  int                     buffer_size;
  gboolean                do_repeat;
  gboolean                do_shuffle;
  gboolean                never_miss_data;
  gboolean                contiguous_queueing_disabled;
  gboolean                terminates;
  GList                  *cddb_canon_titles;
  GList                  *playlist_canon_titles;
  GList                  *minilist;
  int			  repeat_mode;  /* 0 -> off 1 -> all 2 -> one */
};

GdamProducerQueue *gdam_producer_queue_new(GdamChannel *channel);
void            gdam_producer_queue_skip_songs (GdamProducerQueue  *queue,
                                                int                 num);
void            gdam_producer_queue_skip_to     (GdamProducerQueue  *queue,
	             	                         int 		      num);
void            gdam_producer_queue_print_queue (GdamProducerQueue  *queue);
void            gdam_producer_queue_add_filename(GdamProducerQueue  *queue,
				                 const char         *filename);
/*  Counts from 1. */
void            gdam_producer_queue_delete_range (GdamProducerQueue *queue,
				                  guint lower,
						  guint upper);
/*  Counts from 1. */
void            gdam_producer_queue_move_range   (GdamProducerQueue *queue,
				                  guint lower,
						  guint upper,
						  guint dest);
/*  Counts from 1. */
void            gdam_producer_queue_print_range  (GdamProducerQueue *queue,
				                  guint lower,
						  guint upper,
						  guint dest);
void            gdam_producer_queue_set_queue_list(GdamProducerQueue *queue,
                                                   GList       *songinfo_list);
void         gdam_producer_queue_search_by_string (GdamProducerQueue *queue,
                                                   const char  *search_string,
				                   int		direction);
void            gdam_producer_queue_source_file   (GdamProducerQueue *queue, 
                                                   const char        *filename);
void            gdam_queue_set_repeat             (GdamProducerQueue *queue,
						   gboolean val);
void            gdam_producer_queue_shuffle_list  (GdamProducerQueue *queue);

/* whether to try and keep the song in sync or whether to be sloppy,
 * as is required for low bandwidth situations
 */
#define gdam_producer_queue_set_never_miss_data(queue, whether)		\
	G_STMT_START{ (queue)->never_miss_data = (whether); } G_STMT_END
#define gdam_producer_queue_get_never_miss_data(queue)			\
	((queue)->never_miss_data)

#endif
