-
Notifications
You must be signed in to change notification settings - Fork 0
/
Envelopes.h
116 lines (89 loc) · 3.67 KB
/
Envelopes.h
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
#ifndef ENVELOPES_INCLUDED
#define ENVELOPES_INCLUDED
#include "MidiSetup.hpp"
#define MIDI_CHANNEL_EXTENDED_ENVELOPES 11 // channel to receive extended envelope info on
// STRUCTS
enum envelope_types : byte {
ENV_CRASH = 0,
ENV_SPLASH = 1,
ENV_WOBBLY = 2,
ENV_RIDE_BELL = 3,
ENV_RIDE_CYMBAL = 4,
ENV_PITCH_1 = 5, // TODO: enable these...
ENV_PITCH_2 = 6, // TODO: enable these...and add 2 more
ENV_PITCH_3 = 7,
ENV_PITCH_4 = 8
// TODO: more envelope types...
};
#if MUSO_MODE==MUSO_MODE_0B_AND_2A
#define NUM_ENVELOPES 5
#define NUM_ENVELOPES_EXTENDED 9 // extended for envelopes that aren't included in the triggerable envelopes, ie to be used for the harmony outputs
#else
#define NUM_ENVELOPES 5
#define NUM_ENVELOPES_EXTENDED 5
#endif
#define ENV_CC_SPAN 8 // how many CCs to reserve per-envelope
#define ENV_CC_START 64 // what number CC the envelope controls begin at
#define SUSTAIN_MINIMUM 1 // was 32 // minimum sustain volume to use (below this becomes inaudible, so cut it off)
#define ENV_MAX_ATTACK (PPQN*2) //48 // maximum attack stage length in ticks
#define ENV_MAX_HOLD (PPQN*2) //48 // maximum hold stage length
#define ENV_MAX_DECAY (PPQN*2) //48 // maximum decay stage length
#define ENV_MAX_RELEASE (PPQN*4) //96 // maximum release stage length
#define TRIGGER_CHANNEL_OFF 20
//#define TEST_LFOS
enum stage : byte {
OFF = 0,
//DELAY, // time
ATTACK,
HOLD, // time
DECAY,
SUSTAIN,
RELEASE,
//END = 0
LFO_SYNC_RATIO_HOLD_AND_DECAY,
LFO_SYNC_RATIO_SUSTAIN_AND_RELEASE,
ASSIGN_HARMONY_OUTPUT
};
// above enums also used as the envelope CC offsets
//#define LFO_SYNC_RATIO (RELEASE+1)
typedef struct envelope_state {
//#ifndef TEST_LFOS
byte stage = OFF;
/*#else
byte stage = LFO_SYNC_RATIO;
#endif*/
byte velocity = 127; // triggered velocity
byte actual_level = 0; // right now, the level
byte stage_start_level = 0; // level at start of current stage
// TODO: int delay_length = 5; // D - delay before atack starts
unsigned int attack_length = 0; // A - attack - length of stage
unsigned int hold_length = (PPQN / 4) - 1; // H - hold - length to hold at end of attack before decay
unsigned int decay_length = (PPQN / 2) - 1; // D - decay - length of stage
float sustain_ratio = 0.90f; // S - sustain - level to drop to after decay phase
unsigned int release_length = (PPQN / 2) - 1; // R - release - length (time to drop to 0)
byte lfo_sync_ratio_hold_and_decay = 0;
byte lfo_sync_ratio_sustain_and_release = 0;
unsigned long stage_triggered_at = 0;
unsigned long triggered_at = 0;
unsigned long last_sent_at = 0;
int trigger_on = 0; // 0->19 = trigger #, 20 = off, 32->51 = trigger #+loop, 64->84 = trigger #+invert, 96->116 = trigger #+loop+invert
bool loop = false;
bool invert = false;
byte midi_cc;
byte last_sent_lvl; // value but not inverted
byte last_sent_actual_lvl; // actual midi value sent
};
// GLOBALS
byte cc_value_sync_modifier = 24; // initial global clock sync modifier -- number of real ticks per 24 pseudoticks ?
envelope_state envelopes[NUM_ENVELOPES_EXTENDED];
// prototype stubs
void update_envelope (byte env_num, byte velocity, bool state);
bool handle_envelope_ccs(byte channel, byte number, byte value);
void kill_envelopes();
void initialise_envelopes();
void process_envelopes(unsigned long now);
void randomise_envelopes();
void fire_envelope_for_channel(int channel, int velocity = 127);
void douse_envelope_for_channel(int channel, int velocity = 127);
void update_envelopes_for_trigger(int trigger, int velocity = 127, bool state = true);
#endif