Skip to content

Commit 4c8e2b7

Browse files
committed
PoC: Implement += -= *= /= for control point editing
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.
1 parent dda27cd commit 4c8e2b7

File tree

5 files changed

+49
-15
lines changed

5 files changed

+49
-15
lines changed

gtk2_ardour/automation_line.cc

+41-9
Original file line numberDiff line numberDiff line change
@@ -394,26 +394,58 @@ AutomationLine::delta_to_string (double delta) const
394394
* @return Corresponding y fraction.
395395
*/
396396
double
397-
AutomationLine::string_to_fraction (string const & s) const
397+
AutomationLine::string_to_fraction (string const & s, double const old_fraction) const
398398
{
399-
double v;
400-
sscanf (s.c_str(), "%lf", &v);
401-
399+
bool is_db = false;
402400
switch (_desc.type) {
403401
case GainAutomation:
404402
case BusSendLevel:
405403
case EnvelopeAutomation:
406404
case TrimAutomation:
407405
case InsertReturnLevel:
408-
if (s == "-inf") { /* translation */
409-
v = 0;
410-
} else {
411-
v = dB_to_coefficient (v);
412-
}
406+
is_db = true;
413407
break;
414408
default:
415409
break;
416410
}
411+
double v;
412+
if ((s.length() > 2) && index("+-*/", s[0]) && (s[1] == '=')) {
413+
v = old_fraction;
414+
view_to_model_coord_y (v);
415+
if (is_db) {
416+
v = accurate_coefficient_to_dB(v);
417+
}
418+
double op_v;
419+
sscanf (s.c_str() + 2, "%lf", &op_v);
420+
if (op_v != 0.f) {
421+
switch (s[0]) {
422+
case '+':
423+
v += op_v;
424+
break;
425+
case '-':
426+
v -= op_v;
427+
break;
428+
case '*':
429+
v *= op_v;
430+
break;
431+
case '/':
432+
if (op_v > 1.0) {
433+
v /= op_v;
434+
}
435+
break;
436+
}
437+
}
438+
} else {
439+
sscanf (s.c_str(), "%lf", &v);
440+
}
441+
442+
if (is_db) {
443+
if (s == "-inf") { /* translation */
444+
v = 0;
445+
} else {
446+
v = dB_to_coefficient (v);
447+
}
448+
}
417449
return model_to_view_coord_y (v);
418450
}
419451

gtk2_ardour/automation_line.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class AutomationLine : public sigc::trackable, public PBD::StatefulDestructible
125125
std::string get_verbose_cursor_relative_string (double, double) const;
126126
std::string fraction_to_string (double) const;
127127
std::string delta_to_string (double) const;
128-
double string_to_fraction (std::string const &) const;
128+
double string_to_fraction (std::string const &, double old_fraction) const;
129129

130130
void view_to_model_coord_y (double &) const;
131131

gtk2_ardour/control_point_dialog.cc

+4-2
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,11 @@ ControlPointDialog::ControlPointDialog (ControlPoint* p, bool multi)
9090
}
9191

9292
double
93-
ControlPointDialog::get_y_fraction () const
93+
ControlPointDialog::get_y_fraction (ControlPoint* p) const
9494
{
95-
return point_->line().string_to_fraction (value_.get_text ());
95+
double const old_fraction = 1.0 - (p->get_y () / p->line().height ());
96+
97+
return point_->line().string_to_fraction (value_.get_text (), old_fraction);
9698
}
9799

98100
bool

gtk2_ardour/control_point_dialog.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ControlPointDialog : public ArdourDialog
2929
public:
3030
ControlPointDialog (ControlPoint *, bool multi);
3131

32-
double get_y_fraction () const;
32+
double get_y_fraction (ControlPoint *) const;
3333

3434
bool all_selected_points () const;
3535

gtk2_ardour/editor_mouse.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -2514,11 +2514,11 @@ Editor::edit_control_point (ArdourCanvas::Item* item)
25142514
}
25152515

25162516
if (d.all_selected_points ()) {
2517-
p->line().modify_points_y (cps, d.get_y_fraction ());
2517+
p->line().modify_points_y (cps, d.get_y_fraction (p)); // FIXME: multi edit somehow?
25182518
} else {
25192519
cps.clear ();
25202520
cps.push_back (p);
2521-
p->line().modify_points_y (cps, d.get_y_fraction ());
2521+
p->line().modify_points_y (cps, d.get_y_fraction (p));
25222522
}
25232523
}
25242524

0 commit comments

Comments
 (0)