X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fautomation_line.cc;h=aa4f25129934a88b472751e4f05e1fe811cf82c1;hb=5f9e81b105e84988a92c1f448fa46d9054893b55;hp=1cfd7eeb48d4a7c657d27d0142d7b35bb9a53bf6;hpb=e5e12acc5698090f2c0c614385e457cc0b46fbb0;p=ardour.git diff --git a/gtk2_ardour/automation_line.cc b/gtk2_ardour/automation_line.cc index 1cfd7eeb48..aa4f251299 100644 --- a/gtk2_ardour/automation_line.cc +++ b/gtk2_ardour/automation_line.cc @@ -17,14 +17,17 @@ */ +#include + #ifdef COMPILER_MSVC #include -/* isinf() & isnan() are C99 standards, which older MSVC doesn't provide */ -#define isinf(val) !((bool)_finite((double)val)) -#define isnan(val) (bool)_isnan((double)val) + +// 'std::isnan()' is not available in MSVC. +#define isnan_local(val) (bool)_isnan((double)val) +#else +#define isnan_local std::isnan #endif -#include #include #include #include @@ -39,6 +42,7 @@ #include "ardour/automation_list.h" #include "ardour/dB.h" #include "ardour/debug.h" +#include "ardour/parameter_types.h" #include "ardour/tempo.h" #include "evoral/Curve.hpp" @@ -58,6 +62,7 @@ #include "ardour/event_type_map.h" #include "ardour/session.h" +#include "ardour/value_as_string.h" #include "i18n.h" @@ -69,8 +74,11 @@ using namespace Editing; /** @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::Item& parent, - boost::shared_ptr al, +AutomationLine::AutomationLine (const string& name, + TimeAxisView& tv, + ArdourCanvas::Item& parent, + boost::shared_ptr al, + const ParameterDescriptor& desc, Evoral::TimeConverter* converter) : trackview (tv) , _name (name) @@ -79,12 +87,11 @@ AutomationLine::AutomationLine (const string& name, TimeAxisView& tv, ArdourCanv , _parent_group (parent) , _offset (0) , _maximum_time (max_framepos) + , _desc (desc) { if (converter) { - _time_converter = converter; _our_time_converter = false; } else { - _time_converter = new Evoral::IdentityConverter; _our_time_converter = true; } @@ -112,7 +119,8 @@ AutomationLine::AutomationLine (const string& name, TimeAxisView& tv, ArdourCanv trackview.session()->register_with_memento_command_factory(alist->id(), this); if (alist->parameter().type() == GainAutomation || - alist->parameter().type() == EnvelopeAutomation) { + alist->parameter().type() == EnvelopeAutomation || + desc.unit == ParameterDescriptor::DB) { set_uses_gain_mapping (true); } @@ -137,6 +145,13 @@ AutomationLine::event_handler (GdkEvent* event) return PublicEditor::instance().canvas_line_event (event, line, this); } +bool +AutomationLine::is_stepped() const +{ + return (_desc.toggled || + (alist && alist->interpolation() == AutomationList::Discrete)); +} + void AutomationLine::update_visibility () { @@ -145,7 +160,7 @@ AutomationLine::update_visibility () when automation points have been removed (the line will still follow the shape of the old points). */ - if (alist->interpolation() != AutomationList::Discrete && control_points.size() >= 2) { + if (control_points.size() >= 2) { line->show(); } else { line->hide (); @@ -172,7 +187,11 @@ AutomationLine::update_visibility () } else { line->hide (); for (vector::iterator i = control_points.begin(); i != control_points.end(); ++i) { - (*i)->hide (); + if (_visible & ControlPoints) { + (*i)->show (); + } else { + (*i)->hide (); + } } } @@ -191,11 +210,6 @@ AutomationLine::hide () double AutomationLine::control_point_box_size () { - if (alist->interpolation() == AutomationList::Discrete) { - return max((_height*4.0) / (double)(alist->parameter().max() - alist->parameter().min()), - 4.0); - } - if (_height > TimeAxisView::preset_height (HeightLarger)) { return 8.0; } else if (_height > (guint32) TimeAxisView::preset_height (HeightNormal)) { @@ -278,7 +292,7 @@ AutomationLine::modify_point_y (ControlPoint& cp, double y) reset_line_coords (cp); if (line_points.size() > 1) { - line->set (line_points); + line->set_steps (line_points, is_stepped()); } alist->freeze (); @@ -356,24 +370,20 @@ AutomationLine::get_verbose_cursor_relative_string (double original, double frac string AutomationLine::fraction_to_string (double fraction) const { - char buf[32]; - if (_uses_gain_mapping) { + char buf[32]; if (fraction == 0.0) { snprintf (buf, sizeof (buf), "-inf"); } else { snprintf (buf, sizeof (buf), "%.1f", accurate_coefficient_to_dB (slider_position_to_gain_with_max (fraction, Config->get_max_gain()))); } + return buf; } else { view_to_model_coord_y (fraction); - if (EventTypeMap::instance().is_integer (alist->parameter())) { - snprintf (buf, sizeof (buf), "%d", (int)fraction); - } else { - snprintf (buf, sizeof (buf), "%.2f", fraction); - } + return ARDOUR::value_as_string (_desc, fraction); } - return buf; + return ""; /*NOTREACHED*/ } /** @@ -406,11 +416,7 @@ AutomationLine::fraction_to_relative_string (double original, double fraction) c } else { view_to_model_coord_y (original); view_to_model_coord_y (fraction); - if (EventTypeMap::instance().is_integer (alist->parameter())) { - snprintf (buf, sizeof (buf), "%d", (int)fraction - (int)original); - } else { - snprintf (buf, sizeof (buf), "%.2f", fraction - original); - } + return ARDOUR::value_as_string (_desc, fraction - original); } return buf; @@ -715,7 +721,7 @@ AutomationLine::drag_motion (double const x, float fraction, bool ignore_x, bool */ if (line_points.size() > 1) { - line->set (line_points); + line->set_steps (line_points, is_stepped()); } } @@ -909,12 +915,18 @@ AutomationLine::set_selected_points (PointSelection const & points) (*i)->set_selected (true); } + if (points.empty()) { + remove_visibility (SelectedControlPoints); + } else { + add_visibility (SelectedControlPoints); + } + set_colors (); } void AutomationLine::set_colors () { - set_line_color (ARDOUR_UI::config()->get_canvasvar_AutomationLine()); + set_line_color (ARDOUR_UI::config()->get_AutomationLine()); for (vector::iterator i = control_points.begin(); i != control_points.end(); ++i) { (*i)->set_color (); } @@ -967,7 +979,7 @@ AutomationLine::reset_callback (const Evoral::ControlList& events) model_to_view_coord (tx, ty); - if (isnan (tx) || isnan (ty)) { + if (isnan_local (tx) || isnan_local (ty)) { warning << string_compose (_("Ignoring illegal points on AutomationLine \"%1\""), _name) << endmsg; continue; @@ -1022,7 +1034,7 @@ AutomationLine::reset_callback (const Evoral::ControlList& events) line_points[n].y = control_points[n]->get_y(); } - line->set (line_points); + line->set_steps (line_points, is_stepped()); update_visibility (); } @@ -1076,11 +1088,6 @@ AutomationLine::clear () new MementoCommand (memento_command_binder (), &before, &alist->get_state())); } -void -AutomationLine::change_model (AutomationList::iterator /*i*/, double /*x*/, double /*y*/) -{ -} - void AutomationLine::set_list (boost::shared_ptr list) { @@ -1125,17 +1132,13 @@ AutomationLine::remove_visibility (VisibleAspects va) void AutomationLine::track_entered() { - if (alist->interpolation() != AutomationList::Discrete) { - add_visibility (ControlPoints); - } + add_visibility (ControlPoints); } void AutomationLine::track_exited() { - if (alist->interpolation() != AutomationList::Discrete) { - remove_visibility (ControlPoints); - } + remove_visibility (ControlPoints); } XMLNode & @@ -1162,7 +1165,7 @@ AutomationLine::view_to_model_coord (double& x, double& y) const void AutomationLine::view_to_model_coord_y (double& y) const { - /* TODO: This should be more generic ... */ + /* TODO: This should be more generic (use ParameterDescriptor) */ if (alist->parameter().type() == GainAutomation || alist->parameter().type() == EnvelopeAutomation) { y = slider_position_to_gain_with_max (y, Config->get_max_gain()); @@ -1173,17 +1176,18 @@ AutomationLine::view_to_model_coord_y (double& y) const y = 1.0 - y; } else if (alist->parameter().type() == PanWidthAutomation) { y = 2.0 * y - 1.0; - } else if (alist->parameter().type() == PluginAutomation) { - y = y * (double)(alist->get_max_y()- alist->get_min_y()) + alist->get_min_y(); } else { - y = rint (y * alist->parameter().max()); + y = y * (double)(alist->get_max_y() - alist->get_min_y()) + alist->get_min_y(); + if (_desc.toggled || _desc.integer_step) { + y = round(y); + } } } void -AutomationLine::model_to_view_coord (double& x, double& y) const +AutomationLine::model_to_view_coord_y (double& y) const { - /* TODO: This should be more generic ... */ + /* TODO: This should be more generic (use ParameterDescriptor) */ if (alist->parameter().type() == GainAutomation || alist->parameter().type() == EnvelopeAutomation) { y = gain_to_slider_position_with_max (y, Config->get_max_gain()); @@ -1192,12 +1196,15 @@ AutomationLine::model_to_view_coord (double& x, double& y) const y = 1.0 - y; } else if (alist->parameter().type() == PanWidthAutomation) { y = .5 + y * .5; - } else if (alist->parameter().type() == PluginAutomation) { - y = (y - alist->get_min_y()) / (double)(alist->get_max_y()- alist->get_min_y()); } else { - y = y / (double)alist->parameter().max(); /* ... like this */ + y = (y - alist->get_min_y()) / (double)(alist->get_max_y() - alist->get_min_y()); } +} +void +AutomationLine::model_to_view_coord (double& x, double& y) const +{ + model_to_view_coord_y (y); x = _time_converter->to (x) - _offset; } @@ -1205,11 +1212,8 @@ AutomationLine::model_to_view_coord (double& x, double& y) const void AutomationLine::interpolation_changed (AutomationList::InterpolationStyle style) { - if (style == AutomationList::Discrete) { - set_visibility (ControlPoints); - line->hide(); - } else { - set_visibility (Line); + if (line_points.size() > 1) { + line->set_steps(line_points, is_stepped()); } }