/'===============================================================================================
 SimpleEvent Example
 Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.

 Demonstrates basic usage of FMOD's data-driven event library (fmod_event.dll)
==============================================================================================='/
#include "windows.bi"
#include "crt.bi"

#include "fmodex/fmod_event.bi"
#include "fmodex/fmod_errors.bi"

sub ERRCHECK(byval result as FMOD_RESULT)
    if (result <> FMOD_OK) then
        printf(!"FMOD error! (%d) %s\n", result, FMOD_ErrorString(result))
        end -1
end if
end sub

' program start
    dim as FMOD_EVENTSYSTEM  ptr eventsystem = any
    dim as FMOD_EVENT        ptr event = any
    dim as FMOD_RESULT        result = any
    dim as string                key

    printf(!"======================================================================\n")
    printf(!"Simple Event Example.  Copyright (c) Firelight Technologies 2004-2011.\n")
    printf(!"======================================================================\n")
    printf(!"This example simply plays an event created with the FMOD Designer tool.\n")
    printf(!"======================================================================\n\n")

result = FMOD_EventSystem_Create(@eventsystem)
    ERRCHECK(result)
result = FMOD_EventSystem_Init(eventsystem, 64, FMOD_INIT_NORMAL, 0, FMOD_EVENT_INIT_NORMAL)
    ERRCHECK(result)
result = FMOD_EventSystem_SetMediaPath(eventsystem, "media\\")
    ERRCHECK(result)
result = FMOD_EventSystem_Load(eventsystem, "examples.fev", 0, 0)
    ERRCHECK(result)
result = FMOD_EventSystem_GetEvent(eventsystem, "examples/FeatureDemonstration/Basics/SimpleEvent", FMOD_EVENT_DEFAULT, @event)
    ERRCHECK(result)

    printf(!"======================================================================\n")
    printf(!"Press SPACE to play the event.\n")
    printf(!"Press ESC   to quit\n")
    printf(!"======================================================================\n")

    do
        dim as FMOD_EVENT_STATE state = any
            key = inkey

            if (key = " ") then
result = FMOD_Event_Start(event)
                ERRCHECK(result)
            end if

result = FMOD_EventSystem_Update(eventsystem)
        ERRCHECK(result)
        Sleep(15)

result = FMOD_Event_GetState(event, @state)
        ERRCHECK(result)
        printf(!"Event is %s       \r", iif((state and FMOD_EVENT_STATE_PLAYING), @"playing", @"stopped"))

    loop while (key <> chr(27))

result = FMOD_EventSystem_Release(eventsystem)
    ERRCHECK(result)
