2
* recordmediawindowcontroller.m - record media
5
* Christian Vogelgsang <chris@vogelgsang.org>
7
* This file is part of VICE, the Versatile Commodore Emulator.
8
* See README for copyright notice.
10
* This program is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2 of the License, or
13
* (at your option) any later version.
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
20
* You should have received a copy of the GNU General Public License
21
* along with this program; if not, write to the Free Software
22
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
27
#import "recordmediawindowcontroller.h"
28
#import "viceapplication.h"
29
#import "vicenotifications.h"
31
@implementation RecordMediaWindowController
35
self = [super initWithWindowNibName:@"RecordMedia"];
36
[self registerForResourceUpdate:@selector(updateResources:)];
42
[currentMediaType release];
43
[currentMediaFormats release];
49
[mediaFileName setStringValue:@"capture"];
50
[stopRecord setEnabled:FALSE];
52
[self setupMediaType];
53
[self updateMediaType];
54
[self updateResources:nil];
56
[super windowDidLoad];
59
-(void)updateAudioBitrate
61
NSString *res = [NSString stringWithFormat:@"%@AudioBitrate",currentMediaType];
62
int value = [self getIntResource:res];
63
[audioBitrate setIntValue:value];
66
-(void)updateVideoBitrate
68
NSString *res = [NSString stringWithFormat:@"%@VideoBitrate",currentMediaType];
69
int value = [self getIntResource:res];
70
[videoBitrate setIntValue:value];
73
-(void)updateVideoFormat
75
// get current video format
76
NSString *res = [NSString stringWithFormat:@"%@VideoCodec",currentMediaType];
77
int codecId = [self getIntResource:res];
78
NSString *codecName = (NSString *)[currentVideoFormats objectForKey:[NSNumber numberWithInt:codecId]];
80
[videoFormat selectItemWithTitle:codecName];
84
-(void)updateAudioFormat
86
// get current video format
87
NSString *res = [NSString stringWithFormat:@"%@AudioCodec",currentMediaType];
88
int codecId = [self getIntResource:res];
89
NSString *codecName = (NSString *)[currentAudioFormats objectForKey:[NSNumber numberWithInt:codecId]];
91
[audioFormat selectItemWithTitle:codecName];
95
-(void)replaceFileNameExtension:(BOOL)force
97
NSString *fileName = [mediaFileName stringValue];
99
// if not forced only replace if there is no extension
102
doit = [[fileName pathExtension] length] == 0;
106
fileName = [fileName stringByDeletingPathExtension];
107
NSString *result = [NSString stringWithFormat:@"%@.%@",fileName,currentDefaultExtension];
108
[mediaFileName setStringValue:result];
112
-(void)fetchDefaultExtension
114
[currentDefaultExtension release];
115
currentDefaultExtension = [[VICEApplication theMachineController]
116
defaultExtensionForMediaDriver:currentMediaType
117
andFormat:currentMediaFormat];
118
[currentDefaultExtension retain];
120
[self replaceFileNameExtension:TRUE];
123
-(void)updateMediaFormat
125
if(!currentMediaTypeHasOptions)
128
// get current format
129
NSString *res = [NSString stringWithFormat:@"%@Format",currentMediaType];
130
[currentMediaFormat release];
131
currentMediaFormat = [self getStringResource:res];
132
[currentMediaFormat retain];
134
[self fetchDefaultExtension];
137
[mediaFormat selectItemWithTitle:currentMediaFormat];
139
// find media format in description and setup audio and video codecs
141
for(i=0;i<[currentMediaFormats count];i++) {
142
NSArray *fa = (NSArray *)[currentMediaFormats objectAtIndex:i];
143
NSString *formatName = (NSString *)[fa objectAtIndex:0];
145
// set audio and video codecs for current format
146
if([currentMediaFormat compare:formatName]==NSOrderedSame) {
147
currentVideoFormats = (NSDictionary *)[fa objectAtIndex:1];
148
currentAudioFormats = (NSDictionary *)[fa objectAtIndex:2];
150
[videoFormat removeAllItems];
151
[videoFormat addItemsWithTitles:[currentVideoFormats allValues]];
153
[audioFormat removeAllItems];
154
[audioFormat addItemsWithTitles:[currentAudioFormats allValues]];
156
BOOL hasVideoFormats = [currentVideoFormats count] > 0;
157
BOOL hasAudioFormats = [currentAudioFormats count] > 0;
159
[videoFormat setEnabled:hasVideoFormats];
160
[videoBitrate setEnabled:hasVideoFormats];
161
[audioFormat setEnabled:hasAudioFormats];
162
[audioBitrate setEnabled:hasAudioFormats];
168
// set the correct format
169
[self updateAudioFormat];
170
[self updateVideoFormat];
171
[self updateAudioBitrate];
172
[self updateVideoBitrate];
175
-(void)updateMediaType
177
// fetch media type from pop up button
178
[currentMediaType release];
179
currentMediaType = [[mediaType selectedItem] title];
180
[currentMediaType retain];
182
// ask the machine controller if the media type has options
183
currentMediaTypeHasOptions = [[VICEApplication theMachineController] mediaDriverHasOptions:currentMediaType];
184
BOOL hasOptions = currentMediaTypeHasOptions;
186
// enable/disable options
187
[mediaFormat setEnabled:hasOptions];
188
[videoFormat setEnabled:hasOptions];
189
[videoBitrate setEnabled:hasOptions];
190
[audioFormat setEnabled:hasOptions];
191
[audioBitrate setEnabled:hasOptions];
194
// fetch all formats and video/audio codecs from machine controller
195
[currentMediaFormats release];
196
currentMediaFormats = [[VICEApplication theMachineController] enumMediaFormats:currentMediaType];
197
[currentMediaFormats retain];
200
[mediaFormat removeAllItems];
202
for(i=0;i<[currentMediaFormats count];i++) {
203
NSArray *fa = (NSArray *)[currentMediaFormats objectAtIndex:i];
204
NSString *formatName = (NSString *)[fa objectAtIndex:0];
205
[mediaFormat addItemWithTitle:formatName];
208
// set current format and setup audio video codecs
209
[self updateMediaFormat];
211
[currentMediaFormat release];
212
currentMediaFormat = nil;
213
[self fetchDefaultExtension];
217
-(void)setupMediaType
219
[mediaType removeAllItems];
220
[mediaType addItemsWithTitles:[[VICEApplication theMachineController] enumMediaDrivers]];
223
-(void)updateResources:(NSNotification *)notification
225
[self updateMediaFormat];
228
// ----- Actions -----
230
-(IBAction)startRecording:(id)sender
232
int canvasId = [VICEApplication currentCanvasId];
233
NSString *fileName = [mediaFileName stringValue];
234
NSString *driver = [[mediaType selectedItem] title];
236
BOOL ok = [[VICEApplication theMachineController] startRecordingMedia:driver
240
[VICEApplication runErrorMessage:@"Can't start media recording!"];
242
// still recording? enable stop button
243
if([[VICEApplication theMachineController] isRecordingMedia]) {
244
[stopRecord setEnabled:TRUE];
245
[startRecord setEnabled:FALSE];
246
[mediaFileName setEnabled:FALSE];
247
[mediaFileNamePicker setEnabled:FALSE];
252
-(IBAction)stopRecording:(id)sender
254
[[VICEApplication theMachineController] stopRecordingMedia];
256
[stopRecord setEnabled:FALSE];
257
[startRecord setEnabled:TRUE];
258
[mediaFileName setEnabled:TRUE];
259
[mediaFileNamePicker setEnabled:TRUE];
262
-(IBAction)changedMediaFileName:(id)sender
264
[self replaceFileNameExtension:FALSE];
267
-(IBAction)pickMediaFileName:(id)sender
269
NSString *title = [NSString stringWithFormat:@"Record %@ Media",currentDefaultExtension];
270
NSString *fileName = [self pickSaveFileWithTitle:title types:[NSArray arrayWithObjects:currentDefaultExtension,nil]];
272
[mediaFileName setStringValue:fileName];
276
-(IBAction)changedMediaType:(id)sender
278
[self updateMediaType];
281
-(IBAction)changedMediaFormat:(id)sender
283
NSString *res = [NSString stringWithFormat:@"%@Format",currentMediaType];
284
[self setStringResource:res toValue:[mediaFormat titleOfSelectedItem]];
285
[self updateMediaFormat];
288
-(IBAction)changedAudioFormat:(id)sender
290
NSString *curFormat = [audioFormat titleOfSelectedItem];
291
NSArray *keys = [currentAudioFormats allKeysForObject:curFormat];
292
if([keys count]==1) {
293
NSString *res = [NSString stringWithFormat:@"%@AudioCodec",currentMediaType];
294
int value = [(NSNumber *)[keys objectAtIndex:0] intValue];
295
[self setIntResource:res toValue:value];
296
[self updateAudioFormat];
300
-(IBAction)changedAudioBitrate:(id)sender
302
NSString *res = [NSString stringWithFormat:@"%@AudioBitrate",currentMediaType];
303
int value = [audioBitrate intValue];
304
[self setIntResource:res toValue:value];
305
[self updateAudioBitrate];
308
-(IBAction)changedVideoFormat:(id)sender
310
NSString *curFormat = [videoFormat titleOfSelectedItem];
311
NSArray *keys = [currentVideoFormats allKeysForObject:curFormat];
312
if([keys count]==1) {
313
NSString *res = [NSString stringWithFormat:@"%@VideoCodec",currentMediaType];
314
int value = [(NSNumber *)[keys objectAtIndex:0] intValue];
315
[self setIntResource:res toValue:value];
316
[self updateVideoFormat];
320
-(IBAction)changedVideoBitrate:(id)sender
322
NSString *res = [NSString stringWithFormat:@"%@VideoBitrate",currentMediaType];
323
int value = [videoBitrate intValue];
324
[self setIntResource:res toValue:value];
325
[self updateVideoBitrate];