/
Macros.h
504 lines (407 loc) · 14.2 KB
/
Macros.h
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
/* ===========================================================================
*
* This file is part of HISE.
* Copyright 2016 Christoph Hart
*
* HISE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HISE 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HISE. If not, see <http://www.gnu.org/licenses/>.
*
* Commercial licenses for using HISE in an closed source project are
* available on request. Please visit the project's website to get more
* information about commercial licensing:
*
* http://www.hise.audio/
*
* HISE is based on the JUCE library,
* which must be separately licensed for closed source applications:
*
* http://www.juce.com
*
* ===========================================================================
*/
#pragma once
namespace juce
{
using ButtonListener = Button::Listener;
using SliderListener = Slider::Listener;
using ComboBoxListener = ComboBox::Listener;
using TextEditorListener = TextEditor::Listener;
using LabelListener = Label::Listener;
}
namespace hise { using namespace juce;
/** Change this value if you need more than 8 stereo channels in HISE routing. */
#ifndef NUM_MAX_CHANNELS
#define NUM_MAX_CHANNELS 16
#endif
#if NUM_MAX_CHANNELS % 2 != 0
#error "The channel amount must be a multiple of 2"
#endif
#define NUM_MIC_POSITIONS NUM_MAX_CHANNELS / 2
#ifndef NUM_POLYPHONIC_VOICES
#if HISE_IOS
#define NUM_POLYPHONIC_VOICES 128
#else
#define NUM_POLYPHONIC_VOICES 256
#endif
#endif
#if HI_RUN_UNIT_TESTS
#define jassert_skip_unit_test(x)
#else
#define jassert_skip_unit_test(x) jassert(x)
#endif
#ifndef HISE_EVENT_RASTER
#if FRONTEND_IS_PLUGIN
#define HISE_EVENT_RASTER 1 // Do not downsample the control rate for effect plugins
#else
#define HISE_EVENT_RASTER 8
#endif
#endif
#ifndef HISE_CONTROL_RATE_DOWNSAMPLING_FACTOR
#define HISE_CONTROL_RATE_DOWNSAMPLING_FACTOR HISE_EVENT_RASTER
#endif
/** If enabled, this will try to retain as much pitch modulation resolution as possible (it will still get downsampled to the control rate).
*/
#ifndef HISE_ENABLE_FULL_CONTROL_RATE_PITCH_MOD
#define HISE_ENABLE_FULL_CONTROL_RATE_PITCH_MOD 0
#endif
#if (HISE_EVENT_RASTER != 1)
#define HISE_USE_CONTROLRATE_DOWNSAMPLING 1
#else
#define HISE_USE_CONTROLRATE_DOWNSAMPLING 0
#endif
#if HI_ENABLE_EXPANSION_EDITING || USE_BACKEND
#define ENABLE_MARKDOWN true
#else
#define ENABLE_MARKDOWN false
#endif
#if (defined (_WIN32) || defined (_WIN64))
#define JUCE_WINDOWS 1
#endif
#define JUCE_LIVE_CONSTANT_OFF(x) x
#define SCALE_FACTOR() ((float)Desktop::getInstance().getDisplays().getMainDisplay().scale)
#if JUCE_DEBUG || USE_FRONTEND || JUCE_MAC
#define RETURN_IF_NO_THROW(x) return x;
#define RETURN_VOID_IF_NO_THROW() return;
#else
#define RETURN_IF_NO_THROW(x)
#define RETURN_VOID_IF_NO_THROW()
#endif
#if JUCE_WINDOWS || JUCE_MAC || JUCE_IOS
#if HISE_NO_GUI_TOOLS
#define GLOBAL_FONT() (Font().withHeight(15.0f))
#define GLOBAL_BOLD_FONT() (Font().withHeight(15.0f))
#define GLOBAL_MONOSPACE_FONT() (Font().withHeight(15.0f))
#else
static Typeface::Ptr oxygenBoldTypeFace = Typeface::createSystemTypefaceFor(HiBinaryData::FrontendBinaryData::oxygen_bold_ttf, HiBinaryData::FrontendBinaryData::oxygen_bold_ttfSize);
static Typeface::Ptr oxygenTypeFace = Typeface::createSystemTypefaceFor(HiBinaryData::FrontendBinaryData::oxygen_regular_ttf, HiBinaryData::FrontendBinaryData::oxygen_regular_ttfSize);
static Typeface::Ptr sourceCodeProTypeFace = Typeface::createSystemTypefaceFor(HiBinaryData::FrontendBinaryData::SourceCodeProRegular_otf, HiBinaryData::FrontendBinaryData::SourceCodeProRegular_otfSize);
static Typeface::Ptr sourceCodeProBoldTypeFace = Typeface::createSystemTypefaceFor(HiBinaryData::FrontendBinaryData::SourceCodeProBold_otf, HiBinaryData::FrontendBinaryData::SourceCodeProBold_otfSize);
#define GLOBAL_FONT() (Font(oxygenTypeFace).withHeight(13.0f))
#define GLOBAL_BOLD_FONT() (Font(oxygenBoldTypeFace).withHeight(14.0f))
#if JUCE_IOS
#define GLOBAL_MONOSPACE_FONT() Font(Font::getDefaultMonospacedFontName(), 14.0f, Font::plain)
#else
#if JUCE_WINDOWS
#define GLOBAL_MONOSPACE_FONT() (Font("Consolas", 14.0f, Font::plain))
#elif JUCE_MAC
#define GLOBAL_MONOSPACE_FONT() (Font("Menlo", 14.0f, Font::plain))
#else
#define GLOBAL_MONOSPACE_FONT() (Font(sourceCodeProTypeFace).withHeight(14.0f))
#endif
#endif
#endif
#elif JUCE_LINUX && !HISE_NO_GUI_TOOLS
class LinuxFontHandler
{
public:
LinuxFontHandler()
{
Typeface::Ptr oxygenBoldTypeFace = Typeface::createSystemTypefaceFor(HiBinaryData::FrontendBinaryData::oxygen_bold_ttf, HiBinaryData::FrontendBinaryData::oxygen_bold_ttfSize);
Typeface::Ptr oxygenTypeFace = Typeface::createSystemTypefaceFor(HiBinaryData::FrontendBinaryData::oxygen_regular_ttf, HiBinaryData::FrontendBinaryData::oxygen_regular_ttfSize);
Typeface::Ptr sourceCodeProTypeFace = Typeface::createSystemTypefaceFor(HiBinaryData::FrontendBinaryData::SourceCodeProRegular_otf, HiBinaryData::FrontendBinaryData::SourceCodeProRegular_otfSize);
Typeface::Ptr sourceCodeProBoldTypeFace = Typeface::createSystemTypefaceFor(HiBinaryData::FrontendBinaryData::SourceCodeProBold_otf, HiBinaryData::FrontendBinaryData::SourceCodeProBold_otfSize);
globalFont = Font(oxygenTypeFace).withHeight(13.0f);
globalBoldFont = Font(oxygenBoldTypeFace).withHeight(14.0f);
monospaceFont = Font(sourceCodeProTypeFace).withHeight(14.0f);
monospaceBoldFont = Font(sourceCodeProBoldTypeFace).withHeight(14.0f);
}
Font globalFont;
Font globalBoldFont;
Font monospaceFont;
Font monospaceBoldFont;
class Instance
{
public:
Instance() {};
Font getGlobalFont() {return data->globalFont;};
Font getGlobalBoldFont() {return data->globalBoldFont;};
Font getGlobalMonospaceFont() {return data->monospaceFont; }
Font getGlobalMonospaceBoldFont() { return data->monospaceBoldFont; }
private:
SharedResourcePointer<LinuxFontHandler> data;
};
};
#define GLOBAL_FONT() (LinuxFontHandler::Instance().getGlobalFont())
#define GLOBAL_BOLD_FONT() (LinuxFontHandler::Instance().getGlobalBoldFont())
#define GLOBAL_MONOSPACE_FONT() (LinuxFontHandler::Instance().getGlobalMonospaceFont())
#define GLOBAL_BOLD_MONOSPACE_FONT() (LinuxFontHandler::Instance().getGlobalMonospaceBoldFont())
#else
#define GLOBAL_FONT() (Font())
#define GLOBAL_BOLD_FONT() (Font())
#define GLOBAL_MONOSPACE_FONT() (Font())
#define GLOBAL_BOLD_MONOSPACE_FONT() (Font())
#endif
struct StringSanitizer
{
static String get(const String& s)
{
auto p = s.removeCharacters("():,;?");
if (!p.isEmpty() && p.endsWith("/"))
p = p.upToLastOccurrenceOf("/", false, false);
p = p.replace(".md", "");
return p.replaceCharacter(' ', '-').toLowerCase();
}
};
struct FontHelpers
{
static Font getFontBoldened(const Font& f)
{
if (f.isBold())
return f;
if (f.getTypefaceName().startsWith("Oxygen"))
return GLOBAL_BOLD_FONT().withHeight(f.getHeight());
if (f.getTypefaceName().startsWith("Source"))
return GLOBAL_MONOSPACE_FONT().withHeight(f.getHeight());
return f.boldened();
}
static Font getFontNormalised(Font f)
{
if (f.getTypefaceName().startsWith("Oxygen"))
return GLOBAL_FONT().withHeight(f.getHeight());
if (f.getTypefaceName().startsWith("Source"))
return GLOBAL_MONOSPACE_FONT().withHeight(f.getHeight());
if (f.isBold() || f.isItalic())
{
f.setBold(false);
f.setItalic(false);
return f;
}
return f;
}
static Font getFontItalicised(Font f)
{
if (f.isItalic())
return f;
if (f.getTypefaceName().startsWith("Oxygen"))
return GLOBAL_BOLD_FONT().withHeight(f.getHeight());
if (f.getTypefaceName().startsWith("Source"))
return GLOBAL_MONOSPACE_FONT().withHeight(f.getHeight());
return f.italicised();
}
};
#if ENABLE_MARKDOWN
#define MARKDOWN_CHAPTER(chapter) struct chapter {
#define START_MARKDOWN(name) static const String name() { String content; static const String nl = "\n";
#define ML(text) content << text << nl;
#define ML_START_CODE() ML("```javascript")
#define ML_END_CODE() ML("```")
#define END_MARKDOWN() return content; };
#define END_MARKDOWN_CHAPTER() };
#else
#define MARKDOWN_CHAPTER(chapter)
#define START_MARKDOWN(name)
#define ML(text)
#define ML_START_CODE()
#define ML_END_CODE()
#define END_MARKDOWN()
#define END_MARKDOWN_CHAPTER()
#endif
#ifndef RETURN_STATIC_IDENTIFIER
#define RETURN_STATIC_IDENTIFIER(x) const static Identifier id_(x); return id_;
#endif
#define SET_GENERIC_PANEL_ID(x) static Identifier getGenericPanelId() { RETURN_STATIC_IDENTIFIER(x) }
#define SET_PANEL_NAME(x) static Identifier getPanelId() { RETURN_STATIC_IDENTIFIER(x) }; Identifier getIdentifierForBaseClass() const override { return getPanelId(); };
#define GET_PANEL_NAME(className) className::getPanelId()
/** Override this and supply a custom implementation of HiseColourScheme::createAlertWindowLookAndFeel. */
#ifndef HISE_USE_CUSTOM_ALERTWINDOW_LOOKANDFEEL
#define HISE_USE_CUSTOM_ALERTWINDOW_LOOKANDFEEL 0
#endif
struct HiseColourScheme
{
enum Scheme
{
Dark,
Bright,
numSchemes
};
enum ColourIds
{
EditorBackgroundColourId,
EditorBackgroundColourIdBright,
ModulatorSynthBackgroundColourId,
DebugAreaBackgroundColourId,
ModulatorSynthHeader,
ComponentBackgroundColour = 0xFF123532,
ComponentFillTopColourId,
ComponentFillBottomColourId,
ComponentOutlineColourId,
ComponentTextColourId,
numColourIds
};
// Override this and return the look and feel to be used by all alert windows
static LookAndFeel* createAlertWindowLookAndFeel(void* mainController);
static Colour getColour(ColourIds id)
{
switch (id)
{
case HiseColourScheme::EditorBackgroundColourId:
{
switch (currentColourScheme)
{
case HiseColourScheme::Dark:
return JUCE_LIVE_CONSTANT_OFF(Colour(0xff515151));
case HiseColourScheme::Bright:
return JUCE_LIVE_CONSTANT_OFF(Colour(0xff898989));
case HiseColourScheme::numSchemes:
break;
}
}
case HiseColourScheme::EditorBackgroundColourIdBright:
{
switch (currentColourScheme)
{
case HiseColourScheme::Dark:
return JUCE_LIVE_CONSTANT_OFF(Colour(0xFF666666));
case HiseColourScheme::Bright:
return JUCE_LIVE_CONSTANT_OFF(Colour(0xFF666666));
case HiseColourScheme::numSchemes:
break;
}
}
case HiseColourScheme::ModulatorSynthBackgroundColourId:
{
switch (currentColourScheme)
{
case HiseColourScheme::Dark:
return JUCE_LIVE_CONSTANT_OFF(Colour(0xff414141));
case HiseColourScheme::Bright:
return JUCE_LIVE_CONSTANT_OFF(Colour(0xff5e5e5e));
case HiseColourScheme::numSchemes:
break;
}
}
case HiseColourScheme::DebugAreaBackgroundColourId:
{
switch (currentColourScheme)
{
case HiseColourScheme::Dark:
return JUCE_LIVE_CONSTANT_OFF(Colour(0xFF3D3D3D));
case HiseColourScheme::Bright:
return JUCE_LIVE_CONSTANT_OFF(Colour(0xff5d5d5d));
case HiseColourScheme::numSchemes:
break;
}
}
case HiseColourScheme::ModulatorSynthHeader:
{
switch (currentColourScheme)
{
case HiseColourScheme::Dark:
return JUCE_LIVE_CONSTANT_OFF(Colour(0xFFEEEEEE));
case HiseColourScheme::Bright:
return JUCE_LIVE_CONSTANT_OFF(Colour(0xFFEEEEEE));
case HiseColourScheme::numSchemes:
break;
}
}
default:
break;
}
jassertfalse;
return Colours::transparentBlack;
}
static void setDefaultColours(Component& c, bool recursive=false)
{
c.setColour(ComponentBackgroundColour, Colours::transparentBlack);
c.setColour(ComponentFillTopColourId, Colour(0x66333333));
c.setColour(ComponentFillBottomColourId, Colour(0xfb111111));
c.setColour(ComponentOutlineColourId, Colours::white.withAlpha(0.3f));
c.setColour(ComponentTextColourId, Colours::white);
if (recursive)
{
for (int i = 0; i < c.getNumChildComponents(); i++)
setDefaultColours(*c.getChildComponent(i), true);
}
}
static void setColourScheme(Scheme s)
{
currentColourScheme = s;
}
static Scheme getCurrentColourScheme()
{
return currentColourScheme;
}
private:
static Scheme currentColourScheme;
};
#define DEBUG_AREA_BACKGROUND_COLOUR_DARK 0x03000000
#define BACKEND_BG_COLOUR 0xFF888888//0xff4d4d4d
#define BACKEND_BG_COLOUR_BRIGHT 0xFF646464
#define BACKEND_ICON_COLOUR_ON 0xCCFFFFFF
#define BACKEND_ICON_COLOUR_OFF 0xFF333333
#ifndef SIGNAL_COLOUR
#define SIGNAL_COLOUR 0xFF90FFB1
#endif
#ifndef HISE_OK_COLOUR
#define HISE_OK_COLOUR 0xFF4E8E35
#endif
#ifndef HISE_WARNING_COLOUR
#define HISE_WARNING_COLOUR 0xFFFFBA00
#endif
#ifndef HISE_ERROR_COLOUR
#define HISE_ERROR_COLOUR 0xFFBB3434
#endif
#define FLOAT_RECTANGLE(r) r.toFloat();
#define INT_RECTANGLE(r) r.toInt();
#define CONSTRAIN_TO_0_1(x)(jlimit<float>(0.0f, 1.0f, x))
#define DEBUG_AREA_BACKGROUND_COLOUR_DARK 0x03000000
#define BACKEND_BG_COLOUR 0xFF888888//0xff4d4d4d
#define BACKEND_BG_COLOUR_BRIGHT 0xFF646464
#define BACKEND_ICON_COLOUR_ON 0xCCFFFFFF
#define BACKEND_ICON_COLOUR_OFF 0xFF333333
#define DEBUG_BG_COLOUR 0xff636363
#if HISE_IOS
#define SET_IMAGE_RESAMPLING_QUALITY() g.setImageResamplingQuality (Graphics::ResamplingQuality::lowResamplingQuality);
#else
#define SET_IMAGE_RESAMPLING_QUALITY()
#endif
#define BIND_MEMBER_FUNCTION_0(x) std::bind(&x, this)
#define BIND_MEMBER_FUNCTION_1(x) std::bind(&x, this, std::placeholders::_1)
#define BIND_MEMBER_FUNCTION_2(x) std::bind(&x, this, std::placeholders::_1, std::placeholders::_2)
#define BIND_MEMBER_FUNCTION_3(x) std::bind(&x, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)
#ifndef jassertEqual
#if JUCE_DEBUG
#define jassertEqual(expr1, expr2) jassert(expr1 == expr2)
#else
#define jassertEqual(expr1, expr2) ignoreUnused(expr1, expr2)
#endif
#endif
/** This is set by the HISE projects to figure out the default VS version for the export. */
#ifndef HISE_USE_VS2022
#define HISE_USE_VS2022 0
#endif
/** This sets the global raster size for dragging components. */
#ifndef HI_RASTER_SIZE
#define HI_RASTER_SIZE 10
#endif
} // namespace hise