Skip to content

Commit

Permalink
fix mac std::optional::value support using operator *
Browse files Browse the repository at this point in the history
  • Loading branch information
Yikai-Liao committed Dec 25, 2023
1 parent 23c00a8 commit cb23074
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion include/Score.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,7 @@ void Score<T>::from(const Score<U> &other, const std::optional<i32> min_dur) {
auto new_pedals = other.template convert_ttype<Pedal, T>(track.pedals);
if constexpr (std::is_same_v<T, Tick>) {
if(min_dur.has_value()) {
const auto min_dur_tick = min_dur.value();
const auto min_dur_tick = *min_dur;
for(auto &note: new_notes) {
if(note.duration < min_dur_tick) note.duration = min_dur_tick;
}
Expand Down
10 changes: 6 additions & 4 deletions src/symusic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ py::class_<score::Tempo<T>> bind_tempo_class(py::module &m, const std::string &
return time_stamp_base<score::Tempo<T>>(m, name)
// .def(py::init<unit, float>(), py::arg("time"), py::arg("qpm"))
.def(py::init([](unit time, std::optional<double> qpm, std::optional<i32> mspq) {
if (qpm.has_value()) return score::Tempo<T>::from_qpm(time, qpm.value());
else if (mspq.has_value()) return score::Tempo<T>(time, mspq.value());
if (qpm.has_value()) return score::Tempo<T>::from_qpm(time, *qpm);
else if (mspq.has_value()) return score::Tempo<T>(time, *mspq);
else throw std::invalid_argument("qpm or mspq must be specified");
}), py::arg("time"), py::arg("qpm")=py::none(), py::arg("mspq")=py::none())
.def_readwrite("mspq", &score::Tempo<T>::mspq, "Microseconds per quarter note")
Expand Down Expand Up @@ -513,13 +513,15 @@ py::module & core_module(py::module & m){
py::init<const Score<Quarter> &, std::optional<i32>>(), "Convert Quarter to Tick", py::arg("other"), py::arg("min_dur")=std::nullopt)
.def("to", &convert_score<Tick>, py::arg("ttype"), py::arg("min_dur") = std::nullopt, "Convert to another time unit")
.def("resample", [](const Score<Tick> &self, const i32 tpq, const std::optional<i32> min_dur) {
return resample(self, tpq, min_dur.value_or(0));
const auto min_dur_ = min_dur.has_value()? *min_dur: 0;
return resample(self, tpq, min_dur_);
}, py::arg("tpq"), py::arg("min_dur")=std::nullopt, "Resample to another ticks per quarter");
score_quarter.def(
py::init<const Score<Tick> &, std::optional<i32>>(), "Convert Tick to Quarter", py::arg("other"), py::arg("min_dur")=std::nullopt)
.def("to", &convert_score<Quarter>, py::arg("ttype"), py::arg("min_dur")=std::nullopt, "Convert to another time unit")
.def("resample", [](const Score<Quarter> &self, const i32 tpq, const std::optional<i32> min_dur) {
return resample(Score<Tick>(self), tpq, min_dur.value_or(0));
const auto min_dur_ = min_dur.has_value()? *min_dur: 0;
return resample(Score<Tick>(self), tpq, min_dur_);
}, py::arg("tpq"), py::arg("min_dur")=std::nullopt, "Resample to another ticks per quarter");
// bind_score_class<Second>(m, second);
return m;
Expand Down

0 comments on commit cb23074

Please sign in to comment.