-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileread.ck
113 lines (84 loc) · 1.82 KB
/
fileread.ck
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
class PathWrapper
{
string path;
}
public class FileRead {
static PathWrapper @ pathWrapper;
static FileIO @ fio;
fun static int readInt(string parameter, int defaultint) {
// parameter file
pathWrapper.path + "/live/" + parameter => string filename;
// instantiate
// open the file
fio.open( filename, FileIO.READ );
// default value
if( !fio.good() )
{
fio.close();
return defaultint;
}
string strval;
int value;
// read the value
while( fio => value )
{
fio.close();
return value;
}
}
fun static void set(string parameter,int value) {
pathWrapper.path + "/live/" + parameter => string filename;
// instantiate
FileIO fout;
// open the file
fout.open( filename, FileIO.WRITE );
// test
if( !fout.good() )
{
cherr <= "can't open file for writing..." <= IO.newline();
return;
}
fout.write( value );
// close the thing
fout.close();
return;
}
fun static string readString(string parameter, string defaultstring) {
// parameter file
pathWrapper.path + "/live/" + parameter => string filename;
// instantiate
FileIO fio;
// open a file
fio.open( filename, FileIO.READ );
// ensure it's ok
if( !fio.good() )
{
fio.close();
return defaultstring;
}
string value;
// loop until end
while( fio => value )
{
fio.close();
return value;
}
}
}
if( me.args() ) {
new PathWrapper @=> FileRead.pathWrapper;
me.arg(0) @=> FileRead.pathWrapper.path;
} else {
new PathWrapper @=> FileRead.pathWrapper;
me.sourceDir() @=> FileRead.pathWrapper.path;
}
new FileIO @=> FileRead.fio;
//FileRead fr;
// infinite time loop
//while( true )
//{
// // print current bpm in seconds
// <<< "bpm:", fr.readInt("bpm",120) >>>;
// <<< "drums:", fr.readString("drums","xx") >>>;
// 1::second => now;
//}