File: PluginEditor.cpp

package info (click to toggle)
iem-plugin-suite 1.15.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,084 kB
  • sloc: cpp: 58,973; python: 269; sh: 79; makefile: 38
file content (432 lines) | stat: -rw-r--r-- 17,584 bytes parent folder | download
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
/*
 ==============================================================================
 This file is part of the IEM plug-in suite.
 Author: Daniel Rudrich
 Copyright (c) 2017 - Institute of Electronic Music and Acoustics (IEM)
 https://iem.at

 The IEM plug-in suite 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.

 The IEM plug-in suite 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 software.  If not, see <https://www.gnu.org/licenses/>.
 ==============================================================================
 */

#include "PluginEditor.h"
#include "PluginProcessor.h"

//==============================================================================
SceneRotatorAudioProcessorEditor::SceneRotatorAudioProcessorEditor (
    SceneRotatorAudioProcessor& p,
    juce::AudioProcessorValueTreeState& vts) :
    juce::AudioProcessorEditor (&p),
    processor (p),
    valueTreeState (vts),
    footer (p.getOSCParameterInterface())
{
    // ============== BEGIN: essentials ======================
    // set GUI size and lookAndFeel
    //setSize(500, 300); // use this to create a fixed-size GUI
    setResizeLimits (450, 320, 800, 500); // use this to create a resizable GUI
    setResizable (true, true);
    setLookAndFeel (&globalLaF);

    // make title and footer visible, and set the PluginName
    addAndMakeVisible (&title);
    title.setTitle (juce::String ("Scene"), juce::String ("Rotator"));
    title.setFont (globalLaF.robotoBold, globalLaF.robotoLight);
    addAndMakeVisible (&footer);
    // ============= END: essentials ========================

    // create the connection between title component's comboBoxes and parameters
    cbOrderAttachement.reset (
        new ComboBoxAttachment (valueTreeState,
                                "orderSetting",
                                *title.getInputWidgetPtr()->getOrderCbPointer()));
    cbNormalizationAttachement.reset (
        new ComboBoxAttachment (valueTreeState,
                                "useSN3D",
                                *title.getInputWidgetPtr()->getNormCbPointer()));

    // ======================== YAW, PITCH, ROLL GROUP
    yprGroup.setText ("Yaw, Pitch & Roll");
    yprGroup.setTextLabelPosition (juce::Justification::centredLeft);
    addAndMakeVisible (&yprGroup);

    addAndMakeVisible (&slYaw);
    slYawAttachment.reset (new SliderAttachment (valueTreeState, "yaw", slYaw));
    slYaw.setSliderStyle (juce::Slider::RotaryHorizontalVerticalDrag);
    slYaw.setTextBoxStyle (juce::Slider::TextBoxBelow, false, 50, 15);
    slYaw.setReverse (true);
    slYaw.setColour (juce::Slider::rotarySliderOutlineColourId, globalLaF.ClWidgetColours[0]);
    slYaw.setRotaryParameters (juce::MathConstants<float>::pi,
                               3 * juce::MathConstants<float>::pi,
                               false);
    slYaw.setTooltip ("Yaw angle: rotation around z-axis");
    slYaw.setTextValueSuffix (juce::CharPointer_UTF8 (R"(°)"));

    addAndMakeVisible (&slPitch);
    slPitchAttachment.reset (new SliderAttachment (valueTreeState, "pitch", slPitch));
    slPitch.setSliderStyle (juce::Slider::RotaryHorizontalVerticalDrag);
    slPitch.setTextBoxStyle (juce::Slider::TextBoxBelow, false, 50, 15);
    slPitch.setReverse (true);
    slPitch.setColour (juce::Slider::rotarySliderOutlineColourId, globalLaF.ClWidgetColours[1]);
    slPitch.setRotaryParameters (0.5 * juce::MathConstants<float>::pi,
                                 2.5 * juce::MathConstants<float>::pi,
                                 false);
    slPitch.setTooltip ("Pitch angle: rotation around y-axis");
    slPitch.setTextValueSuffix (juce::CharPointer_UTF8 (R"(°)"));

    addAndMakeVisible (&slRoll);
    slRollAttachment.reset (new SliderAttachment (valueTreeState, "roll", slRoll));
    slRoll.setSliderStyle (juce::Slider::RotaryHorizontalVerticalDrag);
    slRoll.setTextBoxStyle (juce::Slider::TextBoxBelow, false, 50, 15);
    slRoll.setColour (juce::Slider::rotarySliderOutlineColourId, globalLaF.ClWidgetColours[2]);
    slRoll.setReverse (false);
    slRoll.setRotaryParameters (juce::MathConstants<float>::pi,
                                3 * juce::MathConstants<float>::pi,
                                false);
    slRoll.setTooltip ("Roll angle: rotation around x-axis");
    slRoll.setTextValueSuffix (juce::CharPointer_UTF8 (R"(°)"));

    addAndMakeVisible (tbInvertYaw);
    tbInvertYawAttachment.reset (new ButtonAttachment (valueTreeState, "invertYaw", tbInvertYaw));
    tbInvertYaw.setColour (juce::ToggleButton::ColourIds::tickColourId,
                           globalLaF.ClWidgetColours[0]);
    tbInvertYaw.setButtonText ("Flip");

    addAndMakeVisible (tbInvertPitch);
    tbInvertPitchAttachment.reset (
        new ButtonAttachment (valueTreeState, "invertPitch", tbInvertPitch));
    tbInvertPitch.setColour (juce::ToggleButton::ColourIds::tickColourId,
                             globalLaF.ClWidgetColours[1]);
    tbInvertPitch.setButtonText ("Flip");

    addAndMakeVisible (tbInvertRoll);
    tbRollFlipAttachment.reset (new ButtonAttachment (valueTreeState, "invertRoll", tbInvertRoll));
    tbInvertRoll.setColour (juce::ToggleButton::ColourIds::tickColourId,
                            globalLaF.ClWidgetColours[2]);
    tbInvertRoll.setButtonText ("Flip");

    addAndMakeVisible (tbInvertQuaternion);
    tbInvertQuaternionAttachment.reset (
        new ButtonAttachment (valueTreeState, "invertQuaternion", tbInvertQuaternion));
    tbInvertQuaternion.setColour (juce::ToggleButton::ColourIds::tickColourId,
                                  globalLaF.ClWidgetColours[0]);
    tbInvertQuaternion.setButtonText ("Invert Quaternions");

    addAndMakeVisible (cbRotationSequence);
    cbRotationSequence.setTooltip ("Sequence of intrinsic rotations");
    cbRotationSequence.addSectionHeading ("Rotation sequence");
    cbRotationSequence.addItem ("Yaw -> Pitch -> Roll", 1);
    cbRotationSequence.addItem ("Roll -> Pitch -> Yaw", 2);
    cbRotationSequence.setJustificationType (juce::Justification::centred);
    cbRotationSequenceAttachment.reset (
        new ComboBoxAttachment (valueTreeState, "rotationSequence", cbRotationSequence));

    // ====================== QUATERNION GROUP
    quatGroup.setText ("Quaternions");
    quatGroup.setTextLabelPosition (juce::Justification::centredLeft);
    addAndMakeVisible (&quatGroup);

    addAndMakeVisible (&slQW);
    slQWAttachment.reset (new SliderAttachment (valueTreeState, "qw", slQW));
    slQW.setSliderStyle (juce::Slider::LinearHorizontal);
    slQW.setTextBoxStyle (juce::Slider::TextBoxLeft, false, 50, 15);
    slQW.setColour (juce::Slider::rotarySliderOutlineColourId, globalLaF.ClWidgetColours[0]);

    addAndMakeVisible (&slQX);
    slQXAttachment.reset (new SliderAttachment (valueTreeState, "qx", slQX));
    slQX.setSliderStyle (juce::Slider::LinearHorizontal);
    slQX.setTextBoxStyle (juce::Slider::TextBoxLeft, false, 50, 15);
    slQX.setColour (juce::Slider::rotarySliderOutlineColourId, globalLaF.ClWidgetColours[0]);

    addAndMakeVisible (&slQY);
    slQYAttachment.reset (new SliderAttachment (valueTreeState, "qy", slQY));
    slQY.setSliderStyle (juce::Slider::LinearHorizontal);
    slQY.setTextBoxStyle (juce::Slider::TextBoxLeft, false, 50, 15);
    slQY.setColour (juce::Slider::rotarySliderOutlineColourId, globalLaF.ClWidgetColours[0]);

    addAndMakeVisible (&slQZ);
    slQZAttachment.reset (new SliderAttachment (valueTreeState, "qz", slQZ));
    slQZ.setSliderStyle (juce::Slider::LinearHorizontal);
    slQZ.setTextBoxStyle (juce::Slider::TextBoxLeft, false, 50, 15);
    slQZ.setColour (juce::Slider::rotarySliderOutlineColourId, globalLaF.ClWidgetColours[0]);

    // ================ LABELS ===================
    addAndMakeVisible (&lbYaw);
    lbYaw.setText ("Yaw");

    addAndMakeVisible (&lbPitch);
    lbPitch.setText ("Pitch");

    addAndMakeVisible (&lbRoll);
    lbRoll.setText ("Roll");

    addAndMakeVisible (&lbQW);
    lbQW.setText ("W");

    addAndMakeVisible (&lbQX);
    lbQX.setText ("X");

    addAndMakeVisible (&lbQY);
    lbQY.setText ("Y");

    addAndMakeVisible (&lbQZ);
    lbQZ.setText ("Z");

    // ====================== MIDI GROUP
    addAndMakeVisible (midiGroup);
    midiGroup.setText ("MIDI Connection");
    midiGroup.setTextLabelPosition (juce::Justification::centredLeft);

    addAndMakeVisible (cbMidiDevices);
    cbMidiDevices.setJustificationType (juce::Justification::centred);
    refreshMidiDeviceList();
    cbMidiDevices.addListener (this);

    addAndMakeVisible (cbMidiScheme);
    cbMidiScheme.setJustificationType (juce::Justification::centred);
    cbMidiScheme.addSectionHeading ("Select Device's MIDI Scheme");
    cbMidiScheme.addItemList (processor.getMidiSchemes(), 1);
    cbMidiScheme.setSelectedId (static_cast<int> (processor.getCurrentMidiScheme()) + 1);
    updateSelectedMidiScheme();
    cbMidiScheme.addListener (this);

    addAndMakeVisible (slMidiDevices);
    slMidiDevices.setText ("Device");

    addAndMakeVisible (slMidiScheme);
    slMidiScheme.setText ("Scheme");

    tooltipWin.setLookAndFeel (&globalLaF);
    tooltipWin.setMillisecondsBeforeTipAppears (500);
    tooltipWin.setOpaque (false);

    // start timer after everything is set up properly
    startTimer (20);
}

