File: DistrhoUIPingPongPan.cpp

package info (click to toggle)
dpf-plugins 1.6%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 145,284 kB
  • sloc: cpp: 299,382; ansic: 61,509; objc: 2,715; makefile: 2,076; xml: 618; sh: 462; java: 211; python: 184
file content (135 lines) | stat: -rw-r--r-- 4,084 bytes parent folder | download | duplicates (2)
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
/*
 * DISTRHO PingPongPan Plugin, based on PingPongPan by Michael Gruhn
 * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation.
 *
 * 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 Lesser General Public License for more details.
 *
 * For a full copy of the license see the LICENSE file.
 */

#include "DistrhoPluginPingPongPan.hpp"
#include "DistrhoUIPingPongPan.hpp"

START_NAMESPACE_DISTRHO

namespace Art = DistrhoArtworkPingPongPan;

// -----------------------------------------------------------------------

DistrhoUIPingPongPan::DistrhoUIPingPongPan()
    : UI(Art::backgroundWidth, Art::backgroundHeight, true),
      fImgBackground(Art::backgroundData, Art::backgroundWidth, Art::backgroundHeight, kImageFormatBGR),
      fAboutWindow(this)
{
    // about
    Image imageAbout(Art::aboutData, Art::aboutWidth, Art::aboutHeight, kImageFormatBGR);
    fAboutWindow.setImage(imageAbout);

    // knobs
    Image knobImage(Art::knobData, Art::knobWidth, Art::knobHeight, kImageFormatBGRA);

    // knob Low-Mid
    fKnobFreq = new ImageKnob(this, knobImage, ImageKnob::Vertical);
    fKnobFreq->setId(DistrhoPluginPingPongPan::paramFreq);
    fKnobFreq->setAbsolutePos(60, 58);
    fKnobFreq->setRange(0.0f, 100.0f);
    fKnobFreq->setDefault(50.0f);
    fKnobFreq->setRotationAngle(270);
    fKnobFreq->setCallback(this);

    // knob Mid-High
    fKnobWidth = new ImageKnob(this, knobImage, ImageKnob::Vertical);
    fKnobWidth->setId(DistrhoPluginPingPongPan::paramWidth);
    fKnobWidth->setAbsolutePos(182, 58);
    fKnobWidth->setRange(0.0f, 100.0f);
    fKnobWidth->setDefault(75.0f);
    fKnobWidth->setRotationAngle(270);
    fKnobWidth->setCallback(this);

    // about button
    Image aboutImageNormal(Art::aboutButtonNormalData, Art::aboutButtonNormalWidth, Art::aboutButtonNormalHeight, kImageFormatBGRA);
    Image aboutImageHover(Art::aboutButtonHoverData, Art::aboutButtonHoverWidth, Art::aboutButtonHoverHeight, kImageFormatBGRA);
    fButtonAbout = new ImageButton(this, aboutImageNormal, aboutImageHover, aboutImageHover);
    fButtonAbout->setAbsolutePos(183, 8);
    fButtonAbout->setCallback(this);

    // set default values
    programLoaded(0);
}

// -----------------------------------------------------------------------
// DSP Callbacks

void DistrhoUIPingPongPan::parameterChanged(uint32_t index, float value)
{
    switch (index)
    {
    case DistrhoPluginPingPongPan::paramFreq:
        fKnobFreq->setValue(value);
        break;
    case DistrhoPluginPingPongPan::paramWidth:
        fKnobWidth->setValue(value);
        break;
    }
}

void DistrhoUIPingPongPan::programLoaded(uint32_t index)
{
    if (index != 0)
        return;

    // Default values
    fKnobFreq->setValue(50.0f);
    fKnobWidth->setValue(75.0f);
}

// -----------------------------------------------------------------------
// Widget Callbacks

void DistrhoUIPingPongPan::imageButtonClicked(ImageButton* button, int)
{
    if (button != fButtonAbout)
        return;

    fAboutWindow.runAsModal();
}

void DistrhoUIPingPongPan::imageKnobDragStarted(ImageKnob* knob)
{
    editParameter(knob->getId(), true);
}

void DistrhoUIPingPongPan::imageKnobDragFinished(ImageKnob* knob)
{
    editParameter(knob->getId(), false);
}

void DistrhoUIPingPongPan::imageKnobValueChanged(ImageKnob* knob, float value)
{
    setParameterValue(knob->getId(), value);
}

void DistrhoUIPingPongPan::onDisplay()
{
    const GraphicsContext& context(getGraphicsContext());

    fImgBackground.draw(context);
}

// -----------------------------------------------------------------------

UI* createUI()
{
    return new DistrhoUIPingPongPan();
}

// -----------------------------------------------------------------------

END_NAMESPACE_DISTRHO