Files
BuboQuark/Classes/BuboBoot.sc
2024-01-07 21:58:34 +01:00

96 lines
3.1 KiB
Python

Boot {
classvar <>clock;
classvar <>localPath;
classvar <>samplePath;
classvar <>serverOptions;
*new {
arg configPath, samplePath, serverOptions;
var p; var c; var t; var s;
var banner = "┳┓ ┓ ┳┓\n"
"┣┫┓┏┣┓┏┓ ┣┫┏┓┏┓╋\n"
"┻┛┗┻┗┛┗┛ ┻┛┗┛┗┛┗";
var ready = "┓ ┳┓┏┏┓ ┏┓┏┓┳┓┏┓ ┳┓┏┓┏┓┳┓┓┏\n"
"┃ ┃┃┃┣ ┃ ┃┃┃┃┣ ┣┫┣ ┣┫┃┃┗┫\n"
"┗┛┻┗┛┗┛ ┗┛┗┛┻┛┗┛ ┛┗┗┛┛┗┻┛┗┛";
this.fancyPrint(banner, 40);
if (serverOptions == nil,
{
"-> Booting using default server configuration".postln;
s = Server.default;
s.options.numBuffers = 1024 * 128;
s.options.memSize = 8192 * 64;
s.options.numWireBufs = 2048;
s.options.maxNodes = 1024 * 32;
s.options.numOutputBusChannels = 16;
s.options.numInputBusChannels = 16;
s.options.outDevice = "BlackHole 16ch";
},
{
"-> Booting using user server configuration".postln;
s = Server.default;
s.options = serverOptions;
},
);
// Using Ableton Link Clock for automatic synchronisation with other peers
this.clock = LinkClock(130 / 60).latency_(Server.default.latency).permanent_(true);
TempoClock.default = this.clock;
c = this.clock;
t = this.clock.tempo;
// Defining the local path as default for configuration files if not configPath
this.localPath = this.class.filenameSymbol.asString.dirname +/+ "Configuration";
p = ProxySpace.push(s.boot, clock: this.clock);
this.samplePath = samplePath ? "/Users/bubo/.config/livecoding/samples";
// Setting up the audio samples/buffers manager
Bank.root = this.samplePath;
Bank.lazyLoading = true;
// Post actions: installing behavior after server boot
Server.default.waitForBoot({
"-> Loading config from: %".format(configPath ? (this.localPath +/+ "Startup.scd")).postln;
(configPath ? (this.localPath +/+ "Startup.scd")).load;
Safety.setLimit(0.8);
this.fancyPrint(ready, 40);
this.installServerTreeBehavior();
this.clock.enableMeterSync();
});
}
*fancyPrint {
arg message, length;
var separator= length.collect({
arg index;
if (index % 2 == 0, "=", "-")
});
separator = separator.join("");
[separator, message, separator].do({
arg each;
each.postln;
});
}
*installServerTreeBehavior {
CmdPeriod.add({
this.fancyPrint("\nBubo SuperCollider Session\nTempo: % | Peers: %\nCPU: % | Peak: %\n".format(
this.clock.tempo * 60, this.clock.numPeers,
Server.default.avgCPU.round(2),
Server.default.peakCPU.round(2)), 40)
}, Server.default);
Event.addEventType(\buboEvent, {
arg server;
if (~sp.notNil && ~nb.notNil,
{ ~buf = Bank(~sp)[~nb % Bank(~sp).buffers.size]; }
);
if (~nb == nil) {~nb = 0};
~type = \note;
currentEnvironment.play;
});
}
}