SceneRotatorAudioProcessorEditor::~SceneRotatorAudioProcessorEditor()
{
    setLookAndFeel (nullptr);
}

//==============================================================================
void SceneRotatorAudioProcessorEditor::paint (juce::Graphics& g)
{
    g.fillAll (globalLaF.ClBackground);
}

void SceneRotatorAudioProcessorEditor::resized()
{
    // ============ BEGIN: header and footer ============
    const int leftRightMargin = 30;
    const int headerHeight = 60;
    const int footerHeight = 25;
    juce::Rectangle<int> area (getLocalBounds());

    juce::Rectangle<int> footerArea (area.removeFromBottom (footerHeight));
    footer.setBounds (footerArea);

    area.removeFromLeft (leftRightMargin);
    area.removeFromRight (leftRightMargin);
    juce::Rectangle<int> headerArea = area.removeFromTop (headerHeight);
    title.setBounds (headerArea);
    area.removeFromTop (10);
    area.removeFromBottom (5);
    // =========== END: header and footer =================

    const int sliderHeight = 17;
    const int rotSliderHeight = 55;
    const int rotSliderSpacing = 10;
    const int sliderSpacing = 4;
    const int rotSliderWidth = 40;
    //const int labelHeight = 15;
    const int labelWidth = 20;

    auto topArea (area.removeFromTop (150));

    // -------------- Yaw Pitch Roll ------------------
    auto yprArea (topArea.removeFromLeft (160));
    yprGroup.setBounds (yprArea);
    yprArea.removeFromTop (25); //for box headline

    auto sliderRow (yprArea.removeFromTop (rotSliderHeight));
    slYaw.setBounds (sliderRow.removeFromLeft (rotSliderWidth + 5));
    sliderRow.removeFromLeft (rotSliderSpacing);
    slPitch.setBounds (sliderRow.removeFromLeft (rotSliderWidth + 5));
    sliderRow.removeFromLeft (rotSliderSpacing);
    slRoll.setBounds (sliderRow.removeFromLeft (rotSliderWidth + 5));

    sliderRow = yprArea.removeFromTop (20);
    lbYaw.setBounds (sliderRow.removeFromLeft (rotSliderWidth + 5));
    sliderRow.removeFromLeft (rotSliderSpacing);
    lbPitch.setBounds (sliderRow.removeFromLeft (rotSliderWidth + 5));
    sliderRow.removeFromLeft (rotSliderSpacing);
    lbRoll.setBounds (sliderRow.removeFromLeft (rotSliderWidth + 5));

    sliderRow = yprArea.removeFromTop (20);
    tbInvertYaw.setBounds (sliderRow.removeFromLeft (rotSliderWidth + 5));
    sliderRow.removeFromLeft (rotSliderSpacing);
    tbInvertPitch.setBounds (sliderRow.removeFromLeft (rotSliderWidth + 5));
    sliderRow.removeFromLeft (rotSliderSpacing);
    tbInvertRoll.setBounds (sliderRow.removeFromLeft (rotSliderWidth + 5));

    yprArea.removeFromTop (5);

    sliderRow = yprArea.removeFromTop (20);
    sliderRow.reduce (10, 0);
    cbRotationSequence.setBounds (sliderRow);

    // ------------- Quaternions ------------------------
    auto quatArea (topArea.removeFromRight (190));
    quatGroup.setBounds (quatArea);
    quatArea.removeFromTop (25); //for box headline

    quatArea.removeFromTop (5);

    sliderRow = quatArea.removeFromTop (sliderHeight);
    slQW.setBounds (sliderRow.removeFromRight (185 - labelWidth));
    lbQW.setBounds (sliderRow);
    quatArea.removeFromTop (sliderSpacing);

    sliderRow = quatArea.removeFromTop (sliderHeight);
    slQX.setBounds (sliderRow.removeFromRight (185 - labelWidth));
    lbQX.setBounds (sliderRow);
    quatArea.removeFromTop (sliderSpacing);

    sliderRow = quatArea.removeFromTop (sliderHeight);
    slQY.setBounds (sliderRow.removeFromRight (185 - labelWidth));
    lbQY.setBounds (sliderRow);
    quatArea.removeFromTop (sliderSpacing);

    sliderRow = quatArea.removeFromTop (sliderHeight);
    slQZ.setBounds (sliderRow.removeFromRight (185 - labelWidth));
    lbQZ.setBounds (sliderRow);
    quatArea.removeFromTop (sliderSpacing);

    sliderRow = quatArea.removeFromTop (20);
    sliderRow.removeFromLeft (20);
    tbInvertQuaternion.setBounds (sliderRow);

    // ------------- MIDI Connection ------------------------
    area.removeFromTop (10);
    midiGroup.setBounds (area);
    area.removeFromTop (25);
    auto row = area.removeFromTop (20);
    auto leftSide = row.removeFromLeft (180);
    slMidiDevices.setBounds (leftSide.removeFromLeft (40));
    cbMidiDevices.setBounds (leftSide);

    row.removeFromLeft (10);
    slMidiScheme.setBounds (row.removeFromLeft (48));
    cbMidiScheme.setBounds (row.removeFromLeft (140));
}

