-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathslipspander.cpp
More file actions
127 lines (116 loc) · 3.05 KB
/
Copy pathslipspander.cpp
File metadata and controls
127 lines (116 loc) · 3.05 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
#include "plugin.hpp"
#include "slipspander.hpp"
#include "slips.hpp"
void Slipspander::process(const ProcessArgs &args)
{
selected_notes.clear();
for (int i = 0; i < 12; i++)
{
if (params[C_PARAM + i].getValue() > 0.5f)
{
notes_on[i] = true;
selected_notes.push_back(i);
}
else
{
notes_on[i] = false;
}
}
if (leftExpander.module && leftExpander.module->model == modelSlips)
{
expanding = true;
if (selected_notes != selected_notes_prev)
{
Slips *slipsModule = dynamic_cast<Slips *>(leftExpander.module);
if (slipsModule)
{
slipsModule->get_custom_scale();
}
}
}
else
{
expanding = false;
}
for (int i = 0; i < 12; i++)
{
lights[C_LIGHT + i].setBrightness(notes_on[i] ? 1.f : 0.f);
}
lights[EXPANDING_LIGHT].setBrightness(expanding ? 1.f : 0.f);
selected_notes_prev = selected_notes;
}
json_t *Slipspander::dataToJson()
{
json_t *rootJ = json_object();
json_t *notes_onJ = json_array();
for (int i = 0; i < 12; i++)
{
json_t *note_onJ = json_boolean(notes_on[i]);
json_array_append_new(notes_onJ, note_onJ);
}
json_object_set_new(rootJ, "notes_on", notes_onJ);
return rootJ;
}
void Slipspander::dataFromJson(json_t *rootJ)
{
json_t *notes_onJ = json_object_get(rootJ, "notes_on");
if (notes_onJ)
{
for (int i = 0; i < 12; i++)
{
json_t *note_onJ = json_array_get(notes_onJ, i);
if (note_onJ)
{
notes_on[i] = json_boolean_value(note_onJ);
}
}
}
}
void SlipspanderWidget::step()
{
Slipspander *spanderModule = dynamic_cast<Slipspander *>(this->module);
if (!spanderModule)
return;
if (use_global_contrast[SLIPS])
{
module_contrast[SLIPS] = global_contrast;
}
if (module_contrast[SLIPS] != panelBackground->contrast)
{
panelBackground->contrast = module_contrast[SLIPS];
if (panelBackground->contrast < 0.4f)
{
panelBackground->invert(true);
inverter->invert = true;
}
else
{
panelBackground->invert(false);
inverter->invert = false;
}
svgPanel->fb->dirty = true;
}
ModuleWidget::step();
}
void SlipspanderWidget::appendContextMenu(Menu *menu)
{
Slipspander *module = dynamic_cast<Slipspander *>(this->module);
assert(module);
menu->addChild(new MenuSeparator());
menu->addChild(createSubmenuItem("contrast", "", [=](Menu *menu)
{
Menu* contrastMenu = new Menu();
ContrastSlider *contrastSlider = new ContrastSlider(&(module_contrast[SLIPS]));
contrastSlider->box.size.x = 200.f;
GlobalOption *globalOption = new GlobalOption(&(use_global_contrast[SLIPS]));
contrastMenu->addChild(globalOption);
contrastMenu->addChild(new MenuSeparator());
contrastMenu->addChild(contrastSlider);
contrastMenu->addChild(createMenuItem("set global contrast", "",
[]() {
global_contrast = module_contrast[SLIPS];
use_global_contrast[SLIPS] = true;
}));
menu->addChild(contrastMenu); }));
}
Model *modelSlipspander = createModel<Slipspander, SlipspanderWidget>("slipspander");