mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-08 15:54:57 +01:00
Allow trim of midi regions to before the start of the source. Fixes #3156.
git-svn-id: svn://localhost/ardour2/branches/3.0@8212 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
f8e16276d9
commit
f3fc6195bc
10 changed files with 82 additions and 21 deletions
|
|
@ -1533,6 +1533,7 @@ TrimDrag::start_grab (GdkEvent* event, Gdk::Cursor*)
|
||||||
framepos_t const pf = adjusted_current_frame (event);
|
framepos_t const pf = adjusted_current_frame (event);
|
||||||
|
|
||||||
if (Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) {
|
if (Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) {
|
||||||
|
/* Move the contents of the region around without changing the region bounds */
|
||||||
_operation = ContentsTrim;
|
_operation = ContentsTrim;
|
||||||
Drag::start_grab (event, _editor->cursors()->trimmer);
|
Drag::start_grab (event, _editor->cursors()->trimmer);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1723,6 +1724,7 @@ TrimDrag::finished (GdkEvent* event, bool movement_occurred)
|
||||||
if (_operation == StartTrim) {
|
if (_operation == StartTrim) {
|
||||||
i->view->trim_front_ending ();
|
i->view->trim_front_ending ();
|
||||||
}
|
}
|
||||||
|
|
||||||
i->view->region()->resume_property_changes ();
|
i->view->region()->resume_property_changes ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3246,4 +3246,9 @@ MidiRegionView::trim_front_ending ()
|
||||||
_note_group->reparent (*group);
|
_note_group->reparent (*group);
|
||||||
delete _temporary_note_group;
|
delete _temporary_note_group;
|
||||||
_temporary_note_group = 0;
|
_temporary_note_group = 0;
|
||||||
|
|
||||||
|
if (_region->start() < 0) {
|
||||||
|
/* Trim drag made start time -ve; fix this */
|
||||||
|
midi_region()->fix_negative_start ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -107,13 +107,20 @@ class MidiRegion : public Region
|
||||||
boost::shared_ptr<MidiModel> model() { return midi_source()->model(); }
|
boost::shared_ptr<MidiModel> model() { return midi_source()->model(); }
|
||||||
boost::shared_ptr<const MidiModel> model() const { return midi_source()->model(); }
|
boost::shared_ptr<const MidiModel> model() const { return midi_source()->model(); }
|
||||||
|
|
||||||
|
void fix_negative_start ();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
virtual bool can_trim_start_before_source_start () const {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class RegionFactory;
|
friend class RegionFactory;
|
||||||
|
|
||||||
MidiRegion (const SourceList&);
|
MidiRegion (const SourceList&);
|
||||||
MidiRegion (boost::shared_ptr<const MidiRegion>, frameoffset_t offset = 0, bool offset_relative = true);
|
MidiRegion (boost::shared_ptr<const MidiRegion>, frameoffset_t offset = 0, bool offset_relative = true);
|
||||||
|
|
||||||
private:
|
|
||||||
framecnt_t _read_at (const SourceList&, Evoral::EventSink<framepos_t>& dst,
|
framecnt_t _read_at (const SourceList&, Evoral::EventSink<framepos_t>& dst,
|
||||||
framepos_t position,
|
framepos_t position,
|
||||||
framecnt_t dur,
|
framecnt_t dur,
|
||||||
|
|
|
||||||
|
|
@ -315,6 +315,10 @@ class Region
|
||||||
/** Constructor for derived types only */
|
/** Constructor for derived types only */
|
||||||
Region (Session& s, framepos_t start, framecnt_t length, const std::string& name, DataType);
|
Region (Session& s, framepos_t start, framecnt_t length, const std::string& name, DataType);
|
||||||
|
|
||||||
|
virtual bool can_trim_start_before_source_start () const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void send_change (const PBD::PropertyChange&);
|
void send_change (const PBD::PropertyChange&);
|
||||||
void mid_thaw (const PBD::PropertyChange&);
|
void mid_thaw (const PBD::PropertyChange&);
|
||||||
|
|
|
||||||
|
|
@ -306,9 +306,22 @@ MidiRegion::model_automation_state_changed (Evoral::Parameter const & p)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* the source will have an iterator into the model, and that iterator will have been set up
|
/* the source will have an iterator into the model, and that iterator will have been set up
|
||||||
for a given set of filtered_paramters, so now that we've changed that list we must invalidate
|
for a given set of filtered_parameters, so now that we've changed that list we must invalidate
|
||||||
the iterator.
|
the iterator.
|
||||||
*/
|
*/
|
||||||
Glib::Mutex::Lock lm (midi_source(0)->mutex());
|
Glib::Mutex::Lock lm (midi_source(0)->mutex());
|
||||||
midi_source(0)->invalidate ();
|
midi_source(0)->invalidate ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** This is called when a trim drag has resulted in a -ve _start time for this region.
|
||||||
|
* Fix it up by adding some empty space to the source.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
MidiRegion::fix_negative_start ()
|
||||||
|
{
|
||||||
|
BeatsFramesConverter c (_session.tempo_map(), _position);
|
||||||
|
|
||||||
|
MidiModel::WriteLock lock (model()->edit_lock ());
|
||||||
|
model()->insert_silence_at_start (c.from (-_start));
|
||||||
|
_start = 0;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -732,13 +732,7 @@ Region::trim_start (framepos_t new_position, void */*src*/)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
framepos_t new_start;
|
framepos_t new_start;
|
||||||
frameoffset_t start_shift;
|
frameoffset_t const start_shift = new_position - _position;
|
||||||
|
|
||||||
if (new_position > _position) {
|
|
||||||
start_shift = new_position - _position;
|
|
||||||
} else {
|
|
||||||
start_shift = -(_position - new_position);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (start_shift > 0) {
|
if (start_shift > 0) {
|
||||||
|
|
||||||
|
|
@ -759,6 +753,7 @@ Region::trim_start (framepos_t new_position, void */*src*/)
|
||||||
} else {
|
} else {
|
||||||
new_start = _start + start_shift;
|
new_start = _start + start_shift;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -813,9 +808,10 @@ Region::modify_front (framepos_t new_position, bool reset_fade, void *src)
|
||||||
framecnt_t newlen = 0;
|
framecnt_t newlen = 0;
|
||||||
framepos_t delta = 0;
|
framepos_t delta = 0;
|
||||||
|
|
||||||
/* can't trim it back passed where source position zero is located */
|
if (!can_trim_start_before_source_start ()) {
|
||||||
|
/* can't trim it back past where source position zero is located */
|
||||||
new_position = max (new_position, source_zero);
|
new_position = max (new_position, source_zero);
|
||||||
|
}
|
||||||
|
|
||||||
if (new_position > _position) {
|
if (new_position > _position) {
|
||||||
newlen = _length - (new_position - _position);
|
newlen = _length - (new_position - _position);
|
||||||
|
|
@ -887,18 +883,13 @@ Region::trim_to (framepos_t position, framecnt_t length, void *src)
|
||||||
void
|
void
|
||||||
Region::trim_to_internal (framepos_t position, framecnt_t length, void */*src*/)
|
Region::trim_to_internal (framepos_t position, framecnt_t length, void */*src*/)
|
||||||
{
|
{
|
||||||
frameoffset_t start_shift;
|
|
||||||
framepos_t new_start;
|
framepos_t new_start;
|
||||||
|
|
||||||
if (locked()) {
|
if (locked()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (position > _position) {
|
frameoffset_t const start_shift = position - _position;
|
||||||
start_shift = position - _position;
|
|
||||||
} else {
|
|
||||||
start_shift = -(_position - position);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (start_shift > 0) {
|
if (start_shift > 0) {
|
||||||
|
|
||||||
|
|
@ -910,7 +901,7 @@ Region::trim_to_internal (framepos_t position, framecnt_t length, void */*src*/)
|
||||||
|
|
||||||
} else if (start_shift < 0) {
|
} else if (start_shift < 0) {
|
||||||
|
|
||||||
if (_start < -start_shift) {
|
if (_start < -start_shift && !can_trim_start_before_source_start ()) {
|
||||||
new_start = 0;
|
new_start = 0;
|
||||||
} else {
|
} else {
|
||||||
new_start = _start + start_shift;
|
new_start = _start + start_shift;
|
||||||
|
|
@ -1609,7 +1600,7 @@ Region::can_trim () const
|
||||||
|
|
||||||
ct = CanTrim (ct | FrontTrimLater | EndTrimEarlier);
|
ct = CanTrim (ct | FrontTrimLater | EndTrimEarlier);
|
||||||
|
|
||||||
if (start() != 0) {
|
if (start() != 0 || can_trim_start_before_source_start ()) {
|
||||||
ct = CanTrim (ct | FrontTrimEarlier);
|
ct = CanTrim (ct | FrontTrimEarlier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -170,6 +170,9 @@ struct Event {
|
||||||
inline const uint8_t* buffer() const { return _buf; }
|
inline const uint8_t* buffer() const { return _buf; }
|
||||||
inline uint8_t*& buffer() { return _buf; }
|
inline uint8_t*& buffer() { return _buf; }
|
||||||
|
|
||||||
|
void set_time (Time);
|
||||||
|
void set_original_time (Time);
|
||||||
|
|
||||||
inline event_id_t id() const { return _id; }
|
inline event_id_t id() const { return _id; }
|
||||||
inline void set_id (event_id_t n) { _id = n; }
|
inline void set_id (event_id_t n) { _id = n; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -173,6 +173,8 @@ public:
|
||||||
|
|
||||||
void set_notes (const Sequence<Time>::Notes& n);
|
void set_notes (const Sequence<Time>::Notes& n);
|
||||||
|
|
||||||
|
void insert_silence_at_start (Time);
|
||||||
|
|
||||||
typedef std::vector< boost::shared_ptr< Event<Time> > > SysExes;
|
typedef std::vector< boost::shared_ptr< Event<Time> > > SysExes;
|
||||||
inline SysExes& sysexes() { return _sysexes; }
|
inline SysExes& sysexes() { return _sysexes; }
|
||||||
inline const SysExes& sysexes() const { return _sysexes; }
|
inline const SysExes& sysexes() const { return _sysexes; }
|
||||||
|
|
|
||||||
|
|
@ -90,6 +90,20 @@ Event<Timestamp>::~Event() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename Timestamp>
|
||||||
|
void
|
||||||
|
Event<Timestamp>::set_time (Timestamp t)
|
||||||
|
{
|
||||||
|
_nominal_time = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Timestamp>
|
||||||
|
void
|
||||||
|
Event<Timestamp>::set_original_time (Timestamp t)
|
||||||
|
{
|
||||||
|
_original_time = t;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // EVORAL_EVENT_ALLOC
|
#endif // EVORAL_EVENT_ALLOC
|
||||||
|
|
||||||
template class Event<Evoral::MusicalTime>;
|
template class Event<Evoral::MusicalTime>;
|
||||||
|
|
|
||||||
|
|
@ -1076,6 +1076,26 @@ Sequence<Time>::control_list_marked_dirty ()
|
||||||
set_edited (true);
|
set_edited (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename Time>
|
||||||
|
void
|
||||||
|
Sequence<Time>::insert_silence_at_start (Time t)
|
||||||
|
{
|
||||||
|
for (typename Notes::iterator i = _notes.begin(); i != _notes.end(); ++i) {
|
||||||
|
(*i)->set_time ((*i)->time() + t);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (typename SysExes::iterator i = _sysexes.begin (); i != _sysexes.end(); ++i) {
|
||||||
|
(*i)->set_time ((*i)->time() + t);
|
||||||
|
(*i)->set_original_time ((*i)->original_time() + t);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (typename Controls::iterator i = _controls.begin(); i != _controls.end(); ++i) {
|
||||||
|
i->second->list()->shift (0, t);
|
||||||
|
}
|
||||||
|
|
||||||
|
_edited = true;
|
||||||
|
}
|
||||||
|
|
||||||
template class Sequence<Evoral::MusicalTime>;
|
template class Sequence<Evoral::MusicalTime>;
|
||||||
|
|
||||||
} // namespace Evoral
|
} // namespace Evoral
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue