From 4d202d9157bef5b6325fe54b7874080952f86a37 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 6 Jan 2015 23:04:28 -0500 Subject: Add modulus operator to MIDI transformer. Useful for doing things like making alternating bowing patterns. --- gtk2_ardour/transform_dialog.cc | 2 +- libs/ardour/ardour/transform.h | 3 ++- libs/ardour/transform.cc | 6 ++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/gtk2_ardour/transform_dialog.cc b/gtk2_ardour/transform_dialog.cc index 35df027187..762f504aa2 100644 --- a/gtk2_ardour/transform_dialog.cc +++ b/gtk2_ardour/transform_dialog.cc @@ -69,7 +69,7 @@ TransformDialog::Model::Model() } static const char* operator_labels[] = { - /* no PUSH */ "+", "-", "*", "/", NULL + /* no PUSH */ "+", "-", "*", "/", "mod", NULL }; for (int o = 0; operator_labels[o]; ++o) { Gtk::TreeModel::Row row = *(operator_list->append()); diff --git a/libs/ardour/ardour/transform.h b/libs/ardour/ardour/transform.h index 2b63bb6af0..08e4a43521 100644 --- a/libs/ardour/ardour/transform.h +++ b/libs/ardour/ardour/transform.h @@ -106,7 +106,8 @@ public: ADD, ///< Add top two values SUB, ///< Subtract top from second-top MULT, ///< Multiply top two values - DIV ///< Divide second-top by top + DIV, ///< Divide second-top by top + MOD ///< Modulus (division remainder) }; Operation(Operator o, const Value& a=Value()) : op(o), arg(a) {} diff --git a/libs/ardour/transform.cc b/libs/ardour/transform.cc index 9a91a65731..3b4f53c860 100644 --- a/libs/ardour/transform.cc +++ b/libs/ardour/transform.cc @@ -106,6 +106,12 @@ Transform::Operation::eval(Context& ctx) const } value /= rhs.to_double(); break; + case MOD: + if (rhs.to_double() == 0.0) { + return; // Program will fail safely + } + value = fmod(value, rhs.to_double()); + break; default: break; } -- cgit v1.2.3