13
0

Add modulus operator to MIDI transformer.

Useful for doing things like making alternating bowing patterns.
This commit is contained in:
David Robillard 2015-01-06 23:04:28 -05:00
parent 82c5349e61
commit 4d202d9157
3 changed files with 9 additions and 2 deletions

View File

@ -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());

View File

@ -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) {}

View File

@ -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;
}