File: UnixFILE.sc

package info (click to toggle)
supercollider 1%3A3.13.0%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 80,292 kB
  • sloc: cpp: 476,363; lisp: 84,680; ansic: 77,685; sh: 25,509; python: 7,909; makefile: 3,440; perl: 1,964; javascript: 974; xml: 826; java: 677; yacc: 314; lex: 175; objc: 152; ruby: 136
file content (145 lines) | stat: -rw-r--r-- 3,808 bytes parent folder | download | duplicates (5)
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
UnixFILE : IOStream {
	// abstract class. Use File or Pipe.

	classvar <openFiles;
	var fileptr;
	// this only supports file sizes < 2^31 for now

	*closeAll {
		if (openFiles.notNil, {
			openFiles.copy.do({ arg file; file.close; });
		});
		openFiles = nil;
	}
	isOpen {
		^fileptr.notNil
	}

	next { ^this.getChar }
	nextN { arg n;
		^String.fill(n, { this.next; });
	}
	contents {
		^this.readAllString;
	}

	put { arg item; this.write(item); }
	putAll { arg aCollection;
		if (aCollection.isKindOf(RawArray), {
			this.write( aCollection );
		},{
			aCollection.do({ arg item; this.write(item) });
		});
	}

	flush {
		_FileFlush
		^this.primitiveFailed
	}

	write { arg item;
		/* writes any of the following items in big endian byte order:
			a double float,
			a 32 bit int,
			a char,
			the name of a Symbol as chars,
			RawArrays,
				(i.e. Strings, Int8Arrays, Int16Arrays,
				Signals, etc.)
		*/
		_FileWrite
		^this.primitiveFailed;
	}
	read { arg buffer;
		// reads big endian data
		// buffer should be a RawArray.
		// fills the buffer, or as much is available.
		// returns bytes read.
		_FileReadRaw;
		^this.primitiveFailed;
	}

	writeLE { arg item;
		/* writes any of the following items in little endian byte order:
			a double float,
			a 32 bit int,
			a char,
			the name of a Symbol as chars,
			RawArrays,
				(i.e. Strings, Int8Arrays, Int16Arrays,
				Signals, etc.)
		*/
		_FileWriteLE
		^this.primitiveFailed;
	}
	readLE { arg buffer;
		// reads little endian data
		// buffer should be a RawArray.
		// fills the buffer, or as much is available.
		// returns bytes read.
		_FileReadRawLE;
		^this.primitiveFailed;
	}

	getLine { arg maxSize=1024;
		var string;
		string = String.newClear(maxSize);
		^this.prGetLine(string);
	}
	prGetLine { arg argString;
		// returns a string up to lesser of next newline
		// or length-1 of the argument string
		_FileReadLine;
		^this.primitiveFailed;
	}

	// for more fine grained control these read and write a single
	// item of the specified type and size
	getChar { _FileGetChar; ^this.primitiveFailed; }
	getInt8 { _FileGetInt8; ^this.primitiveFailed; }
	getInt16 { _FileGetInt16; ^this.primitiveFailed; }
	getInt32 { _FileGetInt32; ^this.primitiveFailed; }
	getFloat { _FileGetFloat; ^this.primitiveFailed; }
	getDouble { _FileGetDouble; ^this.primitiveFailed; }
	getInt16LE { _FileGetInt16LE; ^this.primitiveFailed; }
	getInt32LE { _FileGetInt32LE; ^this.primitiveFailed; }
	getFloatLE { _FileGetFloatLE; ^this.primitiveFailed; }
	getDoubleLE { _FileGetDoubleLE; ^this.primitiveFailed; }

	putChar { arg aChar; _FilePutChar; ^this.primitiveFailed; }
	putInt8 { arg anInteger; _FilePutInt8; ^this.primitiveFailed; }
	putInt16 { arg anInteger; _FilePutInt16; ^this.primitiveFailed; }
	putInt32 { arg anInteger; _FilePutInt32; ^this.primitiveFailed; }
	putFloat { arg aFloat; _FilePutFloat; ^this.primitiveFailed; }
	putDouble { arg aFloat; _FilePutDouble; ^this.primitiveFailed; }
	putInt16LE { arg anInteger; _FilePutInt16LE; ^this.primitiveFailed; }
	putInt32LE { arg anInteger; _FilePutInt32LE; ^this.primitiveFailed; }
	putFloatLE { arg aFloat; _FilePutFloatLE; ^this.primitiveFailed; }
	putDoubleLE { arg aFloat; _FilePutDoubleLE; ^this.primitiveFailed; }
	putString { arg aString; _FilePutString; ^this.primitiveFailed; }
	putString0 { arg aString;
		this.putString(aString);
		this.putInt8(0);
	}

	putPascalString { arg aString;
		if(aString.size >= 256) {
			Error("putPascalString: input string must be shorter than 256 chars: \"%\"".format(aString)).throw;
		};
		this.putInt8(aString.size);
		this.putString(aString);
	}

	getPascalString {
		var size, string;
		size = this.getInt8;
		string = String.newClear(size);
		this.read(string);
		^string
	}

	// PRIVATE
	addOpenFile {
		openFiles = openFiles.add(this);
	}
}