text
stringlengths
12
786k
let get_event_state e = event_state e sdl_query
let set_event_state e s = ignore ( event_state e s )
let flush_event = foreign " SDL_FlushEvent " ( event_type @-> returning void )
let flush_events = foreign " SDL_FlushEvents " ( event_type @-> event_type @-> returning void )
let has_event = foreign " SDL_HasEvent " ( event_type @-> returning bool )
let has_events = foreign " SDL_HasEvents " ( event_type @-> event_type @-> returning bool )
let poll_event = foreign " SDL_PollEvent " ( ptr Event . t @-> returning bool )
let poll_event e = poll_event ( Event . opt_addr e )
let pump_events = foreign " SDL_PumpEvents " ( void @-> returning void )
let push_event = foreign " SDL_PushEvent " ( ptr Event . t @-> returning bool_to_ok )
let push_event e = push_event ( addr e )
let register_events = foreign " SDL_RegisterEvents " ( int @-> returning uint32_t )
let register_event ( ) = match Unsigned . UInt32 . to_int32 ( register_events 1 ) with
let wait_event = foreign ~ release_runtime_lock : true " SDL_WaitEvent " ( ptr Event . t @-> returning int )
let wait_event e = match wait_event ( Event . opt_addr e ) with
let wait_event_timeout = foreign " SDL_WaitEventTimeout " ~ release_runtime_lock : true ( ptr Event . t @-> int @-> returning bool )
let wait_event_timeout e t = wait_event_timeout ( Event . opt_addr e ) t
type haptic = unit ptr
let haptic : haptic typ = ptr void
let haptic_opt : haptic option typ = ptr_opt void
let unsafe_haptic_of_ptr addr : haptic = ptr_of_raw_address addr
let unsafe_ptr_of_haptic haptic = raw_address_of_ptr ( to_voidp haptic )
module Haptic = struct let infinity = - 1l type feature = int let gain = sdl_haptic_gain let autocenter = sdl_haptic_autocenter let status = sdl_haptic_status let pause = sdl_haptic_pause type direction_type = int let polar = sdl_haptic_polar let cartesian = sdl_haptic_cartesian let spherical = sdl_haptic_...
type haptic_effect = Haptic . Effect . t union
let haptic_effect_id : int typ = int
let haptic_close = foreign " SDL_HapticClose " ( haptic @-> returning void )
let haptic_destroy_effect = foreign " SDL_HapticDestroyEffect " ( haptic @-> int @-> returning void )
let haptic_effect_supported = foreign " SDL_HapticEffectSupported " ( haptic @-> ptr Haptic . Effect . t @-> returning bool_to_ok )
let haptic_effect_supported h e = haptic_effect_supported h ( addr e )
let haptic_get_effect_status = foreign " SDL_HapticGetEffectStatus " ( haptic @-> haptic_effect_id @-> returning bool_to_ok )
let haptic_index = foreign " SDL_HapticIndex " ( haptic @-> returning nat_to_ok )
let haptic_name = foreign " SDL_HapticName " ( int @-> returning ( some_to_ok string_opt ) )
let haptic_new_effect = foreign " SDL_HapticNewEffect " ( haptic @-> ptr Haptic . Effect . t @-> returning nat_to_ok )
let haptic_new_effect h e = haptic_new_effect h ( addr e )
let haptic_num_axes = foreign " SDL_HapticNumAxes " ( haptic @-> returning nat_to_ok )
let haptic_num_effects = foreign " SDL_HapticNumEffects " ( haptic @-> returning nat_to_ok )
let haptic_num_effects_playing = foreign " SDL_HapticNumEffectsPlaying " ( haptic @-> returning nat_to_ok )
let haptic_open = foreign " SDL_HapticOpen " ( int @-> returning ( some_to_ok haptic_opt ) )
let haptic_open_from_joystick = foreign " SDL_HapticOpenFromJoystick " ( joystick @-> returning ( some_to_ok haptic_opt ) )
let haptic_open_from_mouse = foreign " SDL_HapticOpenFromMouse " ( void @-> returning ( some_to_ok haptic_opt ) )
let haptic_opened = foreign " SDL_HapticOpened " ( int @-> returning int )
let haptic_opened i = match haptic_opened i with
let haptic_pause = foreign " SDL_HapticPause " ( haptic @-> returning zero_to_ok )
let haptic_query = foreign " SDL_HapticQuery " ( haptic @-> returning int )
let haptic_rumble_init = foreign " SDL_HapticRumbleInit " ( haptic @-> returning zero_to_ok )
let haptic_rumble_play = foreign " SDL_HapticRumblePlay " ( haptic @-> float @-> int32_t @-> returning zero_to_ok )
let haptic_rumble_stop = foreign " SDL_HapticRumbleStop " ( haptic @-> returning zero_to_ok )
let haptic_rumble_supported = foreign " SDL_HapticRumbleSupported " ( haptic @-> returning bool_to_ok )
let haptic_run_effect = foreign " SDL_HapticRunEffect " ( haptic @-> haptic_effect_id @-> int32_t @-> returning zero_to_ok )
let haptic_set_autocenter = foreign " SDL_HapticSetAutocenter " ( haptic @-> int @-> returning zero_to_ok )
let haptic_set_gain = foreign " SDL_HapticSetGain " ( haptic @-> int @-> returning zero_to_ok )
let haptic_stop_all = foreign " SDL_HapticStopAll " ( haptic @-> returning zero_to_ok )
let haptic_stop_effect = foreign " SDL_HapticStopEffect " ( haptic @-> haptic_effect_id @-> returning zero_to_ok )
let haptic_unpause = foreign " SDL_HapticUnpause " ( haptic @-> returning zero_to_ok )
let haptic_update_effect = foreign " SDL_HapticUpdateEffect " ( haptic @-> haptic_effect_id @-> ptr Haptic . Effect . t @-> returning zero_to_ok )
let haptic_update_effect h id e = haptic_update_effect h id ( addr e )
let joystick_is_haptic = foreign " SDL_JoystickIsHaptic " ( joystick @-> returning bool_to_ok )
let mouse_is_haptic = foreign " SDL_MouseIsHaptic " ( void @-> returning bool_to_ok )
let num_haptics = foreign " SDL_NumHaptics " ( void @-> returning nat_to_ok )
let audio_init = foreign " SDL_AudioInit " ( string_opt @-> returning zero_to_ok )
let audio_quit = foreign " SDL_AudioQuit " ( void @-> returning void )
let get_audio_driver = foreign " SDL_GetAudioDriver " ( int @-> returning ( some_to_ok string_opt ) )
let get_current_audio_driver = foreign " SDL_GetCurrentAudioDriver " ( void @-> returning string_opt )
let get_num_audio_drivers = foreign " SDL_GetNumAudioDrivers " ( void @-> returning nat_to_ok )
module Audio = struct type status = int let stopped = sdl_audio_stopped let playing = sdl_audio_playing let paused = sdl_audio_paused type format = int let format = int_as_uint16_t let s8 = audio_s8 let u8 = audio_u8 let s16_lsb = audio_s16lsb let s16_msb = audio_s16msb let s16_sys = audio_s16sys let s16 =...
type audio_callback = unit Ctypes_static . ptr -> Unsigned . uint8 Ctypes_static . ptr -> int -> unit
let audio_callback kind f = let kind_bytes = ba_kind_byte_size kind in let ba_ptr_typ = access_ptr_typ_of_ba_kind kind in fun _ p len -> let p = coerce ( ptr uint8_t ) ba_ptr_typ p in let len = len / kind_bytes in f ( bigarray_of_ptr array1 len kind p )
type audio_spec = { as_freq : int ; as_format : Audio . format ; as_channels : uint8 ; as_silence : uint8 ; as_samples : uint8 ; as_size : uint32 ; as_callback : audio_callback option ; }
let audio_callback kind f = let kind_bytes = ba_kind_byte_size kind in let ba_ptr_typ = access_ptr_typ_of_ba_kind kind in fun _ p len -> let p = coerce ( ptr uint8_t ) ba_ptr_typ p in let len = len / kind_bytes in f ( bigarray_of_ptr array1 len kind p )
let as_callback = ( ptr void @-> ptr uint8_t @-> int @-> returning void )
let audio_spec : _audio_spec structure typ = structure " SDL_AudioSpec "
let as_freq = field audio_spec " freq " int
let as_format = field audio_spec " format " Audio . format
let as_channels = field audio_spec " channels " int_as_uint8_t
let as_silence = field audio_spec " silence " int_as_uint8_t
let as_samples = field audio_spec " samples " int_as_uint16_t
let _ = field audio_spec " padding " uint16_t
let as_size = field audio_spec " size " int32_as_uint32_t
let as_callback = field audio_spec " callback " ( funptr_opt ~ thread_registration : true ~ runtime_lock : true as_callback )
let as_userdata = field audio_spec " userdata " ( ptr void )
let ( ) = seal audio_spec
let audio_spec_of_c c = let as_freq = getf c as_freq in let as_format = getf c as_format in let as_channels = getf c as_channels in let as_silence = getf c as_silence in let as_samples = getf c as_samples in let as_size = getf c as_size in let as_callback = None in { as_freq ; as_format ; as_channels ; ...
let audio_spec_to_c a = let c = make audio_spec in setf c as_freq a . as_freq ; setf c as_format a . as_format ; setf c as_channels a . as_channels ; setf c as_silence a . as_silence ; setf c as_samples a . as_samples ; setf c as_size a . as_size ; setf c as_callback a . as_callback ; setf...
let close_audio_device = foreign " SDL_CloseAudioDevice " ( audio_device_id @-> returning void )
let free_wav = foreign " SDL_FreeWAV " ( ptr void @-> returning void )
let free_wav ba = free_wav ( to_voidp ( bigarray_start array1 ba ) )
let get_audio_device_name = foreign " SDL_GetAudioDeviceName " ( int @-> bool @-> returning ( some_to_ok string_opt ) )
let get_audio_device_status = foreign " SDL_GetAudioDeviceStatus " ( audio_device_id @-> returning int )
let get_num_audio_devices = foreign " SDL_GetNumAudioDevices " ( bool @-> returning nat_to_ok )
let load_wav_rw = foreign ~ release_runtime_lock : true " SDL_LoadWAV_RW " ( rw_ops @-> int @-> ptr audio_spec @-> ptr ( ptr void ) @-> ptr uint32_t @-> returning ( some_to_ok ( ptr_opt audio_spec ) ) )
let load_wav_rw ops spec kind = let d = allocate ( ptr void ) null in let len = allocate uint32_t Unsigned . UInt32 . zero in match load_wav_rw ops 0 ( addr ( audio_spec_to_c spec ) ) d len with | Error _ as e -> e | Ok r -> let rspec = audio_spec_of_c ( !@ r ) in let kind_size = ba_kind...
let lock_audio_device = foreign " SDL_LockAudioDevice " ( audio_device_id @-> returning void )
let open_audio_device = foreign " SDL_OpenAudioDevice " ( string_opt @-> bool @-> ptr audio_spec @-> ptr audio_spec @-> Audio . allow @-> returning int32_as_uint32_t )
let open_audio_device dev capture desired allow = let desiredc = audio_spec_to_c desired in let obtained = make audio_spec in match open_audio_device dev capture ( addr desiredc ) ( addr obtained ) allow with | id when id = Int32 . zero -> error ( ) | id -> Ok ( id , audio_spec_of_c obtained )...
let pause_audio_device = foreign " SDL_PauseAudioDevice " ( audio_device_id @-> bool @-> returning void )
let unlock_audio_device = foreign " SDL_UnlockAudioDevice " ( audio_device_id @-> returning void )
let queue_audio = foreign " SDL_QueueAudio " ( audio_device_id @-> ptr void @-> int_as_uint32_t @-> returning zero_to_ok )
let queue_audio dev ba = let len = Bigarray . Array1 . dim ba in let kind_size = ba_kind_byte_size ( Bigarray . Array1 . kind ba ) in queue_audio dev ( to_voidp ( bigarray_start array1 ba ) ) ( len * kind_size )
let dequeue_audio = foreign " SDL_DequeueAudio " ( audio_device_id @-> ptr void @-> int @-> returning int_as_uint32_t )
let dequeue_audio dev ba = let len = Bigarray . Array1 . dim ba in let kind_size = ba_kind_byte_size ( Bigarray . Array1 . kind ba ) in dequeue_audio dev ( to_voidp ( bigarray_start array1 ba ) ) ( len * kind_size )