Improvement: sampling syntax

Choosing between the mono or stereo sampler is optional. Just use ~sp
and ~nb and the sampler will be picked based on the number of channels
in the audio file getting played.
This commit is contained in:
2024-02-22 21:36:08 +01:00
parent c56b5c6967
commit a916a183b6
2 changed files with 15 additions and 11 deletions

View File

@ -18,7 +18,6 @@ Bank : Singleton {
}) })
} }
*new { *new {
|path, channels| |path, channels|
^super.new(path, channels); ^super.new(path, channels);
@ -37,7 +36,9 @@ Bank : Singleton {
} }
lazyLoading_{ lazyLoading_{
|lazy| |lazy|
if (lazyLoading != lazy) { if (lazyLoading != lazy) {
lazyLoading = lazy; lazyLoading = lazy;
this.prUpdateBuffers(); this.prUpdateBuffers();
@ -178,7 +179,6 @@ Bank : Singleton {
buffers[index] = Buffer.readChannel(Server.default, paths[index], channels:Array.series(channels)); buffers[index] = Buffer.readChannel(Server.default, paths[index], channels:Array.series(channels));
}; };
}; };
buffers[index]; buffers[index];
} }
} }

View File

@ -42,8 +42,8 @@ Boot {
this.samplePath = samplePath ? "/Users/bubo/.config/livecoding/samples"; this.samplePath = samplePath ? "/Users/bubo/.config/livecoding/samples";
// Setting up the audio samples/buffers manager // Setting up the audio samples/buffers manager
Bank.lazyLoading_(true);
Bank.root = this.samplePath; Bank.root = this.samplePath;
Bank.lazyLoading = true;
// Post actions: installing behavior after server boot // Post actions: installing behavior after server boot
Server.default.waitForBoot({ Server.default.waitForBoot({
@ -66,14 +66,18 @@ Boot {
Server.default.peakCPU.round(2)), 40) Server.default.peakCPU.round(2)), 40)
}, Server.default); }, Server.default);
Event.addEventType(\buboEvent, { Event.addEventType(\buboEvent, {
arg server; // This is a custom event that makes it easier to play samples
if (~sp.notNil && ~nb.notNil, arg server;
{ ~buf = Bank(~sp)[~nb % Bank(~sp).buffers.size]; } ~sp = ~sp ?? 'default';
); ~nb = ~nb ?? 0;
if (~nb == nil) {~nb = 0}; ~buf = Bank(~sp)[~nb % Bank(~sp).buffers.size];
if (~sp == nil) {~sp = 'default'}; if (~buf.numChannels == 1) {
~type = \note; ~instrument = \player;
currentEnvironment.play; } {
~instrument = \splayer;
};
~type = \note;
currentEnvironment.play;
}); });
} }
} }