OSDN Git Service

Merge branch 'develop' into macos-develop
[hengbandforosx/hengbandosx.git] / src / cocoa / SoundAndMusic.mm
1 /**
2  * \file SoundAndMusic.m
3  * \brief Define interface to sound and music configuration panel used by the
4  * OS X front end.
5  *
6  * Copyright (c) 2023 Eric Branlund
7  *
8  * This work is free software; you can redistribute it and/or modify it
9  * under the terms of either:
10  *
11  * a) the GNU General Public License as published by the Free Software
12  *    Foundation, version 2, or
13  *
14  * b) the "Angband licence":
15  *    This software may be copied and distributed for educational, research,
16  *    and not for profit purposes provided that this copyright and statement
17  *    are included in all such copies.  Other copyrights may also apply.
18  */
19
20 #import "SoundAndMusic.h"
21
22
23 @implementation SoundAndMusicPanelController
24
25 /*
26  * Don't use the implicit @synthesize since this property is declared in a
27  * superclass, NSWindowController.
28  */
29 @dynamic window;
30
31
32 /*
33  * Handle property methods where need more than is provided by the default
34  * synthesis.
35  */
36 - (BOOL)isSoundEnabled
37 {
38         return ([self soundEnabledControl]
39                 && [self soundEnabledControl].state != NSControlStateValueOff)
40                 ? YES : NO;
41 }
42
43
44 - (void)setSoundEnabled:(BOOL)v
45 {
46         if ([self soundEnabledControl]) {
47                 [self soundEnabledControl].state = (v) ?
48                         NSControlStateValueOn : NSControlStateValueOff;
49         }
50 }
51
52
53 - (NSInteger)soundVolume
54 {
55         return ([self soundVolumeControl]) ?
56                 [self soundVolumeControl].integerValue : 100;
57 }
58
59
60 - (void)setSoundVolume:(NSInteger)v
61 {
62         if ([self soundVolumeControl]) {
63                 if (v < 1) {
64                         v = 1;
65                 } else if (v > 100) {
66                         v = 100;
67                 }
68                 [self soundVolumeControl].integerValue = v;
69         }
70 }
71
72
73 - (BOOL)isMusicEnabled
74 {
75         return ([self musicEnabledControl]
76                 && [self musicEnabledControl].state != NSControlStateValueOff)
77                 ? YES : NO;
78 }
79
80
81 - (void)setMusicEnabled:(BOOL)v
82 {
83         if ([self musicEnabledControl]) {
84                 [self musicEnabledControl].state = (v) ?
85                         NSControlStateValueOn : NSControlStateValueOff;
86         }
87 }
88
89
90 - (BOOL)isMusicPausedWhenInactive
91 {
92         return ([self musicPausedWhenInactiveControl]
93                 && [self musicPausedWhenInactiveControl].state
94                 != NSControlStateValueOn) ? NO : YES;
95 }
96
97
98 - (void)setMusicPausedWhenInactive:(BOOL)v
99 {
100         if ([self musicPausedWhenInactiveControl]) {
101                 [self musicPausedWhenInactiveControl].state =
102                         (v) ? NSControlStateValueOn : NSControlStateValueOff;
103         }
104 }
105
106
107 - (NSInteger)musicVolume
108 {
109         return ([self musicVolumeControl]) ?
110                 [self musicVolumeControl].integerValue : 100;
111 }
112
113
114 - (void)setMusicVolume:(NSInteger)v
115 {
116         if ([self musicVolumeControl]) {
117                 if (v < 1) {
118                         v = 1;
119                 } else if (v > 100) {
120                         v = 100;
121                 }
122                 [self musicVolumeControl].integerValue = v;
123         }
124 }
125
126
127 - (NSInteger)musicTransitionTime
128 {
129         return ([self musicTransitionTimeControl]) ?
130                 [self musicTransitionTimeControl].integerValue : 0;
131 }
132
133
134 - (void)setMusicTransitionTime:(NSInteger)v
135 {
136         if ([self musicTransitionTimeControl]) {
137                 if (v < 0) {
138                         v = 0;
139                 } else if (v > [self musicTransitionTimeControl].maxValue) {
140                         v = (NSInteger)([self musicTransitionTimeControl].maxValue);
141                 }
142                 [self musicTransitionTimeControl].integerValue = v;
143         }
144 }
145
146
147 /**
148  * Supply the NSWindowDelegate's windowWillClose method to relay the close
149  * message through the SoundAndMusicChanges protocol.
150  */
151 - (void)windowWillClose:(NSNotification *)notification
152 {
153         if ([self changeHandler]) {
154                 [[self changeHandler] soundAndMusicPanelWillClose];
155         }
156 }
157
158
159 /**
160  * Override the NSWindowController property getter to get the appropriate nib
161  * file.
162  */
163 - (NSString *)windowNibName
164 {
165         return @"SoundAndMusic";
166 }
167
168
169 /**
170  * Override the NSWindowController function to set some attributes on the
171  * window.
172  */
173 - (void)windowDidLoad
174 {
175         [super windowDidLoad];
176         self.window.floatingPanel = YES;
177         self.window.becomesKeyOnlyIfNeeded = YES;
178         [self.window center];
179         self.window.delegate = self;
180 }
181
182
183 - (IBAction)respondToSoundEnabledToggle:(id)sender
184 {
185         if ([self changeHandler]) {
186                 [[self changeHandler] changeSoundEnabled:self.isSoundEnabled];
187         }
188 }
189
190
191 - (IBAction)respondToSoundVolumeSlider:(id)sender
192 {
193         if ([self changeHandler]) {
194                 [[self changeHandler] changeSoundVolume:self.soundVolume];
195         }
196 }
197
198
199 - (IBAction)respondToMusicEnabledToggle:(id)sender
200 {
201         if ([self changeHandler]) {
202                 [[self changeHandler] changeMusicEnabled:self.isMusicEnabled];
203         }
204 }
205
206
207 - (IBAction)respondToMusicPausedWhenInactiveToggle:(id)sender
208 {
209         if ([self changeHandler]) {
210                 [[self changeHandler] changeMusicPausedWhenInactive:self.isMusicPausedWhenInactive];
211         }
212 }
213
214
215 - (IBAction)respondToMusicVolumeSlider:(id)sender
216 {
217         if ([self changeHandler]) {
218                 [[self changeHandler] changeMusicVolume:self.musicVolume];
219         }
220 }
221
222
223 - (IBAction)respondToMusicTransitionTimeSlider:(id)sender
224 {
225         if ([self changeHandler]) {
226                 [[self changeHandler] changeMusicTransitionTime:self.musicTransitionTime];
227         }
228 }
229
230 @end