Exemple #1
0
void TTExpression::parse(TTValue& toParse)
{
    // parse address
    if (toParse.size() > 0) {
        
        if (toParse[0].type() == kTypeSymbol) {
            
            mAddress = toParse[0];
            
            // parse operator
            if (toParse.size() > 1) {
                
                if (toParse[1].type() == kTypeSymbol) {
                    
                    mOperator = toParse[1];
                    
                    // we need to use word instead of sign because < and > symbol make trouble for XmlFormat parsing
                    if (mOperator == TTSymbol("=="))
                        mOperator = TTSymbol("equal");
                    
                    else if (mOperator == TTSymbol("!="))
                        mOperator = TTSymbol("different");
                    
                    else if (mOperator == TTSymbol(">"))
                        mOperator = TTSymbol("greaterThan");
                    
                    else if (mOperator == TTSymbol(">="))
                        mOperator = TTSymbol("greaterThanOrEqual");
                    
                    else if (mOperator == TTSymbol("<"))
                        mOperator = TTSymbol("lowerThan");
                    
                    else if (mOperator == TTSymbol("<="))
                        mOperator = TTSymbol("lowerThanOrEqual");
                    
                    // parse value
                    if (toParse.size() > 2) {
                        
                        mValue.copyFrom(toParse, 2);
                        
                        // convert to TTFloat64 for comparison purpose (see in evaluate method)
                        if (mValue.size())
                        {
                            if (mValue[0].type() != kTypeSymbol)
                            {
                                for (TTElementIter it = mValue.begin(); it != mValue.end(); it++)
                                    *it = TTFloat64(TTElement(*it));
                            }
                        }
                    }
                }
            }
        }
    }
}
Exemple #2
0
void
DemoApp::SetupScore()
{
    TTValue     args, out;
    TTObject    xmlHandler("XmlHandler");
    
    TTLogMessage("\n*** Initialisation of Score environnement ***\n");
    /////////////////////////////////////////////////////////////////////
    
    // Init the Score library (passing the folder path where all the dylibs are)
    TTScoreInit("/usr/local/jamoma");
    
    
    TTLogMessage("\n*** Reading of an interactive scenario file ***\n");
    /////////////////////////////////////////////////////////////////////
    
    // Create an empty Scenario
    mScenario = TTObject("Scenario");
    
    // Read DemoScenario1.score file to fill mScenario
    xmlHandler.set("object", mScenario);
    xmlHandler.send("Read", "../DemoScenario.score", out);
    
    
    TTLogMessage("\n*** Prepare scenario observation ***\n");
    /////////////////////////////////////////////////////////////////////
    
    // Create a callback for the "EventStatusChanged" notification sent by each event
    mEventStatusChangedCallback = TTObject("callback");
    mEventStatusChangedCallback.set("baton", TTPtr(this));
    mEventStatusChangedCallback.set("function", TTPtr(&DemoAppEventStatusChangedCallback));
    mEventStatusChangedCallback.set("notification", TTSymbol("EventStatusChanged"));
    
    // Get all events of the scenario and attach a callback to them
    TTValue timeEvents;
    mScenario.get("timeEvents", timeEvents);
    
    for (TTElementIter it = timeEvents.begin() ; it != timeEvents.end() ; it++) {
        TTObject event = TTElement(*it);
        event.registerObserverForNotifications(mEventStatusChangedCallback);
    }
    
    
    TTLogMessage("\n*** Start scenario execution ***\n");
    /////////////////////////////////////////////////////////////////////
    
    // Set the execution speed of the scenario
    mScenario.set("speed", 2.);
    
    // Start the scenario
    mScenario.send("Start");
    
    // Poll Scenario information
    mPollingThread = new TTThread(TTThreadCallbackType(DemoAppScenarioPollingThread), this);
}
Exemple #3
0
TTBoolean TTExpression::evaluate(const TTValue& value)
{
    TTValue toCompare = value;
    
    // convert to TTFloat64 to have the same type than mValue (see in parse method)
    if (toCompare.size())
    {
        if (toCompare[0].type() != kTypeSymbol)
        {
            for (TTElementIter it = toCompare.begin(); it != toCompare.end(); it++)
                *it = TTFloat64(TTElement(*it));
        }
    }
    
    if (mOperator == kTTSymEmpty)
        return YES;
    
    if (mOperator == TTSymbol("equal"))
        return toCompare == mValue;
    
    if (mOperator == TTSymbol("different"))
        return toCompare != mValue;
    
    if (mOperator == TTSymbol("greaterThan"))
        return toCompare > mValue;
    
    if (mOperator == TTSymbol("greaterThanOrEqual"))
        return toCompare >= mValue;
    
    if (mOperator == TTSymbol("lowerThan"))
        return toCompare < mValue;
    
    if (mOperator == TTSymbol("lowerThanOrEqual"))
        return toCompare <= mValue;
    
    return NO;
}