Don't leave internal edit mode when clicking on an automation region view (#4747).

git-svn-id: svn://localhost/ardour2/branches/3.0@11749 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Carl Hetherington 2012-03-22 16:41:23 +00:00
parent f9de5f6436
commit 3120bae8b4
10 changed files with 101 additions and 40 deletions

View File

@ -55,19 +55,28 @@ using namespace PBD;
using namespace Editing;
using namespace Gnome; // for Canvas
static const Evoral::IdentityConverter<double, framepos_t> default_converter;
/** @param converter A TimeConverter whose origin_b is the start time of the AutomationList in session frames.
* This will not be deleted by AutomationLine.
*/
AutomationLine::AutomationLine (const string& name, TimeAxisView& tv, ArdourCanvas::Group& parent,
boost::shared_ptr<AutomationList> al,
const Evoral::TimeConverter<double, framepos_t>* converter)
Evoral::TimeConverter<double, framepos_t>* converter)
: trackview (tv)
, _name (name)
, alist (al)
, _time_converter (converter ? converter : new Evoral::IdentityConverter<double, framepos_t>)
, _parent_group (parent)
, _offset (0)
, _time_converter (converter ? (*converter) : default_converter)
, _maximum_time (max_framepos)
{
if (converter) {
_time_converter = converter;
_our_time_converter = false;
} else {
_time_converter = new Evoral::IdentityConverter<double, framepos_t>;
_our_time_converter = true;
}
points_visible = false;
update_pending = false;
_uses_gain_mapping = false;
@ -103,6 +112,10 @@ AutomationLine::~AutomationLine ()
{
vector_delete (&control_points);
delete group;
if (_our_time_converter) {
delete _time_converter;
}
}
bool
@ -225,7 +238,7 @@ AutomationLine::modify_point_y (ControlPoint& cp, double y)
y = min (1.0, y);
y = _height - (y * _height);
double const x = trackview.editor().frame_to_unit (_time_converter.to((*cp.model())->when) - _offset);
double const x = trackview.editor().frame_to_unit (_time_converter->to((*cp.model())->when) - _offset);
trackview.editor().session()->begin_reversible_command (_("automation event move"));
trackview.editor().session()->add_command (
@ -286,11 +299,11 @@ AutomationLine::model_representation (ControlPoint& cp, ModelRepresentation& mr)
/* if xval has not changed, set it directly from the model to avoid rounding errors */
if (mr.xval == trackview.editor().frame_to_unit(_time_converter.to((*cp.model())->when)) - _offset) {
if (mr.xval == trackview.editor().frame_to_unit(_time_converter->to((*cp.model())->when)) - _offset) {
mr.xval = (*cp.model())->when - _offset;
} else {
mr.xval = trackview.editor().unit_to_frame (mr.xval);
mr.xval = _time_converter.from (mr.xval + _offset);
mr.xval = _time_converter->from (mr.xval + _offset);
}
/* convert y to model units; the x was already done above
@ -994,7 +1007,7 @@ AutomationLine::get_selectables (
(as it is the session frame position of the start of the source)
*/
framepos_t const session_frames_when = _time_converter.to (model_when) + _time_converter.origin_b ();
framepos_t const session_frames_when = _time_converter->to (model_when) + _time_converter->origin_b ();
if (session_frames_when >= start && session_frames_when <= end && (*i)->get_y() >= bot_track && (*i)->get_y() <= top_track) {
results.push_back (*i);
@ -1025,8 +1038,8 @@ AutomationLine::point_selection_to_control_points (PointSelection const & s)
for (vector<ControlPoint*>::iterator j = control_points.begin(); j != control_points.end(); ++j) {
double const rstart = trackview.editor().frame_to_unit (_time_converter.to (i->start) - _offset);
double const rend = trackview.editor().frame_to_unit (_time_converter.to (i->end) - _offset);
double const rstart = trackview.editor().frame_to_unit (_time_converter->to (i->start) - _offset);
double const rend = trackview.editor().frame_to_unit (_time_converter->to (i->end) - _offset);
if ((*j)->get_x() >= rstart && (*j)->get_x() <= rend) {
if ((*j)->get_y() >= bot && (*j)->get_y() <= top) {
@ -1212,7 +1225,7 @@ AutomationLine::set_state (const XMLNode &node, int version)
void
AutomationLine::view_to_model_coord (double& x, double& y) const
{
x = _time_converter.from (x);
x = _time_converter->from (x);
view_to_model_coord_y (y);
}
@ -1254,7 +1267,7 @@ AutomationLine::model_to_view_coord (double& x, double& y) const
y = y / (double)alist->parameter().max(); /* ... like this */
}
x = _time_converter.to (x) - _offset;
x = _time_converter->to (x) - _offset;
}
/** Called when our list has announced that its interpolation style has changed */
@ -1373,8 +1386,8 @@ AutomationLine::get_point_x_range () const
pair<framepos_t, framepos_t> r (max_framepos, 0);
for (AutomationList::const_iterator i = the_list()->begin(); i != the_list()->end(); ++i) {
r.first = min (r.first, _time_converter.to ((*i)->when) + _offset + _time_converter.origin_b ());
r.second = max (r.second, _time_converter.to ((*i)->when) + _offset + _time_converter.origin_b ());
r.first = min (r.first, _time_converter->to ((*i)->when) + _offset + _time_converter->origin_b ());
r.second = max (r.second, _time_converter->to ((*i)->when) + _offset + _time_converter->origin_b ());
}
return r;

View File

@ -59,7 +59,7 @@ class AutomationLine : public sigc::trackable, public PBD::StatefulDestructible
public:
AutomationLine (const std::string& name, TimeAxisView&, ArdourCanvas::Group&,
boost::shared_ptr<ARDOUR::AutomationList>,
const Evoral::TimeConverter<double, ARDOUR::framepos_t>* converter = 0);
Evoral::TimeConverter<double, ARDOUR::framepos_t>* converter = 0);
virtual ~AutomationLine ();
void queue_reset ();
@ -135,7 +135,7 @@ class AutomationLine : public sigc::trackable, public PBD::StatefulDestructible
virtual MementoCommandBinder<ARDOUR::AutomationList>* memento_command_binder ();
const Evoral::TimeConverter<double, ARDOUR::framepos_t>& time_converter () const {
return _time_converter;
return *_time_converter;
}
std::pair<ARDOUR::framepos_t, ARDOUR::framepos_t> get_point_x_range () const;
@ -155,6 +155,9 @@ class AutomationLine : public sigc::trackable, public PBD::StatefulDestructible
uint32_t _line_color;
boost::shared_ptr<ARDOUR::AutomationList> alist;
Evoral::TimeConverter<double, ARDOUR::framepos_t>* _time_converter;
/** true if _time_converter belongs to us (ie we should delete it) */
bool _our_time_converter;
bool _visible : 1;
bool _uses_gain_mapping : 1;
@ -207,8 +210,6 @@ class AutomationLine : public sigc::trackable, public PBD::StatefulDestructible
*/
ARDOUR::framecnt_t _offset;
const Evoral::TimeConverter<double, ARDOUR::framepos_t>& _time_converter;
void reset_line_coords (ControlPoint&);
void add_visible_control_point (uint32_t, uint32_t, double, double, ARDOUR::AutomationList::iterator, uint32_t);
double control_point_box_size ();

View File

@ -4076,26 +4076,43 @@ NoteDrag::aborted (bool)
/* XXX: TODO */
}
AutomationRangeDrag::AutomationRangeDrag (Editor* editor, ArdourCanvas::Item* item, list<AudioRange> const & r)
: Drag (editor, item)
/** Make an AutomationRangeDrag for lines in an AutomationTimeAxisView */
AutomationRangeDrag::AutomationRangeDrag (Editor* editor, AutomationTimeAxisView* atv, list<AudioRange> const & r)
: Drag (editor, atv->base_item ())
, _ranges (r)
, _nothing_to_drag (false)
{
DEBUG_TRACE (DEBUG::Drags, "New AutomationRangeDrag\n");
_atav = reinterpret_cast<AutomationTimeAxisView*> (_item->get_data ("trackview"));
assert (_atav);
setup (atv->lines ());
}
/* get all lines in the automation view */
list<boost::shared_ptr<AutomationLine> > lines = _atav->lines ();
/** Make an AutomationRangeDrag for region gain lines */
AutomationRangeDrag::AutomationRangeDrag (Editor* editor, AudioRegionView* rv, list<AudioRange> const & r)
: Drag (editor, rv->get_canvas_group ())
, _ranges (r)
, _nothing_to_drag (false)
{
DEBUG_TRACE (DEBUG::Drags, "New AutomationRangeDrag\n");
/* find those that overlap the ranges being dragged */
list<boost::shared_ptr<AutomationLine> >::iterator i = lines.begin ();
list<boost::shared_ptr<AutomationLine> > lines;
lines.push_back (rv->get_gain_line ());
setup (lines);
}
/** @param lines AutomationLines to drag.
* @param offset Offset from the session start to the points in the AutomationLines.
*/
void
AutomationRangeDrag::setup (list<boost::shared_ptr<AutomationLine> > const & lines)
{
/* find the lines that overlap the ranges being dragged */
list<boost::shared_ptr<AutomationLine> >::const_iterator i = lines.begin ();
while (i != lines.end ()) {
list<boost::shared_ptr<AutomationLine> >::iterator j = i;
list<boost::shared_ptr<AutomationLine> >::const_iterator j = i;
++j;
pair<framepos_t, framepos_t> const r = (*i)->get_point_x_range ();
pair<framepos_t, framepos_t> r = (*i)->get_point_x_range ();
/* check this range against all the AudioRanges that we are using */
list<AudioRange>::const_iterator k = _ranges.begin ();

View File

@ -932,11 +932,14 @@ private:
bool _zoom_out;
};
/** Drag of a range of automation data, changing value but not position */
/** Drag of a range of automation data (either on an automation track or region gain),
* changing value but not position.
*/
class AutomationRangeDrag : public Drag
{
public:
AutomationRangeDrag (Editor *, ArdourCanvas::Item *, std::list<ARDOUR::AudioRange> const &);
AutomationRangeDrag (Editor *, AutomationTimeAxisView *, std::list<ARDOUR::AudioRange> const &);
AutomationRangeDrag (Editor *, AudioRegionView *, std::list<ARDOUR::AudioRange> const &);
void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
void motion (GdkEvent *, bool);
@ -947,9 +950,14 @@ public:
return false;
}
bool active (Editing::MouseMode) {
return true;
}
private:
void setup (std::list<boost::shared_ptr<AutomationLine> > const &);
std::list<ARDOUR::AudioRange> _ranges;
AutomationTimeAxisView* _atav;
/** A line that is part of the drag */
struct Line {

View File

@ -456,9 +456,9 @@ Editor::mouse_mode_toggled (MouseMode m)
instant_save ();
if (!internal_editing()) {
if (mouse_mode != MouseRange && _join_object_range_state == JOIN_OBJECT_RANGE_NONE) {
if (mouse_mode != MouseRange && mouse_mode != MouseGain && _join_object_range_state == JOIN_OBJECT_RANGE_NONE) {
/* in all modes except range and joined object/range, hide the range selection,
/* in all modes except range, gain and joined object/range, hide the range selection,
show the object (region) selection.
*/
@ -824,7 +824,7 @@ Editor::button_press_handler_1 (ArdourCanvas::Item* item, GdkEvent* event, ItemT
AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*> (tvp.first);
if (smart_mode_action->get_active() && atv) {
/* smart "join" mode: drag automation */
_drags->set (new AutomationRangeDrag (this, atv->base_item(), selection->time), event, _cursors->up_down);
_drags->set (new AutomationRangeDrag (this, atv, selection->time), event, _cursors->up_down);
} else {
/* this was debated, but decided the more common action was to
make a new selection */
@ -1040,7 +1040,7 @@ Editor::button_press_handler_1 (ArdourCanvas::Item* item, GdkEvent* event, ItemT
/* if we're over an automation track, start a drag of its data */
AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*> (tvp.first);
if (atv) {
_drags->set (new AutomationRangeDrag (this, atv->base_item(), selection->time), event, _cursors->up_down);
_drags->set (new AutomationRangeDrag (this, atv, selection->time), event, _cursors->up_down);
}
/* if we're over a track and a region, and in the `object' part of a region,
@ -1119,6 +1119,17 @@ Editor::button_press_handler_1 (ArdourCanvas::Item* item, GdkEvent* event, ItemT
return true;
break;
case SelectionItem:
{
AudioRegionView* arv = dynamic_cast<AudioRegionView *> (clicked_regionview);
if (arv) {
_drags->set (new AutomationRangeDrag (this, arv, selection->time), event, _cursors->up_down);
_drags->start_grab (event);
}
return true;
break;
}
case AutomationLineItem:
_drags->set (new LineDrag (this, item), event);
break;
@ -1286,7 +1297,7 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp
break;
case RegionItem:
if (!dynamic_cast<MidiRegionView*> (clicked_regionview)) {
if (!dynamic_cast<MidiRegionView*> (clicked_regionview) && !dynamic_cast<AutomationRegionView*> (clicked_regionview)) {
leave_internal_edit_mode = true;
}
break;

View File

@ -29,7 +29,7 @@ MidiAutomationLine::MidiAutomationLine (
boost::shared_ptr<ARDOUR::AutomationList> list,
boost::shared_ptr<ARDOUR::MidiRegion> region,
Evoral::Parameter parameter,
const Evoral::TimeConverter<double, ARDOUR::framepos_t>* converter)
Evoral::TimeConverter<double, ARDOUR::framepos_t>* converter)
: AutomationLine (name, tav, group, list, converter)
, _region (region)
, _parameter (parameter)

View File

@ -30,7 +30,7 @@ public:
boost::shared_ptr<ARDOUR::AutomationList>,
boost::shared_ptr<ARDOUR::MidiRegion>,
Evoral::Parameter,
const Evoral::TimeConverter<double, ARDOUR::framepos_t>* converter = 0);
Evoral::TimeConverter<double, ARDOUR::framepos_t>* converter = 0);
MementoCommandBinder<ARDOUR::AutomationList>* memento_command_binder ();

View File

@ -44,6 +44,8 @@ AudioRegionGainLine::AudioRegionGainLine (const string & name, AudioRegionView&
// If this isn't true something is horribly wrong, and we'll get catastrophic gain values
assert(l->parameter().type() == EnvelopeAutomation);
_time_converter->set_origin_b (r.region()->position() - r.region()->start());
group->raise_to_top ();
group->property_y() = 2;
set_uses_gain_mapping (true);

View File

@ -43,7 +43,7 @@ class AudioRegionGainLine : public AutomationLine
void remove_point (ControlPoint&);
private:
private:
AudioRegionView& rv;
};

View File

@ -25,6 +25,12 @@ namespace Evoral {
*
* Think of the conversion method names as if they are written in-between
* the two template parameters (i.e. "A <name> B").
*
* _origin_b should be the origin for conversion in the units of B.
* That is, there is some point in time _origin_b, such that:
*
* to() converts a time _origin_b + a into an offset from _origin_b in units of B.
* from() converts a time _origin_b + b into an offset from _origin_b in units of A.
*/
template<typename A, typename B>
class TimeConverter {
@ -52,7 +58,10 @@ protected:
};
/** A stub TimeConverter that simple statically casts between types. */
/** A stub TimeConverter that simple statically casts between types.
* _origin_b has no bearing here, as there is no time conversion
* going on.
*/
template<typename A, typename B>
class IdentityConverter : public TimeConverter<A,B> {
public: