void* ProcessorGraph::createNewProcessor(String& description, int id)//, { GenericProcessor* processor = 0; try // Try/catch block added by Michael Borisov { processor = createProcessorFromDescription(description); } catch (std::exception& e) { NativeMessageBox::showMessageBoxAsync(AlertWindow::WarningIcon, "OpenEphys", e.what()); } // int id = currentNodeId++; if (processor != 0) { processor->setNodeId(id); // identifier within processor graph std::cout << " Adding node to graph with ID number " << id << std::endl; std::cout << std::endl; std::cout << std::endl; addNode(processor,id); // have to add it so it can be deleted by the graph if (processor->isSource()) { // by default, all source nodes record automatically processor->setAllChannelsToRecord(); if (processor->generatesTimestamps()) { getMessageCenter()->addSourceProcessor(processor); if (getMessageCenter()->getSourceNodeId() == 0) { getMessageCenter()->setSourceNodeId(processor->getNodeId()); } } } return processor->createEditor(); } else { CoreServices::sendStatusMessage("Not a valid processor type."); return 0; } }
void ProcessorGraph::updatePointers() { getAudioNode()->setUIComponent(getUIComponent()); getAudioNode()->updateBufferSize(); getRecordNode()->setUIComponent(getUIComponent()); getMessageCenter()->setUIComponent(getUIComponent()); }
void ProcessorGraph::removeProcessor(GenericProcessor* processor) { std::cout << "Removing processor with ID " << processor->getNodeId() << std::endl; int nodeId = processor->getNodeId(); if (processor->isSource()) { getMessageCenter()->removeSourceProcessor(processor); } disconnectNode(nodeId); removeNode(nodeId); if (getMessageCenter()->getSourceNodeId() == nodeId) { int newId = 0; //Look for the next source node. If none is found, set the sourceid to 0 for (int i = 0; i < getNumNodes() && newId == 0; i++) { if (getNode(i)->nodeId != OUTPUT_NODE_ID) { GenericProcessor* p = dynamic_cast<GenericProcessor*>(getNode(i)->getProcessor()); //GenericProcessor* p = static_cast<GenericProcessor*>(getNode(i)->getProcessor()); if (p && p->isSource() && p->generatesTimestamps()) { newId = p->nodeId; } } } getMessageCenter()->setSourceNodeId(newId); } }
int64 getSoftwareTimestamp() { return getMessageCenter()->getTimestamp(true); }
int64 getGlobalTimestamp() { return getMessageCenter()->getTimestamp(); }
void ProcessorGraph::updateConnections(Array<SignalChainTabButton*, CriticalSection> tabs) { clearConnections(); // clear processor graph std::cout << "Updating connections:" << std::endl; std::cout << std::endl; std::cout << std::endl; Array<GenericProcessor*> splitters; // GenericProcessor* activeSplitter = nullptr; for (int n = 0; n < tabs.size(); n++) // cycle through the tabs { std::cout << "Signal chain: " << n << std::endl; std::cout << std::endl; GenericEditor* sourceEditor = (GenericEditor*) tabs[n]->getEditor(); GenericProcessor* source = (GenericProcessor*) sourceEditor->getProcessor(); while (source != nullptr)// && destEditor->isEnabled()) { std::cout << "Source node: " << source->getName() << "." << std::endl; GenericProcessor* dest = (GenericProcessor*) source->getDestNode(); if (source->isEnabledState()) { // add the connections to audio and record nodes if necessary if (!(source->isSink() || source->isSplitter() || source->isMerger() || source->isUtility()) && !(source->wasConnected)) { std::cout << " Connecting to audio and record nodes." << std::endl; connectProcessorToAudioAndRecordNodes(source); } else { std::cout << " NOT connecting to audio and record nodes." << std::endl; } if (dest != nullptr) { while (dest->isMerger()) // find the next dest that's not a merger { dest = dest->getDestNode(); if (dest == nullptr) break; } if (dest != nullptr) { while (dest->isSplitter()) { if (!dest->wasConnected) { if (!splitters.contains(dest)) { splitters.add(dest); dest->switchIO(0); // go down first path } else { int splitterIndex = splitters.indexOf(dest); splitters.remove(splitterIndex); dest->switchIO(1); // go down second path dest->wasConnected = true; // make sure we don't re-use this splitter } } dest = dest->getDestNode(); if (dest == nullptr) break; } if (dest != nullptr) { if (dest->isEnabledState()) { connectProcessors(source, dest); } } } else { std::cout << " No dest node." << std::endl; } } else { std::cout << " No dest node." << std::endl; } } std::cout << std::endl; source->wasConnected = true; source = dest; // switch source and dest if (source == nullptr && splitters.size() > 0) { source = splitters.getLast(); GenericProcessor* newSource;// = source->getSourceNode(); while (source->isSplitter() || source->isMerger()) { newSource = source->getSourceNode(); newSource->setPathToProcessor(source); source = newSource; } } } // end while source != 0 } // end "tabs" for loop //Update RecordNode internal channel mappings Array<EventChannel*> extraChannels; getMessageCenter()->addSpecialProcessorChannels(extraChannels); getRecordNode()->addSpecialProcessorChannels(extraChannels); } // end method