LMMS
Loading...
Searching...
No Matches
ExprSynth.h
Go to the documentation of this file.
1/*
2 * exprfront.h - header file to a Frontend to ExprTk
3 *
4 * Copyright (c) 2016-2017 Orr Dvori
5 *
6 * This file is part of LMMS - https://lmms.io
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program (see COPYING); if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301 USA.
22 *
23 */
24
25#ifndef EXPRSYNTH_H
26#define EXPRSYNTH_H
27
28#include <cmath>
29#include <cstddef>
30#include <limits>
31#include "Graph.h"
32
33namespace lmms
34{
35
36
37class ExprFrontData;
38class FloatModel;
39class NotePlayHandle;
40class SampleFrame;
41
42
44{
45public:
46 using ff1data_functor = float (*)(void*, float);
47 ExprFront(const char* expr, int last_func_samples);
48 ~ExprFront();
49 bool compile();
50 inline bool isValid() { return m_valid; }
51 float evaluate();
52 bool add_variable(const char* name, float & ref);
53 bool add_constant(const char* name, float ref);
54 bool add_cyclic_vector(const char* name, const float* data, size_t length, bool interp = false);
55 void setIntegrate(const unsigned int* frameCounter, unsigned int sample_rate);
57private:
59 bool m_valid;
60
61 static const int max_float_integer_mask=(1<<(std::numeric_limits<float>::digits))-1;
62
63};
64
66{
67public:
69 {
71 m_samples = new float[m_length];
72 for(int i = 0 ; i < m_length ; ++i)
73 m_samples[i] = 0;
74 }
75 WaveSample(const graphModel * graph)
76 {
77 m_length = graph->length();
78 m_samples = new float[m_length];
79 memcpy(m_samples, graph->samples(), m_length * sizeof(float));
80 }
81 inline void copyFrom(const graphModel * graph)
82 {
83 memcpy(m_samples, graph->samples(), m_length * sizeof(float));
84 }
86 {
87 delete [] m_samples;
88 }
89 inline void setInterpolate(bool _interpolate) { m_interpolate = _interpolate; }
90 float *m_samples;
93};
94
96{
97public:
98 ExprSynth(const WaveSample* gW1, const WaveSample* gW2, const WaveSample* gW3, ExprFront* exprO1, ExprFront* exprO2, NotePlayHandle* nph,
99 const sample_rate_t sample_rate, const FloatModel* pan1, const FloatModel* pan2, float rel_trans);
100 virtual ~ExprSynth();
101
102 void renderOutput(f_cnt_t frames, SampleFrame* buf );
103
104
105private:
108 unsigned int m_note_sample;
109 unsigned int m_note_rel_sample;
119
120} ;
121
122
123
124inline float positiveFraction(float x)
125{
126 if (std::isnan(x) || std::isinf(x))
127 return 0;
128 if (x<0)
129 {
130 x+=static_cast<int>(1-x);
131 }
132 return x-static_cast<int>(x);
133}
134
135template <typename T>
136inline void clearArray(T* arr,unsigned int size)
137{
138 const T* const arr_end = arr + size;
139 while(arr < arr_end)
140 {
141 *arr=0;
142 ++arr;
143 }
144}
145
146
147} // namespace lmms
148
149#endif
Definition ExprSynth.cpp:375
Definition ExprSynth.h:44
float(*)(void *, float) ff1data_functor
Definition ExprSynth.h:46
bool m_valid
Definition ExprSynth.h:59
ExprFrontData * m_data
Definition ExprSynth.h:58
~ExprFront()
Definition ExprSynth.cpp:561
bool add_cyclic_vector(const char *name, const float *data, size_t length, bool interp=false)
Definition ExprSynth.cpp:635
void setIntegrate(const unsigned int *frameCounter, unsigned int sample_rate)
Definition ExprSynth.cpp:677
ExprFrontData * getData()
Definition ExprSynth.h:56
float evaluate()
Definition ExprSynth.cpp:593
bool compile()
Definition ExprSynth.cpp:573
static const int max_float_integer_mask
Definition ExprSynth.h:61
ExprFront(const char *expr, int last_func_samples)
Definition ExprSynth.cpp:527
bool add_constant(const char *name, float ref)
Definition ExprSynth.cpp:622
bool add_variable(const char *name, float &ref)
Definition ExprSynth.cpp:609
bool isValid()
Definition ExprSynth.h:50
ExprFront * m_exprO1
Definition ExprSynth.h:106
NotePlayHandle * m_nph
Definition ExprSynth.h:114
const FloatModel * m_pan2
Definition ExprSynth.h:116
const FloatModel * m_pan1
Definition ExprSynth.h:116
const WaveSample * m_W1
Definition ExprSynth.h:107
float m_note_rel_sec
Definition ExprSynth.h:111
ExprSynth(const WaveSample *gW1, const WaveSample *gW2, const WaveSample *gW3, ExprFront *exprO1, ExprFront *exprO2, NotePlayHandle *nph, const sample_rate_t sample_rate, const FloatModel *pan1, const FloatModel *pan2, float rel_trans)
Definition ExprSynth.cpp:697
const sample_rate_t m_sample_rate
Definition ExprSynth.h:115
ExprFront * m_exprO2
Definition ExprSynth.h:106
float m_rel_inc
Definition ExprSynth.h:118
unsigned int m_note_sample
Definition ExprSynth.h:108
unsigned int m_note_rel_sample
Definition ExprSynth.h:109
void renderOutput(f_cnt_t frames, SampleFrame *buf)
Definition ExprSynth.cpp:748
float m_released
Definition ExprSynth.h:113
const WaveSample * m_W2
Definition ExprSynth.h:107
float m_rel_transition
Definition ExprSynth.h:117
float m_note_sample_sec
Definition ExprSynth.h:110
virtual ~ExprSynth()
Definition ExprSynth.cpp:736
float m_frequency
Definition ExprSynth.h:112
const WaveSample * m_W3
Definition ExprSynth.h:107
Definition AutomatableModel.h:463
Definition NotePlayHandle.h:48
Definition SampleFrame.h:41
Definition ExprSynth.h:66
void copyFrom(const graphModel *graph)
Definition ExprSynth.h:81
WaveSample(const graphModel *graph)
Definition ExprSynth.h:75
float * m_samples
Definition ExprSynth.h:90
WaveSample(int length)
Definition ExprSynth.h:68
~WaveSample()
Definition ExprSynth.h:85
void setInterpolate(bool _interpolate)
Definition ExprSynth.h:89
bool m_interpolate
Definition ExprSynth.h:92
int m_length
Definition ExprSynth.h:91
2 dimensional function plot
Definition Graph.h:134
const float * samples() const
Definition Graph.h:171
int length() const
Definition Graph.h:166
register unsigned i
Definition inflate.c:1575
unsigned x[BMAX+1]
Definition inflate.c:1586
static const char * name
Definition pugl.h:1582
JSAMPIMAGE data
Definition jpeglib.h:945
Definition AudioAlsa.cpp:35
float positiveFraction(float x)
Definition ExprSynth.h:124
std::uint32_t sample_rate_t
Definition LmmsTypes.h:42
void clearArray(T *arr, unsigned int size)
Definition ExprSynth.h:136
std::uint64_t f_cnt_t
Definition LmmsTypes.h:43
png_uint_32 length
Definition png.c:2247
memcpy(hh, h, RAND_HEAD_LEN)
ulg size
Definition extract.c:2350