MuseScore  3.4
Music composition and notation
rankwave.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003-2008 Fons Adriaensen <fons@kokkinizita.net>
3 
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.
8 
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.
13 
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.
17 */
18 
19 
20 #ifndef __RANKWAVE_H
21 #define __RANKWAVE_H
22 
23 
24 #include "addsynth.h"
25 #include "rngen.h"
26 
27 
28 #define PERIOD 64
29 
30 
31 class Pipewave
32 {
33 private:
34 
35  Pipewave () :
36  _p0 (0), _p1 (0), _p2 (0), _l1 (0), _k_s (0), _k_r (0), _m_r (0),
37  _link (0), _sbit (0), _sdel (0),
38  _p_p (0), _y_p (0), _z_p (0), _p_r (0), _y_r (0), _g_r (0), _i_r (0)
39  {}
40 
41  ~Pipewave (void) { delete[] _p0; }
42 
43  friend class Rankwave;
44 
45  void genwave (Addsynth *D, int n, float fsamp, float fpipe);
46  void save (FILE *F);
47  void load (FILE *F);
48  void play (void);
49 
50  static void looplen (float f, float fsamp, int lmax, int *aa, int *bb);
51  static void attgain (int n, float p);
52 
53  float *_p0; // attack start
54  float *_p1; // loop start
55  float *_p2; // loop end
56  int32_t _l0; // attack length
57  int32_t _l1; // loop length
58  int16_t _k_s; // sample step
59  int16_t _k_r; // release length
60  float _m_r; // release multiplier
61  float _d_r; // release detune
62  float _d_p; // instability
63 
64  Pipewave *_link; // link to next in active chain
65  uint32_t _sbit; // on state bit
66  uint32_t _sdel; // delayed state
67  float *_out; // audio output buffer
68  float *_p_p; // play pointer
69  float _y_p; // play interpolation
70  float _z_p; // play interpolation speed
71  float *_p_r; // release pointer
72  float _y_r; // release interpolation
73  float _g_r; // release gain
74  int16_t _i_r; // release count
75 
76 
77  static void initstatic (float fsamp);
78 
79  static Rngen _rgen;
80  static float *_arg;
81  static float *_att;
82 };
83 
84 //---------------------------------------------------------
85 // Rankwave
86 //---------------------------------------------------------
87 
88 class Rankwave
89  {
90  Rankwave (const Rankwave&);
91  Rankwave& operator=(const Rankwave&);
92 
93  int _n0;
94  int _n1;
95  uint32_t _sbit;
98  bool _modif;
99 
100 public:
101 
102  Rankwave (int n0, int n1);
103  ~Rankwave ();
104 
105  void note_on (int n) {
106  if ((n < _n0) || (n > _n1)) {
107  qDebug("Rankwave: bad key");
108  return;
109  }
110  Pipewave *P = _pipes + (n - _n0);
111  P->_sbit = _sbit;
112  if (! (P->_sdel || P->_p_p || P->_p_r)) {
113  P->_sdel |= _sbit;
114  P->_link = _list;
115  _list = P;
116  }
117  }
118 
119  void note_off (int n)
120  {
121  if ((n < _n0) || (n > _n1)) return;
122  Pipewave *P = _pipes + (n - _n0);
123  P->_sdel >>= 4;
124  P->_sbit = 0;
125  }
126 
127  void all_off (void)
128  {
129  Pipewave *P;
130  for (P = _list; P; P = P->_link) P->_sbit = 0;
131  }
132 
133  int n0 (void) const { return _n0; }
134  int n1 (void) const { return _n1; }
135  void play (int shift);
136  void set_param (float *out, int del, int pan);
137  void gen_waves (Addsynth *D, float fsamp, float fbase, float *scale);
138  int save (const char *path, Addsynth *D, float fsamp, float fbase, float *scale);
139  int load (const char *path, Addsynth *D, float fsamp, float fbase, float *scale);
140  bool modif (void) const { return _modif; }
141 
142  int _cmask; // used by division logic
143  int _nmask; // used by division logic
144 
145 };
146 
147 
148 #endif
149 
int _cmask
Definition: rankwave.h:142
Pipewave * _list
Definition: rankwave.h:96
uint32_t _sbit
Definition: rankwave.h:65
int16_t _i_r
Definition: rankwave.h:74
int16_t _k_r
Definition: rankwave.h:59
~Pipewave(void)
Definition: rankwave.h:41
friend class Rankwave
Definition: rankwave.h:43
static void attgain(int n, float p)
Definition: rankwave.cpp:314
int _n0
Definition: rankwave.h:93
float * _p_p
Definition: rankwave.h:68
float * _out
Definition: rankwave.h:67
int _n1
Definition: rankwave.h:94
static void looplen(float f, float fsamp, int lmax, int *aa, int *bb)
Definition: rankwave.cpp:271
uint32_t _sdel
Definition: rankwave.h:66
void play(void)
Definition: rankwave.cpp:44
void load(FILE *F)
Definition: rankwave.cpp:366
void genwave(Addsynth *D, int n, float fsamp, float fpipe)
Definition: rankwave.cpp:186
float _z_p
Definition: rankwave.h:70
float * _p_r
Definition: rankwave.h:71
Definition: addsynth.h:85
float _d_p
Definition: rankwave.h:62
int n0(void) const
Definition: rankwave.h:133
void note_on(int n)
Definition: rankwave.h:105
float * _p1
Definition: rankwave.h:54
void note_off(int n)
Definition: rankwave.h:119
int32_t _l0
Definition: rankwave.h:56
float _m_r
Definition: rankwave.h:60
Definition: rankwave.h:88
bool modif(void) const
Definition: rankwave.h:140
int16_t _k_s
Definition: rankwave.h:58
int n1(void) const
Definition: rankwave.h:134
uint32_t _sbit
Definition: rankwave.h:95
static float * _arg
Definition: rankwave.h:80
static Rngen _rgen
Definition: rankwave.h:79
float _y_r
Definition: rankwave.h:72
static void initstatic(float fsamp)
Definition: rankwave.cpp:30
Pipewave()
Definition: rankwave.h:35
Definition: rngen.h:27
void save(FILE *F)
Definition: rankwave.cpp:341
Definition: rankwave.h:31
float _d_r
Definition: rankwave.h:61
float * _p2
Definition: rankwave.h:55
float _y_p
Definition: rankwave.h:69
float * _p0
Definition: rankwave.h:53
static float * _att
Definition: rankwave.h:81
Pipewave * _link
Definition: rankwave.h:64
Pipewave * _pipes
Definition: rankwave.h:97
int32_t _l1
Definition: rankwave.h:57
bool _modif
Definition: rankwave.h:98
float _g_r
Definition: rankwave.h:73
int _nmask
Definition: rankwave.h:143
void all_off(void)
Definition: rankwave.h:127