void SceneRotatorAudioProcessorEditor::timerCallback()
{
    // === update titleBar widgets according to available input/output channel counts
    title.setMaxSize (processor.getMaxSize());
    // ==========================================

    // insert stuff you want to do be done at every timer callback
    if (processor.deviceHasChanged.get())
    {
        processor.deviceHasChanged = false;
        refreshMidiDeviceList();
    }

    if (processor.schemeHasChanged.get())
    {
        processor.schemeHasChanged = false;
        updateSelectedMidiScheme();
    }

    if (processor.showMidiOpenError.get())
    {
        processor.showMidiOpenError = false;
        juce::AlertWindow alert (
            "Could no open device",
            "The MIDI device could not be opened, although it's listed in the available device list. This can happen if this process has already opened that device. Please visit https://plugins.iem.at/docs/scenerotator/ for troubleshooting.",
            juce::AlertWindow::NoIcon);
        alert.setLookAndFeel (&globalLaF);
        alert.addButton ("OK", 1, juce::KeyPress (juce::KeyPress::returnKey, 0, 0));
        alert.addButton ("Visit website", 2);
        if (alert.runModalLoop() == 2)
            juce::URL ("https://plugins.iem.at/docs/scenerotator/").launchInDefaultBrowser();
    }
}

void SceneRotatorAudioProcessorEditor::comboBoxChanged (juce::ComboBox* comboBoxThatHasChanged)
{
    if (comboBoxThatHasChanged == &cbMidiDevices && ! refreshingMidiDevices.get())
    {
        auto id = cbMidiDevices.getSelectedId();

        if (id == -3) // refresh
            refreshMidiDeviceList();
        else if (id == -2)
        {
            processor.closeMidiInput();
            refreshMidiDeviceList();
        }
        else if (id > 0) // an actual device is selected!
        {
            juce::String deviceName = cbMidiDevices.getText();
            processor.openMidiInput (deviceName);
        }
    }
    else if (comboBoxThatHasChanged == &cbMidiScheme && ! updatingMidiScheme.get())
    {
        processor.setMidiScheme (
            SceneRotatorAudioProcessor::MidiScheme (cbMidiScheme.getSelectedId() - 1));
    }
}

