«FxChain class» by kennethflak

on 26 Feb'20 09:36 in utilitieseffectchains

A relatively lightweight way for me to quickly add effects. Not very advanced, but it gets the job done. The effect synths are supposed to do the job of mixing wet/dry signal and so forth. Usage: create an instance of FxChain, and then start addding effects in the required sequence. One nifty feature is the ability to add also effects in parallel. Handy for f.x. multitap delays. When all the effects are added, call .play. TODO: make it possible to add and remove effects while running. This is not a high priority though, as I'm not in the live coding business (yet).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
FxChain { 
    classvar <>numSpeakers=2; 
    classvar <>server;

    var <>fadeInTime,<>level, <>fadeOutTime, <>out, <>group;
    var <in, <fx, bus, <gain;
    var fxGroup, gainGroup;

    *new {|fadeInTime=1, level=1.0, fadeOutTime=1, out=0, group|
        ^super.newCopyArgs(fadeInTime, level, fadeOutTime, out, group).init;
    }

    init { 
        server = server ? Server.default;
        bus = List.new();
        fx = List.new();
        group = group ? Group.new;
        bus.add(Bus.audio(server, numSpeakers));
        in = bus[0];
    } 

    add {|... args|
        var synth, p, name, params, inbus, outbus;
        name = args[0];
        bus.add(Bus.audio(server, numSpeakers));
        inbus = bus[bus.size-2];
        outbus = bus.last;
        params = args[1];
        p = [ \in, inbus, \out, outbus ] ++ params;
        synth = Synth.tail(group, name, p);
        fx.add(synth); 
    }

    addPar {|... fxList|
        var inbus, outbus, synths;
        bus.add(Bus.audio(server, numSpeakers));
        inbus = bus[bus.size-2];
        outbus = bus.last;
        fxList.postln;
        fxList.do({|i, idx|
            var synth;
            if (i.class==Symbol) {
                var name = i, params, p;
                if (fxList[idx+1].isArray){
                    params = fxList[idx+1];
                };
                p = [ \in, inbus, \out, outbus] ++ params; 
                synth = Synth.tail(group, name, p); 
                synths = synths.add(synth);
            }; 
        });
        fx.add(synths);
    }

    play {
        var gainBus;
        if(fx.isEmpty){ 
            gainBus = in 
        }{
            gainBus = bus.last
        };
        gain = NodeProxy.new(server, \audio, numSpeakers, gainBus);
        gain.play(out, numSpeakers, group, vol: level, fadeTime: fadeInTime);
    }

    free {
        gain.clear(fadeOutTime);
        SystemClock.sched(fadeOutTime, {
            group.free;
            bus.do(_.free);
            in.free;
        });
    } 
}
raw 2092 chars (focus & ctrl+a+c to copy)
reception
comments