コード例 #1
0
ファイル: ConstraintElement.cpp プロジェクト: Sciss/i-score
void ConstraintElement::play(TimeValue t)
{
    m_offset = iscore::convert::time(t);
    m_iscore_constraint.duration.setPlayPercentage(0);

    auto start_state = m_ossia_constraint->getStartEvent()->getState();
    auto offset_state = m_ossia_constraint->offset(m_offset);

    flattenAndFilter(start_state);
    flattenAndFilter(offset_state);
    m_state_on_play->launch();

    try {
        m_ossia_constraint->start();
        executionStarted();
    }
    catch(const std::exception& e) {
        qDebug() << e.what();
    }

}
コード例 #2
0
ファイル: ConstraintElement.cpp プロジェクト: Sciss/i-score
void ConstraintElement::flattenAndFilter(const std::shared_ptr<OSSIA::StateElement>& element)
{
    if (!element)
        return;
    
    switch (element->getType())
    {
        case OSSIA::StateElement::Type::MESSAGE :
        {
            std::shared_ptr<OSSIA::Message> messageToAppend = std::dynamic_pointer_cast<OSSIA::Message>(element);
            
            // find message with the same address to replace it
            bool found = false;
            for (auto it = m_state_on_play->stateElements().begin();
                 it != m_state_on_play->stateElements().end();
                 it++)
            {
                std::shared_ptr<OSSIA::Message> messageToCheck = std::dynamic_pointer_cast<OSSIA::Message>(*it);
                
                // replace if addresses are the same
                if (messageToCheck->getAddress() == messageToAppend->getAddress())
                {
                    *it = element;
                    found = true;
                    break;
                }
            }
            
            // if not found append it
            if (!found)
                m_state_on_play->stateElements().push_back(element);
            
            break;
        }
        case OSSIA::StateElement::Type::STATE :
        {
            std::shared_ptr<OSSIA::State> stateToFlatAndFilter = std::dynamic_pointer_cast<OSSIA::State>(element);
            
            for (const auto& e : stateToFlatAndFilter->stateElements())
            {
                flattenAndFilter(e);
            }
            break;
        }
            
        default:
        {
            m_state_on_play->stateElements().push_back(element);
            break;
        }
    }
}
コード例 #3
0
ファイル: TimeNodeElement.cpp プロジェクト: himito/i-score
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(...)
        {

        }
    });
}