29#if JUCE_ENABLE_LIVE_CONSTANT_EDITOR && ! defined (DOXYGEN)
35namespace LiveConstantEditor
37 int64 parseInt (String);
38 double parseDouble (
const String&);
39 String intToString (
int,
bool preferHex);
40 String intToString (
int64,
bool preferHex);
42 template <
typename Type>
43 static void setFromString (Type&
v,
const String&
s) {
v =
static_cast<Type> (
s); }
44 inline void setFromString (
char&
v,
const String&
s) {
v = (char) parseInt (
s); }
45 inline void setFromString (
unsigned char&
v,
const String&
s) {
v = (
unsigned char) parseInt (
s); }
46 inline void setFromString (
short&
v,
const String&
s) {
v = (short) parseInt (
s); }
47 inline void setFromString (
unsigned short&
v,
const String&
s) {
v = (
unsigned short) parseInt (
s); }
48 inline void setFromString (
int&
v,
const String&
s) {
v = (
int) parseInt (
s); }
49 inline void setFromString (
unsigned int&
v,
const String&
s) {
v = (
unsigned int) parseInt (
s); }
50 inline void setFromString (
long&
v,
const String&
s) {
v = (long) parseInt (
s); }
51 inline void setFromString (
unsigned long&
v,
const String&
s) {
v = (
unsigned long) parseInt (
s); }
52 inline void setFromString (
int64&
v,
const String&
s) {
v = (
int64) parseInt (
s); }
53 inline void setFromString (
uint64&
v,
const String&
s) {
v = (
uint64) parseInt (
s); }
54 inline void setFromString (
double&
v,
const String&
s) {
v = parseDouble (
s); }
55 inline void setFromString (
float&
v,
const String&
s) {
v = (float) parseDouble (
s); }
56 inline void setFromString (
bool&
v,
const String&
s) {
v = (
s ==
"true"); }
57 inline void setFromString (String&
v,
const String&
s) {
v =
s; }
58 inline void setFromString (Colour&
v,
const String&
s) {
v = Colour ((
uint32) parseInt (
s)); }
60 template <
typename Type>
61 inline String getAsString (
const Type&
v,
bool) {
return String (
v); }
62 inline String getAsString (
char v,
bool preferHex) {
return intToString ((
int)
v, preferHex); }
63 inline String getAsString (
unsigned char v,
bool preferHex) {
return intToString ((
int)
v, preferHex); }
64 inline String getAsString (
short v,
bool preferHex) {
return intToString ((
int)
v, preferHex); }
65 inline String getAsString (
unsigned short v,
bool preferHex) {
return intToString ((
int)
v, preferHex); }
66 inline String getAsString (
int v,
bool preferHex) {
return intToString ((
int)
v, preferHex); }
67 inline String getAsString (
unsigned int v,
bool preferHex) {
return intToString ((
int)
v, preferHex); }
68 inline String getAsString (
bool v,
bool) {
return v ?
"true" :
"false"; }
69 inline String getAsString (
int64 v,
bool preferHex) {
return intToString ((
int64)
v, preferHex); }
70 inline String getAsString (
uint64 v,
bool preferHex) {
return intToString ((
int64)
v, preferHex); }
71 inline String getAsString (Colour
v,
bool) {
return intToString ((
int)
v.getARGB(),
true); }
73 template <
typename Type>
struct isStringType {
enum {
value = 0 }; };
74 template <>
struct isStringType<String> {
enum {
value = 1 }; };
76 template <
typename Type>
77 inline String getAsCode (Type&
v,
bool preferHex) {
return getAsString (
v, preferHex); }
79 inline String getAsCode (
const String&
v,
bool) {
return CppTokeniserFunctions::addEscapeChars(
v).
quoted(); }
80 inline String getAsCode (
const char*
v,
bool) {
return getAsCode (String (
v),
false); }
82 template <
typename Type>
83 inline const char* castToCharPointer (
const Type&) {
return ""; }
84 inline const char* castToCharPointer (
const String&
s) {
return s.toRawUTF8(); }
86 struct LivePropertyEditorBase;
91 LiveValueBase (
const char*
file,
int line);
92 virtual ~LiveValueBase();
94 virtual LivePropertyEditorBase* createPropertyComponent (CodeDocument&) = 0;
95 virtual String getStringValue (
bool preferHex)
const = 0;
96 virtual String getCodeValue (
bool preferHex)
const = 0;
97 virtual void setStringValue (
const String&) = 0;
98 virtual String getOriginalStringValue (
bool preferHex)
const = 0;
99 virtual bool isString()
const = 0;
101 String
name, sourceFile;
108 struct JUCE_API LivePropertyEditorBase :
public Component
110 LivePropertyEditorBase (LiveValueBase&, CodeDocument&);
112 void paint (Graphics&)
override;
113 void resized()
override;
115 void applyNewValue (
const String&);
116 void selectOriginalValue();
117 void findOriginalValueInCode();
119 LiveValueBase&
value;
121 TextEditor valueEditor;
122 TextButton resetButton {
"reset" };
123 CodeDocument& document;
124 CPlusPlusCodeTokeniser tokeniser;
125 CodeEditorComponent sourceEditor;
126 CodeDocument::Position valueStart, valueEnd;
127 std::unique_ptr<Component> customComp;
134 Component* createColourEditor (LivePropertyEditorBase&);
135 Component* createIntegerSlider (LivePropertyEditorBase&);
136 Component* createFloatSlider (LivePropertyEditorBase&);
137 Component* createBoolSlider (LivePropertyEditorBase&);
139 template <
typename Type>
struct CustomEditor {
static Component* create (LivePropertyEditorBase&) {
return nullptr; } };
140 template <>
struct CustomEditor<char> {
static Component* create (LivePropertyEditorBase&
e) {
return createIntegerSlider (
e); } };
141 template <>
struct CustomEditor<unsigned char> {
static Component* create (LivePropertyEditorBase&
e) {
return createIntegerSlider (
e); } };
142 template <>
struct CustomEditor<
int> {
static Component* create (LivePropertyEditorBase&
e) {
return createIntegerSlider (
e); } };
143 template <>
struct CustomEditor<unsigned
int> {
static Component* create (LivePropertyEditorBase&
e) {
return createIntegerSlider (
e); } };
144 template <>
struct CustomEditor<short> {
static Component* create (LivePropertyEditorBase&
e) {
return createIntegerSlider (
e); } };
145 template <>
struct CustomEditor<unsigned short> {
static Component* create (LivePropertyEditorBase&
e) {
return createIntegerSlider (
e); } };
146 template <>
struct CustomEditor<
int64> {
static Component* create (LivePropertyEditorBase&
e) {
return createIntegerSlider (
e); } };
147 template <>
struct CustomEditor<
uint64> {
static Component* create (LivePropertyEditorBase&
e) {
return createIntegerSlider (
e); } };
148 template <>
struct CustomEditor<float> {
static Component* create (LivePropertyEditorBase&
e) {
return createFloatSlider (
e); } };
149 template <>
struct CustomEditor<double> {
static Component* create (LivePropertyEditorBase&
e) {
return createFloatSlider (
e); } };
150 template <>
struct CustomEditor<Colour> {
static Component* create (LivePropertyEditorBase&
e) {
return createColourEditor (
e); } };
151 template <>
struct CustomEditor<bool> {
static Component* create (LivePropertyEditorBase&
e) {
return createBoolSlider (
e); } };
153 template <
typename Type>
154 struct LivePropertyEditor :
public LivePropertyEditorBase
156 template <
typename ValueType>
157 LivePropertyEditor (ValueType&
v, CodeDocument&
d) : LivePropertyEditorBase (
v,
d)
159 customComp.reset (CustomEditor<Type>::create (*
this));
160 addAndMakeVisible (customComp.get());
165 template <
typename Type>
166 struct LiveValue :
public LiveValueBase
168 LiveValue (
const char*
file,
int line,
const Type& initialValue)
169 : LiveValueBase (
file, line),
value (initialValue), originalValue (initialValue)
174 operator const char*()
const {
return castToCharPointer (
value); }
176 LivePropertyEditorBase* createPropertyComponent (CodeDocument& doc)
override
178 return new LivePropertyEditor<Type> (*
this, doc);
181 String getStringValue (
bool preferHex)
const override {
return getAsString (
value, preferHex); }
182 String getCodeValue (
bool preferHex)
const override {
return getAsCode (
value, preferHex); }
183 String getOriginalStringValue (
bool preferHex)
const override {
return getAsString (originalValue, preferHex); }
184 void setStringValue (
const String&
s)
override { setFromString (
value,
s); }
185 bool isString()
const override {
return isStringType<Type>::value; }
193 class JUCE_API ValueList :
private AsyncUpdater,
194 private DeletedAtShutdown
198 ~ValueList()
override;
202 template <typename Type>
203 LiveValue<Type>& getValue (
const char*
file,
int line,
const Type& initialValue)
206 using ValueType = LiveValue<Type>;
208 for (
auto*
v : values)
209 if (
v->sourceLine == line &&
v->sourceFile ==
file)
210 return *
static_cast<ValueType*
> (
v);
212 auto v =
new ValueType (
file, line, initialValue);
218 OwnedArray<LiveValueBase> values;
219 OwnedArray<CodeDocument> documents;
220 Array<File> documentFiles;
222 Component::SafePointer<EditorWindow> editorWindow;
223 CriticalSection lock;
225 CodeDocument& getDocument (
const File&);
226 void addValue (LiveValueBase*);
227 void handleAsyncUpdate()
override;
230 template <
typename Type>
231 inline LiveValue<Type>& getValue (
const char*
file,
int line,
const Type& initialValue)
239 return ValueList::getInstance()->getValue (
file, line, initialValue);
242 inline LiveValue<String>& getValue (
const char*
file,
int line,
const char* initialValue)
244 return getValue (
file, line, String (initialValue));
251#if JUCE_ENABLE_LIVE_CONSTANT_EDITOR || DOXYGEN
298 #define JUCE_LIVE_CONSTANT(initialValue) \
299 (juce::LiveConstantEditor::getValue (__FILE__, __LINE__ - 1, initialValue).get())
301 #define JUCE_LIVE_CONSTANT(initialValue) \
#define noexcept
Definition DistrhoDefines.h:72
int64_t int64
Definition basics.h:91
uint64_t uint64
Definition basics.h:92
uint32_t uint32
Definition basics.h:90
static bool isAbsolutePath(StringRef path)
Definition File.cpp:406
static String toHexString(int number)
Definition String.cpp:1830
String paddedLeft(water_uchar padCharacter, int minimumLength) const
Definition String.cpp:1042
String quoted(water_uchar quoteCharacter='"') const
Definition String.cpp:1509
* e
Definition inflate.c:1404
unsigned v[N_MAX]
Definition inflate.c:1584
unsigned d
Definition inflate.c:940
unsigned s
Definition inflate.c:1555
static PuglViewHint int value
Definition pugl.h:1708
static const char * name
Definition pugl.h:1582
#define JUCE_DECLARE_SINGLETON(Classname, doNotRecreateAfterDeletion)
Definition juce_Singleton.h:184
#define JUCE_API
Definition juce_StandardHeader.h:152
auto & get(ProcessorChain< Processors... > &chain) noexcept
Definition juce_ProcessorChain.h:133
Definition carla_juce.cpp:31
CriticalSection::ScopedLockType ScopedLock
Definition juce_CriticalSection.h:186
Type
Definition Lv2Ports.h:60
typedef int(UZ_EXP MsgFn)()
struct zdirent * file
Definition win32.c:1500
#define const
Definition zconf.h:137