Skip to content

Commit ad2de42

Browse files
committed
Start to make text editor plugin usable
Signed-off-by: falkTX <[email protected]>
1 parent 88d9564 commit ad2de42

File tree

7 files changed

+109
-18
lines changed

7 files changed

+109
-18
lines changed

dpf

plugins/ImGuiDemo/PluginDSP.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class ImGuiDemoPlugin : public Plugin
4040
*/
4141
const char* getMaker() const noexcept override
4242
{
43-
return "falkTX";
43+
return "DISTRHO";
4444
}
4545

4646
/**

plugins/TextEditor/DistrhoPluginInfo.h

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Text Editor example
3-
* Copyright (C) 2023 Filipe Coelho <[email protected]>
3+
* Copyright (C) 2023-2025 Filipe Coelho <[email protected]>
44
* SPDX-License-Identifier: ISC
55
*/
66

@@ -95,7 +95,7 @@
9595
@see Plugin::initState(uint32_t, String&, String&)
9696
@see Plugin::setState(const char*, const char*)
9797
*/
98-
#define DISTRHO_PLUGIN_WANT_STATE 0
98+
#define DISTRHO_PLUGIN_WANT_STATE 1
9999

100100
/**
101101
Whether the plugin implements the full state API.
@@ -172,10 +172,26 @@
172172
#define DISTRHO_UI_USER_RESIZABLE 1
173173

174174
/**
175-
The %UI URI when exporting in LV2 format.@n
176-
By default this is set to @ref DISTRHO_PLUGIN_URI with "#UI" as suffix.
175+
Whether to %UI is going to use file browser dialogs.@n
176+
By default this is false, with the file browser APIs not available for use.
177177
*/
178-
#define DISTRHO_UI_URI DISTRHO_PLUGIN_URI "#UI"
178+
#define DISTRHO_UI_FILE_BROWSER 1
179+
180+
/**
181+
A 4-character symbol that identifies a brand or manufacturer, with at least one non-lower case character.@n
182+
Plugins from the same brand should use the same symbol.
183+
@note This macro is required when building AU plugins, and used for VST3 if present
184+
@note Setting this macro will change the uid of a VST3 plugin.
185+
If you already released a DPF-based VST3 plugin make sure to also enable DPF_VST3_DONT_USE_BRAND_ID
186+
*/
187+
#define DISTRHO_PLUGIN_BRAND_ID Dstr
188+
189+
/**
190+
A 4-character symbol which identifies a plugin.@n
191+
It must be unique within at least a set of plugins from the brand.
192+
@note This macro is required when building AU plugins
193+
*/
194+
#define DISTRHO_PLUGIN_UNIQUE_ID dTxt
179195

180196
/**
181197
Custom LV2 category for the plugin.@n

plugins/TextEditor/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ BUILD_CXX_FLAGS += -I../../dpf-widgets/opengl
2828
# --------------------------------------------------------------
2929
# Enable all possible plugin types
3030

31-
all: clap dssi jack lv2_sep vst2 vst3
31+
all: au clap dssi jack lv2_sep vst2 vst3
3232

3333
# --------------------------------------------------------------

plugins/TextEditor/PluginDSP.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Text Editor example
3-
* Copyright (C) 2023 Filipe Coelho <[email protected]>
3+
* Copyright (C) 2023-2025 Filipe Coelho <[email protected]>
44
* SPDX-License-Identifier: ISC
55
*/
66

@@ -18,7 +18,7 @@ class TextEditorPlugin : public Plugin
1818
You must set all parameter values to their defaults, matching ParameterRanges::def.
1919
*/
2020
TextEditorPlugin()
21-
: Plugin(0, 0, 0) // parameters, programs, states
21+
: Plugin(0, 0, 1) // parameters, programs, states
2222
{
2323
}
2424

@@ -40,7 +40,7 @@ class TextEditorPlugin : public Plugin
4040
*/
4141
const char* getMaker() const noexcept override
4242
{
43-
return "falkTX";
43+
return "DISTRHO";
4444
}
4545

