| 87 | } |
| 88 | |
| 89 | bool ProcessorChain::setProcessorBusesLayout(Processor* proc, const String& targetOutputLayout) { |
| 90 | traceScope(); |
| 91 | |
| 92 | if (!proc->isLoaded()) { |
| 93 | return false; |
| 94 | } |
| 95 | |
| 96 | auto layout = getBusesLayout(); |
| 97 | int chIn = getLayoutNumChannels(layout, true), chOut = getLayoutNumChannels(layout, false); |
| 98 | auto procLayouts = proc->getSupportedBusLayouts(); |
| 99 | AudioProcessor::BusesLayout targetLayout; |
| 100 | int targetChIn = 0, targetChOut = 0, extraInChannels = 0, extraOutChannels = 0; |
| 101 | bool found = false; |
| 102 | |
| 103 | auto setTargetLayout = [&](const BusesLayout& l, int in, int out) { |
| 104 | targetLayout = l; |
| 105 | targetChIn = in; |
| 106 | targetChOut = out; |
| 107 | found = true; |
| 108 | }; |
| 109 | |
| 110 | if (procLayouts.isEmpty()) { |
| 111 | logln("no processor layouts cached, checking now..."); |
| 112 | procLayouts = Processor::findSupportedLayouts(proc); |
| 113 | } |
| 114 | |
| 115 | if (targetOutputLayout.isNotEmpty()) { |
| 116 | logln("requested target output layout: " << targetOutputLayout); |
| 117 | } |
| 118 | |
| 119 | if (targetOutputLayout.isNotEmpty() && targetOutputLayout != "Default") { |
| 120 | for (auto& l : procLayouts) { |
| 121 | int checkChIn = getLayoutNumChannels(l, true), checkChOut = getLayoutNumChannels(l, false); |
| 122 | String sinputs = describeLayout(l, true, false, true), soutputs = describeLayout(l, false, true, true); |
| 123 | if (soutputs == targetOutputLayout) { |
| 124 | if (chIn == 0 || checkChIn == checkChOut) { |
| 125 | setTargetLayout(l, checkChIn, checkChOut); |
| 126 | if (chIn == 0 || sinputs == soutputs) { |
| 127 | break; |
| 128 | } |
| 129 | } else if (l.inputBuses.size() == 2 && l.outputBuses.size() == 1) { |
| 130 | // inputs with sidechain? |
| 131 | auto lNoSC = l; |
| 132 | lNoSC.inputBuses.remove(1); |
| 133 | if (describeLayout(lNoSC, true, false, true) == soutputs) { |
| 134 | setTargetLayout(l, checkChIn, checkChOut); |
| 135 | break; |
| 136 | } |
| 137 | } else { |
| 138 | if (found) { |
| 139 | break; |
| 140 | } |
| 141 | if (checkChIn > targetChIn) { |
| 142 | setTargetLayout(l, checkChIn, checkChOut); |
| 143 | } |
| 144 | } |
| 145 | } |
| 146 | } |
nothing calls this directly
no test coverage detected