«Remap Channel Outputs» by Bernardo Barros

on 27 May'24 09:12 in remap output channels

This code sets up a remapping system where input channels are mapped to output channels based on a predefined configuration. The remapping is done using a SynthDef that reads input signals, applies the remapping, and outputs the remapped signals. The ServerTree.add ensures that the remap synth is created and added to the server's node tree upon server startup and cmd-. and ctrl-.

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
(

~remapConfig = IdentityDictionary[
    0  ->  1,
    1  ->  2,
    2  ->  3,
    3  ->  4,
    4  ->  5,
    5  ->  6,
    6  ->  7,
    7  ->  8,
    8  ->  9,
    9  -> 12,
    10 -> 13,
    11 -> 14,
    12 -> 15,
    13 -> 16,
    14 -> 17
];


~generateRemapSynthDef = { |numInputChannels, numOutputChannels|
    SynthDef(\remapOutputs, {
        var sig = In.ar(0, numInputChannels);  
        var remapped = Array.fill(numOutputChannels, { Silent.ar(1) });  

        ~remapConfig.keysValuesDo { |src, dest|
            if (src < numInputChannels and: { dest < numOutputChannels }) {
                remapped[dest] = sig[src];
            }
        };

        ReplaceOut.ar(0, remapped);
    }).add;
};

~generateRemapSynthDef.(16, 18);  
)

(
~createRemapSynth = {
    ~remapSynth = Synth(\remapOutputs, target: s.defaultGroup, addAction: \addAfter);
};

ServerTree.add( ~createRemapSynth);

)
raw 951 chars (focus & ctrl+a+c to copy)
reception
comments