-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSampleManager.sc
64 lines (54 loc) · 1.37 KB
/
SampleManager.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
/*
MasterSequencer.instance = nil
MasterSequencer();
*/
SampleManager {
classvar <>samples;
*initClass{
samples = Dictionary.new;
}
*loadSample { |path, section|
var key = path.basename.drop(-4).asSymbol;
if( Server.default.serverRunning ) {
if( section.notNil ){
// if there is not yet such a section, create one
if( samples[section].isNil ) { samples[section] = Dictionary.new };
// check if that file was already loaded on that section
samples[section][key] = samples[section][key] ?? {
//("Loading sample % in section %".format(key, section)).postln;
Buffer.read(Server.default, path);
};
} {
// check if that file was already loaded
samples[key] = samples[key] ?? {
//("Loading sample % at root level".format(key)).postln;
Buffer.read(Server.default, path)
};
}
} {
warn("Boot the server first!");
};
}
*loadSamples { |paths, section|
paths.do{ |path|
SampleManager.loadSample(path, section);
}
}
*getSection{ |section|
^samples[section]
}
*getSample{ |key, section|
//key.postln;
//key.class.postln;
if( section.isNil ) {
//"retreiving sample %".format(key).postln;
^samples[key]
} {
//"retreiving sample % from %".format(key, section).postln;
^samples[section][key]
}
}
*getSamples{ |keys, section|
^keys.collect{ |key| SampleManager.getSample(key, section) }
}
}