Skip to content

Commit 7869106

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

File tree

5 files changed

+282
-7
lines changed

5 files changed

+282
-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: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,20 @@ 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));
110124
}
111125

112126
void CCetoneUI::parameterChanged(uint32_t index, float value)
@@ -349,14 +363,46 @@ void CCetoneUI::parameterChanged(uint32_t index, float value)
349363

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

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

src/CetoneUI.hpp

Lines changed: 17 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,14 @@ 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+
96112
// -------------------------------------------------------------------
97113
// Helpers
98114

@@ -127,5 +143,6 @@ class CCetoneUI : public DISTRHO::UI,
127143
// Button IDs
128144

129145
constexpr uint BTN_PANIC = d_cconst('p', 'n', 'i', 'c');
146+
constexpr uint BTN_ABOUT = d_cconst('a', 'b', 't', '.');
130147

131148
// -----------------------------------------------------------------------

src/Widgets/ImGui_UI.cpp

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
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+
77+
default:
78+
requestMenuId = 0;
79+
}
80+
81+
//
82+
// Create popup menus
83+
// [NOTICE] ImGui::BeginPopup() MUST be put after ImGui::OpenPopup(), otherwise popup won't show!
84+
//
85+
86+
ImGui::SetNextWindowPos(menuPos); // Specify menu position
87+
88+
if (ImGui::BeginPopup("menu_osc1_wave"))
89+
{
90+
ImGui::SeparatorText("Waveform");
91+
if (ImGui::MenuItem("Saw")) { _triggerParamUpdate(pOsc1Wave, ui->_pi2f(OWAVE_SAW, OWAVE_MAX)); }
92+
if (ImGui::MenuItem("Pulse")) { _triggerParamUpdate(pOsc1Wave, ui->_pi2f(OWAVE_PULSE, OWAVE_MAX)); }
93+
if (ImGui::MenuItem("Triangle")) { _triggerParamUpdate(pOsc1Wave, ui->_pi2f(OWAVE_TRI, OWAVE_MAX)); }
94+
if (ImGui::MenuItem("Sine")) { _triggerParamUpdate(pOsc1Wave, ui->_pi2f(OWAVE_SINE, OWAVE_MAX)); }
95+
if (ImGui::MenuItem("C64 Noise")) { _triggerParamUpdate(pOsc1Wave, ui->_pi2f(OWAVE_C64NOISE, OWAVE_MAX)); }
96+
ImGui::EndPopup();
97+
}
98+
99+
ImGui::SetNextWindowPos(menuPos); // Specify menu position
100+
101+
if (ImGui::BeginPopup("menu_osc2_wave"))
102+
{
103+
ImGui::SeparatorText("Waveform");
104+
if (ImGui::MenuItem("Saw")) { _triggerParamUpdate(pOsc2Wave, ui->_pi2f(OWAVE_SAW, OWAVE_MAX)); }
105+
if (ImGui::MenuItem("Pulse")) { _triggerParamUpdate(pOsc2Wave, ui->_pi2f(OWAVE_PULSE, OWAVE_MAX)); }
106+
if (ImGui::MenuItem("Triangle")) { _triggerParamUpdate(pOsc2Wave, ui->_pi2f(OWAVE_TRI, OWAVE_MAX)); }
107+
if (ImGui::MenuItem("Sine")) { _triggerParamUpdate(pOsc2Wave, ui->_pi2f(OWAVE_SINE, OWAVE_MAX)); }
108+
if (ImGui::MenuItem("C64 Noise")) { _triggerParamUpdate(pOsc2Wave, ui->_pi2f(OWAVE_C64NOISE, OWAVE_MAX)); }
109+
ImGui::EndPopup();
110+
}
111+
112+
ImGui::SetNextWindowPos(menuPos); // Specify menu position
113+
114+
if (ImGui::BeginPopup("menu_osc3_wave"))
115+
{
116+
ImGui::SeparatorText("Waveform");
117+
if (ImGui::MenuItem("Saw")) { _triggerParamUpdate(pOsc3Wave, ui->_pi2f(OWAVE_SAW, OWAVE_MAX)); }
118+
if (ImGui::MenuItem("Pulse")) { _triggerParamUpdate(pOsc3Wave, ui->_pi2f(OWAVE_PULSE, OWAVE_MAX)); }
119+
if (ImGui::MenuItem("Triangle")) { _triggerParamUpdate(pOsc3Wave, ui->_pi2f(OWAVE_TRI, OWAVE_MAX)); }
120+
if (ImGui::MenuItem("Sine")) { _triggerParamUpdate(pOsc3Wave, ui->_pi2f(OWAVE_SINE, OWAVE_MAX)); }
121+
if (ImGui::MenuItem("C64 Noise")) { _triggerParamUpdate(pOsc3Wave, ui->_pi2f(OWAVE_C64NOISE, OWAVE_MAX)); }
122+
ImGui::EndPopup();
123+
}
124+
125+
ImGui::SetNextWindowPos(menuPos); // Specify menu position
126+
127+
if (ImGui::BeginPopup("menu_filter_type"))
128+
{
129+
ImGui::SeparatorText("Filter Type");
130+
if (ImGui::MenuItem("None")) { _triggerParamUpdate(pFilterType, ui->_pi2f(FTYPE_NONE, FTYPE_MAX)); }
131+
if (ImGui::MenuItem("Dirty")) { _triggerParamUpdate(pFilterType, ui->_pi2f(FTYPE_DIRTY, FTYPE_MAX)); }
132+
if (ImGui::MenuItem("Moog")) { _triggerParamUpdate(pFilterType, ui->_pi2f(FTYPE_MOOG, FTYPE_MAX)); }
133+
if (ImGui::MenuItem("Moog 2")) { _triggerParamUpdate(pFilterType, ui->_pi2f(FTYPE_MOOG2, FTYPE_MAX)); }
134+
if (ImGui::MenuItem("Ch12db")) { _triggerParamUpdate(pFilterType, ui->_pi2f(FTYPE_CH12DB, FTYPE_MAX)); }
135+
if (ImGui::MenuItem("x0x (303)")) { _triggerParamUpdate(pFilterType, ui->_pi2f(FTYPE_303, FTYPE_MAX)); }
136+
if (ImGui::MenuItem("8580")) { _triggerParamUpdate(pFilterType, ui->_pi2f(FTYPE_8580, FTYPE_MAX)); }
137+
if (ImGui::MenuItem("Bi12db (Budda)")) { _triggerParamUpdate(pFilterType, ui->_pi2f(FTYPE_BUDDA, FTYPE_MAX)); }
138+
ImGui::EndPopup();
139+
}
140+
141+
ImGui::SetNextWindowPos(menuPos);
142+
143+
if (ImGui::BeginPopup("menu_filter_mode"))
144+
{
145+
ImGui::SeparatorText("Filter Mode");
146+
if (ImGui::MenuItem("Low pass")) { _triggerParamUpdate(pFilterMode, ui->_pi2f(FMODE_LOW, FMODE_MAX)); }
147+
if (ImGui::MenuItem("Band pass")) { _triggerParamUpdate(pFilterMode, ui->_pi2f(FMODE_BAND, FMODE_MAX)); }
148+
if (ImGui::MenuItem("High pass")) { _triggerParamUpdate(pFilterMode, ui->_pi2f(FMODE_HIGH, FMODE_MAX)); }
149+
if (ImGui::MenuItem("Notch")) { _triggerParamUpdate(pFilterMode, ui->_pi2f(FMODE_NOTCH, FMODE_MAX)); }
150+
ImGui::EndPopup();
151+
}
152+
}
153+
154+
void ImGuiUI::_triggerParamUpdate(uint32_t paramId, float newValue)
155+
{
156+
ui->setParameterValue(paramId, newValue); // Tell the DSP to update parameter value
157+
ui->parameterChanged(paramId, newValue); // Request UI refresh
158+
}

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)