From 25745504b2acec08280375f429798ccc43ad9b89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Forment?= Date: Sun, 12 May 2024 23:02:39 +0200 Subject: [PATCH] refactor eventshortener --- Classes/BuboNodeProxy.sc | 51 ++++----------------------------------- Classes/EventShortener.sc | 32 +++++++++++++++--------- with_midi.scd | 40 ++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 58 deletions(-) create mode 100644 with_midi.scd diff --git a/Classes/BuboNodeProxy.sc b/Classes/BuboNodeProxy.sc index 60541ad..6427741 100644 --- a/Classes/BuboNodeProxy.sc +++ b/Classes/BuboNodeProxy.sc @@ -1,8 +1,6 @@ + NodeProxy { - /* Simple FX chain management */ - fx { arg number=1, wet=1, function = {|in| in}; this[number] = \filter -> function; @@ -51,9 +49,7 @@ var quant = this.getQuantFromPattern(pattern); var fade = this.getFadeFromPattern(pattern); pattern = EventShortener.process( - pattern, - this.key, - [type: 'midi'] + pattern, this.key, \midi, 0 ); this[0] = Pbind(*pattern); this.prepareToPlay(this, quant, fade); @@ -66,9 +62,7 @@ var quant = this.getQuantFromPattern(pattern); var fade = this.getFadeFromPattern(pattern); pattern = EventShortener.process( - pattern, - this.key, - [\type, \buboEvent] + pattern, this.key, \buboEvent, 0 ); this[0] = Pbind(*pattern); this.prepareToPlay(this, quant, fade); @@ -84,13 +78,7 @@ var nbSlices = this.getValueFromPattern(pattern, 'slices', 1); var time = (Pkey(\dur) / Pfunc { currentEnvironment.clock.tempo }) / nbSlices; pattern = EventShortener.process( - pattern, - this.key, - [ - \type, \buboLoopEvent, - \legato, 1, - \time, time - ] + pattern, this.key, \looper, time ); this[0] = Pmono(*pattern); this.prepareToPlay(this, quant, fade); @@ -102,41 +90,14 @@ arg pattern; var quant = this.getQuantFromPattern(pattern); var fade = this.getFadeFromPattern(pattern); - pattern = EventShortener.processPmono( - pattern, - this.key + pattern = EventShortener.process( + pattern, this.key, 'pmono', 0 ); this[0] = Pmono(*pattern); this.prepareToPlay(this; quant, fade); ^this } - f { - arg value; - this.fadeTime = value; - ^this - } - - p { - arg quant, fade; - this.quant = quant; - this.fadeTime = fade; - this.play(fadeTime: fade); - ^this - } - - s { - arg duration; - this.stop(fadeTime: duration) - ^this - } - - / { - arg pattern; - this.stop(1); - ^this - } - getValueFromPattern { arg pattern, key, default; var keyIndex = pattern.indexOf(key); @@ -156,6 +117,4 @@ arg pattern; ^this.getValueFromPattern(pattern, 'fade', 0.01) } - - } diff --git a/Classes/EventShortener.sc b/Classes/EventShortener.sc index 6d01dce..189258b 100644 --- a/Classes/EventShortener.sc +++ b/Classes/EventShortener.sc @@ -1,13 +1,27 @@ EventShortener { *process { - arg pattern, key, other_keys; + arg pattern, key, type, time; + var additionalKeys = Dictionary.newFrom([ + \midi, [ + type: \midi + ], + \buboEvent, [ + type: \buboEvent, + ], + \looper, [ + type: \buboLoopEvent, + legato: 1, + time: time + ], + \pmono, [], + ]); + pattern = this.findShortcuts(pattern); + pattern = this.functionsToNdef(pattern, key); + pattern = pattern ++ additionalKeys[type] ; if (pattern.includes('pat'), { pattern = this.patternize(pattern); }); - pattern = this.findShortcuts(pattern); - pattern = this.functionsToNdef(pattern, key); - pattern = pattern ++ other_keys ; ^pattern } @@ -34,7 +48,7 @@ EventShortener { } )}); ]; - if (pattern.includes('i') || pattern.includes('instrument') == false, { + if (pattern.includes(\midi) || pattern.includes('i') || pattern.includes('instrument') == false, { new_pattern = new_pattern ++ [ sp: Pkey(\str), nb: Pkey(\num), @@ -47,16 +61,10 @@ EventShortener { }); }) }); + new_pattern.postln; ^new_pattern } - *processPmono { - arg pattern, key; - pattern = this.findShortcuts(pattern); - pattern = this.functionsToNdef(pattern, key); - ^pattern - } - *functionsToNdef { arg pattern, key; var new_pattern = List.new(); diff --git a/with_midi.scd b/with_midi.scd new file mode 100644 index 0000000..9d23880 --- /dev/null +++ b/with_midi.scd @@ -0,0 +1,40 @@ +MIDIClient.destinations; + +m + +( +~test => [ sp: "kick", nb: 0 ]; +~test.play; +) + +( +~test = Pbind( + \instrument, 'splayer', + \sp, Bank("kick")[0], +); +~test.play; +) + +( +~test >> [ + pat: "0 2 3 4", + midiout: m +]; +~test.play; +) + +( +m = MIDIOut.newByName("MIDI", "Bus 1"); +~test >> [ pat: "0 2 3 4", midiout: m ]; +~test.play; +) + +( +~baba = Pbind( + \type, \midi, + [\trig, \delta, \dur, \str, \num], Pmini("[1 2 3 4]/2"), + \degree, Pfunc({ |e| if(e.trig > 0) { e.str.asInteger } { \rest } }), + \midiout, m +); +~baba.play; +)