<commit_before>/**
 * @file data.cpp
 * @brief  Data sources of various kinds (including Diamond Apparatus)
 *
 */

#include "model.h"
#include <diamondapparatus/diamondapparatus.h>

class DiamondComponent : public ComponentType {
    FloatParameter *pAdd,*pMul;
    StringParameter *pTopic;
public:
    DiamondComponent() : ComponentType("diamond","data"){}
    virtual void init() {
        setOutput(0,tFloat,"out");
        setParams(pTopic=new StringParameter("topic","data"),
                  pMul=new FloatParameter("mul",-100,100,1),
                  pAdd=new FloatParameter("mul",-100,100,1),
                  NULL);
    }
    
    virtual void initComponentInstance(ComponentInstance *c){
        try {
            diamondapparatus::init();
            const char *s = pTopic->get(c->component);
            diamondapparatus::subscribe(s);
        } catch(diamondapparatus::DiamondException e){
            printf("Diamond problem : %s\n",e.what());
        }
    }
    
    virtual void onParamChanged(ComponentInstance *ci,UNUSED Parameter *p){
        if(p == pTopic){
            const char *s = pTopic->get(ci->component);
            diamondapparatus::subscribe(s);
        }
    }
    
    virtual void shutdownComponentInstance(ComponentInstance *c){
        diamondapparatus::destroy();
    }
    
    virtual void run(ComponentInstance *ci,int out){
        Component *c = ci->component;
        const char *s = pTopic->get(c);
        diamondapparatus::Topic t = diamondapparatus::get(s);
        float o;
        o = t[0].f();
        
        o *= pMul->get(c);
        o += pAdd->get(c);
        tFloat->setOutput(ci,0,o);
    }
};

static DiamondComponent diamondgen;
        
              
    
    
<commit_msg>Diamond bug fixes. Still a weird problem on exit..<commit_after>/**
 * @file data.cpp
 * @brief  Data sources of various kinds (including Diamond Apparatus)
 *
 */

#include "model.h"
#include <diamondapparatus/diamondapparatus.h>

class DiamondComponent : public ComponentType {
    FloatParameter *pAdd,*pMul;
    StringParameter *pTopic;
public:
    DiamondComponent() : ComponentType("diamond","data"){}
    virtual void init() {
        setOutput(0,tFloat,"out");
        setParams(pTopic=new StringParameter("topic","data"),
                  pMul=new FloatParameter("mul",-100,100,1),
                  pAdd=new FloatParameter("add",-100,100,0),
                  NULL);
    }
    
    virtual void initComponentInstance(ComponentInstance *c){
        try {
            diamondapparatus::init();
            const char *s = pTopic->get(c->component);
            diamondapparatus::subscribe(s);
        } catch(diamondapparatus::DiamondException e){
            printf("Diamond problem : %s\n",e.what());
        }
    }
    
    virtual void onParamChanged(ComponentInstance *ci,UNUSED Parameter *p){
        try {
            if(p == pTopic){
                const char *s = pTopic->get(ci->component);
                diamondapparatus::subscribe(s);
            }
        } catch(diamondapparatus::DiamondException e){
            printf("Diamond problem : %s\n",e.what());
        }
    }
    
    virtual void shutdownComponentInstance(ComponentInstance *c){
        diamondapparatus::destroy();
    }
    
    virtual void run(ComponentInstance *ci,int out){
        Component *c = ci->component;
        const char *s = pTopic->get(c);
        try {
            diamondapparatus::Topic t = diamondapparatus::get(s);
            float o;
            o = t[0].f();
            
            o *= pMul->get(c);
            o += pAdd->get(c);
            tFloat->setOutput(ci,0,o);
        } catch(diamondapparatus::DiamondException e){
            printf("Diamond problem : %s\n",e.what());
        }
    }
};

static DiamondComponent diamondgen;





{'fraction_non_alphanumeric': 0.13121220089403102, 'fraction_numerical': 0.008940310281356823, 'mean_word_length': 2.2512820512820513, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3483474', 'n_tokens_mistral': 1152, 'n_tokens_neox': 1095, 'n_words': 218}