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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
|
/**
bespoke synth, a software modular synthesizer
Copyright (C) 2021 Ryan Challinor (contact: awwbees@gmail.com)
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/>.
**/
//
// CanvasElement.h
// Bespoke
//
// Created by Ryan Challinor on 1/4/15.
//
//
#pragma once
#include "Curve.h"
#include "ModulationChain.h"
class Canvas;
class Sample;
class IUIControl;
class FloatSlider;
class IntSlider;
class TextEntry;
class FileStreamIn;
class FileStreamOut;
class PatchCableSource;
class EventCanvas;
class CanvasElement
{
public:
CanvasElement(Canvas* canvas, int col, int row, float offset, float length);
virtual ~CanvasElement() {}
void Draw(ofVec2f offset);
void DrawOffscreen();
void SetHighlight(bool highlight) { mHighlighted = highlight; }
bool GetHighlighted() const { return mHighlighted; }
ofRectangle GetRect(bool clamp, bool wrapped, ofVec2f offset = ofVec2f(0, 0)) const;
float GetStart() const;
void SetStart(float start, bool preserveLength);
virtual float GetEnd() const;
void SetEnd(float end);
std::vector<IUIControl*>& GetUIControls() { return mUIControls; }
void MoveElementByDrag(ofVec2f dragOffset);
virtual bool IsResizable() const { return true; }
virtual CanvasElement* CreateDuplicate() const = 0;
virtual void CheckboxUpdated(std::string label, bool value, double time);
virtual void FloatSliderUpdated(std::string label, float oldVal, float newVal, double time);
virtual void IntSliderUpdated(std::string label, int oldVal, float newVal, double time);
virtual void ButtonClicked(std::string label, double time);
virtual void SaveState(FileStreamOut& out);
virtual void LoadState(FileStreamIn& in);
int mRow;
int mCol;
float mOffset;
float mLength;
protected:
virtual void DrawContents(bool clamp, bool wrapped, ofVec2f offset) = 0;
void DrawElement(bool clamp, bool wrapped, ofVec2f offset);
void AddElementUIControl(IUIControl* control);
void GetDragDestinationData(ofVec2f dragOffset, int& newRow, int& newCol, float& newOffset) const;
ofRectangle GetRectAtDestination(bool clamp, bool wrapped, ofVec2f dragOffset) const;
float GetStart(int col, float offset) const;
float GetEnd(int col, float offset, float length) const;
Canvas* mCanvas{ nullptr };
bool mHighlighted{ false };
std::vector<IUIControl*> mUIControls;
};
class NoteCanvasElement : public CanvasElement
{
public:
NoteCanvasElement(Canvas* canvas, int col, int row, float offset, float length);
static CanvasElement* Create(Canvas* canvas, int col, int row) { return new NoteCanvasElement(canvas, col, row, 0, 1); }
void SetVelocity(float vel) { mVelocity = vel; }
float GetVelocity() const { return mVelocity; }
void SetVoiceIdx(int voiceIdx) { mVoiceIdx = voiceIdx; }
int GetVoiceIdx() const { return mVoiceIdx; }
ModulationChain* GetPitchBend() { return &mPitchBend; }
ModulationChain* GetModWheel() { return &mModWheel; }
ModulationChain* GetPressure() { return &mPressure; }
float GetPan() { return mPan; }
void UpdateModulation(float pos);
void WriteModulation(float pos, float pitchBend, float modWheel, float pressure, float pan);
CanvasElement* CreateDuplicate() const override;
void SaveState(FileStreamOut& out) override;
void LoadState(FileStreamIn& in) override;
private:
void DrawContents(bool clamp, bool wrapped, ofVec2f offset) override;
float mVelocity{ .8 };
FloatSlider* mElementOffsetSlider{ nullptr };
FloatSlider* mElementLengthSlider{ nullptr };
IntSlider* mElementRowSlider{ nullptr };
IntSlider* mElementColSlider{ nullptr };
FloatSlider* mVelocitySlider{ nullptr };
int mVoiceIdx{ -1 };
ModulationChain mPitchBend{ ModulationParameters::kDefaultPitchBend };
ModulationChain mModWheel{ ModulationParameters::kDefaultModWheel };
ModulationChain mPressure{ ModulationParameters::kDefaultPressure };
float mPan{ 0 };
Curve mPitchBendCurve{ ModulationParameters::kDefaultPitchBend };
Curve mModWheelCurve{ ModulationParameters::kDefaultModWheel };
Curve mPressureCurve{ ModulationParameters::kDefaultPressure };
Curve mPanCurve{ 0 };
};
class SampleCanvasElement : public CanvasElement
{
public:
SampleCanvasElement(Canvas* canvas, int col, int row, float offset, float length);
~SampleCanvasElement();
static CanvasElement* Create(Canvas* canvas, int col, int row) { return new SampleCanvasElement(canvas, col, row, 0, 1); }
void SetSample(Sample* sample);
Sample* GetSample() const { return mSample; }
float GetVolume() const { return mVolume; }
bool IsMuted() const { return mMute; }
CanvasElement* CreateDuplicate() const override;
void CheckboxUpdated(std::string label, bool value, double time) override;
void ButtonClicked(std::string label, double time) override;
void SaveState(FileStreamOut& out) override;
void LoadState(FileStreamIn& in) override;
private:
void DrawContents(bool clamp, bool wrapped, ofVec2f offset) override;
Sample* mSample{ nullptr };
FloatSlider* mElementOffsetSlider{ nullptr };
float mVolume{ 1 };
FloatSlider* mVolumeSlider{ nullptr };
bool mMute{ false };
Checkbox* mMuteCheckbox{ nullptr };
ClickButton* mSplitSampleButton{ nullptr };
ClickButton* mResetSpeedButton{ nullptr };
};
class EventCanvasElement : public CanvasElement
{
public:
EventCanvasElement(Canvas* canvas, int col, int row, float offset);
~EventCanvasElement();
static CanvasElement* Create(Canvas* canvas, int col, int row) { return new EventCanvasElement(canvas, col, row, 0); }
CanvasElement* CreateDuplicate() const override;
void SetUIControl(IUIControl* control);
void SetValue(float value) { mValue = value; }
void Trigger(double time);
void TriggerEnd(double time);
bool IsResizable() const override { return mIsCheckbox; }
float GetEnd() const override;
void SaveState(FileStreamOut& out) override;
void LoadState(FileStreamIn& in) override;
private:
void DrawContents(bool clamp, bool wrapped, ofVec2f offset) override;
IUIControl* mUIControl{ nullptr };
float mValue{ 0 };
TextEntry* mValueEntry{ nullptr };
EventCanvas* mEventCanvas{ nullptr };
bool mIsCheckbox{ false };
bool mIsButton{ false };
};
|