2 Copyright (C) 2001 Steve Harris & Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #ifndef __ardour_logcurve_h__
22 #define __ardour_logcurve_h__
24 #include <pbd/fastlog.h>
25 #include <glibmm/thread.h>
31 LogCurve (float steepness = 0.2, uint32_t len = 0) {
35 b = 1.0f / log(1.0f + (1.0f / S));
38 bool operator== (const LogCurve& other) const {
39 return S == other.S && l == other.l;
42 bool operator!= (const LogCurve& other) const {
43 return S != other.S || l != other.l;
46 float value (float frac) const {
47 return (fast_log(frac + S) - a) * b;
50 float value (uint32_t pos) const {
51 return (fast_log(((float) pos/l) + S) - a) * b;
54 float invert_value (float frac) const {
55 return (a - fast_log(frac + S)) * b;
58 float invert_value (uint32_t pos) const {
59 return (a - fast_log(((float) pos/l) + S)) * b;
62 void fill (float *vec, uint32_t veclen, bool invert) const {
63 float dx = 1.0f/veclen;
72 for (i = 1, x = 0; i < veclen - 1; x += dx, i++) {
81 for (i = veclen-2, x = 0.0f; i > 0; x += dx, i--) {
87 float steepness() const { return S; }
88 uint32_t length() const { return l; }
90 void set_steepness (float steepness) {
93 b = 1.0f / log(1.0f + (1.0f / S));
95 void set_length (uint32_t len) { l = len; }
97 mutable Glib::Mutex lock;
106 class LogCurveIn : public LogCurve
109 LogCurveIn (float steepness = 0.2, uint32_t len = 0)
110 : LogCurve (steepness, len) {}
112 float value (float frac) const {
113 return (fast_log(frac + S) - a) * b;
116 float value (uint32_t pos) const {
117 return (fast_log(((float) pos/l) + S) - a) * b;
121 class LogCurveOut : public LogCurve
124 LogCurveOut (float steepness = 0.2, uint32_t len = 0)
125 : LogCurve (steepness, len) {}
129 }; /* namespace ARDOUR */
131 #endif /* __ardour_logcurve_h__ */