From 7fbc7c297c0a5b4f23bfd285789ad55b72f792f3 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 22 Feb 2007 04:16:05 +0000 Subject: Machina quantization, various timing related fixes. git-svn-id: http://svn.drobilla.net/lad/raul@326 a436a847-0d15-0410-975c-d299462d15a1 --- raul/Makefile.am | 3 ++- raul/Quantizer.h | 36 ++++++++++++++++++++++++++++++++++++ raul/TimeSlice.h | 6 +++++- tests/Makefile.am | 4 +++- tests/quantize_test.cpp | 28 ++++++++++++++++++++++++++++ tests/time_test.cpp | 1 - 6 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 raul/Quantizer.h create mode 100644 tests/quantize_test.cpp diff --git a/raul/Makefile.am b/raul/Makefile.am index 76c9031..70aa03a 100644 --- a/raul/Makefile.am +++ b/raul/Makefile.am @@ -27,7 +27,8 @@ raulinclude_HEADERS = \ Stateful.h \ Thread.h \ WeakPtr.h \ - TimeSlice.h + TimeSlice.h \ + Quantizer.h if WITH_LIBLO raulinclude_HEADERS += AtomLiblo.h diff --git a/raul/Quantizer.h b/raul/Quantizer.h new file mode 100644 index 0000000..c6a9bfb --- /dev/null +++ b/raul/Quantizer.h @@ -0,0 +1,36 @@ +/* This file is part of Raul. + * Copyright (C) 2007 Dave 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 2 of the License, or (at your option) 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 details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef RAUL_QUANTIZER_H +#define RAUL_QUANTIZER_H + +#include + +namespace Raul { + + +class Quantizer { +public: + inline static double quantize(double q, double value) { + return lrint(value / q) * q; + } +}; + + +} // namespace Raul + +#endif // RAUL_QUANTIZER_H diff --git a/raul/TimeSlice.h b/raul/TimeSlice.h index 289233c..7ffd8a4 100644 --- a/raul/TimeSlice.h +++ b/raul/TimeSlice.h @@ -81,6 +81,10 @@ public: return (time >= start_ticks() && time < start_ticks() + length_ticks()); } + double tick_rate() { return _tick_rate; } + double beat_rate() { return _beat_rate; } + double bpm() { return 60/_beat_rate; } + void set_tick_rate(double tick_rate) { _tick_rate = tick_rate; update_beat_time(); @@ -88,7 +92,7 @@ public: void set_bpm(double bpm) { _beat_rate = 60.0/bpm; - update_beat_time(); + //update_beat_time(); } inline Seconds beats_to_seconds(BeatTime beats) const { diff --git a/tests/Makefile.am b/tests/Makefile.am index 05b0f21..9e8e6c8 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -3,7 +3,7 @@ if BUILD_TESTS AM_CXXFLAGS = -I.. -lpthread @RASQAL_CFLAGS@ @GLIBMM_CFLAGS@ ALL_LIBS = @RASQAL_LIBS@ @GLIBMM_LIBS@ ../src/libraul.la -bin_PROGRAMS = path_test thread_test queue_test atomic_test list_test time_test +bin_PROGRAMS = path_test thread_test queue_test atomic_test list_test time_test quantize_test thread_test_LDADD = $(ALL_LIBS) path_test_LDADD = $(ALL_LIBS) @@ -11,6 +11,7 @@ queue_test_LDADD = $(ALL_LIBS) atomic_test_LDADD = $(ALL_LIBS) list_test_LDADD = $(ALL_LIBS) time_test_LDADD = $(ALL_LIBS) +quantize_test_LDADD = $(ALL_LIBS) path_test_SOURCES = path_test.cpp thread_test_SOURCES = thread_test.cpp @@ -18,5 +19,6 @@ queue_test_SOURCES = queue_test.cpp atomic_test_SOURCES = atomic_test.cpp list_test_SOURCES = list_test.cpp time_test_SOURCES = time_test.cpp +quantize_test_SOURCES = quantize_test.cpp endif diff --git a/tests/quantize_test.cpp b/tests/quantize_test.cpp new file mode 100644 index 0000000..434df2e --- /dev/null +++ b/tests/quantize_test.cpp @@ -0,0 +1,28 @@ +#include +#include + +using namespace std; +using namespace Raul; + + +int +main() +{ + double q = 0; + double beats = 0; + + cout << "Quantization: "; + cin >> q; + cout << endl; + + while (true) { + cout << "Beats: "; + cin >> beats; + + cout << "Quantized: "; + cout << Quantizer::quantize(q, beats) << endl << endl; + } + + return 0; +} + diff --git a/tests/time_test.cpp b/tests/time_test.cpp index 0eb0a83..0ffdc61 100644 --- a/tests/time_test.cpp +++ b/tests/time_test.cpp @@ -10,7 +10,6 @@ main() { TimeSlice ts(1/48000.0, 120); - string in_string; double in_double = 0; cout << "Beats: "; -- cgit v1.2.1