-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStepSequencerComponent.cpp
More file actions
169 lines (128 loc) · 3.97 KB
/
Copy pathStepSequencerComponent.cpp
File metadata and controls
169 lines (128 loc) · 3.97 KB
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
/*
==============================================================================
StepSequencerComponent.cpp
Created: 22 Nov 2017 4:08:36pm
Author: Mael Derio
==============================================================================
*/
#include "StepSequencerComponent.h"
StepSequencerComponent::StepSequencerComponent ()
: numberOfSteps_(8), numberOfPulses_(5), currentStep_(0)
{
// Make sure that before the constructor has finished, you've set the
// editor's size to whatever you need it to be.
//setSize (80, 100);
//Initialize the step states to 0
for(int i=0;i<numberOfSteps_;i++)
stepStates_.push_back(0);
}
StepSequencerComponent::~StepSequencerComponent()
{
}
//==============================================================================
void StepSequencerComponent::paint (juce::Graphics& g)
{
// (Our component is opaque, so we must completely fill the background with a solid colour)
//g.fillAll (juce::Colour((juce::uint8)44,(juce::uint8)53,(juce::uint8)57,1.0f));
//g.setColour (juce::Colour((juce::uint8)34,(juce::uint8)43,(juce::uint8)47,1.0f));
g.setFont (15.0f);
float scaleSize = 1, scaleTop = 1; //Change the size of the rectangle if current step
float stepWidth = (getWidth())/numberOfSteps_;
for(int i=0;i<numberOfSteps_;i++)
{
if(stepStates_[i]==1)
g.setColour(juce::Colours::slategrey);
else
g.setColour (juce::Colour((juce::uint8)34,(juce::uint8)43,(juce::uint8)47,1.0f));
//Change the size of the rectangle
//paint is asynchronous, so step() adds one to current step before it shows
//we compensate for this by starting the number of steps at -1
if(currentStep_ == i)
{
scaleSize = 0.95;
scaleTop = 0.025;
}
else
{
scaleSize = 0.9;
scaleTop = 0.05;
}
g.fillRoundedRectangle(stepWidth*i, 10, stepWidth*.9*scaleSize, 40*scaleSize, 5.f);
}
}
void StepSequencerComponent::step()
{
if(currentStep_<numberOfSteps_-1) {
currentStep_+=1;
}
else
currentStep_=0;
repaint();
}
void StepSequencerComponent::mouseDown(const juce::MouseEvent& event)
{
int x = event.getMouseDownX();
float stepWidth = getWidth()/numberOfSteps_;
for(int i=0;i<numberOfSteps_;i++)
{
if(x>i*stepWidth && x<i*stepWidth+stepWidth) {
if(stepStates_[i]==1) {
stepStates_[i] = 0;
}
else {
stepStates_[i] = 1;
}
}
repaint();
}
}
void StepSequencerComponent::resized()
{
// This is generally where you'll want to lay out the positions of any
// subcomponents in your editor..
}
//Getters/Setters
int StepSequencerComponent::getNumberOfSteps()
{
return numberOfSteps_;
}
int StepSequencerComponent::getNumberOfPulses()
{
return numberOfPulses_;
}
int StepSequencerComponent::getCurrentStep()
{
return currentStep_;
}
void StepSequencerComponent::setNumberOfSteps(int num)
{
numberOfSteps_ = num;
}
void StepSequencerComponent::setNumberOfPulses(int num)
{
numberOfPulses_ = num;
}
void StepSequencerComponent::setOffset(int num)
{
offset_ = num;
}
void StepSequencerComponent::setCurrentStep(int num)
{
currentStep_ = num;
}
void StepSequencerComponent::setStepStates(std::vector<bool> states)
{
stepStates_.clear();
for(int i=0;i<states.size();i++)
stepStates_.push_back(states[i]);
repaint();
}
int StepSequencerComponent::getCurrentStepState()
{
jassert(currentStep_<stepStates_.size());
return stepStates_[currentStep_];
}
std::vector<bool> StepSequencerComponent::getStepStates()
{
return stepStates_;
}