3 * \brief Declare an interface for handling incidental sounds and background
4 * music in the OS X front end.
6 #ifndef INCLUDED_ANGBAND_AUDIO_H
7 #define INCLUDED_ANGBAND_AUDIO_H
9 #import <AVFAudio/AVFAudio.h>
11 @class AngbandAudioManager;
14 @interface AngbandActiveAudio : NSObject <AVAudioPlayerDelegate> {
16 AVAudioPlayer *player;
20 @property (nonatomic, readonly, getter=isPlaying) BOOL playing;
22 @property (nonatomic, readonly, weak) AngbandActiveAudio *priorAudio;
24 @property (nonatomic, readonly, strong) AngbandActiveAudio *nextAudio;
26 - (id)initWithPlayer:(AVAudioPlayer *)aPlayer fadeInBy:(NSInteger)fadeIn
27 prior:(AngbandActiveAudio *)p paused:(BOOL)isPaused
28 NS_DESIGNATED_INITIALIZER;
30 - (id)init NS_UNAVAILABLE;
38 - (void)fadeOutBy:(NSInteger)t;
40 - (void)changeVolumeTo:(NSInteger)v;
42 /* Methods for internal use to manage the lifetime of the active audio track. */
43 - (void)handleFadeOutTimer:(NSTimer *)timer;
45 - (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)aPlayer
46 successfully:(BOOL)flag;
51 @interface AngbandAudioManager : NSObject {
54 * These are sentinels for the beginning and end, respectively, of
55 * the background muisc tracks currently playing in the order they
58 AngbandActiveAudio *tracksPlayingHead;
59 AngbandActiveAudio *tracksPlayingTail;
62 * Stores instances of AVAudioPlayer keyed by path so the same
63 * incidental sound can be used for multiple events.
65 NSMutableDictionary *soundsByPath;
68 * Stores arrays of AVAudioPlayer instances keyed by event number.
70 NSMutableDictionary *soundArraysByEvent;
73 * Stores paths to music tracks keyed first by the music type and
76 NSMutableDictionary *musicByTypeAndID;
79 * If NO, then do not play beeps or incidental sounds and pause
80 * the background music track if isPausedWhenInactive is YES.
86 * Holds whether a beep will be played. If NO, then playBeep effectively
87 * becomes a do nothing operation.
89 @property (nonatomic, getter=isBeepEnabled) BOOL beepEnabled;
92 * Holds whether incidental sounds will be played. If NO, then playSound
93 * effectively becomes a do nothing operation.
95 @property (nonatomic, getter=isSoundEnabled) BOOL soundEnabled;
98 * Holds the volume (as a percentage, 0 - 100, of the system volume) for
101 @property (nonatomic) NSInteger soundVolume;
104 * Holds whether background music will be played. If NO, then playMusicType
105 * effectively becomes a do nothing operation.
107 @property (nonatomic, getter=isMusicEnabled) BOOL musicEnabled;
110 * Holds whether music is paused when the application is iconified or otherwise
111 * marked as being an inactive application. Beeps and incidental sounds are
112 * never played when the application is an inactive application.
114 @property (nonatomic, getter=isMusicPausedWhenInactive)
115 BOOL musicPausedWhenInactive;
118 * Holds the volume (as a percentage, 0 - 100, of the system volume) for
121 @property (nonatomic) NSInteger musicVolume;
124 * Holds the amount of time, in milliseconds, for transitions between
125 * different music tracks. If less than or equal to zero, there's no
126 * transition interval: one track stops playing and the other starts playing
129 @property (nonatomic) NSInteger musicTransitionTime;
132 * Set up for lazy initialization in playSound() and playMusicType(). Set
133 * appActive to YES, beepEnabled to YES, soundEnabled to YES, soundVolume
134 * to 30, musicEnabled to YES, pausedWhenInactive to YES,
135 * musicVolume to 20, and musicTransitionTime to 3000.
140 * If self.beepEnabed is YES, make a beep.
145 * If self.soundEnabled is YES and the given event has one or more sounds
146 * corresponding to it in the catalog, plays one of those sounds, chosen at
149 - (void)playSound:(int)event;
152 * If self.musicEnabled is YES and the given music type and id exists, play
155 - (void)playMusicType:(int)t ID:(int)i;
158 * Return YES if combination of the given type and ID is in the music
159 * catalog. Otherwise, return NO.
161 - (BOOL)musicExists:(int)t ID:(int)i;
164 * Stop all currently playing music tracks.
166 - (void)stopAllMusic;
169 * Set up to act appropiately if the containing application is inactive.
171 - (void)setupForInactiveApp;
174 * Set up to act appropriately if the containing application is active.
176 - (void)setupForActiveApp;
179 * Impose an arbitrary limit on the number of possible samples for an
180 * incidental sound event or the background music tracks for a type/ID
183 @property (class, nonatomic, readonly) NSInteger maxSamples;
186 * Return the shared audio manager instance, creating it if it does not
189 @property (class, nonatomic, strong, readonly) AngbandAudioManager
193 * Release any resources associated with the shared audio manager.
195 + (void)clearSharedManager;
198 * Help playSound() to set up a catalog of the incidental sounds.
200 + (NSMutableDictionary *)setupSoundArraysByEvent;
203 * Help playMusicType() to set up a catalog of the background music.
205 + (NSMutableDictionary *)setupMusicByTypeAndID;
210 #endif /* include guard */