From 9dbc37d2c62bb79351f37de82fbfa4aac329c851 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 11 Jan 2013 21:10:59 +0000 Subject: Remove pointless Quantizer class. git-svn-id: http://svn.drobilla.net/lad/trunk/machina@4922 a436a847-0d15-0410-975c-d299462d15a1 --- src/engine/LearnRequest.cpp | 4 ++-- src/engine/MachineBuilder.cpp | 4 ++-- src/engine/Quantizer.hpp | 47 ------------------------------------------- src/engine/SMFDriver.cpp | 4 ++-- src/engine/quantize.hpp | 46 ++++++++++++++++++++++++++++++++++++++++++ src/engine/quantize_test.cpp | 6 +++--- 6 files changed, 55 insertions(+), 56 deletions(-) delete mode 100644 src/engine/Quantizer.hpp create mode 100644 src/engine/quantize.hpp 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, 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/Quantizer.hpp b/src/engine/Quantizer.hpp deleted file mode 100644 index 8970b06..0000000 --- a/src/engine/Quantizer.hpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - This file is part of Raul. - Copyright 2007-2012 David Robillard - - Raul is free software: you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation, either version 3 of the License, or any later version. - - Raul is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Raul. If not, see . -*/ - -#ifndef RAUL_QUANTIZER_HPP -#define RAUL_QUANTIZER_HPP - -#include -#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; - } -}; - -} // namespace Machina - -#endif // RAUL_QUANTIZER_HPP 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 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/quantize.hpp b/src/engine/quantize.hpp new file mode 100644 index 0000000..5d1b4f2 --- /dev/null +++ b/src/engine/quantize.hpp @@ -0,0 +1,46 @@ +/* + This file is part of Raul. + Copyright 2007-2012 David Robillard + + Raul is free software: you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation, either version 3 of the License, or any later version. + + Raul is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Raul. If not, see . +*/ + +#ifndef MACHINA_QUANTIZE_HPP +#define MACHINA_QUANTIZE_HPP + +#include + +#include "raul/TimeStamp.hpp" + +namespace Machina { + +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 // 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 -#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; } -- cgit v1.2.1