MCPcopy Create free account
hub / github.com/DamRsn/NeuralNote / TimeQuantizeOptions

Class TimeQuantizeOptions

NeuralNote/Source/TimeQuantizeOptions.h:14–124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12class NeuralNoteAudioProcessor;
13
14class TimeQuantizeOptions : public ValueTree::Listener
15{
16public:
17 struct Parameters {
18 bool enable = false;
19 TimeQuantizeUtils::TimeDivisions division = TimeQuantizeUtils::_1_4;
20 float quantizationForce = 0.f;
21 };
22
23 struct TimeQuantizeInfo {
24 double bpm = 120.0;
25 int timeSignatureNum = 4;
26 int timeSignatureDenom = 4;
27
28 // Reference bar + position with corresponding time in seconds
29 double refLastBarQn = 0.0;
30 double refPositionQn = 0.0;
31 double refPositionSeconds = 0.0;
32
33 /**
34 * Convert a duration in quarter notes to seconds
35 */
36 static double qnToSec(double inDurationQn, double inBPM) { return inDurationQn * 60.0 / inBPM; }
37
38 /**
39 * Convert a duration in seconds to quarter notes
40 */
41 static double secToQn(double inDurationSeconds, double inBPM) { return inDurationSeconds * inBPM / 60.0; }
42
43 /**
44 * @return The start position in quarter notes
45 */
46 double getStartQn() const { return refPositionQn - secToQn(refPositionSeconds, bpm); }
47
48 /**
49 * @return Last bar position (before recording started) in quarter notes
50 */
51 double getStartLastBarQn() const
52 {
53 const double bar_duration_qn = timeSignatureNum * 4.0 / timeSignatureDenom;
54 const auto start_qn = getStartQn();
55
56 double num_bars = std::ceil((refLastBarQn - start_qn) / bar_duration_qn);
57
58 return refLastBarQn - num_bars * bar_duration_qn;
59 }
60
61 /**
62 * @return Get the time in seconds for the last bar start before recording started. Will be <= 0.
63 */
64 double getStartLastBarSec() const
65 {
66 const double bar_duration_qn = timeSignatureNum * 4.0 / timeSignatureDenom;
67 const double bar_duration_sec = qnToSec(bar_duration_qn, bpm);
68 const double ref_last_bar_seconds = refPositionSeconds - qnToSec(refPositionQn - refLastBarQn, bpm);
69
70 const auto num_bars = static_cast<int>(std::ceil(ref_last_bar_seconds / bar_duration_sec));
71

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected