/*
**    GrabKEY
**
**        © 1996 by Timo C. Nentwig
**        All Rights Reserved !
**
**        Tcn@techbase.in-berlin.de
**
**
*/

/// #include

#include "gk_GST.h"
#include "gk_Protos.h"

///
/// #define

#define    NOTIFY_SIGNAL    50

///
/// proto

proto Object *    LoadSound    (STRPTR Name);
proto VOID        PlaySound    (STRPTR Name);

///

/// LoadSound ()

	/*
	 *    FUNCTION    Load & return a sound Object *.
	 *
	 *    NOTE
	 *
	 *    EXAMPLE     LoadSound ("samples:my_sample.DT");
	 *
	 */


Object *
LoadSound (STRPTR Name)
{

	if ( ! (StrEmpty (Name)))
	{

		Object   *Sound;

		if (Sound = NewDTObject (Name, DTA_SourceType,    DTST_FILE,
									   DTA_GroupID,       GID_SOUND,
									   SDTA_Volume,       64,
									   SDTA_Cycles,       1,
									   SDTA_SignalTask,   (ULONG) FindTask (NULL),
									   SDTA_SignalBit,    (ULONG) NOTIFY_SIGNAL,
									   TAG_END))
									   {

										   return (Sound);

									   }
									   else
									   {

										   LONG    ErrNum = IoErr();
										   UBYTE   ErrBuf [80];

										   if (ErrNum >= DTERROR_UNKNOWN_DATATYPE)
										   {

											   sprintf (ErrBuf, GetDTString (ErrNum), Name);

										   }
										   else
										   {

											   Fault (ErrNum, NULL, ErrBuf, sizeof (ErrBuf));

										   }

										   ErrorRequest ("OK", "%s %ld\n\n%s: %s", LocaleString (MSG_ERR_ERROR), ErrNum, Name, ErrBuf);

									   }

	}

	return (NULL);

}

///
/// PlaySound ()

	/*
	 *    FUNCTION    Load & play a sound.
	 *
	 *    NOTE
	 *
	 *    EXAMPLE     PlaySound ();
	 *
	 */


VOID
PlaySound (STRPTR Name)
{

	Object   *Sound = LoadSound (Name);

	if (Sound)
	{

		DoMethod (Sound, DTM_TRIGGER, NULL, STM_PLAY, NULL);
		Wait (NOTIFY_SIGNAL);
		DisposeDTObject (Sound);

	}

}

///
