Add modulus operator to MIDI transformer.
Useful for doing things like making alternating bowing patterns.
This commit is contained in:
parent
82c5349e61
commit
4d202d9157
@ -69,7 +69,7 @@ TransformDialog::Model::Model()
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const char* operator_labels[] = {
|
static const char* operator_labels[] = {
|
||||||
/* no PUSH */ "+", "-", "*", "/", NULL
|
/* no PUSH */ "+", "-", "*", "/", "mod", NULL
|
||||||
};
|
};
|
||||||
for (int o = 0; operator_labels[o]; ++o) {
|
for (int o = 0; operator_labels[o]; ++o) {
|
||||||
Gtk::TreeModel::Row row = *(operator_list->append());
|
Gtk::TreeModel::Row row = *(operator_list->append());
|
||||||
|
@ -106,7 +106,8 @@ public:
|
|||||||
ADD, ///< Add top two values
|
ADD, ///< Add top two values
|
||||||
SUB, ///< Subtract top from second-top
|
SUB, ///< Subtract top from second-top
|
||||||
MULT, ///< Multiply top two values
|
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) {}
|
Operation(Operator o, const Value& a=Value()) : op(o), arg(a) {}
|
||||||
|
@ -106,6 +106,12 @@ Transform::Operation::eval(Context& ctx) const
|
|||||||
}
|
}
|
||||||
value /= rhs.to_double();
|
value /= rhs.to_double();
|
||||||
break;
|
break;
|
||||||
|
case MOD:
|
||||||
|
if (rhs.to_double() == 0.0) {
|
||||||
|
return; // Program will fail safely
|
||||||
|
}
|
||||||
|
value = fmod(value, rhs.to_double());
|
||||||
|
break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user