File: rankwave.h

package info (click to toggle)
musescore 2.0.3%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 202,532 kB
  • ctags: 58,769
  • sloc: cpp: 257,595; xml: 172,226; ansic: 139,931; python: 6,565; sh: 6,383; perl: 423; makefile: 290; awk: 142; pascal: 67; sed: 3
file content (149 lines) | stat: -rw-r--r-- 4,188 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
    Copyright (C) 2003-2008 Fons Adriaensen <fons@kokkinizita.net>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/


#ifndef __RANKWAVE_H
#define __RANKWAVE_H


#include "addsynth.h"
#include "rngen.h"


#define PERIOD 64


class Pipewave
{
private:

    Pipewave () :
        _p0 (0), _p1 (0), _p2 (0), _l1 (0), _k_s (0),  _k_r (0), _m_r (0),
        _link (0), _sbit (0), _sdel (0),
        _p_p (0), _y_p (0), _z_p (0), _p_r (0), _y_r (0), _g_r (0), _i_r (0)
    {}

    ~Pipewave (void) { delete[] _p0; }

    friend class Rankwave;

    void genwave (Addsynth *D, int n, float fsamp, float fpipe);
    void save (FILE *F);
    void load (FILE *F);
    void play (void);

    static void looplen (float f, float fsamp, int lmax, int *aa, int *bb);
    static void attgain (int n, float p);

    float     *_p0;    // attack start
    float     *_p1;    // loop start
    float     *_p2;    // loop end
    int32_t    _l0;    // attack length
    int32_t    _l1;    // loop length
    int16_t    _k_s;   // sample step
    int16_t    _k_r;   // release lenght
    float      _m_r;   // release multiplier
    float      _d_r;   // release detune
    float      _d_p;   // instability

    Pipewave  *_link;  // link to next in active chain
    uint32_t   _sbit;  // on state bit
    uint32_t   _sdel;  // delayed state
    float     *_out;   // audio output buffer
    float     *_p_p;   // play pointer
    float      _y_p;   // play interpolation
    float      _z_p;   // play interpolation speed
    float     *_p_r;   // release pointer
    float      _y_r;   // release interpolation
    float      _g_r;   // release gain
    int16_t    _i_r;   // release count


    static void initstatic (float fsamp);

    static   Rngen   _rgen;
    static   float  *_arg;
    static   float  *_att;
};

//---------------------------------------------------------
//   Rankwave
//---------------------------------------------------------

class Rankwave
      {
      Rankwave (const Rankwave&);
      Rankwave& operator=(const Rankwave&);

      int         _n0;
      int         _n1;
      uint32_t    _sbit;
      Pipewave   *_list;
      Pipewave   *_pipes;
      bool        _modif;

public:

      Rankwave (int n0, int n1);
      ~Rankwave ();

      void note_on (int n) {
            if ((n < _n0) || (n > _n1)) {
                  qDebug("Rankwave: bad key");
                  return;
                  }
            Pipewave *P = _pipes + (n - _n0);
            P->_sbit = _sbit;
            if (! (P->_sdel || P->_p_p || P->_p_r)) {
                  P->_sdel |= _sbit;
                  P->_link = _list;
                  _list = P;
                  }
            }

    void note_off (int n)
    {
        if ((n < _n0) || (n > _n1)) return;
        Pipewave *P = _pipes + (n - _n0);
        P->_sdel >>= 4;
        P->_sbit = 0;
    }

    void all_off (void)
    {
        Pipewave *P;
        for (P = _list; P; P = P->_link) P->_sbit = 0;
    }

    int  n0 (void) const { return _n0; }
    int  n1 (void) const { return _n1; }
    void play (int shift);
    void set_param (float *out, int del, int pan);
    void gen_waves (Addsynth *D, float fsamp, float fbase, float *scale);
    int  save (const char *path, Addsynth *D, float fsamp, float fbase, float *scale);
    int  load (const char *path, Addsynth *D, float fsamp, float fbase, float *scale);
    bool modif (void) const { return _modif; }

    int  _cmask;  // used by division logic
    int  _nmask;  // used by division logic

};


#endif