4646
/**
@@ -61,14 +61,22 @@ class TextEditorPlugin : public Plugin
6161
return d_version(1, 0, 0);
6262
}
6363

64+
// ----------------------------------------------------------------------------------------------------------------
65+
// Init
66+
6467
/**
65-
Get the plugin unique Id.@n
66-
This value is used by LADSPA, DSSI and VST plugin formats.
67-
@see d_cconst()
68+
Initialize the state @a index.@n
69+
This function will be called once, shortly after the plugin is created.@n
70+
Must be implemented by your plugin class only if DISTRHO_PLUGIN_WANT_STATE is enabled.
6871
*/
69-
int64_t getUniqueId() const noexcept override
72+
void initState(uint32_t index, State& state) override
7073
{
71-
return d_cconst('d', 'T', 'x', 't');
74+
if (index != 0)
75+
return;
76+
77+
state.hints = kStateIsHostWritable | kStateIsOnlyForUI;
78+
state.key = "text";
79+
state.label = "Text";
7280
}
7381

7482
// ----------------------------------------------------------------------------------------------------------------

plugins/TextEditor/PluginUI.cpp

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
/*
22
* Text Editor example
3-
* Copyright (C) 2023 Filipe Coelho <[email protected]>
3+
* Copyright (C) 2023-2025 Filipe Coelho <[email protected]>
44
* SPDX-License-Identifier: ISC
55
*/
66

77
#include "DistrhoUI.hpp"
88

9+
#include <fstream>
10+
911
START_NAMESPACE_DISTRHO
1012

1113
// --------------------------------------------------------------------------------------------------------------------
1214

1315
class TextEditorUI : public UI
1416
{
17+
bool textChanged = false;
18+
1519
public:
1620
/**
1721
UI class constructor.
@@ -33,6 +37,8 @@ class TextEditorUI : public UI
3337
setGeometryConstraints(width, height);
3438
setSize(width, height);
3539
}
40+
41+
showMenu();
3642
}
3743

3844
protected:
@@ -45,6 +51,67 @@ class TextEditorUI : public UI
4551
*/
4652
void parameterChanged(uint32_t, float) override {}
4753

54+
/**
55+
A state has changed on the plugin side.@n
56+
This is called by the host to inform the UI about state changes.
57+
*/
58+
void stateChanged(const char* key, const char* value) override
59+
{
60+
if (std::strcmp(key, "text") != 0)
61+
return;
62+
63+
setText(value);
64+
}
65+
66+
// ----------------------------------------------------------------------------------------------------------------
67+
// UI Callbacks
68+
69+
/**
70+
UI idle function, called to give idle time to the plugin UI directly from the host.
71+
This is called right after OS event handling and Window idle events (within the same cycle).
72+
There are no guarantees in terms of timing.
73+
*/
74+
void uiIdle() override
75+
{
76+
if (hasTextChangedSinceLastTime())
77+
{
78+
textChanged = true;
79+
return;
80+
}
81+
82+
// wait for first idle with no more text changes
83+
if (textChanged)
84+
{
85+
textChanged = false;
86+
setState("text", getText().c_str());
87+
}
88+
}
89+
90+
/**
91+
Window file selected function, called when a path is selected by the user, as triggered by openFileBrowser().
92+
This function is for plugin UIs to be able to override Window::onFileSelected(const char*).
93+
94+
This action happens after the user confirms the action, so the file browser dialog will be closed at this point.
95+
The default implementation does nothing.
96+
97+
If you need to use files as plugin state, please setup and use states with kStateIsFilenamePath instead.
98+
*/
99+
void uiFileBrowserSelected(const char* const filename) override
100+
{
101+
// TODO check if this can be null, add to docs if that can happen
102+
if (filename == nullptr)
103+
return;
104+
105+
std::ifstream filestream(filename);
106+
107+
if (filestream.good())
108+
{
109+
const std::string text((std::istreambuf_iterator<char>(filestream)), std::istreambuf_iterator<char>());
110+
setText(text);
111+
setState("text", text.c_str());
112+
}
113+
}
114+
48115
// ----------------------------------------------------------------------------------------------------------------
49116

50117
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(TextEditorUI)

0 commit comments

Comments
 (0)