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

typedef struct _GdamInputIntEvent GdamInputIntEvent;
typedef struct _GdamInputStringEvent GdamInputStringEvent;
typedef struct _GdamInputEventRange GdamInputEventRange;
typedef struct _GdamInputEventSignal GdamInputEventSignal;
typedef struct _GdamInputEvent GdamInputEvent;
typedef struct _GdamInputEventTypeInfo GdamInputEventTypeInfo;

#include "gdaminputdevice.h"

/*
 * InputEvents
 *
 * Events which transpire as the result of people twiddling knobs
 * or pressing buttons.
 */

struct _GdamInputEvent {
	guint			event_type;
	GdamInputDevice*	input_device;
	guint			input_id;
};

unsigned        gdam_input_event_hash          (GdamInputEvent     *event);
gboolean        gdam_input_event_equal         (GdamInputEvent     *event_a,
                                                GdamInputEvent     *event_b);
char           *gdam_input_event_stringify     (GdamInputEvent     *event);
GdamInputEvent *gdam_input_event_canonicalize  (GdamInputEvent     *event);
void            gdam_input_event_destroy       (GdamInputEvent     *event);

GHashTable     *gdam_input_event_to_keyvalues  (GdamInputEvent     *event);
GdamInputEvent *gdam_input_event_from_keyvalues(int                 type,
                                                GHashTable         *table);

struct _GdamInputEventRange {
	/* From GdamInputEvent. */
	guint			event_type;
        GdamInputDevice        *input_device;
	guint			input_id;

	/* The boundaries of the event. */
	gdouble			min_value, max_value;

	/* The actual value. */
	gdouble			value;
};

struct _GdamInputEventSignal {
	/* From GdamInputEvent. */
	guint			event_type;
        GdamInputDevice        *input_device;
	guint			input_id;

	int			signal_length;
	char                   *signal_name;
	int			handler_length;
	char                   *handler_name;
};

struct _GdamInputIntEvent {
	/* From GdamInputEvent. */
	guint			event_type;
        GdamInputDevice        *input_device;
	guint			input_id;

	int			number;
        const char             *enum_name;
};

struct _GdamInputStringEvent {
	/* From GdamInputEvent. */
	guint			event_type;
	GdamInputDevice*	input_device;
	guint			input_id;

	int			length;
        char                   *data;
};

/*
 *               GdamInputEventType
 *
 * Define a new type of event.
 */
struct _GdamInputEventTypeInfo {
        const char           *event_type_name;
        char               *(*stringify)     (GdamInputEvent *input_event);
        unsigned            (*hash)          (GdamInputEvent *input_event);
        gboolean            (*equal)         (GdamInputEvent *input_event1,
                                              GdamInputEvent *input_event2);
        GHashTable         *(*to_keyvalues)  (GdamInputEvent *input_event);
        GdamInputEvent     *(*from_keyvalues)(int             type,
                                              GHashTable     *table);
        GdamInputEvent     *(*canonicalize)  (GdamInputEvent *input_event);
        void                (*destroy)       (GdamInputEvent *input_event);
};

guint           gdam_input_event_get_unique    (guint               ev_parent,
                                                GtkType             device_type,
                                                GdamInputEventTypeInfo *type);
const char     *gdam_input_event_type_name     (int                 ev_type);
gboolean        gdam_input_event_type_is_a     (guint               child, 
                                                guint               parent);

GdamInputEventTypeInfo*
               gdam_input_event_get_type_info_by_name(const char *name);
int            gdam_input_event_get_type_id_by_name  (const char *name);

guint          gdam_input_event_get_type();
guint          gdam_input_event_range_get_type();
guint          gdam_input_event_int_get_type();
guint          gdam_input_event_string_get_type();
guint          gdam_input_event_signal_get_type();


int            gdam_input_fetch_int            (GHashTable         *str_table,
                                                const char         *name);
char          *gdam_input_fetch_string         (GHashTable         *str_table,
                                                const char         *name);
gdouble        gdam_input_fetch_double         (GHashTable         *str_table,
                                                const char         *name);
void           gdam_input_store_int            (GHashTable         *str_table,
                                                const char         *name,
                                                int                 value);
void           gdam_input_store_double         (GHashTable         *str_table,
                                                const char         *name,
                                                gdouble             value);
void           gdam_input_store_string         (GHashTable         *str_table,
                                                const char         *name,
                                                const char         *value);
gboolean       gdam_input_event_parse_device   (GdamInputEvent     *event,
                                                const char         *dev_name);
#endif
