1 | //
|
---|
2 | // PSMediaAlert.m
|
---|
3 | // Pester
|
---|
4 | //
|
---|
5 | // Created by Nicholas Riley on Tue Apr 08 2003.
|
---|
6 | // Copyright (c) 2003 Nicholas Riley. All rights reserved.
|
---|
7 | //
|
---|
8 |
|
---|
9 | #import "PSMediaAlert.h"
|
---|
10 | #import "NSDictionary-NJRExtensions.h"
|
---|
11 | #import "NJRSoundManager.h"
|
---|
12 |
|
---|
13 | // property list keys
|
---|
14 | static NSString * const PLAlertRepetitions = @"times"; // NSString
|
---|
15 | static NSString * const PLAlertOutputVolume = @"volume"; // NSNumber
|
---|
16 |
|
---|
17 | const float PSMediaAlertNoVolume = 0;
|
---|
18 |
|
---|
19 | @implementation PSMediaAlert
|
---|
20 |
|
---|
21 | #pragma mark initialize-release
|
---|
22 |
|
---|
23 | - (id)initWithRepetitions:(unsigned short)numReps;
|
---|
24 | {
|
---|
25 | if ( (self = [super init]) != nil) {
|
---|
26 | // XXX not DRY, but can't think of a more sensible way
|
---|
27 | if (numReps < 1)
|
---|
28 | numReps = 1;
|
---|
29 | else if (numReps > 99)
|
---|
30 | numReps = 99;
|
---|
31 | repetitions = numReps;
|
---|
32 | }
|
---|
33 | return self;
|
---|
34 | }
|
---|
35 |
|
---|
36 | #pragma mark accessing
|
---|
37 |
|
---|
38 | - (unsigned short)repetitions;
|
---|
39 | {
|
---|
40 | return repetitions;
|
---|
41 | }
|
---|
42 |
|
---|
43 | - (float)outputVolume;
|
---|
44 | {
|
---|
45 | return outputVolume;
|
---|
46 | }
|
---|
47 |
|
---|
48 | - (void)setOutputVolume:(float)volume;
|
---|
49 | {
|
---|
50 | if ([NJRSoundManager volumeIsNotMutedOrInvalid: volume])
|
---|
51 | outputVolume = volume;
|
---|
52 | else
|
---|
53 | outputVolume = PSMediaAlertNoVolume;
|
---|
54 | }
|
---|
55 |
|
---|
56 | #pragma mark property list serialization (Pester 1.1)
|
---|
57 |
|
---|
58 | - (NSDictionary *)propertyListRepresentation;
|
---|
59 | {
|
---|
60 | NSMutableDictionary *plAlert = [[super propertyListRepresentation] mutableCopy];
|
---|
61 | [plAlert setObject: [NSNumber numberWithUnsignedShort: repetitions] forKey: PLAlertRepetitions];
|
---|
62 | if (outputVolume != PSMediaAlertNoVolume) {
|
---|
63 | [plAlert setObject: [NSNumber numberWithFloat: outputVolume] forKey: PLAlertOutputVolume];
|
---|
64 | }
|
---|
65 | return [plAlert autorelease];
|
---|
66 | }
|
---|
67 |
|
---|
68 | - (id)initWithPropertyList:(NSDictionary *)dict;
|
---|
69 | {
|
---|
70 | if ( (self = [self initWithRepetitions: [[dict objectForRequiredKey: PLAlertRepetitions] unsignedShortValue]]) != nil) {
|
---|
71 | [self setOutputVolume: [[dict objectForKey: PLAlertOutputVolume] floatValue]];
|
---|
72 | }
|
---|
73 | return self;
|
---|
74 | }
|
---|
75 |
|
---|
76 | @end
|
---|