void triggers::paste (midipulse paste_tick) { if (m_trigger_copied) { midipulse len = m_clipboard.tick_end() - m_clipboard.tick_start() + 1; if (paste_tick == SEQ64_NO_PASTE_TRIGGER) { add(m_clipboard.tick_end() + 1, len, m_clipboard.offset() + len); m_clipboard.tick_start(m_clipboard.tick_end() + 1); m_clipboard.tick_end(m_clipboard.tick_start() + len - 1); midipulse offset = m_clipboard.offset() + len; m_clipboard.offset(adjust_offset(offset)); } else { /* * Set the +/- distance to paste the tick, from the start. */ long offset = paste_tick - m_clipboard.tick_start(); add(paste_tick, len, m_clipboard.offset() + offset); m_clipboard.tick_start(paste_tick); m_clipboard.tick_end(m_clipboard.tick_start() + len - 1); m_clipboard.increment_offset(offset); m_clipboard.offset(adjust_offset(m_clipboard.offset())); set_trigger_paste_tick(SEQ64_NO_PASTE_TRIGGER); /* reset */ } } }
/*---------------------------------------------------------------------------*/ static void incoming_packet(void) { if(packetbuf_totlen() != 0) { /* We check the authority level of the sender of the incoming packet. If the sending node has a lower authority level than we have, we synchronize to the time of the sending node and set our own authority level to be one more than the sending node. */ if(cc2420_authority_level_of_sender < authority_level) { adjust_offset(cc2420_time_of_departure, cc2420_time_of_arrival); if(cc2420_authority_level_of_sender + 1 != authority_level) { authority_level = cc2420_authority_level_of_sender + 1; } } } }
/*---------------------------------------------------------------------------*/ static void broadcast_recv(struct broadcast_conn *c, const rimeaddr_t *from) { struct timesynch_msg msg; memcpy(&msg, packetbuf_dataptr(), sizeof(msg)); /* We check the authority level of the sender of the incoming packet. If the sending node has a lower authority level than we have, we synchronize to the time of the sending node and set our own authority level to be one more than the sending node. */ if(msg.authority_level < authority_level) { adjust_offset(msg.timestamp + msg.authority_offset, packetbuf_attr(PACKETBUF_ATTR_TIMESTAMP)); timesynch_set_authority_level(msg.authority_level + 1); } }
/*---------------------------------------------------------------------------*/ void timesynch_incoming_packet(void) { if(packetbuf_totlen() != 0) { /* We check the authority level of the sender of the incoming packet. If the sending node has a lower authority level than we have, we synchronize to the time of the sending node and set our own authority level to be one more than the sending node. */ if(adjust_offset(cc2420_time_of_departure, cc2420_time_of_arrival)) { last_correction = clock_seconds(); authority_timeouts = 0; if(cc2420_authority_level_of_sender + 1 != authority_level) { authority_level = cc2420_authority_level_of_sender + 1; } } else if (authority_level == 0){ last_correction = clock_seconds(); } } }
void triggers::add ( midipulse tick, midipulse len, midipulse offset, bool fixoffset ) { trigger t; t.offset(fixoffset ? adjust_offset(offset) : offset); t.selected(false); t.tick_start(tick); t.tick_end(tick + len - 1); #ifdef SEQ64_USE_DEBUG_OUTPUT printf ( "triggers::add(): tick = %ld; len = %ld; offset = %ld; fix = %s\n", tick, len, offset, bool_string(fixoffset) ); #endif for (List::iterator i = m_triggers.begin(); i != m_triggers.end(); ++i) { if (i->tick_start() >= t.tick_start() && i->tick_end() <= t.tick_end()) { m_triggers.erase(i); /* inside the new one? erase */ i = m_triggers.begin(); /* THERE IS A BETTER WAY */ continue; } else if (i->tick_end() >= t.tick_end() && i->tick_start() <= t.tick_end()) { i->tick_start(t.tick_end() + 1); /* is the event's end inside? */ } else if ( i->tick_end() >= t.tick_start() && i->tick_start() <= t.tick_start() ) { i->tick_end(t.tick_start() - 1); /* last start inside new end? */ } } m_triggers.push_front(t); m_triggers.sort(); /* hmmm, another sort */ }
void triggers::adjust_offsets_to_length (midipulse newlength) { for (List::iterator i = m_triggers.begin(); i != m_triggers.end(); ++i) { i->offset(adjust_offset(i->offset())); i->offset(m_length - i->offset()); /* flip */ midipulse inverse_offset = m_length - (i->tick_start() % m_length); midipulse local_offset = (inverse_offset - i->offset()); local_offset %= m_length; midipulse inverse_offset_new = newlength - (i->tick_start() % newlength); midipulse new_offset = inverse_offset_new - local_offset; /** COMMON CODE? **/ i->offset(new_offset % newlength); i->offset(newlength - i->offset()); } }
Rect2 AnimatedSprite::get_item_rect() const { if (!frames.is_valid() || !frames->has_animation(animation) || frame<0 || frame>=frames->get_frame_count(animation)) { return Node2D::get_item_rect(); } Ref<Texture> t; if (animation) t = frames->get_frame(animation,frame); if (t.is_null()) return Node2D::get_item_rect(); Size2i s = t->get_size(); Point2 ofs=offset; adjust_offset(ofs, s); if (s==Size2(0,0)) s=Size2(1,1); return Rect2(ofs,s); }
bool triggers::move_selected (midipulse tick, bool fixoffset, grow_edit_t which) { bool result = true; midipulse mintick = 0; midipulse maxtick = 0x7ffffff; List::iterator s = m_triggers.begin(); for (List::iterator i = m_triggers.begin(); i != m_triggers.end(); ++i) { if (i->selected()) { /* * Too tricky. Beware the side-effect of incrementing the * i iterator. */ s = i; if (++i != m_triggers.end()) maxtick = i->tick_start() - 1; midipulse deltatick = 0; if (which == GROW_END) { midipulse ppqn_start = s->tick_start() + (m_ppqn / 8); deltatick = tick - s->tick_end(); if (deltatick > 0 && tick > maxtick) deltatick = maxtick - s->tick_end(); if (deltatick < 0 && (deltatick + s->tick_end() <= ppqn_start)) deltatick = ppqn_start - s->tick_end(); } else if (which == GROW_START) { midipulse ppqn_end = s->tick_end() - (m_ppqn / 8); deltatick = tick - s->tick_start(); if (deltatick < 0 && tick < mintick) deltatick = mintick - s->tick_start(); if (deltatick > 0 && (deltatick + s->tick_start() >= ppqn_end)) deltatick = ppqn_end - s->tick_start(); } else if (which == GROW_MOVE) { deltatick = tick - s->tick_start(); if (deltatick < 0 && tick < mintick) deltatick = mintick - s->tick_start(); if (deltatick > 0 && (deltatick + s->tick_end()) > maxtick) deltatick = maxtick - s->tick_end(); } /* * This code must be executed, even if deltatick == 0! * And setting result = deltatick == 0 causes some weirdness * in selection movement with the arrow keys in the perfroll. */ if (which == GROW_START || which == GROW_MOVE) s->increment_tick_start(deltatick); if (which == GROW_END || which == GROW_MOVE) s->increment_tick_end(deltatick); if (fixoffset) { s->increment_offset(deltatick); s->offset(adjust_offset(s->offset())); } break; } else mintick = i->tick_end() + 1; } return result; }
void triggers::move (midipulse starttick, midipulse distance, bool direction) { midipulse endtick = starttick + distance; for (List::iterator i = m_triggers.begin(); i != m_triggers.end(); ++i) { if (i->tick_start() < starttick && starttick < i->tick_end()) { if (direction) /* forward */ split(*i, starttick); else /* back */ split(*i, endtick); } if (i->tick_start() < starttick && starttick < i->tick_end()) { if (direction) /* forward */ split(*i, starttick); else /* back */ i->tick_end(starttick - 1); } if ( i->tick_start() >= starttick && i->tick_end() <= endtick && ! direction ) { m_triggers.erase(i); i = m_triggers.begin(); /* A BETTER WAY? */ } if (i->tick_start() < endtick && endtick < i->tick_end()) { if (! direction) /* forward */ i->tick_start(endtick); } } for (List::iterator i = m_triggers.begin(); i != m_triggers.end(); ++i) { if (direction) /* forward */ { if (i->tick_start() >= starttick) { midipulse added = i->tick_start() + distance; i->tick_start(added); added = i->tick_end() + distance; i->tick_end(added); added = (i->offset() + distance) % m_length; i->offset(added); } } else /* back */ { if (i->tick_start() >= endtick) { midipulse deducted = i->tick_start() - distance; i->tick_start(deducted); deducted = i->tick_end() - distance; i->tick_end(deducted); deducted = (m_length - (distance % m_length)) % m_length; i->offset(deducted); } } i->offset(adjust_offset(i->offset())); } }
void AnimatedSprite::_notification(int p_what) { switch(p_what) { case NOTIFICATION_PROCESS: { if (frames.is_null()) return; if (!frames->has_animation(animation)) return; if (frame<0) return; float speed = frames->get_animation_speed(animation) * play_rate; if (speed==0) return; //do nothing float remaining = get_process_delta_time(); while(remaining) { if (timeout<=0) { int fc = frames->get_frame_count(animation); if (frame>=fc-1) { if (frames->get_animation_loop(animation)) { frame=0; } else { frame=fc-1; // early exit so we don't do anything for non-looping ended animations, may want to // broadcast once more "frame" notify, pending break; } } else { frame++; } // to avoid timeout being reset for non-looping animations so queries can be use timeout value timeout = 1.0 / speed; update(); _change_notify("frame"); } float to_process = MIN(timeout,remaining); remaining-=to_process; timeout-=to_process; } } break; case NOTIFICATION_DRAW: { if (frames.is_null()) { print_line("no draw no faemos"); return; } if (frame<0) { print_line("no draw frame <0"); return; } if (!frames->has_animation(animation)) { print_line("no draw no anim: "+String(animation)); return; } Ref<Texture> texture = frames->get_frame(animation,frame); if (texture.is_null()) { print_line("no draw texture is null"); return; } //print_line("DECIDED TO DRAW"); RID ci = get_canvas_item(); /* texture->draw(ci,Point2()); break; */ Size2i s; s = texture->get_size(); Point2 ofs=offset; adjust_offset(ofs, s); if (OS::get_singleton()->get_use_pixel_snap()) { ofs=ofs.floor(); } Rect2 dst_rect(ofs,s); if (hflip) dst_rect.size.x=-dst_rect.size.x; if (vflip) dst_rect.size.y=-dst_rect.size.y; //texture->draw_rect(ci,dst_rect,false,modulate); texture->draw_rect_region(ci,dst_rect,Rect2(Vector2(),texture->get_size()),modulate); // VisualServer::get_singleton()->canvas_item_add_texture_rect_region(ci,dst_rect,texture->get_rid(),src_rect,modulate); } break; } }