TimeNodeElement::TimeNodeElement( std::shared_ptr<OSSIA::TimeNode> ossia_tn, const Scenario::TimeNodeModel& element, const Device::DeviceList& devlist, QObject* parent): QObject{parent}, m_ossia_node{ossia_tn}, m_iscore_node{element}, m_deviceList{devlist} { if(element.trigger() && element.trigger()->active()) { try { auto expr = iscore::convert::expression( element.trigger()->expression(), m_deviceList); m_ossia_node->setExpression(expr); } catch(std::exception& e) { qDebug() << e.what(); m_ossia_node->setExpression(OSSIA::Expression::create(true)); } } connect(m_iscore_node.trigger(), &Scenario::TriggerModel::triggeredByGui, this, [&] () { try { m_ossia_node->trigger(); auto accumulator = OSSIA::State::create(); for(auto& event : m_ossia_node->timeEvents()) { if(event->getStatus() == OSSIA::TimeEvent::Status::HAPPENED) flattenAndFilter(event->getState(), accumulator); } accumulator->launch(); } catch(...) { } }); }
TimeNodeComponent::TimeNodeComponent( OSSIA::Node& parent, const Id<iscore::Component>& id, Scenario::TimeNodeModel& timeNode, const TimeNodeComponent::system_t& doc, const iscore::DocumentContext& ctx, QObject* parent_comp): Component{id, "TimeNodeComponent", parent_comp}, m_thisNode{parent, timeNode.metadata, this} { make_metadata_node(timeNode.metadata, thisNode(), m_properties, this); m_properties.push_back( add_setProperty<State::impulse_t>(thisNode(), "trigger", [&] (auto) { timeNode.trigger()->triggeredByGui(); })); }
void TAVisitor::visit(const Scenario::TimeNodeModel &timenode) { using namespace Scenario; // First we create a point for the timenode. The ingoing // constraints will end on this point. QString tn_name = name(timenode); // Create an interaction point. TA::Point tn_point{tn_name}; tn_point.kill_p = scenario.kill; tn_point.en = "en_" + tn_name; tn_point.event = "event_" + tn_name; tn_point.skip = "skip_" + tn_name; tn_point.event_t = "ok_" + tn_name; if(timenode.trigger()->active()) { set_point_condition(tn_point, timenode.trigger()->expression()); } else { tn_point.condition = 0; tn_point.conditionValue = 0; } tn_point.conditionMessage = "msg" + tn_name; tn_point.urgent = true; scenario.bools.insert(tn_point.en); scenario.ints.insert(tn_point.conditionMessage); scenario.broadcasts.insert(tn_point.event); scenario.broadcasts.insert(tn_point.skip); scenario.broadcasts.insert(tn_point.event_t); // If there are multiple constraints ending on this timenode, // we put a Control inbetween. auto prev_csts = previousConstraints(timenode, scenario.iscore_scenario); if(prev_csts.size() > 1) { QString control_name = "Control_" + tn_name; TA::Control ctrl( control_name, prev_csts.size(), "event_s1_" + control_name, "skip_p_" + control_name, "skip_" + control_name, "event_e_" + control_name, scenario.kill, "event_s2_" + control_name); scenario.controls.push_back(ctrl); tn_point.skip_p = ctrl.skip; tn_point.event_e = ctrl.event_s2; tn_point.event_s = ctrl.event_e; scenario.broadcasts.insert(ctrl.event_s1); scenario.broadcasts.insert(ctrl.skip_p); scenario.broadcasts.insert(ctrl.skip); scenario.broadcasts.insert(ctrl.event_e); scenario.broadcasts.insert(ctrl.event_s2); } else if(prev_csts.size() == 1) { tn_point.skip_p = "skip_p_" + tn_name; tn_point.event_e = "event_e_" + tn_name; tn_point.event_s = "event_s_" + tn_name; scenario.broadcasts.insert(tn_point.skip_p); scenario.broadcasts.insert(tn_point.event_e); scenario.broadcasts.insert(tn_point.event_s); } else if(&timenode == &scenario.iscore_scenario.startTimeNode()) { tn_point.skip_p = scenario.skip; tn_point.event_s = scenario.event_s; tn_point.event_e = scenario.event_s; } else { ISCORE_ABORT; } // If there is a trigger we create a corresponding event. if(timenode.trigger()->active()) { TA::Event_ND node_event{ "EventND_" + tn_name, tn_point.conditionMessage, tn_point.event, timenode.date(), // TODO throw a rand 0 }; scenario.events_nd.push_back(node_event); } else { TA::Event node_event{ "Event_" + tn_name, tn_point.conditionMessage, tn_point.event, timenode.date(), // TODO throw a rand 0 }; scenario.events.push_back(node_event); } if(! timenode.trigger()->active()) { // TODO TA::Mix point_start_mix{ "Mix_" + tn_name, tn_point.event_s, "mix_event_e" + tn_point.event_e, tn_point.skip_p, tn_point.kill_p }; tn_point.event_e = point_start_mix.event_out; scenario.broadcasts.insert(point_start_mix.event_out); scenario.mixs.push_back(point_start_mix); } tn_point.comment = "TimeNode Name : " + timenode.metadata().getName() + ". Label : " + timenode.metadata().getLabel(); /* // We create a flexible that will go to each event of the timenode. QString flexible_name = "__after__" + tn_name; TA::Flexible flexible{flexible_name}; flexible.dmin = TimeValue::zero(); flexible.dmax = TimeValue::infinite(); flexible.finite = false; flexible.event_s = tn_point.event_t; flexible.skip_p = scenario.skip; flexible.kill_p = scenario.kill; flexible.event_min = "emin_" + flexible_name; flexible.event_max = "emax_" + flexible_name; flexible.event_i = "event_" + flexible_name; flexible.skip = "skip_" + flexible_name; flexible.kill = "kill_" + flexible_name; scenario.flexibles.push_back(flexible); scenario.broadcasts.insert(flexible.event_min); scenario.broadcasts.insert(flexible.event_max); scenario.broadcasts.insert(flexible.skip); scenario.broadcasts.insert(flexible.kill); */ scenario.points.push_back(tn_point); }