summaryrefslogtreecommitdiff
path: root/muse_qt4_evolution/synti/organ/organ.h
blob: 971e6cc9550620b1882da245beca47a93d5bb683 (plain)
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
150
151
//=========================================================
//  MusE
//  Linux Music Editor
//  $Id: organ.h,v 1.5 2004/04/15 13:46:18 wschweer Exp $
//
//  Parts of this file taken from:
//      Organ - Additive Organ Synthesizer Voice
//      Copyright (c) 1999, 2000 David A. Bartold
//
//  (C) Copyright 2001-2007 Werner Schweer (ws@seh.de)
//=========================================================

#ifndef __ORGAN_H__
#define __ORGAN_H__

#include "muse/midictrl.h"
#include "libsynti/mess2.h"

static const int NO_VOICES = 128;    // max polyphony
static const int NO_KEYS = 97 - 36;
class OrganGui;
class Reverb;

static const int MAX_ATTENUATION = 960;
static const int NO_BUSES        = 9;
static const int NO_WHEELS       = 91;
static const int NO_ELEMENTS     = 194;

enum {
      DRAWBAR0 = CTRL_RPN14_OFFSET, DRAWBAR1, DRAWBAR2,
         DRAWBAR3, DRAWBAR4, DRAWBAR5, DRAWBAR6, DRAWBAR7, DRAWBAR8,
      REVERB_ON, REVERB_ROOM_SIZE, REVERB_MIX,
      VIBRATO_ON, VIBRATO_FREQ, VIBRATO_DEPTH,
      PERC_ON, PERC_GAIN, PERC_DECAY, PERC_HARMONY,
      ROTARY_ON, ROT1_FREQ, ROT1_DEPTH, ROT2_FREQ, ROT2_DEPTH
      };

//---------------------------------------------------------
//   Wheel
//---------------------------------------------------------

struct Wheel {
      unsigned frameStep;
      unsigned accu;

      int refCount;
      bool active;
      float gain[NO_BUSES];

      // envelopes:
      float* env[NO_BUSES];
      int envCount[NO_BUSES];
      float deltaGain[NO_BUSES];
      };

//---------------------------------------------------------
//   Elem
//---------------------------------------------------------

struct Elem {
      char wheel;
      char bus;
      float level;

      Elem() { bus = -1; }
      Elem(char w, char b, float l) : wheel(w), bus(b), level(l) {}
      };

//---------------------------------------------------------
//   Organ
//---------------------------------------------------------

class Organ : public Mess2 {
      static int useCount;

      static float* waveTable;
      static double cb2amp_tab[MAX_ATTENUATION];
      static double cb2amp(int cb);
      static Elem routing[NO_KEYS][NO_ELEMENTS];
      static float* attackEnv;
      static float* releaseEnv;
      static int envSize;
      static float keyCompression[NO_VOICES];

      OrganGui* gui;
      Reverb* reverb;
      bool reverbOn;
      double volume;

      unsigned vibratoStep;
      unsigned vibratoAccu;

      bool vibratoOn;
      double vibratoFreq;
      double vibratoDepth;

      // key compression
      float keyCompressionDelta;
      float keyCompressionValue;
      int keyCompressionCount;

      // percussion
      int percussionBus;      // usually drawbar 3 or drawbar 4
      bool percussionOn;
      double percDecay;
      double percussionEnvDecay;
      double percGain;
      double percGainInit;

      // rotary speaker emulation
      bool rotaryOn;
      double rot1Freq;        // horn: 0,67 - 6,7
      double rot1Depth;
      double rot2Freq;        // drum: 0,5  - 5,5
      double rot2Depth;
      unsigned rot1Step;
      unsigned rot1AccuL;
      unsigned rot1AccuR;
      unsigned rot2Step;
      unsigned rot2AccuL;
      unsigned rot2AccuR;

      float drawBarGain[NO_BUSES];
      Wheel wheels[NO_WHEELS];
      QList<char> pressedKeys;
      QList<Wheel*> activeWheels;

      void setController(int ctrl, int val);
      void changeKeyCompression();
      void percussionChanged();

      virtual void process(float**, int, int);
      virtual bool playNote(int channel, int pitch, int velo);
      virtual bool setController(int channel, int ctrl, int val);
	virtual bool sysex(int, const unsigned char*);

      virtual bool guiVisible() const;
      virtual void showGui(bool);
      virtual bool hasGui() const { return true; }
      virtual void getGeometry(int* x, int* y, int* w, int* h) const;
      virtual void setGeometry(int x, int y, int w, int h);

   public:
      friend class OrganGui;
      Organ(int sampleRate);
      ~Organ();
      bool init(const char* name);
      };

#endif