
#ifndef	DTLIB_H
#define	DTLIB_H

/*================================================================*/
/* DTLib.I -- External declarations for DES-Tracker Library v1.1  */
/*                                                                */
/* Designed and written by Darren Schebek                         */
/* Copyright (c)1992 by Darren Schebek                            */
/*                                                                */
/* v1.1        Begun: Sunday, August 31, 1991                     */
/*      Last updated: Friday, May 22, 1992                        */
/*================================================================*/


/*===================================*/
/* Library Data Structures follow... */
/*===================================*/


/*------------------------------------------------------------------------------*/
/* CHANNELSTATUS structure follows. DTL_Base contains four instances of this	*/
/* structure, called dtl_Channel0, dtl_Channel1, etc.  This structure contains	*/
/* information concerning an individual sound channel (0 to 3).  The info		*/
/* contained here is only valid when a module is loaded and a play sequence		*/
/* is active...																	*/

struct CHANNELSTATUS
	{
	UBYTE	cs_Note;		/* The # of last note played (0..11).					*/
	UBYTE	cs_Octave;		/* The octave # of the last note played (0..2).			*/
	UBYTE	cs_NoteNum;		/* cs_Note & cs_Octave combined (Note+(12*Octave)).		*/
	UBYTE	cs_Volume;		/* Current volume of this channel (0..64).				*/
	UWORD	cs_Period;		/* Current period of this channel.						*/
	APTR	cs_Instrument;	/* Pointer to INSTSTATUS struct used by this channel.	*/
	};


/*------------------------------------------------------------------------------*/
/* MODULESTATUS structure follows.  DTL_Base contains an instance of this		*/
/* structure.  It contains information specific to the currently loaded module.	*/
/* This information is valid only when a module is loaded...					*/

struct MODULESTATUS
	{
	APTR	ms_Name;
	ULONG	ms_Length;
	APTR	ms_Address;			/* Length of entire module in memory.			*/
	UBYTE	ms_Format;			/* Either MF_SOUNDTRACKER or MF_NOISETRACKER.	*/
	UBYTE	ms_Version;			/* Module format version.						*/
	UBYTE	ms_Revision;		/* Module format revision.						*/
	UBYTE	ms_Reserved;		/* Always 0.									*/
	APTR	ms_Instruments;		/* Ptr to 1st INSTSTATUS struct in linked list.	*/
	UWORD	ms_NumPatterns;		/* Number of unique patterns defined in module.	*/
	UWORD	ms_NumPositions;	/* Numberof 4-pattern groups to play in module.	*/
	};

/* Values for ms_Format... */

#define	MF_SOUNDTRACKER	1
#define	MF_NOISETRACKER	2

/*----------------------------------------------------------------------------------*/
/* Instrument Status structure follows.  The ms_Instruments field points to the		*/
/* first of a linked list of these structures.  There is one instrument structure	*/
/* in the linked list for each instrument used by the module...						*/

struct INSTSTATUS
	{
	APTR	is_Next;		/* Pointer to next instrument in linked list.	*/
	APTR	is_Name;		/* Pointer to name of this instrument.			*/
	APTR	is_Address;		/* Pointer to instrument in memory.				*/
	ULONG	is_Length;		/* Length of this instrument in bytes.			*/
	ULONG	is_Repeat;		/* Repeat loop offset in bytes.					*/
	ULONG	is_RepeatLen;	/* Length of repeat loop in bytes.				*/
	UBYTE	is_Number;		/* The number of this instrument within module.	*/
	BYTE	is_FineTune;	/* Fine tune amount for instrument (-8..7).		*/
	UBYTE	is_Volume;		/* The default volume of this instrument.		*/
	UBYTE	is_Reserved;	/* Reserved field. Should always be 0.			*/
	};


/*------------------------------------------------------------------------------*/
/* DTL_Base structure, returned by OpenLibrary.  This is the structure that		*/
/* you get a pointer to when you open this library. It contains lots of			*/
/* information about each sound channel, the currenlty loaded module (if one	*/
/* is loaded), and the play sequence parameters.								*/
/*																				*/
/* NOTE: EVERY ONE of these variables are READ ONLY!  NEVER attempt to write	*/
/*       to ANY of them. (Besides, you cannot affect the library by changing	*/
/*       the parameters in this structure, you will only be destroying valuable	*/
/*       status information for both you and anyone else using the library).	*/

