1. -- 
  2. -- Copyright (c) 2012 Kevin Wellwood 
  3. -- All rights reserved. 
  4. -- 
  5. -- This source code is distributed under the Modified BSD License. For terms and 
  6. -- conditions, see license.txt. 
  7. -- 
  8.  
  9. with Events;                            use Events; 
  10. with Events.Corrals;                    use Events.Corrals; 
  11. with Events.Listeners;                  use Events.Listeners; 
  12. with Objects;                           use Objects; 
  13. with Processes;                         use Processes; 
  14.  
  15. private with Ada.Containers.Indefinite_Hashed_Maps; 
  16. private with Ada.Strings.Equal_Case_Insensitive; 
  17. private with Ada.Strings.Hash_Case_Insensitive; 
  18. private with Allegro.Audio; 
  19. private with Resources; 
  20.  
  21. package Audio_Players is 
  22.  
  23.     -- Audio_Player objects listen for certain audio events and play sound 
  24.     -- effects or music on command. The player contains an internal task for 
  25.     -- playing audio in the background. 
  26.     type Audio_Player is new Limited_Object and Process and Event_Listener with private; 
  27.     type A_Audio_Player is access all Audio_Player'Class; 
  28.  
  29.     -- Creates a new Audio_Player that will listen for audio events in 'corral'. 
  30.     function Create_Audio_Player( corral : not null A_Corral ) return A_Audio_Player; 
  31.     pragma Postcondition( Create_Audio_Player'Result /= null ); 
  32.  
  33.     -- Deletes the Audio_Player. 
  34.     procedure Delete( this : in out A_Audio_Player ); 
  35.     pragma Postcondition( this = null ); 
  36.  
  37. private 
  38.  
  39.     use Allegro.Audio; 
  40.     use Resources; 
  41.  
  42.     type Sound; 
  43.     type A_Sound is access all Sound; 
  44.  
  45.     package Sound_Maps is new 
  46.         Ada.Containers.Indefinite_Hashed_Maps( String, 
  47.                                                A_Sound, 
  48.                                                Ada.Strings.Hash_Case_Insensitive, 
  49.                                                Ada.Strings.Equal_Case_Insensitive, 
  50.                                                "=" ); 
  51.  
  52.     ---------------------------------------------------------------------------- 
  53.  
  54.     type Audio_Player is new Limited_Object and Process and Event_Listener with 
  55.         record 
  56.             voice       : A_Allegro_Voice := null; 
  57.             mixer       : A_Allegro_Mixer := null; 
  58.             corral      : A_Corral := null; 
  59.             musicRes    : A_Resource_File := null; 
  60.             musicStream : A_Allegro_Audio_Stream := null; 
  61.             sounds      : Sound_Maps.Map; 
  62.         end record; 
  63.  
  64.     procedure Construct( this : access Audio_Player; corral : not null A_Corral ); 
  65.  
  66.     procedure Delete( this : in out Audio_Player ); 
  67.  
  68.     -- Handles Play_Music, Stop_Music, and Play_Sound events. 
  69.     procedure Handle_Event( this : access Audio_Player; 
  70.                             evt  : in out A_Event; 
  71.                             resp : out Response_Type ); 
  72.     pragma Precondition( evt /= null ); 
  73.  
  74.     function Get_Process_Name( this : access Audio_Player ) return String; 
  75.  
  76.     procedure Tick( this : access Audio_Player; time : Tick_Time ); 
  77.  
  78. end Audio_Players;