/
RSChannels.sc
64 lines (58 loc) · 1.67 KB
/
RSChannels.sc
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
BandInfo {
var <>left, <>right; // floats
*new {
left = right = 0.0;
^super.new
}
}
BeatInfo {
var <>bands;
*new {
arg size;
^super.newCopyArgs(Array.new(size));
}
}
RSChannels[slot] {
var <channels;
*newWithFilename {
arg filename;
j = this.new;
j.read(filename)
}
read {
arg filename;
var file = File.open(filename, "rb");
if ( !file.isOpen, { Error("couldn't open file" + filename + "!").throw } );
var nextChar = file.getChar();
var bandcount = "";
while ( { nextChar != $| && nextChar != nil }, { bandcount = bandcount ++ nextChar; nextChar = file.getChar() } );
if (nextChar == nil, { Error("premature eof in" + filename).throw });
bandcount = bandcount.asInteger;
var done = false;
nextChar = file.getChar();
var beats;
while ( { done == false }, {
var inputname;
while ( { nextChar != $| && nextChar != nil }, { inputname = inputname ++ nextChar; nextChar = file.getChar() } );
if (nextChar == nil, { Error("premature eof in" + filename).throw });
nextChar = file.getChar();
var beatcount = "";
while ( { nextChar != $| && nextChar != nil }, { beatcount = beatcount ++ nextChar; nextChar = file.getChar() } );
if (nextChar == nil, { Error("premature eof in" + filename).throw });
beatcount = beatcount.asInteger;
beats = Array.new(beatcount)
beatcount.do({
arg beat;
beats[beat] = BeatInfo.new(bandcount);
bandcount.do({
arg band;
beats[beat].bands[band] = BandInfo.new();
beats[beat].bands[band].left = file.getDouble();
beats[beat].bands[band].right = file.getDouble();
});
});
nextChar = file.getChar();
if ( nextChar == nil, {done = true});
});
^beats;
}