struct	DTL_Base
	{
	struct	Library	dtl_lib;	/* DTBase (public data).					*/
	APTR	dtl_SysLib;			/* A pointer to ExecBase for you to use.	*/
	APTR	dtl_DosLib;			/* A pointer to DosBase for you to use.		*/
	APTR	dtl_RexxSysLib;		/* A pointer to RexxSysBase for me to use.	*/
	APTR	dtl_SegList;		/* Off limits. Ne touche pas!				*/
	APTR	dtl_System;			/* Off limits as well.						*/
	UBYTE	dtl_SysFlags;		/* Once again... off limits.				*/
	UBYTE	dtl_Reserved1;		/* Reserved. Always 0.						*/

/* The following variables are always valid, whether a module is loaded or not... */

	APTR	dtl_DefaultPath;	/* Pointer to NULL-terminated default path.			*/
	UWORD	dtl_Flags;			/* DTL_Base flags (see below).						*/
	UBYTE	dtl_GlobalVolume;	/* Global volume for all channels (0..63).			*/
	BYTE	dtl_GlobalTempo;	/* Global tempo for all modules (-16..15).			*/
	BYTE	dtl_FineTempo;		/* Fine tempo adjustment (-128..127).				*/
	UBYTE	dtl_DefaultTempo;	/* Default tempo (0..255) for start of play seq.	*/
	UBYTE	dtl_VolFadeRate;	/* Speed at which volume fades transpire.			*/
	UBYTE	dtl_Iterations;		/* Number of iterations for play sequence.			*/
	UBYTE	dtl_TimingMode;		/* Holds 0 if NTSC timing is used, 1 if PAL.		*/
	UBYTE	dtl_SaveFormat;		/* Holds save file format for SaveModule func.		*/

/* The following variables are valid only when a module is loaded... */

	UBYTE	dtl_IterationsToGo;	/* Number of iterations left including current.	*/
	UBYTE	dtl_CurPosition;	/* Current position in play sequence.			*/
	UBYTE	dtl_CurNoteIndex;	/* Current note index into current position.	*/
	UBYTE	dtl_StartPosition;	/* Play sequence start position.				*/
	UBYTE	dtl_StartNoteIndex;	/* Play sequence start note index into pos.		*/
	UBYTE	dtl_EndPosition;	/* Play sequence end position.					*/
	UBYTE	dtl_EndNoteIndex;	/* Play sequence end note index into pos.		*/
	UBYTE	dtl_CurrentTempo;	/* Current tempo (including global tempo).		*/

	struct	CHANNELSTATUS dtl_Channel0;	/* Status info for channel 0. */
	struct	CHANNELSTATUS dtl_Channel1;	/* Status info for channel 1. */
	struct	CHANNELSTATUS dtl_Channel2;	/* Status info for channel 2. */
	struct	CHANNELSTATUS dtl_Channel3;	/* Status info for channel 3. */

	struct	MODULESTATUS dtl_ModuleStatus;	/* Status info for currently loaded module. */

/* The following variables are valid only when a song is playing... */

	UBYTE	dtl_ElapsedHours;	/* # of hours that song has been playing for.	*/
	UBYTE	dtl_ElapsedMinutes;	/* # of minutes elapsed while playing.			*/
	UBYTE	dtl_ElapsedSeconds;	/* # of seconds elapsed.						*/
	UBYTE	dtl_ElapsedJiffies;	/* # of 60ths of a second elapsed.				*/
	};


/* Bit Field values for dtl_Flags... */

#define	DF_LIBLOCKED		15	/* Set when someone has OWNed the library.			*/
#define	DF_MODULECHANGED	14	/* Toggles each time a change is made to a module.	*/
#define	DF_LOOPINTENT		13	/* Set to 1 if this song is meant to loop.			*/
#define	DF_AUTOTIMING		12	/* Set to 1 if auto timing detection is enabled.	*/
#define	DF_CH3NOTEHIT		11	/* Toggles between 1 and 0 when a note is played.	*/
#define	DF_CH2NOTEHIT		10	/* Same as above,  but for channel 2.				*/
#define	DF_CH1NOTEHIT		9	/* Same for channel 1.								*/
#define	DF_CH0NOTEHIT		8	/* Same for channel 0.								*/
#define	DF_PLAYING			7	/* Set to 1 whenever a play sequence is active.		*/
#define	DF_PLAYSEQDONE		6	/* Set to 1 when a play sequence ends.				*/
#define	DF_MODULELOADED		5	/* Set to 1 when a module is currently loaded.		*/
#define	DF_FILTERSTATUS		4	/* Set to 1 when filter is on, 0 when off.			*/
#define	DF_CH3STATUS		3	/* Set to 1 if channel 3 is enabled, 0 if disabled.	*/
#define	DF_CH2STATUS		2	/* Same as above, but for channel 2.				*/
#define	DF_CH1STATUS		1	/* Same for channel 1.								*/
#define	DF_CH0STATUS		0	/* Same for channel 0.								*/

/* Bit Mask values for dtl_Flags... */

#define	DFM_LIBLOCKED		0x8000
#define	DFM_MODULECHANGED	0x4000
#define	DFM_LOOPINTENT		0x2000
#define	DFM_AUTOTIMING		0x1000
#define	DFM_CH3NOTEHIT		0x0800
#define	DFM_CH2NOTEHIT		0x0400
#define	DFM_CH1NOTEHIT		0x0200
#define	DFM_CH0NOTEHIT		0x0100
#define	DFM_PLAYING			0x0080
#define	DFM_PLAYSEQDONE		0x0040
#define	DFM_MODULELOADED	0x0020
#define	DFM_FILTERSTATUS	0x0010
#define	DFM_CH3STATUS		0x0008
#define	DFM_CH2STATUS		0x0004
#define	DFM_CH1STATUS		0x0002
#define	DFM_CH0STATUS		0x0001


/*--------------------------------------------------------------*/
/* Error codes returned by the library routines...				*/

#define	DE_SUCCESS		0

#define	DE_LIB_ALREADY_OWNED	-1
#define	DE_NO_MODULE_LOADED		-2
#define	DE_NO_PLAY_SEQ_ACTIVE	-3
#define	DE_IVALUE_OUT_OF_RANGE	-4
#define	DE_VALUE_WAS_TRIMMED	-5
#define	DE_FILE_LOAD_ERROR		-6
#define	DE_INSUFFICIENT_MEMORY	-7
#define	DE_ILLEGAL_PATHNAME		-8
#define	DE_UNKNOWN_FORMAT		-9
#define	DE_NO_PATTERNS_LEFT		-10
#define	DE_FILE_SAVE_ERROR		-11
#define	DE_NO_INSTRUMENT		-12
#define	DE_FILE_NOT_FOUND		-13

/*--------------------------------------------------------------*/
/* A macro for you to use (that you should use)...				*/

#define	DTLIBNAME	"destracker.library",0

#endif
