From a916a183b69e3dfb5358464d837e703a3aca9d4d Mon Sep 17 00:00:00 2001 From: Raphael Forment Date: Thu, 22 Feb 2024 21:36:08 +0100 Subject: [PATCH] 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. --- Classes/Bank.sc | 4 ++-- Classes/BuboBoot.sc | 22 +++++++++++++--------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Classes/Bank.sc b/Classes/Bank.sc index 406b1e0..1735023 100644 --- a/Classes/Bank.sc +++ b/Classes/Bank.sc @@ -18,7 +18,6 @@ Bank : Singleton { }) } - *new { |path, channels| ^super.new(path, channels); @@ -37,7 +36,9 @@ Bank : Singleton { } lazyLoading_{ + |lazy| + if (lazyLoading != lazy) { lazyLoading = lazy; this.prUpdateBuffers(); @@ -178,7 +179,6 @@ Bank : Singleton { buffers[index] = Buffer.readChannel(Server.default, paths[index], channels:Array.series(channels)); }; }; - buffers[index]; } } diff --git a/Classes/BuboBoot.sc b/Classes/BuboBoot.sc index dda8994..7f5c235 100644 --- a/Classes/BuboBoot.sc +++ b/Classes/BuboBoot.sc @@ -42,8 +42,8 @@ Boot { this.samplePath = samplePath ? "/Users/bubo/.config/livecoding/samples"; // Setting up the audio samples/buffers manager + Bank.lazyLoading_(true); Bank.root = this.samplePath; - Bank.lazyLoading = true; // Post actions: installing behavior after server boot Server.default.waitForBoot({ @@ -66,14 +66,18 @@ Boot { 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}; - if (~sp == nil) {~sp = 'default'}; - ~type = \note; - currentEnvironment.play; + // This is a custom event that makes it easier to play samples + arg server; + ~sp = ~sp ?? 'default'; + ~nb = ~nb ?? 0; + ~buf = Bank(~sp)[~nb % Bank(~sp).buffers.size]; + if (~buf.numChannels == 1) { + ~instrument = \player; + } { + ~instrument = \splayer; + }; + ~type = \note; + currentEnvironment.play; }); } }