diff options
author | David Robillard <d@drobilla.net> | 2013-01-11 21:10:59 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2013-01-11 21:10:59 +0000 |
commit | 9dbc37d2c62bb79351f37de82fbfa4aac329c851 (patch) | |
tree | 69932db1c0fa7da646088c44bd6aabadffaf2dae | |
parent | bef1c2ea010da638ffbb437c37a6d32ddc99b568 (diff) | |
download | machina-9dbc37d2c62bb79351f37de82fbfa4aac329c851.tar.gz machina-9dbc37d2c62bb79351f37de82fbfa4aac329c851.tar.bz2 machina-9dbc37d2c62bb79351f37de82fbfa4aac329c851.zip |
Remove pointless Quantizer class.
git-svn-id: http://svn.drobilla.net/lad/trunk/machina@4922 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r-- | src/engine/LearnRequest.cpp | 4 | ||||
-rw-r--r-- | src/engine/MachineBuilder.cpp | 4 | ||||
-rw-r--r-- | src/engine/SMFDriver.cpp | 4 | ||||
-rw-r--r-- | src/engine/quantize.hpp (renamed from src/engine/Quantizer.hpp) | 43 | ||||
-rw-r--r-- | src/engine/quantize_test.cpp | 6 |
5 files changed, 30 insertions, 31 deletions
diff --git a/src/engine/LearnRequest.cpp b/src/engine/LearnRequest.cpp index 1dd5767..ae77e7b 100644 --- a/src/engine/LearnRequest.cpp +++ b/src/engine/LearnRequest.cpp @@ -16,7 +16,7 @@ */ #include "LearnRequest.hpp" -#include "Quantizer.hpp" +#include "quantize.hpp" namespace Machina { @@ -55,7 +55,7 @@ LearnRequest::finish(TimeStamp time) _node->set_enter_action(_enter_action); _node->set_exit_action(_exit_action); - //TimeDuration duration = Quantizer::quantize(_quantization, time - _start_time); + //TimeDuration duration = quantize(_quantization, time - _start_time); //_node->set_duration(duration); } diff --git a/src/engine/MachineBuilder.cpp b/src/engine/MachineBuilder.cpp index 4f4d599..0460299 100644 --- a/src/engine/MachineBuilder.cpp +++ b/src/engine/MachineBuilder.cpp @@ -27,7 +27,7 @@ #include "MachineBuilder.hpp" #include "MidiAction.hpp" #include "Node.hpp" -#include "Quantizer.hpp" +#include "quantize.hpp" using namespace std; using namespace Raul; @@ -70,7 +70,7 @@ MachineBuilder::set_node_duration(SharedPtr<Node> node, Raul::TimeDuration d) co return; } - Raul::TimeStamp q_dur = Quantizer::quantize(TimeStamp(d.unit(), _quantization), d); + Raul::TimeStamp q_dur = quantize(TimeStamp(d.unit(), _quantization), d); // Never quantize a note to duration 0 if (q_dur.is_zero() && ( node->enter_action() || node->exit_action() )) diff --git a/src/engine/SMFDriver.cpp b/src/engine/SMFDriver.cpp index e3e95b8..000ce0e 100644 --- a/src/engine/SMFDriver.cpp +++ b/src/engine/SMFDriver.cpp @@ -25,10 +25,10 @@ #include "machina/Machine.hpp" #include "Edge.hpp" -#include "Quantizer.hpp" #include "SMFDriver.hpp" #include "SMFReader.hpp" #include "SMFWriter.hpp" +#include "quantize.hpp" using namespace std; @@ -122,7 +122,7 @@ SMFDriver::learn_track(SharedPtr<MachineBuilder> builder, while (reader.read_event(4, buf, &ev_size, &ev_delta_time) >= 0) { unquantized_t += ev_delta_time; - t = Quantizer::quantize(q, unquantized_t); + t = quantize(q, unquantized_t); builder->set_time(TimeStamp(max_duration.unit(), (double)t)); diff --git a/src/engine/Quantizer.hpp b/src/engine/quantize.hpp index 8970b06..5d1b4f2 100644 --- a/src/engine/Quantizer.hpp +++ b/src/engine/quantize.hpp @@ -14,34 +14,33 @@ along with Raul. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef RAUL_QUANTIZER_HPP -#define RAUL_QUANTIZER_HPP +#ifndef MACHINA_QUANTIZE_HPP +#define MACHINA_QUANTIZE_HPP #include <cmath> + #include "raul/TimeStamp.hpp" namespace Machina { -/** Quantizer. - * \ingroup raul - */ -class Quantizer { -public: - inline static TimeStamp quantize(TimeStamp q, TimeStamp t) { - assert(q.unit() == t.unit()); - // FIXME: Precision problem? Should probably stay in discrete domain - const double qd = q.to_double(); - const double td = t.to_double(); - return TimeStamp(t.unit(), (qd > 0) ? lrint(td / qd) * qd : td); - } - - inline static double quantize(double q, double t) { - return (q > 0) - ? lrint(t / q) * q - : t; - } -}; +inline TimeStamp +quantize(TimeStamp q, TimeStamp t) +{ + assert(q.unit() == t.unit()); + // FIXME: Precision problem? Should probably stay in discrete domain + const double qd = q.to_double(); + const double td = t.to_double(); + return TimeStamp(t.unit(), (qd > 0) ? lrint(td / qd) * qd : td); +} + +inline double +quantize(double q, double t) +{ + return (q > 0) + ? lrint(t / q) * q + : t; +} } // namespace Machina -#endif // RAUL_QUANTIZER_HPP +#endif // MACHINA_QUANTIZE_HPP diff --git a/src/engine/quantize_test.cpp b/src/engine/quantize_test.cpp index dfb3b4b..2a2c11a 100644 --- a/src/engine/quantize_test.cpp +++ b/src/engine/quantize_test.cpp @@ -16,7 +16,7 @@ #include <iostream> -#include "Quantizer.hpp" +#include "quantize.hpp" using namespace std; using namespace Machina; @@ -30,9 +30,9 @@ main() TimeStamp beats(TimeUnit(TimeUnit::BEATS, 19200), in); /*cout << "Q(" << in << ", 1/4) = " - << Quantizer::quantize(q, beats) << endl;*/ + << quantize(q, beats) << endl;*/ - if (Quantizer::quantize(q, beats).subticks() % (19200/4) != 0) + if (quantize(q, beats).subticks() % (19200/4) != 0) return 1; } |