Skip to content

Commit 9bdaab7

Browse files
committed
(WIP) UI: Implement Dear ImGui UI part
1 parent 344d84f commit 9bdaab7

File tree

5 files changed

+308
-7
lines changed

5 files changed

+308
-7
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ add_subdirectory (dpf)
1212

1313
include_directories (
1414
src/
15+
dpf-widgets/opengl/
1516
)
1617

1718
set (SRC_BACKEND
@@ -42,5 +43,7 @@ dpf_add_plugin (${PROJECT_NAME}
4243
src/CetoneUIHelper.cpp
4344
src/Images/CetoneArtwork.cpp
4445
src/Fonts/CetoneFonts.cpp
46+
dpf-widgets/opengl/DearImGui.cpp
47+
src/Widgets/ImGui_UI.cpp
4548
)
4649

src/CetoneUI.cpp

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,22 @@ CCetoneUI::CCetoneUI()
107107
_createSwitchButton(fBtnGlideState, pPortaMode, 764, 150);
108108

109109
_createSwitchButton(fBtnLFOTrigger, pLfo1Trig, 677, 260);
110+
111+
/* ImGui instance (popup menus, subwindows, etc.) */
112+
fImGuiInstance = new ImGuiUI(getTopLevelWidget(), this);
113+
114+
/* "About" button (by clicking the plugin logo) */
115+
_createHiddenButton(fBtnAbout, BTN_ABOUT, Size<uint>(118, 25), Point<int>(0, 0));
116+
117+
/* Popup menu button on params which has constant value sets */
118+
_createHiddenButton(fBtnOsc1Waveform, pOsc1Wave, Size<uint>(45, 10 + 2), Point<int>(10 + 48 * 2, 200 + 2));
119+
_createHiddenButton(fBtnOsc2Waveform, pOsc2Wave, Size<uint>(45, 10 + 2), Point<int>(262 + 48 * 2, 200 + 2));
120+
_createHiddenButton(fBtnOsc3Waveform, pOsc3Wave, Size<uint>(45, 10 + 2), Point<int>(514 + 48 * 2, 200 + 2));
121+
122+
_createHiddenButton(fBtnFilterType, pFilterType, Size<uint>(45, 10 + 2), Point<int>(514, 96 - 4));
123+
_createHiddenButton(fBtnFilterMode, pFilterMode, Size<uint>(45, 10 + 2), Point<int>(514 + 48, 96 - 4));
124+
125+
_createHiddenButton(fBtnLfo1Waveform, pLfo1Wave, Size<uint>(45, 10 + 2), Point<int>(534 + 48, 316 - 4));
110126
}
111127

112128
void CCetoneUI::parameterChanged(uint32_t index, float value)
@@ -349,14 +365,52 @@ void CCetoneUI::parameterChanged(uint32_t index, float value)
349365

