-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyDocument.m
132 lines (98 loc) · 4.17 KB
/
MyDocument.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
//
// MyDocument.m
// CisXView
//
// Created by Fantine on 2/27/11.
// Copyright __MyCompanyName__ 2011 . All rights reserved.
//
#import "MyDocument.h"
@implementation MyDocument
- (id)init
{
self = [super init];
if (self) {
// Add your subclass-specific initialization here.
// If an error occurs here, send a [self release] message and return nil.
}
return self;
}
- (NSString *)windowNibName
{
// Override returning the nib file name of the document
// If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this method and override -makeWindowControllers instead.
return @"MyDocument";
}
- (void)windowControllerDidLoadNib:(NSWindowController *) aController
{
[super windowControllerDidLoadNib:aController];
// Add any code here that needs to be executed once the windowController has loaded the document's window.
}
- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
{
// Insert code here to write your document to data of the specified type. If the given outError != NULL, ensure that you set *outError when returning nil.
// You can also choose to override -fileWrapperOfType:error:, -writeToURL:ofType:error:, or -writeToURL:ofType:forSaveOperation:originalContentsURL:error: instead.
// For applications targeted for Panther or earlier systems, you should use the deprecated API -dataRepresentationOfType:. In this case you can also choose to override -fileWrapperRepresentationOfType: or -writeToFile:ofType: instead.
if ( outError != NULL ) {
*outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL];
}
return nil;
}
- (BOOL)readFromURL:(NSURL *)absoluteURL ofType:(NSString *)pTypeName error:(NSError **)outError
{
NSLog(@"URL: %@ typething: %@",[absoluteURL path],pTypeName);
if([pTypeName isEqualToString:@"CISDataType"])
{
// NSString *data = [NSString stringWithContentsOfURL:absoluteURL encoding:NSMacOSRomanStringEncoding error:outError];
NSData *rawCISHeaderStream = [NSData dataWithContentsOfURL:absoluteURL];
// try segmenting file
// NSFileHandle *rawCISFile = [NSFileHandle fileHandleForReadingAtPath:[absoluteURL path]];
// NSData *rawCISHeaderStream = [rawCISFile readDataOfLength:40];
*outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL];
if (rawCISHeaderStream==nil)
{
NSLog(@"Error Reading file at %@: %@", [absoluteURL path],outError);
return NO;
}
else
{
[self init];
//[rawMIDIByteStream retain];
NSLog(@"implied data length: %lu",[rawCISHeaderStream length]);
// NSScanner? for cis files
// characterAtIndex:
//NSString *CISHeaderID = [rawCISHeaderStream substringToIndex:40];
NSData *cisHeaderData = [rawCISHeaderStream subdataWithRange:NSMakeRange(0,40)];
//UInt8 *pDebugBytes = (UInt8 *)[rawCISHeaderStream bytes];
// pDebugBytes = (UInt8 *)[cisHeaderData bytes];
NSString *cisHeaderText = [[[NSString alloc] initWithData:cisHeaderData encoding:NSASCIIStringEncoding] autorelease];
NSLog(@"CIS Header text:");
NSLog(@"%@",cisHeaderText);
NSRange restOfFile = {40, [rawCISHeaderStream length]-40};
cisRawData = [rawCISHeaderStream subdataWithRange:restOfFile];
//UInt8 *pMIDIFileStream = (UInt8 *)[rawMIDIByteStream bytes];
//standardMIDIFileFormat = pMIDIFileStream[8] << 8 | pMIDIFileStream[9];
//UInt16 nMIDITracks = pMIDIFileStream[10] << 8 | pMIDIFileStream[11];
//standardMIDIFileDivision = pMIDIFileStream[12] << 8 | pMIDIFileStream[13];
//NSLog(@" MThd %d %d %d (0x%x)", standardMIDIFileFormat,nMIDITracks,standardMIDIFileDivision,standardMIDIFileDivision);
return YES;
}
} else {
return [super readFromURL:absoluteURL ofType:pTypeName error:outError];
}
}
- (void) awakeFromNib
{
NSLog(@"myDoc awake from nib ");
if(cisView)
{
NSLog(@"we have a view");
// simply send the rest of the data to the view class to finish parsing
// and set the window from
[(CISRollView *)cisView displayCISLinesFromData:cisRawData];
}
else
{
NSLog(@"** ERROR -- unable to set view class frame and Data Model");
}
}
@end