Ardour  9.0-pre0-582-g084a23a80d
logcurve.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2006 Taybin Rutkin <taybin@taybin.com>
3  * Copyright (C) 2007-2013 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2009 David Robillard <d@drobilla.net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #pragma once
22 
23 #include "pbd/fastlog.h"
24 #include <glibmm/threads.h>
25 
27 
28 #include <cstdint>
29 
30 namespace ARDOUR {
31 
33  public:
34  LogCurve (float steepness = 0.2, uint32_t len = 0) {
35  l = len;
36  S = steepness;
37  a = log(S);
38  b = 1.0f / log(1.0f + (1.0f / S));
39  }
40 
41  bool operator== (const LogCurve& other) const {
42  return S == other.S && l == other.l;
43  }
44 
45  bool operator!= (const LogCurve& other) const {
46  return S != other.S || l != other.l;
47  }
48 
49  float value (float frac) const {
50  return (fast_log(frac + S) - a) * b;
51  }
52 
53  float value (uint32_t pos) const {
54  return (fast_log(((float) pos/l) + S) - a) * b;
55  }
56 
57  float invert_value (float frac) const {
58  return (a - fast_log(frac + S)) * b;
59  }
60 
61  float invert_value (uint32_t pos) const {
62  return (a - fast_log(((float) pos/l) + S)) * b;
63  }
64 
65  void fill (float *vec, uint32_t veclen, bool invert) const {
66  float dx = 1.0f/veclen;
67  float x;
68  uint32_t i;
69 
70  if (!invert) {
71 
72  vec[0] = 0.0;
73  vec[veclen-1] = 1.0;
74 
75  for (i = 1, x = 0; i < veclen - 1; x += dx, i++) {
76  vec[i] = value (x);
77  }
78 
79  } else {
80 
81  vec[0] = 1.0;
82  vec[veclen-1] = 0.0;
83 
84  for (i = veclen-2, x = 0.0f; i > 0; x += dx, i--) {
85  vec[i] = value (x);
86  }
87  }
88  }
89 
90  float steepness() const { return S; }
91  uint32_t length() const { return l; }
92 
93  void set_steepness (float steepness) {
94  S = steepness;
95  a = log(S);
96  b = 1.0f / log(1.0f + (1.0f / S));
97  }
98  void set_length (uint32_t len) { l = len; }
99 
100  mutable Glib::Threads::Mutex lock;
101 
102  protected:
103  float a;
104  float b;
105  float S;
106  uint32_t l;
107 };
108 
110 {
111  public:
112  LogCurveIn (float steepness = 0.2, uint32_t len = 0)
113  : LogCurve (steepness, len) {}
114 
115  float value (float frac) const {
116  return (fast_log(frac + S) - a) * b;
117  }
118 
119  float value (uint32_t pos) const {
120  return (fast_log(((float) pos/l) + S) - a) * b;
121  }
122 };
123 
125 {
126  public:
127  LogCurveOut (float steepness = 0.2, uint32_t len = 0)
128  : LogCurve (steepness, len) {}
129 
130 };
131 
132 } // namespace ARDOUR
133 
134 
135 
float value(float frac) const
Definition: logcurve.h:115
LogCurveIn(float steepness=0.2, uint32_t len=0)
Definition: logcurve.h:112
float value(uint32_t pos) const
Definition: logcurve.h:119
LogCurveOut(float steepness=0.2, uint32_t len=0)
Definition: logcurve.h:127
float invert_value(uint32_t pos) const
Definition: logcurve.h:61
void fill(float *vec, uint32_t veclen, bool invert) const
Definition: logcurve.h:65
float invert_value(float frac) const
Definition: logcurve.h:57
void set_steepness(float steepness)
Definition: logcurve.h:93
uint32_t length() const
Definition: logcurve.h:91
float value(uint32_t pos) const
Definition: logcurve.h:53
uint32_t l
Definition: logcurve.h:106
float steepness() const
Definition: logcurve.h:90
LogCurve(float steepness=0.2, uint32_t len=0)
Definition: logcurve.h:34
Glib::Threads::Mutex lock
Definition: logcurve.h:100
float value(float frac) const
Definition: logcurve.h:49
void set_length(uint32_t len)
Definition: logcurve.h:98
static float fast_log(const float val)
Definition: fastlog.h:35
#define LIBARDOUR_API
bool operator==(const ProcessorSelection &a, const ProcessorSelection &b)