1. with Events;                            use Events; 
  2. with Events.Corrals;                    use Events.Corrals; 
  3. with Events.Listeners;                  use Events.Listeners; 
  4. with Objects;                           use Objects; 
  5. with Processes;                         use Processes; 
  6.  
  7. private with Ada.Real_Time; 
  8. private with Ada.Strings.Unbounded; 
  9.  
  10. package Audio_Players is 
  11.  
  12.     -- Audio_Player objects listen for certain audio events and play sound 
  13.     -- effects or music on command. The player contains an internal task for 
  14.     -- playing audio in the background. 
  15.     type Audio_Player is new Object and Process and Event_Listener with private; 
  16.     type A_Audio_Player is access all Audio_Player'Class; 
  17.  
  18.     -- Creates a new Audio_Player that will listen for events in 'corral'. 
  19.     function Create_Audio_Player( corral : not null A_Corral ) return A_Audio_Player; 
  20.     pragma Postcondition( Create_Audio_Player'Result /= null ); 
  21.  
  22.     -- Starts the Audio_Player's internals. This must be called before any 
  23.     -- audio can be played. 
  24.     procedure Start( this : not null access Audio_Player'Class ); 
  25.  
  26.     -- Stops the audio player's internals. This must be called after Start and 
  27.     -- before deleting the object. 
  28.     procedure Stop( this : not null access Audio_Player'Class ); 
  29.  
  30.     -- Deletes the Audio_Player. 
  31.     procedure Delete( this : in out A_Audio_Player ); 
  32.     pragma Postcondition( this = null ); 
  33.  
  34. private 
  35.  
  36.     use Ada.Real_Time; 
  37.     use Ada.Strings.Unbounded; 
  38.  
  39.     type Sound_Registry; 
  40.     type A_Sound_Registry is access all Sound_Registry; 
  41.  
  42.     procedure Delete( registry : in out A_Sound_Registry ); 
  43.     pragma Postcondition( registry = null ); 
  44.  
  45.     type Polling_Task; 
  46.     type A_Polling_Task is access all Polling_Task; 
  47.  
  48.     procedure Delete( pollTask : in out A_Polling_Task ); 
  49.     pragma Postcondition( pollTask = null ); 
  50.  
  51.     ---------------------------------------------------------------------------- 
  52.  
  53.     type Audio_Player is new Object and Process and Event_Listener with 
  54.         record 
  55.             started   : Boolean := False; 
  56.             stopped   : Boolean := False; 
  57.             corral    : A_Corral := null; 
  58.             tickDelta : Time_Span := Time_Span_Zero; 
  59.             registry  : A_Sound_Registry := null; 
  60.             process   : A_Polling_Task := null; 
  61.             music     : Unbounded_String; 
  62.         end record; 
  63.  
  64.     -- Raises COPY_NOT_ALLOWED. 
  65.     procedure Adjust( this : access Audio_Player ); 
  66.  
  67.     procedure Construct( this : access Audio_Player; corral : not null A_Corral ); 
  68.  
  69.     procedure Delete( this : in out Audio_Player ); 
  70.  
  71.     function Get_Process_Name( this : access Audio_Player ) return String; 
  72.     pragma Postcondition( Get_Process_Name'Result'Length > 0 ); 
  73.  
  74.     procedure Handle_Event( this : access Audio_Player; 
  75.                             evt  : in out A_Event; 
  76.                             resp : out Response_Type ); 
  77.     pragma Precondition( evt /= null ); 
  78.  
  79.     procedure Play_Music( this : not null access Audio_Player'Class; name : String ); 
  80.     pragma Precondition( name'Length > 0 ); 
  81.  
  82.     procedure Play_Sound( this : not null access Audio_Player'Class; name : String ); 
  83.     pragma Precondition( name'Length > 0 ); 
  84.  
  85.     procedure Stop_Music( this : not null access Audio_Player'Class ); 
  86.  
  87.     procedure Tick( this : access Audio_Player; upTime, dt : Time_Span ); 
  88.  
  89. end Audio_Players;