MidiTimeAxisView* const mtv = dynamic_cast<MidiTimeAxisView*>(&trackview);
MidiStreamView* const view = mtv->midi_view();
+ boost::shared_ptr<MidiRegion> mr = boost::dynamic_pointer_cast<MidiRegion> (_region);
+
+ if (!mr) {
+ return;
+ }
// Start of note in frames relative to region start
if (snap_t) {
t = snap_frame_to_grid_underneath (t, grid_frames);
}
- const MidiModel::TimeType beat_time = region_frames_to_region_beats(
- t + _region->start());
-
+ const MidiModel::TimeType beat_time = Evoral::Beats (trackview.session()->tempo_map().beat_at_frame (_region->position() + t)
+ - (mr->beat() - mr->start_beats().to_double()));
const double note = view->y_to_note(y);
const uint8_t chan = mtv->get_channel_for_add();
const uint8_t velocity = get_velocity_for_add(beat_time);
Trimmable::CanTrim can_trim () const;
PositionLockStyle position_lock_style () const { return _position_lock_style; }
-
+ double beat () { return _beat; }
void set_position_lock_style (PositionLockStyle ps);
void recompute_position_from_lock_style ();
virtual void set_position_internal (framepos_t pos, bool allow_bbt_recompute);
virtual void set_length_internal (framecnt_t);
virtual void set_start_internal (framecnt_t);
+ bool verify_start_and_length (framepos_t, framecnt_t&);
+ void first_edit ();
DataType _type;
private:
void mid_thaw (const PBD::PropertyChange&);
- void trim_to_internal (framepos_t position, framecnt_t length);
+ virtual void trim_to_internal (framepos_t position, framecnt_t length);
void modify_front (framepos_t new_position, bool reset_fade);
void modify_end (framepos_t new_position, bool reset_fade);
void maybe_uncopy ();
- void first_edit ();
bool verify_start (framepos_t);
- bool verify_start_and_length (framepos_t, framecnt_t&);
bool verify_start_mutable (framepos_t&_start);
bool verify_length (framecnt_t&);
void
MidiRegion::set_start_beats_from_start_frames ()
{
- BeatsFramesConverter c (_session.tempo_map(), _position - _start);
- _start_beats = c.from (_start);
+ _start_beats = Evoral::Beats (beat() - _session.tempo_map().beat_at_frame (_position - _start));
}
void
{
Region::update_after_tempo_map_change (false);
- /* _position has now been updated for the new tempo map */
- _start = _position - _session.tempo_map().framepos_minus_beats (_position, _start_beats);
+ /* _start has now been updated. */
_length = _session.tempo_map().framepos_plus_beats (_position, _length_beats) - _position;
PropertyChange s_and_l;
void
MidiRegion::update_length_beats ()
{
- BeatsFramesConverter converter (_session.tempo_map(), _position);
- _length_beats = converter.from (_length);
+ _length_beats = Evoral::Beats (_session.tempo_map().beat_at_frame (_position + _length) - beat());
}
void
Region::set_position_internal (pos, allow_bbt_recompute);
/* set _start to new position in tempo map */
- _start = _position - _session.tempo_map().framepos_minus_beats (_position, _start_beats);
+ _start = _position - _session.tempo_map().frame_at_beat (beat() - _start_beats.val().to_double());
/* leave _length_beats alone, and change _length to reflect the state of things
at the new position (tempo map may dictate a different number of frames).
*/
- BeatsFramesConverter converter (_session.tempo_map(), _position);
- Region::set_length_internal (converter.to (_length_beats));
+ Region::set_length_internal (_session.tempo_map().frame_at_beat (beat() + _length_beats.val().to_double()) - _position);
}
framecnt_t
Region::set_start_internal (s);
set_start_beats_from_start_frames ();
}
+
+void
+MidiRegion::trim_to_internal (framepos_t position, framecnt_t length)
+{
+ framepos_t new_start;
+
+ if (locked()) {
+ return;
+ }
+
+ PropertyChange what_changed;
+
+ /* beat has not been set by set_position_internal */
+ const double beat_delta = _session.tempo_map().beat_at_frame (position) - beat();
+ const double old_beat = beat();
+
+ /* Set position before length, otherwise for MIDI regions this bad thing happens:
+ * 1. we call set_length_internal; length in beats is computed using the region's current
+ * (soon-to-be old) position
+ * 2. we call set_position_internal; position is set and length in frames re-computed using
+ * length in beats from (1) but at the new position, which is wrong if the region
+ * straddles a tempo/meter change.
+ */
+
+ if (_position != position) {
+ set_position_internal (position, true);
+ what_changed.add (Properties::position);
+ }
+
+ const double new_beat = _session.tempo_map().beat_at_frame (position);
+ const double new_start_beat = _start_beats.val().to_double() + beat_delta;
+
+ new_start = _position - _session.tempo_map().frame_at_beat (new_beat - new_start_beat);
+
+ if (!verify_start_and_length (new_start, length)) {
+ return;
+ }
+
+ if (_start != new_start) {
+ _start_beats = Evoral::Beats (new_start_beat);
+ what_changed.add (Properties::start_beats);
+
+ set_start_internal (new_start);
+ what_changed.add (Properties::start);
+ }
+
+
+
+ if (_length != length) {
+ set_length_internal (length);
+ what_changed.add (Properties::length);
+ }
+
+ set_whole_file (false);
+
+ PropertyChange start_and_length;
+
+ start_and_length.add (Properties::start);
+ start_and_length.add (Properties::length);
+
+ if (what_changed.contains (start_and_length)) {
+ first_edit ();
+ }
+
+ if (!what_changed.empty()) {
+ send_change (what_changed);
+ }
+}
}
- _last_length = _length;
set_length_internal (len);
_whole_file = false;
first_edit ();
void
Region::set_length_internal (framecnt_t len)
{
+ _last_length = _length;
_length = len;
}
PropertyChange what_changed;
+ if (_start != new_start) {
+ set_start_internal (new_start);
+ what_changed.add (Properties::start);
+ }
+
+
/* Set position before length, otherwise for MIDI regions this bad thing happens:
* 1. we call set_length_internal; length in beats is computed using the region's current
* (soon-to-be old) position
what_changed.add (Properties::position);
}
- if (_start != new_start) {
- set_start_internal (new_start);
- what_changed.add (Properties::start);
- }
-
if (_length != length) {
if (!property_changes_suspended()) {
_last_length = _length;
return _position + (minlen - _start) - 1;
}
-