Skip to content

Commit

Permalink
PoC: Implement += -= *= /= for control point editing
Browse files Browse the repository at this point in the history
For example, if editing a control point at 7 dB and entering "+= 3"
in the input field instead of "7", it will set the control pointto 10
dB.

This is especially useful when editing multiple automation points at
once.
  • Loading branch information
kiilerix committed Sep 18, 2023
1 parent dda27cd commit 4c8e2b7
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 15 deletions.
50 changes: 41 additions & 9 deletions gtk2_ardour/automation_line.cc
Original file line number Diff line number Diff line change
Expand Up @@ -394,26 +394,58 @@ AutomationLine::delta_to_string (double delta) const
* @return Corresponding y fraction.
*/
double
AutomationLine::string_to_fraction (string const & s) const
AutomationLine::string_to_fraction (string const & s, double const old_fraction) const
{
double v;
sscanf (s.c_str(), "%lf", &v);

bool is_db = false;
switch (_desc.type) {
case GainAutomation:
case BusSendLevel:
case EnvelopeAutomation:
case TrimAutomation:
case InsertReturnLevel:
if (s == "-inf") { /* translation */
v = 0;
} else {
v = dB_to_coefficient (v);
}
is_db = true;
break;
default:
break;
}
double v;
if ((s.length() > 2) && index("+-*/", s[0]) && (s[1] == '=')) {
v = old_fraction;
view_to_model_coord_y (v);
if (is_db) {
v = accurate_coefficient_to_dB(v);
}
double op_v;
sscanf (s.c_str() + 2, "%lf", &op_v);
if (op_v != 0.f) {
switch (s[0]) {
case '+':
v += op_v;
break;
case '-':
v -= op_v;
break;
case '*':
v *= op_v;
break;
case '/':
if (op_v > 1.0) {
v /= op_v;
}
break;
}
}
} else {
sscanf (s.c_str(), "%lf", &v);
}

if (is_db) {
if (s == "-inf") { /* translation */
v = 0;
} else {
v = dB_to_coefficient (v);
}
}
return model_to_view_coord_y (v);
}

Expand Down
2 changes: 1 addition & 1 deletion gtk2_ardour/automation_line.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class AutomationLine : public sigc::trackable, public PBD::StatefulDestructible
std::string get_verbose_cursor_relative_string (double, double) const;
std::string fraction_to_string (double) const;
std::string delta_to_string (double) const;
double string_to_fraction (std::string const &) const;
double string_to_fraction (std::string const &, double old_fraction) const;

void view_to_model_coord_y (double &) const;

Expand Down
6 changes: 4 additions & 2 deletions gtk2_ardour/control_point_dialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@ ControlPointDialog::ControlPointDialog (ControlPoint* p, bool multi)
}

double
ControlPointDialog::get_y_fraction () const
ControlPointDialog::get_y_fraction (ControlPoint* p) const
{
return point_->line().string_to_fraction (value_.get_text ());
double const old_fraction = 1.0 - (p->get_y () / p->line().height ());

return point_->line().string_to_fraction (value_.get_text (), old_fraction);
}

bool
Expand Down
2 changes: 1 addition & 1 deletion gtk2_ardour/control_point_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ControlPointDialog : public ArdourDialog
public:
ControlPointDialog (ControlPoint *, bool multi);

double get_y_fraction () const;
double get_y_fraction (ControlPoint *) const;

bool all_selected_points () const;

Expand Down
4 changes: 2 additions & 2 deletions gtk2_ardour/editor_mouse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2514,11 +2514,11 @@ Editor::edit_control_point (ArdourCanvas::Item* item)
}

if (d.all_selected_points ()) {
p->line().modify_points_y (cps, d.get_y_fraction ());
p->line().modify_points_y (cps, d.get_y_fraction (p)); // FIXME: multi edit somehow?
} else {
cps.clear ();
cps.push_back (p);
p->line().modify_points_y (cps, d.get_y_fraction ());
p->line().modify_points_y (cps, d.get_y_fraction (p));
}
}

Expand Down

0 comments on commit 4c8e2b7

Please sign in to comment.