kwave  18.07.70
Functions.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  Functions.cpp - list of simple periodic functions
3  -------------------
4  begin : Jan 21 2001
5  copyright : (C) 2001 by Thomas Eschenbacher
6  email : Thomas Eschenbacher <thomas.eschenbacher@gmx.de>
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "config.h"
19 #include <math.h>
20 
21 #include <QString>
22 
23 #include <KLocalizedString>
24 
25 #include "libkwave/Functions.h"
26 #include "libkwave/String.h"
27 
28 //***************************************************************************
29 static double rect(double param)
30 {
31  double div = param / (2 * M_PI);
32  param = param - (floor(div) * (2 * M_PI));
33  if (param > M_PI) return -1;
34  return 1;
35 }
36 
37 //***************************************************************************
38 static double sin2(double param)
39 {
40  double y = sin(param);
41  return y*y;
42 }
43 
44 //***************************************************************************
45 static double sin3(double param)
46 {
47  double y = sin(param);
48  return y*y*y;
49 }
50 
51 //***************************************************************************
52 static double saw(double param)
53 {
54  double div = param / (2 * M_PI);
55  param -= (floor(div) * (2 * M_PI));
56  param /= M_PI;
57  param -= 1;
58  return param;
59 }
60 
61 //***************************************************************************
62 static double sawinv(double param)
63 {
64  double div = param / (2 * M_PI);
65  param -= (floor(div) * (2 * M_PI));
66  param = 2 * M_PI - param;
67  param /= M_PI;
68  param -= 1;
69  return param;
70 }
71 
72 //***************************************************************************
73 static double tri(double param)
74 {
75  param += M_PI / 2;
76  double div = param / (2 * M_PI);
77  param -= (floor(div) * (2 * M_PI));
78  if (param > M_PI) return (((param -M_PI) / M_PI)*2)-1;
79  return (((M_PI -param) / M_PI)*2)-1;
80 }
81 
82 //***************************************************************************
83 static double zero(double)
84 {
85  return 0.0;
86 }
87 
88 //***************************************************************************
89 //***************************************************************************
90 
91 //***************************************************************************
93 {
94  append(0, &sin, _("sinus"), _(I18N_NOOP("Sinus")));
95  append(1, &rect, _("rectangular"), _(I18N_NOOP("Rectangular")));
96  append(2, &saw, _("sawtooth"), _(I18N_NOOP("Sawtooth")));
97  append(3, &sawinv, _("inverse_sawtooth"), _(I18N_NOOP("Inverse Sawtooth")));
98  append(4, &tri, _("triangular"), _(I18N_NOOP("Triangular")));
99  append(5, &sin2, _("square_sinus"), _(I18N_NOOP("Square Sinus")));
100  append(6, &sin3, _("cubic_sinus"), _(I18N_NOOP("Cubic Sinus")));
101 }
102 
103 //***************************************************************************
105 {
106 }
107 
108 //***************************************************************************
110 {
111 }
112 
113 //***************************************************************************
114 QString Kwave::Functions::name(unsigned int index)
115 {
116  Q_ASSERT(index < m_functions_map.count());
117  if (index >= m_functions_map.count()) return _("Zero");
118  return m_functions_map.name(index);
119 }
120 
121 //***************************************************************************
123  unsigned int index) const
124 {
126 
127  Q_ASSERT(index < m_functions_map.count());
128  if (index < m_functions_map.count()) f = m_functions_map.data(index);
129 
130  if (!f) return *(&zero);
131  return *f;
132 }
133 
134 //***************************************************************************
135 unsigned int Kwave::Functions::count() const
136 {
137  return m_functions_map.count();
138 }
139 
140 //***************************************************************************
141 //***************************************************************************
double() periodic_function_t(double)
Definition: Functions.h:38
unsigned int count() const
Definition: TypesMap.h:81
DATA data(IDX type) const
Definition: TypesMap.h:110
static double sawinv(double param)
Definition: Functions.cpp:62
periodic_function_t & function(unsigned int index) const
Definition: Functions.cpp:122
static double tri(double param)
Definition: Functions.cpp:73
unsigned int count() const
Definition: Functions.cpp:135
virtual void append(unsigned int index, periodic_function_t * data, const QString &name, const QString &description)
Definition: TypesMap.h:72
virtual void fill() Q_DECL_OVERRIDE
Definition: Functions.cpp:92
FunctionTypesMap m_functions_map
Definition: Functions.h:81
static double saw(double param)
Definition: Functions.cpp:52
static double sin2(double param)
Definition: Functions.cpp:38
#define _(m)
Definition: memcpy.c:66
static double sin3(double param)
Definition: Functions.cpp:45
QString name(IDX type) const
Definition: TypesMap.h:117
virtual ~Functions()
Definition: Functions.cpp:109
static double zero(double)
Definition: Functions.cpp:83
static double rect(double param)
Definition: Functions.cpp:29
QString name(unsigned int index)
Definition: Functions.cpp:114