Exemple #1
0
void osc_wire_t::event_start(unsigned seq, const piw::data_nb_t &id, const piw::xevent_data_buffer_t &b)
{
    output_ = piw::xevent_data_buffer_t(OUT_MASK,PIW_DATAQUEUE_SIZE_NORM);

    input_ = b.iterator();

    unsigned long long t = id.time();
    last_from_ = t;

	piw::data_nb_t d;
	if(input_->latest(IN_KEY,d,t))
	{
		process(IN_KEY,d,t);
	}

    source_start(seq,id,output_);

    root_->add_ticker(this);
}
Exemple #2
0
void eleap::eleap_t::impl_t::thing_dequeue_fast(const piw::data_nb_t &d)
{
    unsigned long long dt = d.time();
    unsigned char type = dt&0xff;
    int32_t arg1 = (dt&0xffffffff)>>8;
    //unsigned char arg2 = (t&0xff0000)>>16;
    
    switch(type)
    {
        case DATA_KNOWN_HANDS:
            if(d.is_array())
            {
                int32_t *hand_ids = (int32_t *)d.as_array();

                // check if known hands are still valid
                for(int i = 0; i < HANDS; ++i)
                {
                    hand_t *h = hands_[i].ptr();

                    if(h->leap_id_)
                    {
                        bool valid = false;
                        for(unsigned j = 0; j < d.as_arraylen(); ++j)
                        {
                            if(hand_ids[j] && h->leap_id_ == hand_ids[j])
                            {
                                valid = true;
                                break;
                            }
                        }
                    
                        if(!valid)
                        {
                            h->palm_wire_.ptr()->stop();
                            h->leap_id_ = 0;
                        }
                    }
                }
                
                // check if there are available hands to handle new ones
                for(unsigned i = 0; i < d.as_arraylen(); ++i)
                {
                    int32_t hand_id = hand_ids[i];
                    if(0 == hand_id)
                    {
                        continue;
                    }
                    
                    bool exists = false;
                    hand_t *available_hand = 0;
                    
                    for(int j = 0; j < HANDS; ++j)
                    {
                        hand_t *h = hands_[j].ptr();
                        if(!available_hand && 0 == h->leap_id_)
                        {
                            available_hand = h;
                        }
                        
                        if(hand_id == h->leap_id_)
                        {
                            exists = true;
                            break;
                        }
                    }
                    
                    if(!exists)
                    {
                        if(!available_hand)
                        {
                            break;
                        }
                        else
                        {
                            available_hand->leap_id_ = hand_id;
                            available_hand->palm_wire_.ptr()->start();
                        }
                    }
                }
            }
            break;
            
        case DATA_PALM_POSITION:
            if(d.is_array())
            {
                hand_t *h = 0;
                
                // try to use a known hand
                for(int i = 0; i < HANDS; ++i)
                {
                    if(hands_[i].ptr()->leap_id_ == arg1)
                    {
                        h = hands_[i].ptr();
                    }
                }
                
                if(h)
                {
                    h->palm_wire_.ptr()->add_palm_position(d.as_array_member(0), d.as_array_member(1), d.as_array_member(2));
                }
            }
            break;
    }
}