void SceneRotatorAudioProcessorEditor::refreshMidiDeviceList()
{
    cbMidiDevices.clear();
    cbMidiDevices.addItem ("(refresh list...)", -3);
    cbMidiDevices.addItem ("none / use DAW input", -2);

    juce::MidiDeviceInfo currentDevice = processor.getCurrentMidiDeviceInfo();

    int select = -2;

    juce::Array<juce::MidiDeviceInfo> devices = juce::MidiInput::getAvailableDevices();
    if (! currentDevice.identifier.isEmpty())
    {
        if (devices.contains (currentDevice))
            select = devices.indexOf (currentDevice) + 1;
        else
        {
            cbMidiDevices.addItem (currentDevice.name + " (not available)", -1);
            select = -1;
        }
    }

    cbMidiDevices.addSeparator();
    cbMidiDevices.addSectionHeading ("Available Devices");
    for (int i = 0; i < devices.size(); ++i)
    {
        cbMidiDevices.addItem (devices[i].name, i + 1);
    }

    juce::ScopedValueSetter<juce::Atomic<bool>> refreshing (refreshingMidiDevices, true, false);
    cbMidiDevices.setSelectedId (select, juce::sendNotificationSync);
}

void SceneRotatorAudioProcessorEditor::updateSelectedMidiScheme()
{
    juce::ScopedValueSetter<juce::Atomic<bool>> refreshing (updatingMidiScheme, true, false);
    //cbMidiScheme.setSelectedId (select, juce::sendNotificationSync);
}