|
6 | 6 | #include <cmath>
|
7 | 7 | #include "symusic/conversion.h"
|
8 | 8 | #include "symusic/ops.h"
|
9 |
| -#include "symusic/mtype.h" |
10 | 9 |
|
11 | 10 | namespace symusic {
|
12 | 11 |
|
@@ -53,9 +52,8 @@ struct SimpleConverter {
|
53 | 52 | }
|
54 | 53 |
|
55 | 54 | template<template<class> class T>
|
56 |
| - [[nodiscard]] pyvec<T<To>> duration_vec( |
57 |
| - const pyvec<T<From>>& data, typename To::unit min_dur |
58 |
| - ) const { |
| 55 | + [[nodiscard]] pyvec<T<To>> duration_vec(const pyvec<T<From>>& data, typename To::unit min_dur) |
| 56 | + const { |
59 | 57 | const auto self = static_cast<const Converter*>(this);
|
60 | 58 | min_dur = std::max(min_dur, static_cast<typename To::unit>(0));
|
61 | 59 |
|
@@ -352,30 +350,32 @@ shared<pyvec<T>> resample_dur(
|
352 | 350 | capsule.reserve(data.size());
|
353 | 351 |
|
354 | 352 | for (const auto& item : data) {
|
355 |
| - capsule.emplace_back( |
356 |
| - convert(item->time), std::max(convert(item->duration), min_dur), item |
357 |
| - ); |
| 353 | + capsule.emplace_back(convert(item->time), std::max(convert(item->duration), min_dur), item); |
358 | 354 | }
|
359 | 355 | return std::make_shared<pyvec<T>>(std::move(capsule));
|
360 | 356 | }
|
361 | 357 |
|
362 | 358 | Score<Tick> resample_inner(const Score<Tick>& score, const i32 tpq, const i32 min_dur) {
|
363 |
| - if(tpq <= 0) { |
| 359 | + if (tpq <= 0) { |
364 | 360 | throw std::invalid_argument("symusic::resample: ticks_per_quarter must be positive");
|
365 | 361 | }
|
366 |
| - if(min_dur < 0) { |
| 362 | + if (min_dur < 0) { |
367 | 363 | throw std::invalid_argument("symusic::resample: min_dur must be non-negative");
|
368 | 364 | }
|
369 | 365 | Score<Tick> ans(tpq);
|
370 |
| - const f64 scale_rate = static_cast<f64>(tpq) / static_cast<f64>(score.ticks_per_quarter); |
| 366 | + const f64 scale_rate = static_cast<f64>(tpq) / static_cast<f64>(score.ticks_per_quarter); |
| 367 | + |
371 | 368 | auto f64toi32 = [](const f64 x) {
|
372 |
| - if(x > static_cast<f64>(std::numeric_limits<i32>::max())) { |
373 |
| - throw std::overflow_error("symusic::resample: time after resample (" + std::to_string(x) + ") is out of int32 range"); |
374 |
| - } return static_cast<i32>(std::round(x)); |
| 369 | + if (x > static_cast<f64>(std::numeric_limits<i32>::max())) { |
| 370 | + throw std::overflow_error( |
| 371 | + "symusic::resample: time after resample (" + std::to_string(x) |
| 372 | + + ") is out of int32 range" |
| 373 | + ); |
| 374 | + } |
| 375 | + return static_cast<i32>(std::round(x)); |
375 | 376 | };
|
376 | 377 |
|
377 |
| - const auto from_tpq = static_cast<double>(score.ticks_per_quarter); |
378 |
| - auto convert = [f64toi32, scale_rate](const Tick::unit t) -> Tick::unit { |
| 378 | + auto convert = [f64toi32, scale_rate](const Tick::unit t) -> Tick::unit { |
379 | 379 | return f64toi32(scale_rate * static_cast<f64>(t));
|
380 | 380 | };
|
381 | 381 |
|
|
0 commit comments