Commit | Line | Data |
---|---|---|
ef79bbde P |
1 | #import "PluginController.h" |
2 | #include "stdafx.h" | |
3 | #include "externals.h" | |
4 | ||
5 | #define APP_ID @"net.sf.peops.SPUPlugin" | |
6 | #define PrefsKey APP_ID @" Settings" | |
7 | ||
8 | static PluginController *pluginController; | |
9 | char * pConfigFile=NULL; | |
10 | ||
11 | void DoAbout() | |
12 | { | |
13 | // Get parent application instance | |
14 | NSApplication *app = [NSApplication sharedApplication]; | |
15 | NSBundle *bundle = [NSBundle bundleWithIdentifier:APP_ID]; | |
16 | ||
17 | // Get Credits.rtf | |
18 | NSString *path = [bundle pathForResource:@"Credits" ofType:@"rtf"]; | |
19 | NSAttributedString *credits; | |
20 | if (path) { | |
21 | credits = [[[NSAttributedString alloc] initWithPath: path | |
22 | documentAttributes:NULL] autorelease]; | |
23 | } else { | |
24 | credits = [[[NSAttributedString alloc] initWithString:@""] autorelease]; | |
25 | } | |
26 | ||
27 | // Get Application Icon | |
28 | NSImage *icon = [[NSWorkspace sharedWorkspace] iconForFile:[bundle bundlePath]]; | |
29 | NSSize size = NSMakeSize(64, 64); | |
30 | [icon setSize:size]; | |
31 | ||
32 | [app orderFrontStandardAboutPanelWithOptions:[NSDictionary dictionaryWithObjectsAndKeys: | |
33 | [bundle objectForInfoDictionaryKey:@"CFBundleName"], @"ApplicationName", | |
34 | icon, @"ApplicationIcon", | |
35 | [bundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"], @"ApplicationVersion", | |
36 | [bundle objectForInfoDictionaryKey:@"CFBundleVersion"], @"Version", | |
37 | [bundle objectForInfoDictionaryKey:@"NSHumanReadableCopyright"], @"Copyright", | |
38 | credits, @"Credits", | |
39 | nil]]; | |
40 | } | |
41 | ||
42 | ||
43 | long DoConfiguration() | |
44 | { | |
45 | NSWindow *window; | |
46 | ||
47 | if (pluginController == nil) { | |
48 | pluginController = [[PluginController alloc] initWithWindowNibName:@"NetSfPeopsSpuPluginMain"]; | |
49 | } | |
50 | window = [pluginController window]; | |
51 | ||
52 | /* load values */ | |
53 | [pluginController loadValues]; | |
54 | ||
55 | [window center]; | |
56 | [window makeKeyAndOrderFront:nil]; | |
57 | ||
58 | return 0; | |
59 | } | |
60 | ||
61 | void ReadConfig(void) | |
62 | { | |
63 | NSDictionary *keyValues; | |
64 | NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; | |
65 | [defaults registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys: | |
66 | [[NSMutableDictionary alloc] initWithObjectsAndKeys: | |
67 | [NSNumber numberWithBool:YES], @"High Compatibility Mode", | |
68 | [NSNumber numberWithBool:YES], @"SPU IRQ Wait", | |
69 | [NSNumber numberWithBool:NO], @"XA Pitch", | |
70 | [NSNumber numberWithInt:0], @"Interpolation Quality", | |
71 | [NSNumber numberWithInt:1], @"Reverb Quality", | |
72 | nil], PrefsKey, | |
73 | nil]]; | |
74 | ||
75 | keyValues = [defaults dictionaryForKey:PrefsKey]; | |
76 | ||
77 | iUseTimer = [[keyValues objectForKey:@"High Compatibility Mode"] boolValue] ? 2 : 0; | |
78 | iSPUIRQWait = [[keyValues objectForKey:@"SPU IRQ Wait"] boolValue]; | |
79 | iDisStereo = [[keyValues objectForKey:@"Mono Sound Output"] boolValue]; | |
80 | iXAPitch = [[keyValues objectForKey:@"XA Pitch"] boolValue]; | |
81 | ||
82 | iUseInterpolation = [[keyValues objectForKey:@"Interpolation Quality"] intValue]; | |
83 | iUseReverb = [[keyValues objectForKey:@"Reverb Quality"] intValue]; | |
84 | ||
85 | iVolume=1; | |
86 | } | |
87 | ||
88 | @implementation PluginController | |
89 | ||
90 | - (IBAction)cancel:(id)sender | |
91 | { | |
92 | [self close]; | |
93 | } | |
94 | ||
95 | - (IBAction)ok:(id)sender | |
96 | { | |
97 | NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; | |
98 | ||
99 | NSMutableDictionary *writeDic = [NSMutableDictionary dictionaryWithDictionary:keyValues]; | |
100 | [writeDic setObject:[NSNumber numberWithInt:[hiCompBox intValue]] forKey:@"High Compatibility Mode"]; | |
101 | [writeDic setObject:[NSNumber numberWithInt:[irqWaitBox intValue]] forKey:@"SPU IRQ Wait"]; | |
102 | [writeDic setObject:[NSNumber numberWithInt:[monoSoundBox intValue]] forKey:@"Mono Sound Output"]; | |
103 | [writeDic setObject:[NSNumber numberWithInt:[xaSpeedBox intValue]] forKey:@"XA Pitch"]; | |
104 | ||
105 | [writeDic setObject:[NSNumber numberWithInt:[interpolValue intValue]] forKey:@"Interpolation Quality"]; | |
106 | [writeDic setObject:[NSNumber numberWithInt:[reverbValue intValue]] forKey:@"Reverb Quality"]; | |
107 | ||
108 | // write to defaults | |
109 | [defaults setObject:writeDic forKey:PrefsKey]; | |
110 | [defaults synchronize]; | |
111 | ||
112 | // and set global values accordingly | |
113 | ReadConfig(); | |
114 | ||
115 | [self close]; | |
116 | } | |
117 | ||
118 | - (IBAction)reset:(id)sender | |
119 | { | |
120 | NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; | |
121 | [defaults removeObjectForKey:PrefsKey]; | |
122 | [self loadValues]; | |
123 | } | |
124 | ||
125 | - (void)loadValues | |
126 | { | |
127 | NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; | |
128 | ||
129 | ReadConfig(); | |
130 | ||
131 | /* load from preferences */ | |
132 | [keyValues release]; | |
133 | keyValues = [[defaults dictionaryForKey:PrefsKey] retain]; | |
134 | ||
135 | [hiCompBox setIntValue:[[keyValues objectForKey:@"High Compatibility Mode"] intValue]]; | |
136 | [irqWaitBox setIntValue:[[keyValues objectForKey:@"SPU IRQ Wait"] intValue]]; | |
137 | [monoSoundBox setIntValue:[[keyValues objectForKey:@"Mono Sound Output"] intValue]]; | |
138 | [xaSpeedBox setIntValue:[[keyValues objectForKey:@"XA Pitch"] intValue]]; | |
139 | ||
140 | [interpolValue setIntValue:[[keyValues objectForKey:@"Interpolation Quality"] intValue]]; | |
141 | [reverbValue setIntValue:[[keyValues objectForKey:@"Reverb Quality"] intValue]]; | |
142 | } | |
143 | ||
144 | - (void)awakeFromNib | |
145 | { | |
146 | [interpolValue setStrings:[NSArray arrayWithObjects: | |
147 | @"(No Interpolation)", | |
148 | @"(Simple Interpolation)", | |
149 | @"(Gaussian Interpolation)", | |
150 | @"(Cubic Interpolation)", | |
151 | nil]]; | |
152 | ||
153 | [reverbValue setStrings:[NSArray arrayWithObjects: | |
154 | @"(No Reverb)", | |
155 | @"(Simple Reverb)", | |
156 | @"(PSX Reverb)", | |
157 | nil]]; | |
158 | } | |
159 | ||
160 | @end |