void ComponentGate::update(float milliseconds) { timeInState += milliseconds; switch(state) { case STATE_A: break; case STATE_B: break; case STATE_TRANSITION_AB: update_transition(milliseconds, timeInState, timeToTransitionAB, STATE_B, positionA, positionB); break; case STATE_TRANSITION_BA: update_transition(milliseconds, timeInState, timeToTransitionBA, STATE_A, positionB, positionA); break; } }
/* update motor output for quadplane */ void QuadPlane::update(void) { if (!setup()) { return; } bool quad_mode = (plane.control_mode == QSTABILIZE || plane.control_mode == QHOVER || plane.control_mode == QLOITER || in_vtol_auto()); if (!quad_mode) { update_transition(); } else { assisted_flight = false; // run low level rate controllers attitude_control->rate_controller_run(); // output to motors motors->output(); transition_start_ms = 0; if (throttle_wait && !plane.is_flying()) { transition_state = TRANSITION_DONE; } else { transition_state = TRANSITION_AIRSPEED_WAIT; } last_throttle = motors->get_throttle(); } // disable throttle_wait when throttle rises above 10% if (throttle_wait && (plane.channel_throttle->control_in > 10 || plane.failsafe.ch3_failsafe || plane.failsafe.ch3_counter>0)) { throttle_wait = false; } }
/** * For the random number r \in [0,1], get the selected Transition, * perform its actions, and update any downstream dependencies */ void LatticeTransitionManager::move(double r) { std::size_t selected = transition(r); for (const Action& a : transitions_[selected]->actions()) { lattice::State* prev = lattice_->perform(a); // These transitions had a condition on the previous state, // which changed, so now they must be disabled if (prev != a.state()) { for (const std::size_t& affected : downstream_coord_[a.coord()][prev->id()]) { enabled_rates_[affected] = 0.0; } } } // These transitions have a condition on the new state(s), // and may now be enabled (if they were disabled before) for (const std::size_t& affected : downstream_[selected]) { if (enabled_rates_[affected] == 0.0) { update_transition(affected); } } update_accumulated_rates(); }
int AModule::render(Samples *buffer, int64_t input_len, int64_t start_position, int direction, int sample_rate, int use_nudge) { int64_t edl_rate = get_edl()->session->sample_rate; const int debug = 0; if(debug) printf("AModule::render %d\n", __LINE__); if(use_nudge) start_position += track->nudge * sample_rate / edl_rate; AEdit *playable_edit; int64_t end_position; if(direction == PLAY_FORWARD) end_position = start_position + input_len; else end_position = start_position - input_len; int buffer_offset = 0; int result = 0; // // Flip range around so the source is always read forward. // if(direction == PLAY_REVERSE) // { // start_project -= input_len; // end_position -= input_len; // } // Clear buffer bzero(buffer->get_data(), input_len * sizeof(double)); // The EDL is normalized to the requested sample rate because // the requested rate may be the project sample rate and a sample rate // might as well be directly from the source rate to the requested rate. // Get first edit containing the range if(direction == PLAY_FORWARD) playable_edit = (AEdit*)track->edits->first; else playable_edit = (AEdit*)track->edits->last; if(debug) printf("AModule::render %d\n", __LINE__); while(playable_edit) { int64_t edit_start = playable_edit->startproject; int64_t edit_end = playable_edit->startproject + playable_edit->length; // Normalize to requested rate edit_start = edit_start * sample_rate / edl_rate; edit_end = edit_end * sample_rate / edl_rate; if(direction == PLAY_FORWARD) { if(start_position < edit_end && end_position > edit_start) { break; } playable_edit = (AEdit*)playable_edit->next; } else { if(end_position < edit_end && start_position > edit_start) { break; } playable_edit = (AEdit*)playable_edit->previous; } } if(debug) printf("AModule::render %d\n", __LINE__); // Fill output one fragment at a time while(start_position != end_position) { int64_t fragment_len = input_len; if(debug) printf("AModule::render %d " _LD " " _LD "\n", __LINE__, start_position, end_position); // Clamp fragment to end of input if(direction == PLAY_FORWARD && start_position + fragment_len > end_position) fragment_len = end_position - start_position; else if(direction == PLAY_REVERSE && start_position - fragment_len < end_position) fragment_len = start_position - end_position; if(debug) printf("AModule::render %d " _LD "\n", __LINE__, fragment_len); // Normalize position here since update_transition is a boolean operation. update_transition(start_position * edl_rate / sample_rate, PLAY_FORWARD); if(playable_edit) { AEdit *previous_edit = (AEdit*)playable_edit->previous; // Normalize EDL positions to requested rate int64_t edit_startproject = playable_edit->startproject; int64_t edit_endproject = playable_edit->startproject + playable_edit->length; int64_t edit_startsource = playable_edit->startsource; if(debug) printf("AModule::render %d " _LD "\n", __LINE__, fragment_len); edit_startproject = edit_startproject * sample_rate / edl_rate; edit_endproject = edit_endproject * sample_rate / edl_rate; edit_startsource = edit_startsource * sample_rate / edl_rate; if(debug) printf("AModule::render %d " _LD "\n", __LINE__, fragment_len); // Clamp fragment to end of edit if(direction == PLAY_FORWARD && start_position + fragment_len > edit_endproject) fragment_len = edit_endproject - start_position; else if(direction == PLAY_REVERSE && start_position - fragment_len < edit_startproject) fragment_len = start_position - edit_startproject; if(debug) printf("AModule::render %d " _LD "\n", __LINE__, fragment_len); // Clamp to end of transition int64_t transition_len = 0; if(transition && previous_edit) { transition_len = transition->length * sample_rate / edl_rate; if(direction == PLAY_FORWARD && start_position < edit_startproject + transition_len && start_position + fragment_len > edit_startproject + transition_len) fragment_len = edit_startproject + transition_len - start_position; else if(direction == PLAY_REVERSE && start_position > edit_startproject + transition_len && start_position - fragment_len < edit_startproject + transition_len) fragment_len = start_position - edit_startproject - transition_len; } if(debug) printf("AModule::render %d buffer_offset=%d fragment_len=" _LD "\n", __LINE__, buffer_offset, fragment_len); Samples output(buffer); output.set_offset(output.get_offset() + buffer_offset); if(import_samples(playable_edit, start_position, edit_startproject, edit_startsource, direction, sample_rate, &output, fragment_len)) result = 1; if(debug) printf("AModule::render %d\n", __LINE__); // Read transition into temp and render if(transition && previous_edit) { int64_t previous_startproject = previous_edit->startproject * sample_rate / edl_rate; int64_t previous_startsource = previous_edit->startsource * sample_rate / edl_rate; // Allocate transition temp size int transition_fragment_len = fragment_len; if(direction == PLAY_FORWARD && fragment_len + start_position > edit_startproject + transition_len) fragment_len = edit_startproject + transition_len - start_position; // Read into temp buffers // Temp + master or temp + temp ? temp + master if(transition_temp && transition_temp->get_allocated() < fragment_len) { delete transition_temp; transition_temp = 0; } if(!transition_temp) { transition_temp = new Samples(fragment_len); } if(debug) printf("AModule::render %d " _LD "\n", __LINE__, fragment_len); if(transition_fragment_len > 0) { // Previous_edit is always the outgoing segment, regardless of direction import_samples(previous_edit, start_position, previous_startproject, previous_startsource, direction, sample_rate, transition_temp, transition_fragment_len); int64_t current_position; // Reverse buffers here so transitions always render forward. if(direction == PLAY_REVERSE) { Resample::reverse_buffer(output.get_data(), transition_fragment_len); Resample::reverse_buffer(transition_temp->get_data(), transition_fragment_len); current_position = start_position - transition_fragment_len - edit_startproject; } else { current_position = start_position - edit_startproject; } transition_server->process_transition( transition_temp, &output, current_position, transition_fragment_len, transition->length); // Reverse output buffer here so transitions always render forward. if(direction == PLAY_REVERSE) Resample::reverse_buffer(output.get_data(), transition_fragment_len); } } if(debug) printf("AModule::render %d start_position=" _LD " end_position=" _LD " fragment_len=" _LD "\n", __LINE__, start_position, end_position, fragment_len); if(direction == PLAY_REVERSE) { if(playable_edit && start_position - fragment_len <= edit_startproject) playable_edit = (AEdit*)playable_edit->previous; } else { if(playable_edit && start_position + fragment_len >= edit_endproject) playable_edit = (AEdit*)playable_edit->next; } } if(fragment_len > 0) { buffer_offset += fragment_len; if(direction == PLAY_FORWARD) start_position += fragment_len; else start_position -= fragment_len; } } if(debug) printf("AModule::render %d\n", __LINE__); return result; }
/** * Mark all Transitions as enabled/disabled */ void LatticeTransitionManager::update_all_transitions() { for (std::size_t t = 0; t < transitions_.size(); t++) { update_transition(t); } }