350366
void CCetoneUI::imageButtonClicked(ImageButton* button, int)
351367
{
352-
#if 0
353-
switch (button->getId()) {
354-
case BTN_PANIC: {
355-
panic();
356-
break;
357-
}
368+
DISTRHO_SAFE_ASSERT_RETURN(fImGuiInstance, )
369+
370+
switch (button->getId())
371+
{
372+
case BTN_ABOUT:
373+
{
374+
fImGuiInstance->isAboutWindowOpen = !fImGuiInstance->isAboutWindowOpen;
375+
break;
376+
}
377+
case pOsc1Wave:
378+
{
379+
fImGuiInstance->menuPos = ImVec2(fBtnOsc1Waveform->getAbsolutePos().getX(), fBtnOsc1Waveform->getAbsolutePos().getY() + fBtnOsc1Waveform->getHeight());
380+
fImGuiInstance->requestMenuId = pOsc1Wave;
381+
break;
382+
}
383+
case pOsc2Wave:
384+
{
385+
fImGuiInstance->menuPos = ImVec2(fBtnOsc2Waveform->getAbsolutePos().getX(), fBtnOsc2Waveform->getAbsolutePos().getY() + fBtnOsc2Waveform->getHeight());
386+
fImGuiInstance->requestMenuId = pOsc2Wave;
387+
break;
388+
}
389+
case pOsc3Wave:
390+
{
391+
fImGuiInstance->menuPos = ImVec2(fBtnOsc3Waveform->getAbsolutePos().getX(), fBtnOsc3Waveform->getAbsolutePos().getY() + fBtnOsc3Waveform->getHeight());
392+
fImGuiInstance->requestMenuId = pOsc3Wave;
393+
break;
394+
}
395+
case pFilterType:
396+
{
397+
fImGuiInstance->menuPos = ImVec2(fBtnFilterType->getAbsolutePos().getX(), fBtnFilterType->getAbsolutePos().getY() + fBtnFilterType->getHeight());
398+
fImGuiInstance->requestMenuId = pFilterType;
399+
break;
400+
}
401+
case pFilterMode:
402+
{
403+
fImGuiInstance->menuPos = ImVec2(fBtnFilterMode->getAbsolutePos().getX(), fBtnFilterMode->getAbsolutePos().getY() + fBtnFilterMode->getHeight());
404+
fImGuiInstance->requestMenuId = pFilterMode;
405+
break;
406+
}
407+
case pLfo1Wave:
408+
{
409+
fImGuiInstance->menuPos = ImVec2(fBtnLfo1Waveform->getAbsolutePos().getX(), fBtnLfo1Waveform->getAbsolutePos().getY() + fBtnLfo1Waveform->getHeight());
410+
fImGuiInstance->requestMenuId = pLfo1Wave;
411+
break;
412+
}
358413
}
359-
#endif
360414
}
361415

362416
void CCetoneUI::imageSwitchClicked(ImageSwitch* button, bool down)

src/CetoneUI.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "ImageWidgets.hpp"
55
#include "NanoVG.hpp"
66

7+
#include "Widgets/ImGui_UI.hpp"
8+
79
using DGL_NAMESPACE::ImageAboutWindow;
810
using DGL_NAMESPACE::ImageButton;
911
using DGL_NAMESPACE::ImageKnob;
@@ -55,6 +57,12 @@ class CCetoneUI : public DISTRHO::UI,
5557
NanoVG fNanoText;
5658
char fLabelBuffer[32 + 1];
5759

60+
// -------------------------------------------------------------------
61+
// Dear ImGui Instance
62+
63+
ScopedPointer<ImGuiUI> fImGuiInstance;
64+
friend class ImGuiUI;
65+
5866
// -------------------------------------------------------------------
5967
// Image resources
6068

@@ -93,6 +101,15 @@ class CCetoneUI : public DISTRHO::UI,
93101
ScopedPointer<ImageSwitch> fBtnGlideState;
94102
ScopedPointer<ImageSwitch> fBtnLFOTrigger;
95103

104+
// -------------------------------------------------------------------
105+
// Buttons
106+
107+
ScopedPointer<ImageButton> fBtnAbout;
108+
109+
ScopedPointer<ImageButton> fBtnOsc1Waveform, fBtnOsc2Waveform, fBtnOsc3Waveform;
110+
ScopedPointer<ImageButton> fBtnFilterType, fBtnFilterMode;
111+
ScopedPointer<ImageButton> fBtnLfo1Waveform;
112+
96113
// -------------------------------------------------------------------
97114
// Helpers
98115

@@ -127,5 +144,6 @@ class CCetoneUI : public DISTRHO::UI,
127144
// Button IDs
128145

129146
constexpr uint BTN_PANIC = d_cconst('p', 'n', 'i', 'c');
147+
constexpr uint BTN_ABOUT = d_cconst('a', 'b', 't', '.');
130148

131149
// -----------------------------------------------------------------------

src/Widgets/ImGui_UI.cpp

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
#include "ImGui_UI.hpp"
2+
#include "DistrhoPluginInfo.h"
3+
4+
#include "Structures.h"
5+
#include "Defines.h"
6+
7+
#include "CetoneUI.hpp" // For class CCetoneUI
8+
9+
void ImGuiUI::onImGuiDisplay()
10+
{
11+
double scaleFactor = getScaleFactor() * userScaling;
12+
const double initialSize = 800 * scaleFactor;
13+
14+
//
15+
// "About" Window
16+
//
17+
{
18+
ImGui::SetNextWindowPos(ImVec2(initialSize / 4, initialSize / 16), ImGuiCond_Once);
19+
ImGui::SetNextWindowSize(ImVec2(600, 230), ImGuiCond_Once);
20+
21+
if (isAboutWindowOpen)
22+
{
23+
ImGui::Begin("About " DISTRHO_PLUGIN_NAME, &isAboutWindowOpen, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize);
24+
{
25+
ImGui::SeparatorText("Cetone Synth Light");
26+
ImGui::Text("Light-weight monophonic analogue-style synthesizer, by Neotec Software.\n");
27+
28+
ImGui::SeparatorText("Authors");
29+
ImGui::BulletText("René 'Neotec' Jeschke - Original developer");
30+
ImGui::BulletText("AnClark Liu <[email protected]> - Ported to DPF, Further developments");
31+
32+
ImGui::SeparatorText("License");
33+
ImGui::BulletText("This project is licensed under GNU General Public License, version 3.");
34+
35+
ImGui::Text("\n\n");
36+
ImGui::Dummy(ImVec2(490, 0));
37+
ImGui::SameLine();
38+
if (ImGui::Button("OK", ImVec2(80, 0)))
39+
isAboutWindowOpen = false;
40+
}
41+
ImGui::End();
42+
}
43+
}
44+
45+
//
46+
// Handle menu opening requests
47+
//
48+
// Here, variable `requestTestMenuOpen` acts as an "event flag" to request ImGui to show the menu.
49+
//
50+
// Dear ImGui has its own mechanism to show popup menus, which does not require a flag to control its exisitance.
51+
// This is quite different from window (ImGui::Begin()).
52+
// So just call this function once, your popup will stick on the screen unless you do some operations.
53+
//
54+
switch (requestMenuId)
55+
{
56+
case pOsc1Wave:
57+
ImGui::OpenPopup("menu_osc1_wave");
58+
requestMenuId = 0;
59+
break;
60+
case pOsc2Wave:
61+
ImGui::OpenPopup("menu_osc2_wave");
62+
requestMenuId = 0;
63+
break;
64+
case pOsc3Wave:
65+
ImGui::OpenPopup("menu_osc3_wave");
66+
requestMenuId = 0;
67+
break;
68+
case pFilterType:
69+
ImGui::OpenPopup("menu_filter_type");
70+
requestMenuId = 0;
71+
break;
72+
case pFilterMode:
73+
ImGui::OpenPopup("menu_filter_mode");
74+
requestMenuId = 0;
75+
break;
76+
case pLfo1Wave:
77+
ImGui::OpenPopup("menu_lfo1_wave");
78+
requestMenuId = 0;
79+
break;
80+
81+
default:
82+
requestMenuId = 0;
83+
}
84+
85+
//
86+
// Create popup menus
87+
// [NOTICE] ImGui::BeginPopup() MUST be put after ImGui::OpenPopup(), otherwise popup won't show!
88+
//
89+
90+
ImGui::SetNextWindowPos(menuPos); // Specify menu position
91+
92+
if (ImGui::BeginPopup("menu_osc1_wave"))
93+
{
94+
ImGui::SeparatorText("Waveform");
95+
if (ImGui::MenuItem("Saw")) { _triggerParamUpdate(pOsc1Wave, ui->_pi2f(OWAVE_SAW, OWAVE_MAX)); }
96+
if (ImGui::MenuItem("Pulse")) { _triggerParamUpdate(pOsc1Wave, ui->_pi2f(OWAVE_PULSE, OWAVE_MAX)); }
97+
if (ImGui::MenuItem("Triangle")) { _triggerParamUpdate(pOsc1Wave, ui->_pi2f(OWAVE_TRI, OWAVE_MAX)); }
98+
if (ImGui::MenuItem("Sine")) { _triggerParamUpdate(pOsc1Wave, ui->_pi2f(OWAVE_SINE, OWAVE_MAX)); }
99+
if (ImGui::MenuItem("C64 Noise")) { _triggerParamUpdate(pOsc1Wave, ui->_pi2f(OWAVE_C64NOISE, OWAVE_MAX)); }
100+
ImGui::EndPopup();
101+
}
102+
103+
ImGui::SetNextWindowPos(menuPos); // Specify menu position
104+
105+
if (ImGui::BeginPopup("menu_osc2_wave"))
106+
{
107+
ImGui::SeparatorText("Waveform");
108+
if (ImGui::MenuItem("Saw")) { _triggerParamUpdate(pOsc2Wave, ui->_pi2f(OWAVE_SAW, OWAVE_MAX)); }
109+
if (ImGui::MenuItem("Pulse")) { _triggerParamUpdate(pOsc2Wave, ui->_pi2f(OWAVE_PULSE, OWAVE_MAX)); }
110+
if (ImGui::MenuItem("Triangle")) { _triggerParamUpdate(pOsc2Wave, ui->_pi2f(OWAVE_TRI, OWAVE_MAX)); }
111+
if (ImGui::MenuItem("Sine")) { _triggerParamUpdate(pOsc2Wave, ui->_pi2f(OWAVE_SINE, OWAVE_MAX)); }
112+
if (ImGui::MenuItem("C64 Noise")) { _triggerParamUpdate(pOsc2Wave, ui->_pi2f(OWAVE_C64NOISE, OWAVE_MAX)); }
113+
ImGui::EndPopup();
114+
}
115+
116+
ImGui::SetNextWindowPos(menuPos); // Specify menu position
117+
118+
if (ImGui::BeginPopup("menu_osc3_wave"))
119+
{
120+
ImGui::SeparatorText("Waveform");
121+
if (ImGui::MenuItem("Saw")) { _triggerParamUpdate(pOsc3Wave, ui->_pi2f(OWAVE_SAW, OWAVE_MAX)); }
122+
if (ImGui::MenuItem("Pulse")) { _triggerParamUpdate(pOsc3Wave, ui->_pi2f(OWAVE_PULSE, OWAVE_MAX)); }
123+
if (ImGui::MenuItem("Triangle")) { _triggerParamUpdate(pOsc3Wave, ui->_pi2f(OWAVE_TRI, OWAVE_MAX)); }
124+
if (ImGui::MenuItem("Sine")) { _triggerParamUpdate(pOsc3Wave, ui->_pi2f(OWAVE_SINE, OWAVE_MAX)); }
125+
if (ImGui::MenuItem("C64 Noise")) { _triggerParamUpdate(pOsc3Wave, ui->_pi2f(OWAVE_C64NOISE, OWAVE_MAX)); }
126+
ImGui::EndPopup();
127+
}
128+
129+
ImGui::SetNextWindowPos(menuPos); // Specify menu position
130+
131+
if (ImGui::BeginPopup("menu_filter_type"))
132+
{
133+
ImGui::SeparatorText("Filter Type");
134+
if (ImGui::MenuItem("None")) { _triggerParamUpdate(pFilterType, ui->_pi2f(FTYPE_NONE, FTYPE_MAX)); }
135+
if (ImGui::MenuItem("Dirty")) { _triggerParamUpdate(pFilterType, ui->_pi2f(FTYPE_DIRTY, FTYPE_MAX)); }
136+
if (ImGui::MenuItem("Moog")) { _triggerParamUpdate(pFilterType, ui->_pi2f(FTYPE_MOOG, FTYPE_MAX)); }
137+
if (ImGui::MenuItem("Moog 2")) { _triggerParamUpdate(pFilterType, ui->_pi2f(FTYPE_MOOG2, FTYPE_MAX)); }
138+
if (ImGui::MenuItem("Ch12db")) { _triggerParamUpdate(pFilterType, ui->_pi2f(FTYPE_CH12DB, FTYPE_MAX)); }
139+
if (ImGui::MenuItem("x0x (303)")) { _triggerParamUpdate(pFilterType, ui->_pi2f(FTYPE_303, FTYPE_MAX)); }
140+
if (ImGui::MenuItem("8580")) { _triggerParamUpdate(pFilterType, ui->_pi2f(FTYPE_8580, FTYPE_MAX)); }
141+
if (ImGui::MenuItem("Bi12db (Budda)")) { _triggerParamUpdate(pFilterType, ui->_pi2f(FTYPE_BUDDA, FTYPE_MAX)); }
142+
ImGui::EndPopup();
143+
}
144+
145+
ImGui::SetNextWindowPos(menuPos);
146+
147+
if (ImGui::BeginPopup("menu_filter_mode"))
148+
{
149+
ImGui::SeparatorText("Filter Mode");
150+
if (ImGui::MenuItem("Low pass")) { _triggerParamUpdate(pFilterMode, ui->_pi2f(FMODE_LOW, FMODE_MAX)); }
151+
if (ImGui::MenuItem("Band pass")) { _triggerParamUpdate(pFilterMode, ui->_pi2f(FMODE_BAND, FMODE_MAX)); }
152+
if (ImGui::MenuItem("High pass")) { _triggerParamUpdate(pFilterMode, ui->_pi2f(FMODE_HIGH, FMODE_MAX)); }
153+
if (ImGui::MenuItem("Notch")) { _triggerParamUpdate(pFilterMode, ui->_pi2f(FMODE_NOTCH, FMODE_MAX)); }
154+
ImGui::EndPopup();
155+
}
156+
157+
ImGui::SetNextWindowPos(menuPos); // Specify menu position
158+
159+
if (ImGui::BeginPopup("menu_lfo1_wave"))
160+
{
161+
ImGui::SeparatorText("Waveform");
162+
if (ImGui::MenuItem("Saw")) { _triggerParamUpdate(pLfo1Wave, ui->_pi2f(OWAVE_SAW, OWAVE_MAX)); }
163+
if (ImGui::MenuItem("Pulse")) { _triggerParamUpdate(pLfo1Wave, ui->_pi2f(OWAVE_PULSE, OWAVE_MAX)); }
164+
if (ImGui::MenuItem("Triangle")) { _triggerParamUpdate(pLfo1Wave, ui->_pi2f(OWAVE_TRI, OWAVE_MAX)); }
165+
if (ImGui::MenuItem("Sine")) { _triggerParamUpdate(pLfo1Wave, ui->_pi2f(OWAVE_SINE, OWAVE_MAX)); }
166+
if (ImGui::MenuItem("C64 Noise")) { _triggerParamUpdate(pLfo1Wave, ui->_pi2f(OWAVE_C64NOISE, OWAVE_MAX)); }
167+
ImGui::EndPopup();
168+
}
169+
}
170+
171+
void ImGuiUI::_triggerParamUpdate(uint32_t paramId, float newValue)
172+
{
173+
ui->setParameterValue(paramId, newValue); // Tell the DSP to update parameter value
174+
ui->parameterChanged(paramId, newValue); // Request UI refresh
175+
}

src/Widgets/ImGui_UI.hpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Inspector Window for DPF
3+
* Copyright (C) 2022-2025 Filipe Coelho <[email protected]>
4+
*
5+
* Permission to use, copy, modify, and/or distribute this software for any purpose with
6+
* or without fee is hereby granted, provided that the above copyright notice and this
7+
* permission notice appear in all copies.
8+
*
9+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
10+
* TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
11+
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
12+
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
13+
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14+
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15+
*/
16+
17+
#pragma once
18+
19+
#include "DearImGui.hpp"
20+
21+
// Forward decls.
22+
class CCetoneUI;
23+
24+
25+
// --------------------------------------------------------------------------------------------------------------------
26+
27+
class ImGuiUI : public ImGuiTopLevelWidget
28+
{
29+
30+
public:
31+
CCetoneUI *ui;
32+
33+
bool isAboutWindowOpen = false;
34+
uint16_t requestMenuId = 0;
35+
36+
ImVec2 menuPos{0, 0};
37+
38+
double userScaling = 1.0f;
39+
40+
ImGuiUI(TopLevelWidget* const tlw, CCetoneUI* const ui) :
41+
ImGuiTopLevelWidget(tlw->getWindow()),
42+
ui(ui)
43+
{
44+
}
45+
46+
protected:
47+
void onImGuiDisplay() override;
48+
49+
private:
50+
void _triggerParamUpdate(uint32_t paramId, float newValue);
51+
};

0 commit comments

Comments
 (0)