| 2191 | }; |
| 2192 | |
| 2193 | void ModularSynth::ArrangeAudioSourceDependencies() |
| 2194 | { |
| 2195 | if (mIsLoadingState) |
| 2196 | { |
| 2197 | mArrangeDependenciesWhenLoadCompletes = true; |
| 2198 | return; |
| 2199 | } |
| 2200 | |
| 2201 | //ofLog() << "Calculating audio source dependencies:"; |
| 2202 | |
| 2203 | std::vector<SourceDepInfo> deps; |
| 2204 | for (int i = 0; i < mSources.size(); ++i) |
| 2205 | deps.push_back(SourceDepInfo(mSources[i])); |
| 2206 | |
| 2207 | for (int i = 0; i < mSources.size(); ++i) |
| 2208 | { |
| 2209 | for (int j = 0; j < mSources.size(); ++j) |
| 2210 | { |
| 2211 | for (int k = 0; k < mSources[i]->GetNumTargets(); ++k) |
| 2212 | { |
| 2213 | if (mSources[i]->GetTarget(k) != nullptr && |
| 2214 | mSources[i]->GetTarget(k) == dynamic_cast<IAudioReceiver*>(mSources[j])) |
| 2215 | { |
| 2216 | deps[j].mDeps.push_back(mSources[i]); |
| 2217 | } |
| 2218 | } |
| 2219 | } |
| 2220 | } |
| 2221 | |
| 2222 | /*for (int i=0; i<deps.size(); ++i) |
| 2223 | { |
| 2224 | string depStr; |
| 2225 | for (int j=0;j<deps[i].mDeps.size();++j) |
| 2226 | { |
| 2227 | depStr += dynamic_cast<IDrawableModule*>(deps[i].mDeps[j])->Name(); |
| 2228 | if (j<deps[i].mDeps.size()-1) |
| 2229 | depStr += ", "; |
| 2230 | } |
| 2231 | ofLog() << dynamic_cast<IDrawableModule*>(deps[i].mMe)->Name() << "depends on:" << depStr; |
| 2232 | }*/ |
| 2233 | |
| 2234 | //TODO(Ryan) detect circular dependencies |
| 2235 | const int kMaxLoopCount = 1000; //how many times we loop over the graph before deciding that it must contain a circular dependency |
| 2236 | mSources.clear(); |
| 2237 | int loopCount = 0; |
| 2238 | while (deps.size() > 0 && loopCount < kMaxLoopCount) //stupid circular dependency detection, make better |
| 2239 | { |
| 2240 | for (int i = 0; i < deps.size(); ++i) |
| 2241 | { |
| 2242 | bool hasDeps = false; |
| 2243 | for (int j = 0; j < deps[i].mDeps.size(); ++j) |
| 2244 | { |
| 2245 | bool found = false; |
| 2246 | for (int k = 0; k < mSources.size(); ++k) |
| 2247 | { |
| 2248 | if (deps[i].mDeps[j] == mSources[k]) |
| 2249 | found = true; |
| 2250 | } |
no test coverage detected