From afebd967d20db26c6e78d494792986b5f7030ffc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Forment?= Date: Tue, 14 May 2024 16:46:57 +0200 Subject: [PATCH] No more segfaults ? --- Classes/BuboBoot.sc | 43 +++++++++++++++++++------------------- Classes/BuboUtils.sc | 10 ++++++++- Classes/EventShortener.sc | 5 ++--- dev_sessions/with_midi.scd | 20 +++++++++++++++++- 4 files changed, 52 insertions(+), 26 deletions(-) diff --git a/Classes/BuboBoot.sc b/Classes/BuboBoot.sc index 04cff5a..bb5fba2 100644 --- a/Classes/BuboBoot.sc +++ b/Classes/BuboBoot.sc @@ -95,19 +95,17 @@ Boot { Event.addEventType(\buboLoopEvent, { arg server; - [~sp, ~nb].postln; ~sp = BuboUtils.cleanSampleName(~sp); ~nb = BuboUtils.cleanSampleIndex(~nb); - [~sp, ~nb].postln; if (~sp.notNil && ~nb.notNil, { - ~sp = ~sp ?? 'default'; - ~nb = ~nb ?? 0; - ~buf = Bank(~sp)[~nb % Bank(~sp).paths.size]; - if (Bank(~sp).metadata[~nb % Bank(~sp).size][\numChannels] == 1) { - ~instrument = \looperMono; - } { - ~instrument = \looperStereo; - }; + if (~sp != "", { + ~buf = Bank(~sp)[~nb % Bank(~sp).paths.size]; + if (Bank(~sp).metadata[~nb % Bank(~sp).size][\numChannels] == 1) { + ~instrument = \looperMono; + } { + ~instrument = \looperStereo; + }; + }) }); ~type = \note; currentEnvironment.play; @@ -115,17 +113,20 @@ Boot { Event.addEventType(\buboEvent, { arg server; - ~sp = BuboUtils.cleanSampleName(~sp); - ~nb = BuboUtils.cleanSampleIndex(~nb); - if (~sp.notNil && ~nb.notNil, { - if (~sp != "", { - ~buf = Bank(~sp)[~nb % Bank(~sp).paths.size]; - if (Bank(~sp).metadata[~nb % Bank(~sp).size][\numChannels] == 1) { - ~instrument = \player; - } { - ~instrument = \splayer; - }; - }) + [~sp, ~nb, ~instrument].postln; + if (BuboUtils.stringIsNumber(~sp), {}, { + ~sp = BuboUtils.cleanSampleName(~sp); + ~nb = BuboUtils.cleanSampleIndex(~nb); + if (~sp.notNil && ~nb.notNil, { + if (~sp !== "", { + ~buf = Bank(~sp)[~nb % Bank(~sp).paths.size]; + if (Bank(~sp).metadata[~nb % Bank(~sp).size][\numChannels] == 1) { + ~instrument = \player; + } { + ~instrument = \splayer; + }; + }) + }); }); ~type = \note; currentEnvironment.play; diff --git a/Classes/BuboUtils.sc b/Classes/BuboUtils.sc index 18808e8..ac4ef01 100644 --- a/Classes/BuboUtils.sc +++ b/Classes/BuboUtils.sc @@ -15,7 +15,7 @@ BuboUtils { *cleanSampleName { arg str; var good_string; - if (str == nil, { ^nil }); + if (str == nil, { ^"" }); good_string = str.asList.collect({ |char| if (char.isAlphaNum, char, "") @@ -23,6 +23,14 @@ BuboUtils { ^good_string } + *stringIsNumber { + arg string; + if (string == nil, { ^true }); + string = string.asList.collect({arg char; char.ascii}); + string = (48..57).includesAll(string); + ^string + } + *cleanSampleIndex { arg number; if (number.isKindOf(Number), { ^number }, { ^0 }); diff --git a/Classes/EventShortener.sc b/Classes/EventShortener.sc index 13e9a0c..7f8206f 100644 --- a/Classes/EventShortener.sc +++ b/Classes/EventShortener.sc @@ -54,9 +54,8 @@ EventShortener { if (type !== 'midi', { if (pattern.includes('i') || pattern.includes('instrument') == false, { new_pattern = new_pattern ++ [ - sp: Pfunc { |e| e.str ? 'default' }, - nb: Pfunc(\num), - instrument: 'default', + sp: Pfunc { |e| e.str ? "" }, + nb: Pfunc { |e| e.num ? 0 }, fast: 1, ]; }); diff --git a/dev_sessions/with_midi.scd b/dev_sessions/with_midi.scd index a777123..ec38f11 100644 --- a/dev_sessions/with_midi.scd +++ b/dev_sessions/with_midi.scd @@ -37,7 +37,25 @@ m = MIDIOut.newByName("MIDI", "Bus 1"); ~plop.play; ) -Bank.list + +// TEST: Cinquième test +( +~testInstrument => [ + instrument: 'default', + pat: "0 2 3 4" +]; +~testInstrument.play; +) + +// TEST: Sixième test +// WARNING: celui-ci crashe ! +( +~testInstrument => [ + pat: "0 2 3 4" +]; +~testInstrument.play; +) + Sweep.help