diff --git a/src/sfizz/Opcode.h b/src/sfizz/Opcode.h index 79694ca5..45011a82 100644 --- a/src/sfizz/Opcode.h +++ b/src/sfizz/Opcode.h @@ -35,6 +35,12 @@ #include "absl/strings/numbers.h" namespace sfz { +/** + * @brief Opcode description class; should be very lightweight to use + * and move around. The class parses the parameters of the opcode + * on construction. + * + */ struct Opcode { Opcode() = delete; Opcode(absl::string_view inputOpcode, absl::string_view inputValue); @@ -45,6 +51,16 @@ struct Opcode { LEAK_DETECTOR(Opcode); }; +/** + * @brief Read a value from the sfz file and cast it to the destination parameter along + * with a proper clamping into range if needed. This particular template version acts on + * integral target types, but can accept floats as an input. + * + * @tparam ValueType the target casting type + * @param value the string value to be read and stored + * @param validRange the range of admitted values + * @return absl::optional the cast value, or null + */ template ::value, int> = 0> inline absl::optional readOpcode(absl::string_view value, const Range& validRange) { @@ -64,6 +80,16 @@ inline absl::optional readOpcode(absl::string_view value, const Range return validRange.clamp(static_cast(returnedValue)); } +/** + * @brief Read a value from the sfz file and cast it to the destination parameter along + * with a proper clamping into range if needed. This particular template version acts on + * floating types. + * + * @tparam ValueType the target casting type + * @param value the string value to be read and stored + * @param validRange the range of admitted values + * @return absl::optional the cast value, or null + */ template ::value, int> = 0> inline absl::optional readOpcode(absl::string_view value, const Range& validRange) { @@ -74,6 +100,9 @@ inline absl::optional readOpcode(absl::string_view value, const Range return validRange.clamp(returnedValue); } +/** + * @brief Read a boolean value from the sfz file and cast it to the destination parameter. + */ inline absl::optional readBooleanFromOpcode(const Opcode& opcode) { switch (hash(opcode.value)) { @@ -86,6 +115,15 @@ inline absl::optional readBooleanFromOpcode(const Opcode& opcode) } } +/** + * @brief Set a target parameter from an opcode value, with possibly a textual note rather + * than a number + * + * @tparam ValueType + * @param opcode the source opcode + * @param target the value to update + * @param validRange the range of admitted values used to clamp the opcode + */ template inline void setValueFromOpcode(const Opcode& opcode, ValueType& target, const Range& validRange) { @@ -96,6 +134,15 @@ inline void setValueFromOpcode(const Opcode& opcode, ValueType& target, const Ra target = *value; } +/** + * @brief Set a target parameter from an opcode value, with possibly a textual note rather + * than a number + * + * @tparam ValueType + * @param opcode the source opcode + * @param target the value to update + * @param validRange the range of admitted values used to clamp the opcode + */ template inline void setValueFromOpcode(const Opcode& opcode, absl::optional& target, const Range& validRange) { @@ -106,6 +153,15 @@ inline void setValueFromOpcode(const Opcode& opcode, absl::optional& target = *value; } +/** + * @brief Set a target end of a range from an opcode value, with possibly a textual note rather + * than a number + * + * @tparam ValueType + * @param opcode the source opcode + * @param target the value to update + * @param validRange the range of admitted values used to clamp the opcode + */ template inline void setRangeEndFromOpcode(const Opcode& opcode, Range& target, const Range& validRange) { @@ -116,6 +172,15 @@ inline void setRangeEndFromOpcode(const Opcode& opcode, Range& target target.setEnd(*value); } +/** + * @brief Set a target beginning of a range from an opcode value, with possibly a textual note rather + * than a number + * + * @tparam ValueType + * @param opcode the source opcode + * @param target the value to update + * @param validRange the range of admitted values used to clamp the opcode + */ template inline void setRangeStartFromOpcode(const Opcode& opcode, Range& target, const Range& validRange) { @@ -126,6 +191,14 @@ inline void setRangeStartFromOpcode(const Opcode& opcode, Range& targ target.setStart(*value); } +/** + * @brief Set a CC modulation parameter from an opcode value. + * + * @tparam ValueType + * @param opcode the source opcode + * @param target the new CC modulation parameter + * @param validRange the range of admitted values used to clamp the opcode + */ template inline void setCCPairFromOpcode(const Opcode& opcode, absl::optional& target, const Range& validRange) {