File: mainwindow.cpp

package info (click to toggle)
abgate 1.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,104 kB
  • sloc: cpp: 1,482; makefile: 32; sh: 5
file content (206 lines) | stat: -rw-r--r-- 5,411 bytes parent folder | download | duplicates (7)
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QWidget(parent),
    designer_ui(new Ui::MainWindow)
{
    designer_ui->setupUi(this);

    defaultKnobParams();
    KnobStyle = NULL;
    updateKnobStyle();

}

MainWindow::~MainWindow()
{
    delete designer_ui;
    if (KnobStyle) { delete KnobStyle; }
}


void MainWindow::defaultKnobParams()
{
    bypass_bool = BYPASS_DEFAULT > 0 ? true : false;
    designer_ui->bypass->setChecked(bypass_bool);

    designer_ui->threshold->setMouseTracking(false);
    designer_ui->threshold->setMinimum(THRESHOLD_MIN);
    designer_ui->threshold->setMaximum(THRESHOLD_MAX);
    designer_ui->threshold->setValue(THRESHOLD_DEFAULT);

    designer_ui->attack->setMouseTracking(false);
    designer_ui->attack->setMinimum(ATTACK_MIN);
    designer_ui->attack->setMaximum(ATTACK_MAX);
    designer_ui->attack->setValue(ATTACK_DEFAULT);

    designer_ui->hold->setMouseTracking(false);
    designer_ui->hold->setMinimum(HOLD_MIN);
    designer_ui->hold->setMaximum(HOLD_MAX);
    designer_ui->hold->setValue(HOLD_DEFAULT);

    designer_ui->decay->setMouseTracking(false);
    designer_ui->decay->setMinimum(DECAY_MIN);
    designer_ui->decay->setMaximum(DECAY_MAX);
    designer_ui->decay->setValue(DECAY_DEFAULT);

    designer_ui->range->setMouseTracking(false);
    designer_ui->range->setMinimum(RANGE_MIN);
    designer_ui->range->setMaximum(RANGE_MAX);
    designer_ui->range->setValue(RANGE_DEFAULT);
}

void MainWindow::updateKnobStyle()
{
    KnobStyleNum style = KnobStyleNum(abGate);
    if (KnobStyle) {
        delete KnobStyle;
    }
    switch (style) {
    case Classic:
        //KnobStyle = new DialClassicStyle();
        KnobStyle = NULL;
        break;
    case abGate:
        KnobStyle = new abGateStyle();
        break;
    default:
        KnobStyle = NULL;
        break;
    }
    // Change the style for all of the dials
     QList<QDial *> all_dials = findChildren<QDial *>();
    foreach(QDial* knob, all_dials) {
        knob->setStyle(KnobStyle);
        // Show nothes
        if (style != abGate) { knob->setNotchesVisible(true); } else { knob->setNotchesVisible(false); }
    }

    //ui->decay->setStyle(KnobStyle);
}

// Informing GUI about changes in the control ports
void MainWindow::gui_port_event(LV2UI_Handle ui, uint32_t port_index, uint32_t buffer_size, uint32_t format, const void * buffer) {

        float val;
        val = * static_cast<const float*>(buffer);

    // Checking if params are the same as specified in the LV2 documentation
    if (format != 0) { return; }
    if (buffer_size != 4) { return; }

    // Updating values for GUI changes

        switch(port_index){
            case p_switch:
                bypass_bool = val > 0 ? true : false;
                designer_ui->bypass->setChecked(bypass_bool);
                //bypass->set_toggle_value(val);
                break;
            case p_threshold:
                designer_ui->threshold->setValue(val);
                break;
            case p_attack:
                designer_ui->attack->setValue(val);
                break;
            case p_hold:
                designer_ui->hold->setValue(val);
                break;
            case p_decay:
                designer_ui->decay->setValue(val);
                break;
            case p_gaterange:
                designer_ui->range->setValue(val);
                break;
        default:
            return;
    }


}

void MainWindow::write_control(uint32_t port_index, float value) {
    write_function(controller, port_index, 4, 0, &value);
}

void MainWindow::on_threshold_actionTriggered(int action)
{
    write_control(p_threshold, designer_ui->threshold->value());
}

void MainWindow::on_threshold_dialPressed()
{
     write_control(p_threshold, designer_ui->threshold->value());
}

void MainWindow::on_threshold_dialReleased()
{
     write_control(p_threshold, designer_ui->threshold->value());
}

void MainWindow::on_attack_actionTriggered(int action)
{
    write_control(p_attack, designer_ui->attack->value());
}

void MainWindow::on_attack_dialPressed()
{
    write_control(p_attack, designer_ui->attack->value());
}

void MainWindow::on_attack_dialReleased()
{
    write_control(p_attack, designer_ui->attack->value());
}

void MainWindow::on_hold_actionTriggered(int action)
{
    write_control(p_hold, designer_ui->hold->value());
}

void MainWindow::on_hold_dialPressed()
{
    write_control(p_hold, designer_ui->hold->value());
}

void MainWindow::on_hold_dialReleased()
{
    write_control(p_hold, designer_ui->hold->value());
}

void MainWindow::on_decay_actionTriggered(int action)
{
    write_control(p_decay, designer_ui->decay->value());
}

void MainWindow::on_decay_dialPressed()
{
    write_control(p_decay, designer_ui->decay->value());
}

void MainWindow::on_decay_dialReleased()
{
    write_control(p_decay, designer_ui->decay->value());
}

void MainWindow::on_range_actionTriggered(int action)
{
    write_control(p_gaterange, designer_ui->range->value());
}

void MainWindow::on_range_dialPressed()
{
    write_control(p_gaterange, designer_ui->range->value());
}

void MainWindow::on_range_dialReleased()
{
    write_control(p_gaterange, designer_ui->range->value());
}

void MainWindow::on_bypass_toggled(bool checked)
{
    bypass_float = checked != true ? 0 : 1;
    write_control(p_switch, bypass_float);
}