+ if (from_undo) {
+ return;
+ }
+
+ if (!_track || Config->get_automation_follows_regions () == false) {
+ return;
+ }
+
+ list< Evoral::RangeMove<double> > movements;
+
+ for (list< Evoral::RangeMove<framepos_t> >::const_iterator i = movements_frames.begin();
+ i != movements_frames.end();
+ ++i) {
+
+ movements.push_back(Evoral::RangeMove<double>(i->from, i->length, i->to));
+ }
+
+ /* move panner automation */
+ boost::shared_ptr<Pannable> pannable = _track->pannable();
+ Evoral::ControlSet::Controls& c (pannable->controls());
+
+ for (Evoral::ControlSet::Controls::iterator ci = c.begin(); ci != c.end(); ++ci) {
+ boost::shared_ptr<AutomationControl> ac = boost::dynamic_pointer_cast<AutomationControl>(ci->second);
+ if (!ac) {
+ continue;
+ }
+ boost::shared_ptr<AutomationList> alist = ac->alist();
+
+ XMLNode & before = alist->get_state ();
+ bool const things_moved = alist->move_ranges (movements);
+ if (things_moved) {
+ _session.add_command (new MementoCommand<AutomationList> (
+ *alist.get(), &before, &alist->get_state ()));
+ }
+ }
+
+ /* move processor automation */
+ _track->foreach_processor (boost::bind (&Diskstream::move_processor_automation, this, _1, movements_frames));
+}
+
+void
+Diskstream::move_processor_automation (boost::weak_ptr<Processor> p, list< Evoral::RangeMove<framepos_t> > const & movements_frames)
+{
+ boost::shared_ptr<Processor> processor (p.lock ());
+ if (!processor) {
+ return;
+ }
+
+ list< Evoral::RangeMove<double> > movements;
+ for (list< Evoral::RangeMove<framepos_t> >::const_iterator i = movements_frames.begin(); i != movements_frames.end(); ++i) {
+ movements.push_back(Evoral::RangeMove<double>(i->from, i->length, i->to));
+ }
+
+ set<Evoral::Parameter> const a = processor->what_can_be_automated ();
+
+ for (set<Evoral::Parameter>::const_iterator i = a.begin (); i != a.end (); ++i) {
+ boost::shared_ptr<AutomationList> al = processor->automation_control(*i)->alist();
+ XMLNode & before = al->get_state ();
+ bool const things_moved = al->move_ranges (movements);
+ if (things_moved) {
+ _session.add_command (
+ new MementoCommand<AutomationList> (
+ *al.get(), &before, &al->get_state ()
+ )
+ );
+ }
+ }
+}
+
+void
+Diskstream::check_record_status (framepos_t transport_frame, bool can_record)
+{
+ int possibly_recording;
+ int rolling;
+ int change;
+ const int transport_rolling = 0x4;
+ const int track_rec_enabled = 0x2;
+ const int global_rec_enabled = 0x1;
+ const int fully_rec_enabled = (transport_rolling|track_rec_enabled|global_rec_enabled);
+
+ /* merge together the 3 factors that affect record status, and compute
+ * what has changed.
+ */
+
+ rolling = _session.transport_speed() != 0.0f;
+ possibly_recording = (rolling << 2) | ((int)record_enabled() << 1) | (int)can_record;
+ change = possibly_recording ^ last_possibly_recording;
+
+ if (possibly_recording == last_possibly_recording) {
+ return;
+ }
+
+ const framecnt_t existing_material_offset = _session.worst_playback_latency();
+
+ if (possibly_recording == fully_rec_enabled) {
+
+ if (last_possibly_recording == fully_rec_enabled) {
+ return;
+ }
+
+ capture_start_frame = _session.transport_frame();
+ first_recordable_frame = capture_start_frame + _capture_offset;
+ last_recordable_frame = max_framepos;
+
+ DEBUG_TRACE (DEBUG::CaptureAlignment, string_compose ("%1: @ %7 (%9) FRF = %2 CSF = %4 CO = %5, EMO = %6 RD = %8 WOL %10 WTL %11\n",
+ name(), first_recordable_frame, last_recordable_frame, capture_start_frame,
+ _capture_offset,
+ existing_material_offset,
+ transport_frame,
+ _roll_delay,
+ _session.transport_frame(),
+ _session.worst_output_latency(),
+ _session.worst_track_latency()));
+
+
+ if (_alignment_style == ExistingMaterial) {
+ first_recordable_frame += existing_material_offset;
+ DEBUG_TRACE (DEBUG::CaptureAlignment, string_compose ("\tshift FRF by EMO %1\n",
+ first_recordable_frame));
+ }
+
+ prepare_record_status (capture_start_frame);
+
+ } else {
+
+ if (last_possibly_recording == fully_rec_enabled) {
+
+ /* we were recording last time */
+
+ if (change & transport_rolling) {
+
+ /* transport-change (stopped rolling): last_recordable_frame was set in ::prepare_to_stop(). We
+ * had to set it there because we likely rolled past the stopping point to declick out,
+ * and then backed up.
+ */
+
+ } else {
+ /* punch out */
+
+ last_recordable_frame = _session.transport_frame() + _capture_offset;
+
+ if (_alignment_style == ExistingMaterial) {
+ last_recordable_frame += existing_material_offset;
+ }
+ }
+ }
+ }
+
+ last_possibly_recording = possibly_recording;
+}
+
+void
+Diskstream::route_going_away ()
+{
+ _io.reset ();
+}
+
+void
+Diskstream::calculate_record_range (Evoral::OverlapType ot, framepos_t transport_frame, framecnt_t nframes,
+ framecnt_t & rec_nframes, framecnt_t & rec_offset)
+{
+ switch (ot) {
+ case Evoral::OverlapNone:
+ rec_nframes = 0;
+ break;
+
+ case Evoral::OverlapInternal:
+ /* ---------- recrange
+ * |---| transrange
+ */
+ rec_nframes = nframes;
+ rec_offset = 0;
+ break;
+
+ case Evoral::OverlapStart:
+ /* |--------| recrange
+ * -----| transrange
+ */
+ rec_nframes = transport_frame + nframes - first_recordable_frame;
+ if (rec_nframes) {
+ rec_offset = first_recordable_frame - transport_frame;
+ }
+ break;
+
+ case Evoral::OverlapEnd:
+ /* |--------| recrange
+ * |-------- transrange
+ */
+ rec_nframes = last_recordable_frame - transport_frame;
+ rec_offset = 0;
+ break;
+
+ case Evoral::OverlapExternal:
+ /* |--------| recrange
+ * -------------- transrange
+ */
+ rec_nframes = last_recordable_frame - first_recordable_frame;
+ rec_offset = first_recordable_frame - transport_frame;
+ break;
+ }
+
+ DEBUG_TRACE (DEBUG::CaptureAlignment, string_compose ("%1 rec? %2 @ %3 (for %4) FRF %5 LRF %6 : rf %7 @ %8\n",
+ _name, enum_2_string (ot), transport_frame, nframes,
+ first_recordable_frame, last_recordable_frame, rec_nframes, rec_offset));
+}
+
+void
+Diskstream::prepare_to_stop (framepos_t transport_frame, framepos_t audible_frame)
+{
+ switch (_alignment_style) {
+ case ExistingMaterial:
+ last_recordable_frame = transport_frame + _capture_offset;
+ DEBUG_TRACE (DEBUG::CaptureAlignment, string_compose("%1: prepare to stop sets last recordable frame to %2 + %3 = %4\n", _name, transport_frame, _capture_offset, last_recordable_frame));
+ break;
+
+ case CaptureTime:
+ last_recordable_frame = audible_frame; // note that capture_offset is zero
+ /* we may already have captured audio before the last_recordable_frame (audible frame),
+ so deal with this.
+ */
+ if (last_recordable_frame > capture_start_frame) {
+ capture_captured = min (capture_captured, last_recordable_frame - capture_start_frame);
+ }
+ DEBUG_TRACE (DEBUG::CaptureAlignment, string_compose("%1: prepare to stop sets last recordable frame to audible frame @ %2\n", _name, audible_frame));
+ break;
+ }
+
+}
+
+void
+Diskstream::engage_record_enable ()
+{
+ g_atomic_int_set (&_record_enabled, 1);
+}
+
+void
+Diskstream::disengage_record_enable ()
+{
+ g_atomic_int_set (&_record_enabled, 0);
+}
+
+void
+Diskstream::engage_record_safe ()
+{
+ g_atomic_int_set (&_record_safe, 1);
+}
+
+void
+Diskstream::disengage_record_safe ()
+{
+ g_atomic_int_set (&_record_safe, 0);
+}
+
+framecnt_t
+Diskstream::default_disk_read_chunk_frames()
+{
+ return 65536;
+}
+
+framecnt_t
+Diskstream::default_disk_write_chunk_frames ()
+{
+ return 65536;
+}
+
+void
+Diskstream::set_buffering_parameters (BufferingPreset bp)
+{
+ framecnt_t read_chunk_size;
+ framecnt_t read_buffer_size;
+ framecnt_t write_chunk_size;
+ framecnt_t write_buffer_size;
+
+ if (!get_buffering_presets (bp, read_chunk_size, read_buffer_size, write_chunk_size, write_buffer_size)) {