I’m new to programming and stackoverflow and have decided to start by learning objective c.
In at the deep end, I know.
I am stuck trying to work out the best way to parse an edl file.
It is basically an ASCII text file of no more than 100KB.
Here is the structure of a typical cmx3600 edl:
TITLE: EP1 FINAL.EDL SECTION2
FCM: NON-DROP FRAME
001 A199_C00 V C 20:38:24:15 20:38:26:04 10:30:00:02 10:30:01:16
* SOURCE FILE: A199_C008_0915AH_001
002 A199_C00 V C 20:34:48:17 20:34:51:23 10:30:01:16 10:30:04:22
* SOURCE FILE: A199_C007_0915VE_001
I’m trying to work out the best way to parse or scan each element into fields/arrays ie,
editNum = 001
tapeName = A199_C00
channel = V
Operation = C
sourceIn = 20:38:24:15
sourceOut = 20:38:26:04
recIn = 10:30:00:02
recOut = 10:30:01:16
sourceFile = A199_C008_0915AH_001
This is my code so far:
-(IBAction)importEdl:(id)sender {
//defines an Array of allowed file types with file extension ".EDL and .edl"
NSOpenPanel *myPanel = [NSOpenPanel openPanel];
NSArray *fileTypes = [NSArray arrayWithObjects:@"EDL", @"edl", nil];
myPanel.allowedFileTypes = fileTypes;
myPanel.allowsMultipleSelection = NO;
if ([myPanel runModal] == NSOKButton)
{
NSString *theFilePath = [myPanel filename];
NSString *psEdlFile = [NSString stringWithContentsOfFile:theFilePath encoding:NSASCIIStringEncoding error:NULL];
// Reads the file as one string. EDL's are simple ASCII text files of roughly 50KB.
NSArray *psEdlLines = [psEdlFile componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
// Separates the data into lines.
if([psEdlLines count] == 0)
{
NSLog(@"Error!");
} //prints error if EDL file has no events.
NSUInteger count;
int i;
for (i = 0, count = [psEdlLines count]; i < count; i = i + 1)
{
NSString *lineStrings = [psEdlLines objectAtIndex:i];
NSLog(@"Line %d is %@",i+1,lineStrings);
//NSArray *linesEnum = [psEdlLines objectAtIndex:i];
//this creates an array of lines
//NSLog(@"index is: %d %@",i, linesEnum);
}
}
}
@end
The output is:
2012-03-20 15:22:08.956 TestProgram[412:903] Line 1 is TITLE: EP1 FINAL.EDL SECTION2
2012-03-20 15:22:08.957 TestProgram[412:903] Line 2 is FCM: NON-DROP FRAME
2012-03-20 15:22:08.957 TestProgram[412:903] Line 3 is 001 A199_C00 V C 20:38:24:15 20:38:26:04 10:30:00:02 10:30:01:16
2012-03-20 15:22:08.957 TestProgram[412:903] Line 4 is * SOURCE FILE: A199_C008_0915AH_001
2012-03-20 15:22:08.957 TestProgram[412:903] Line 5 is 002 A199_C00 V C 20:34:48:17 20:34:51:23 10:30:01:16 10:30:04:22
2012-03-20 15:22:08.957 TestProgram[412:903] Line 6 is * SOURCE FILE: A199_C007_0915VE_001
2012-03-20 15:22:08.957 TestProgram[412:903] Line 7 is 003 A199_C00 V C 20:42:32:01 20:42:35:19 10:30:04:22 10:30:08:15
2012-03-20 15:22:08.957 TestProgram[412:903] Line 8 is * SOURCE FILE: A199_C009_0915RX_001
2012-03-20 15:22:08.957 TestProgram[412:903] Line 9 is
2012-03-20 15:22:08.958 TestProgram[412:903] Line 10 is
I haven’t got very far as you can see.
Any ideas would be much appreciated.
Thanks in advance,
Pete.
More Progress.
Outputs the following.