forked from BespokeSynth/BespokeSynth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathADSRDisplay.h
127 lines (112 loc) · 3.87 KB
/
ADSRDisplay.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
117
118
119
120
121
122
123
124
125
126
127
/**
bespoke synth, a software modular synthesizer
Copyright (C) 2021 Ryan Challinor (contact: [email protected])
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 3 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, see <http://www.gnu.org/licenses/>.
**/
//
// ADSRDisplay.h
// modularSynth
//
// Created by Ryan Challinor on 4/28/13.
//
//
#pragma once
#include "IUIControl.h"
#include "ADSR.h"
#include "Slider.h"
class IDrawableModule;
class EnvelopeEditor;
class ADSRDisplay : public IUIControl
{
public:
ADSRDisplay(IDrawableModule* owner, const char* name, int x, int y, int w, int h, ::ADSR* adsr);
void Render() override;
void MouseReleased() override;
bool MouseMoved(float x, float y) override;
void SetVol(float vol) { mVol = vol; }
void SetHighlighted(bool highlighted) { mHighlighted = highlighted; }
float GetMaxTime() const { return mMaxTime; }
float& GetMaxTime() { return mMaxTime; }
void SetMaxTime(float maxTime);
void SetADSR(::ADSR* adsr);
::ADSR* GetADSR() { return mAdsr; }
void SpawnEnvelopeEditor();
void SetOverrideDrawTime(double time) { mOverrideDrawTime = time; }
void SetDimensions(float w, float h)
{
mWidth = w;
mHeight = h;
}
void SetShowing(bool showing) override
{
IUIControl::SetShowing(showing);
UpdateSliderVisibility();
}
FloatSlider* GetASlider() { return mASlider; }
FloatSlider* GetDSlider() { return mDSlider; }
FloatSlider* GetSSlider() { return mSSlider; }
FloatSlider* GetRSlider() { return mRSlider; }
//IUIControl
void SetFromMidiCC(float slider, double time, bool setViaModulator) override {}
void SetValue(float value, double time, bool forceUpdate = false) override {}
bool CanBeTargetedBy(PatchCableSource* source) const override { return false; }
void SaveState(FileStreamOut& out) override;
void LoadState(FileStreamIn& in, bool shouldSetValue = true) override;
bool GetNoHover() const override { return true; }
enum DisplayMode
{
kDisplayEnvelope,
kDisplaySliders
};
static void ToggleDisplayMode();
protected:
~ADSRDisplay(); //protected so that it can't be created on the stack
private:
enum AdjustParam
{
kAdjustAttack,
kAdjustDecaySustain,
kAdjustRelease,
kAdjustEnvelopeEditor,
kAdjustNone,
kAdjustAttackAR,
kAdjustReleaseAR,
kAdjustViewLength
} mAdjustMode{ AdjustParam::kAdjustNone };
void OnClicked(float x, float y, bool right) override;
void GetDimensions(float& width, float& height) override
{
width = mWidth;
height = mHeight;
}
void UpdateSliderVisibility();
ofVec2f GetDrawPoint(float time, const ADSR::EventInfo& adsrEvent);
float mWidth;
float mHeight;
float mVol{ 1 };
float mMaxTime{ 1000 };
bool mClick{ false };
::ADSR* mAdsr;
ofVec2f mClickStart;
::ADSR mClickAdsr;
float mClickLength{ 1000 };
bool mHighlighted{ false };
FloatSlider* mASlider{ nullptr };
FloatSlider* mDSlider{ nullptr };
FloatSlider* mSSlider{ nullptr };
FloatSlider* mRSlider{ nullptr };
static DisplayMode sDisplayMode;
EnvelopeEditor* mEditor{ nullptr };
double mOverrideDrawTime{ -1 };
std::array<double, 10> mDrawTimeHistory{};
int mDrawTimeHistoryIndex{ 0 };
};