-
Notifications
You must be signed in to change notification settings - Fork 1
/
AudIntAppDelegate.m
407 lines (349 loc) · 14.3 KB
/
AudIntAppDelegate.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
//
// AudIntAppDelegate.m
// AudInt
//
// Created by Justin Blinder + Jon Cohrs on 5/3/11.
// Copyright 2011 AUDiNT. All rights reserved.
//
#import "AudIntAppDelegate.h"
@implementation AudIntAppDelegate
@synthesize window;
- (void)awakeFromNib
{
// [window setBackgroundColor:[NSColor colorWithPatternImage:[NSImage imageNamed:@"newbg.png"]]];
encodeImportTrackURL = [[NSString alloc] init];
filePaths = [[NSMutableDictionary alloc] init];
self.window.title = @"GhostCoder";
}
- (void)applicationDidBecomeActive:(NSNotification *)notification
{
[NSApp activateIgnoringOtherApps:YES];
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[NSApp activateIgnoringOtherApps:YES];
}
-(IBAction)encodeAudioFile:(id)sender
{
NSFileManager *manager = [[NSFileManager alloc] init];
switch ([sender tag]) {
case 1:
if(![manager fileExistsAtPath:[filePaths objectForKey:@"encodeInTrack"]])
{
[self promptAlert:@"No Track Selected." altMessage:@"Select A Track."];
}
else if(![manager fileExistsAtPath:[filePaths objectForKey:@"encodeInHidden"]])
{
[self promptAlert:@"No Hidden Track Selected." altMessage:@"Select A Hidden Track."];
}
else if([[encodeSaveToTitle stringValue] isEqualTo:nil] || [[encodeSaveToTitle stringValue] isEqualTo:@""] && [replaceEncodedSong state] == NSOffState)
{
[self promptAlert:@"No Filename Entered." altMessage:@"Enter a filename."];
}
else if ([replaceEncodedSong state] == NSOffState)
{
NSLog(@"%@",[[filePaths objectForKey:@"encodeInTrack"] stringByDeletingLastPathComponent]);
NSString *tempFileA = [NSString stringWithFormat:@"%@/temp1.wav",[[filePaths objectForKey:@"encodeInTrack"] stringByDeletingLastPathComponent]];
NSString *tempFileB = [NSString stringWithFormat:@"%@/temp2.wav",[[filePaths objectForKey:@"encodeInTrack"] stringByDeletingLastPathComponent]];
NSArray *arguments1 = [NSArray arrayWithObjects: [filePaths objectForKey:@"encodeInTrack"], @"-f", @"-S", @"-G", @"-V", @"-b", @"16", @"-r", @"384k",tempFileA, nil];
NSArray *arguments2 = [NSArray arrayWithObjects: [filePaths objectForKey:@"encodeInHidden"], @"-f", @"-S", @"-G", @"-V", @"-b", @"16", @"-r", @"384k", tempFileB,@"gain", @"-n", @"speed", @"70", @"highpass", @"90k", @"pad", @"2", @"0", nil];
// NSArray *arguments3 = [NSArray arrayWithObjects: tempFileA, tempFileB, @"-f", @"-S", @"-G",[filePaths objectForKey:@"encodeOut"], nil];
NSArray *arguments3 = [NSArray arrayWithObjects: @"-m", tempFileA, tempFileB, @"-f", @"-C", @"8", @"-S", @"-G",[filePaths objectForKey:@"encodeOut"],@"gain", @"+6", nil];
NSArray *soxCommands = [NSArray arrayWithObjects:arguments1,arguments2,arguments3,nil];
[self processAudio:soxCommands];
}
else
{
NSLog(@"%@",[[filePaths objectForKey:@"encodeInTrack"] stringByDeletingLastPathComponent]);
NSString *tempFileA = [NSString stringWithFormat:@"%@/temp1.wav",[[filePaths objectForKey:@"encodeInTrack"] stringByDeletingLastPathComponent]];
NSString *tempFileB = [NSString stringWithFormat:@"%@/temp2.wav",[[filePaths objectForKey:@"encodeInTrack"] stringByDeletingLastPathComponent]];
NSArray *arguments1 = [NSArray arrayWithObjects: [filePaths objectForKey:@"encodeInTrack"], @"-f", @"-S", @"-G", @"-V", @"-b", @"16", @"-r", @"44.1k",tempFileA, nil];
NSArray *arguments2 = [NSArray arrayWithObjects: [filePaths objectForKey:@"encodeInHidden"], @"-f", @"-S", @"-G", @"-V", @"-b", @"16", @"-r", @"384k", tempFileB,@"gain", @"-n", @"speed", @"70", @"highpass", @"90k", @"pad", @"2", @"0", nil];
// NSArray *arguments3 = [NSArray arrayWithObjects: tempFileA, tempFileB, @"-f", @"-S", @"-G",[filePaths objectForKey:@"encodeInTrack"], nil];
NSArray *arguments3 = [NSArray arrayWithObjects: @"-m", tempFileA, tempFileB, @"-f", @"-C", @"8", @"-S", @"-G",[filePaths objectForKey:@"encodeInTrack"],@"gain", @"+6", nil];
NSArray *soxCommands = [NSArray arrayWithObjects:arguments1,arguments2,arguments3,nil];
[self processAudio:soxCommands];
}
break;
case 2:
if(![manager fileExistsAtPath:[filePaths objectForKey:@"decodeInTrack"]])
{
[self promptAlert:@"No Track Selected." altMessage:@"Select A Track."];
}
else if([[decodeSaveToTitle stringValue] isEqualTo:nil] || [[decodeSaveToTitle stringValue] isEqualTo:@""] && [replaceEncodedSong state] == NSOffState)
{
[self promptAlert:@"No Filename Entered." altMessage:@"Enter a filename."];
}
else if ([replaceDecodedSong state] == NSOffState)
{
NSLog(@"%@",[[filePaths objectForKey:@"encodeInTrack"] stringByDeletingLastPathComponent]);
NSArray *arguments1 = [NSArray arrayWithObjects: [filePaths objectForKey:@"decodeInTrack"], @"-f", @"-S", @"-G", @"-b", @"16", @"-r", @"44.1k",[filePaths objectForKey:@"decodeOut"], @"gain", @"-n", @"trim", @"2", @"5", @"speed", @"0.014", @"highpass", @"200", nil];
NSArray *soxCommands = [NSArray arrayWithObject:arguments1];
[self processAudio:soxCommands];
}
else
{
//./sox vvvvvv.flac justsegment.flac trim 0 5
//./sox vvvvvv.flac justsegment.flac pitch .5
NSLog(@"%@",[[filePaths objectForKey:@"encodeInTrack"] stringByDeletingLastPathComponent]);
// NSArray *arguments1 = [NSArray arrayWithObjects: [filePaths objectForKey:@"decodeInTrack"], @"-f", @"-S", @"-G", @"-b", @"16", @"-r", @"44.1k",[filePaths objectForKey:@"decodeInTrack"],@"trim", @"0", @"5", @"speed", @"0.015", nil];
NSArray *arguments1 = [NSArray arrayWithObjects: [filePaths objectForKey:@"decodeInTrack"], @"-f", @"-S", @"-G", @"-b", @"16", @"-r", @"44.1k",[filePaths objectForKey:@"decodeInTrack"], @"gain", @"-n", @"trim", @"2", @"5", @"speed", @"0.014", @"highpass", @"200", nil];
NSArray *soxCommands = [NSArray arrayWithObject:arguments1];
[self processAudio:soxCommands];
}
break;
default:
break;
}
[manager release];
// {
/*
NSFileManager *manager = [[NSFileManager alloc] init];
NSArray *arguments1;
arguments1 = [NSArray arrayWithObjects: @"/Users/novatheory/Desktop/testing/Vampire Weekend - Giving Up The Gun_test.flac", @"-f", @"-S", @"-G", @"-V", @"-b", @"24", @"-r", @"384k", @"/Users/novatheory/Desktop/testing/temp.wav", nil];
NSArray *arguments2;
arguments2 = [NSArray arrayWithObjects: @"/Users/novatheory/Desktop/testing/Vampire Weekend - Giving Up The Gun-embeded-6x.flac", @"-f", @"-S", @"-G", @"-V", @"-b", @"24", @"-r", @"384k", @"/Users/novatheory/Desktop/testing/temp2.wav", @"speed", @"80", @"highpass", @"60k", nil];
NSArray *arguments3;
//sox -m $ouput.wav $encode_output.wav -f -S -G $embed_output.flac
arguments3 = [NSArray arrayWithObjects: @"/Users/novatheory/Desktop/testing/temp.wav",@"/Users/novatheory/Desktop/testing/temp2.wav", @"-f", @"-S", @"-G",@"/Users/novatheory/Desktop/testing/final.flac", nil];
//if([manager fileExistsAtPath:[encodeImportTrackURL path]] && [manager fileExistsAtPath:[encodeImportDiscreteURL path]])
// {
NSLog(@"sender: %@", [sender alternateTitle]);
NSTask *task;
task = [[NSTask alloc] init];
[task setStandardInput:[NSPipe pipe]]; //allows for nslog when using bash
[task setLaunchPath:path];
[task setArguments: arguments1];
NSPipe *pipe;
pipe = [NSPipe pipe];
[task setStandardOutput: pipe];
NSFileHandle *file;
file = [pipe fileHandleForReading];
[task launch];
//NSData *data;
// data = [file readDataToEndOfFile];
//
// NSString *string;
// string = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
//
// NSLog (@"stuff :\n%@", string);
//
// [string release];
[task waitUntilExit];
[task release];
task = [[NSTask alloc] init];
[task setStandardInput:[NSPipe pipe]]; //allows for nslog when using bash
[task setLaunchPath:path];
[task setArguments: arguments2];
pipe = [NSPipe pipe];
[task setStandardOutput: pipe];
file = [pipe fileHandleForReading];
[task launch];
[task waitUntilExit];
[task release];
task = [[NSTask alloc] init];
[task setStandardInput:[NSPipe pipe]]; //allows for nslog when using bash
[task setLaunchPath:path];
[task setArguments: arguments3];
pipe = [NSPipe pipe];
[task setStandardOutput: pipe];
file = [pipe fileHandleForReading];
[task launch];
[task waitUntilExit];
[task release];
//data = [file readDataToEndOfFile];
// string = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
//}
//else
// {
//error
// }
*/
}
-(void)processAudio:(NSArray *)commands
{
[conversionProgress setHidden:NO];
[conversionProgress startAnimation:self];
NSString *path=[[NSBundle mainBundle] pathForResource:@"sox" ofType:nil];
[self disableInterfaceElements];
for(id obj in commands)
{
NSTask *task;
task = [[NSTask alloc] init];
[task setStandardInput:[NSPipe pipe]];
[task setLaunchPath:path];
[task setArguments: obj];
NSPipe *pipe;
pipe = [NSPipe pipe];
[task setStandardOutput: pipe];
// NSFileHandle *file;
// file = [pipe fileHandleForReading];
//// NSData *data;
//// data = [file readDataToEndOfFile];
////
//// NSString *string;
//// string = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
//// [rawOutput setStringValue:string];
////// NSLog (@"stuff :\n%@", string);
[task launch];
[task waitUntilExit];
[task release];
}
if([commands count] == 3) [self cleanUp]; //delete temp files
[conversionProgress stopAnimation:self];
[conversionProgress setHidden:YES];
[self enableInterfaceElements]; //enabel interface
}
-(IBAction)manageInterface:(id)sender
{
switch ([sender tag]) {
case 1:
if([sender state] == NSOnState)
{
[encodeSaveTo setEnabled:NO];
[encodeSaveToTitle setEnabled:NO];
}
else if([sender state] == NSOffState)
{
[encodeSaveTo setEnabled:YES];
[encodeSaveToTitle setEnabled:YES];
}
break;
case 2:
if([sender state] == NSOnState)
{
[decodeSaveTo setEnabled:NO];
[decodeSaveToTitle setEnabled:NO];
}
else if([sender state] == NSOffState)
{
[decodeSaveTo setEnabled:YES];
[decodeSaveToTitle setEnabled:YES];
}
break;
default:
break;
}
}
-(IBAction)openFile:(id)sender
{
NSOpenPanel *oPanel = [[NSOpenPanel openPanel] retain];
[oPanel setCanChooseDirectories:NO];
[oPanel setCanChooseFiles:YES];
[oPanel setCanCreateDirectories:NO];
switch([oPanel runModal])
{
case NSFileHandlingPanelOKButton:
{
switch([sender tag])
{
case 1:
encodeImportTrackURL = [[NSString alloc] initWithString:[[oPanel URL] path]];
[filePaths setObject:encodeImportTrackURL forKey:@"encodeInTrack"];
[encodeImportTrack setStringValue:encodeImportTrackURL];
NSLog(@"URL import: %@", encodeImportTrackURL );
break;
case 2:
encodeImportDiscreteURL = [[NSString alloc] initWithString:[[oPanel URL] path]];
[filePaths setObject:encodeImportDiscreteURL forKey:@"encodeInHidden"];
[encodeImportDiscrete setStringValue:encodeImportDiscreteURL];
NSLog(@"URL import: %@", encodeImportDiscreteURL );
break;
case 3:
decodeImportTrackURL = [[NSString alloc] initWithString:[[oPanel URL] path]];
[filePaths setObject:decodeImportTrackURL forKey:@"decodeInTrack"];
[decodedImportTrack setStringValue:decodeImportTrackURL];
NSLog(@"URL import: %@", encodeImportDiscreteURL );
break;
default:
break;
}
}
case NSFileHandlingPanelCancelButton:
{
return;
}
}
[oPanel release];
}
-(void)disableInterfaceElements
{
[encodeButton setEnabled:NO];
[importTrack setEnabled:NO];
[encodeSaveTo setEnabled:NO];
[replaceEncodedSong setEnabled:NO];
[encodeSaveToTitle setEnabled:NO];
[encodeImportTrack setEnabled:NO];
[encodeImportDiscrete setEnabled:NO];
[decodeSaveTo setEnabled:NO];
[replaceDecodedSong setEnabled:NO];
[decodeSaveToTitle setEnabled:NO];
[decodedImportTrack setEnabled:NO];
}
-(void)enableInterfaceElements
{
[encodeButton setEnabled:YES];
[importTrack setEnabled:YES];
[encodeSaveTo setEnabled:YES];
[replaceEncodedSong setEnabled:YES];
[encodeSaveToTitle setEnabled:YES];
[encodeImportTrack setEnabled:YES];
[encodeImportDiscrete setEnabled:YES];
[decodeSaveTo setEnabled:YES];
[replaceDecodedSong setEnabled:YES];
[decodeSaveToTitle setEnabled:YES];
[decodedImportTrack setEnabled:YES];
}
-(void)promptAlert:(NSString *)mainText altMessage:(NSString *)altText
{
NSAlert *alert = [[[NSAlert alloc] init] autorelease];
[alert addButtonWithTitle:@"OK"];
[alert setMessageText:mainText];
[alert setInformativeText:altText];
[alert setAlertStyle:NSWarningAlertStyle];
[alert beginSheetModalForWindow:[self window] modalDelegate:self didEndSelector:nil contextInfo:nil];
}
-(IBAction)openDir:(id)sender
{
NSSavePanel *savePanel = [NSSavePanel savePanel];
// [savePanel setAllowedFileTypes:[NSArray arrayWithObject:@"txt"]];
int tvarInt = [savePanel runModal];
if(tvarInt == NSOKButton)
{
NSLog(@"do Save As we have an OK button");
}
else if(tvarInt == NSCancelButton)
{
return;
}
else
{
return;
}
NSString * saveDir = [savePanel directory];
NSString * saveFile = [savePanel filename];
NSLog(@"%@",[filePaths objectForKey:@"encodeOut"]);
switch([sender tag])
{
case 1:
[filePaths setObject:[NSString stringWithFormat:@"%@.flac",saveFile] forKey:@"encodeOut"];
[encodeSaveToTitle setStringValue: [filePaths objectForKey:@"encodeOut"]];
break;
case 2:
[filePaths setObject:[NSString stringWithFormat:@"%@.wav",saveFile] forKey:@"decodeOut"];
[decodeSaveToTitle setStringValue: [filePaths objectForKey:@"decodeOut"]];
break;
default:
break;
}
}
-(void)cleanUp
{
NSFileManager *manager = [[NSFileManager alloc] init];
BOOL isDir;
NSString *tempFileA = [NSString stringWithFormat:@"%@/temp1.wav",[[filePaths objectForKey:@"encodeInTrack"] stringByDeletingLastPathComponent]];
NSString *tempFileB = [NSString stringWithFormat:@"%@/temp2.wav",[[filePaths objectForKey:@"encodeInTrack"] stringByDeletingLastPathComponent]];
if([manager fileExistsAtPath:tempFileA]) [manager removeItemAtPath:tempFileA error:nil];
if([manager fileExistsAtPath:tempFileB]) [manager removeItemAtPath:tempFileB error:nil];
}
@end