1 /* B.Oops
2  * Glitch effect sequencer LV2 plugin
3  *
4  * Copyright (C) 2020 by Sven Jähnichen
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 3, or (at your option)
9  * 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
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  */
20 
21 #ifndef FXTAPESTOP_HPP_
22 #define FXTAPESTOP_HPP_
23 
24 #include "Fx.hpp"
25 
26 #define FX_TAPESTOP_REACH 0
27 #define FX_TAPESTOP_REACHRAND 1
28 #define FX_TAPESTOP_ORDER 2
29 #define FX_TAPESTOP_ORDERRAND 3
30 
31 class FxTapeStop : public Fx
32 {
33 public:
34 	FxTapeStop () = delete;
35 
FxTapeStop(RingBuffer<Stereo> ** buffer,float * params,Pad * pads,double * framesPerStep)36 	FxTapeStop (RingBuffer<Stereo>** buffer, float* params, Pad* pads, double* framesPerStep) :
37 		Fx (buffer, params, pads),
38 		framesPerStepPtr (framesPerStep),
39 		framesPerStep (24000),
40 		reach (1.0), order (1.0), r (0.0)
41 	{
42 		if (!framesPerStep) throw std::invalid_argument ("Fx initialized with framesPerStep nullptr");
43 	}
44 
init(const double position)45 	virtual void init (const double position) override
46 	{
47 		Fx::init (position);
48 		const double r1 = bidist (rnd);
49 		reach = LIMIT (params[SLOTS_OPTPARAMS + FX_TAPESTOP_REACH] + r1 * params[SLOTS_OPTPARAMS + FX_TAPESTOP_REACHRAND], 0.0, 1.0);
50 		const int startPos = position;
51 		r = reach * pads[startPos].size;
52 		const double r2 = bidist (rnd);
53 		order = LIMIT (1.0 + 9.0 * (params[SLOTS_OPTPARAMS + FX_TAPESTOP_ORDER] + r2 * params[SLOTS_OPTPARAMS + FX_TAPESTOP_ORDERRAND]), 1.0, 10.0);
54 		framesPerStep = *framesPerStepPtr;
55 	}
56 
process(const double position,const double size)57 	virtual Stereo process (const double position, const double size) override
58 	{
59 		return getSample ((log (exp (order * std::min (position, double (NR_STEPS))) + exp (order * reach) - 1) / order - reach) * framesPerStep);
60 	}
61 
62 protected:
63 	double* framesPerStepPtr;
64 	double framesPerStep;
65 	double reach;
66 	double order;
67 	double r;
68 };
69 
70 #endif /* FXTAPESTOP_HPP_ */
71