/
StaticNodeWrappers.h
1156 lines (864 loc) · 26.7 KB
/
StaticNodeWrappers.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
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* ===========================================================================
*
* 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 also must be licenced for commercial applications:
*
* http://www.juce.com
*
* ===========================================================================
*/
#pragma once
namespace scriptnode
{
namespace scriptnode_initialisers
{
struct no
{
static void initialise(void*, NodeBase*)
{};
};
}
using namespace juce;
using namespace hise;
struct ComponentHelpers
{
static NodeComponent* createDefaultComponent(NodeBase* n);
static void addExtraComponentToDefault(NodeComponent* nc, Component* c);
};
struct NoExtraComponent
{
static Component* createExtraComponent(void* , PooledUIUpdater*) { return nullptr; }
};
template <class WType> class InterpretedNodeBase
{
public:
using WrapperType = WType;
virtual ~InterpretedNodeBase() {};
InterpretedNodeBase() = default;
template <typename T, bool AddDataOffsetToUIPtr> void init()
{
obj.getWrappedObject().template create<T>();
if constexpr (AddDataOffsetToUIPtr && std::is_base_of<data::pimpl::provider_base, T>())
{
auto offset = T::getDataOffset();
asWrapperNode()->setUIOffset(offset);
}
this->obj.initialise(asWrapperNode());
postInit();
}
void initFromDll(dll::HostFactory& f, int index)
{
f.initOpaqueNode(&obj.getWrappedObject(), index);
this->obj.initialise(asWrapperNode());
postInit();
}
virtual void postInit()
{
ParameterDataList pData;
obj.getWrappedObject().createParameters(pData);
asWrapperNode()->initParameterData(pData);
}
protected:
WrapperType obj;
void* getObjectPtrFromWrapper()
{
return obj.getWrappedObject().getObjectPtr();
}
ParameterDataList createInternalParameterListFromWrapper()
{
ParameterDataList pList;
obj.getWrappedObject().createParameters(pList);
return pList;
}
private:
WrapperNode* asWrapperNode()
{
return dynamic_cast<WrapperNode*>(this);
}
};
class InterpretedNode : public WrapperNode,
public InterpretedNodeBase<bypass::smoothed<OpaqueNode>>
{
using Base = InterpretedNodeBase<bypass::smoothed<OpaqueNode>>;
public:
InterpretedNode(DspNetwork* parent, ValueTree d):
WrapperNode(parent, d),
Base()
{}
void postInit() override
{
setDefaultValue(PropertyIds::BypassRampTimeMs, 20.0f);
Base::postInit();
}
template <typename T, typename ComponentType, bool AddDataOffsetToUIPtr> static NodeBase* createNode(DspNetwork* n, ValueTree d)
{
auto newNode = new InterpretedNode(n, d);
newNode->template init<T, AddDataOffsetToUIPtr>();
newNode->extraComponentFunction = ComponentType::createExtraComponent;
return newNode;
};
SN_OPAQUE_WRAPPER(InterpretedModNode, WrapperType);
void* getObjectPtr() override
{
return getObjectPtrFromWrapper();
}
ParameterDataList createInternalParameterList() override
{
return createInternalParameterListFromWrapper();
}
void reset();
bool isPolyphonic() const override { return this->obj.isPolyphonic(); }
void prepare(PrepareSpecs specs) final override;
void processFrame(NodeBase::FrameType& data) final override;
void processMonoFrame(MonoFrameType& data) final override;
void processStereoFrame(StereoFrameType& data) final override;
void process(ProcessDataDyn& data) noexcept final override;
void setBypassed(bool shouldBeBypassed) final override;
void handleHiseEvent(HiseEvent& e) final override;
valuetree::PropertyListener bypassListener;
};
class InterpretedModNode : public ModulationSourceNode,
public InterpretedNodeBase<wrap::mod<parameter::dynamic_base_holder, OpaqueNode>>
{
using Base = InterpretedNodeBase<wrap::mod<parameter::dynamic_base_holder, OpaqueNode>>;
public:
SN_OPAQUE_WRAPPER(InterpretedModNode, WrapperType);
InterpretedModNode(DspNetwork* parent, ValueTree d):
ModulationSourceNode(parent, d),
Base()
{
}
void postInit() override
{
getParameterHolder()->setRingBuffer(ringBuffer.get());
stop();
Base::postInit();
}
template <typename T, typename ComponentType, bool AddDataOffsetToUIPtr> static NodeBase* createNode(DspNetwork* n, ValueTree d)
{
auto mn = new InterpretedModNode(n, d);
mn->init<T, AddDataOffsetToUIPtr>();
mn->extraComponentFunction = ComponentType::createExtraComponent;
return mn;
};
void* getObjectPtr() override
{
return getObjectPtrFromWrapper();
}
ParameterDataList createInternalParameterList() override
{
return createInternalParameterListFromWrapper();
}
void timerCallback() override;
bool isUsingNormalisedRange() const override;
parameter::dynamic_base_holder* getParameterHolder() override;
bool isPolyphonic() const override;
void reset();
void prepare(PrepareSpecs specs) final override;
void writeToRingBuffer(double value, int numSamplesForAnalysis);
void processFrame(NodeBase::FrameType& data) final override;
void processMonoFrame(MonoFrameType& data) final override;
void processStereoFrame(StereoFrameType& data) final override;
void process(ProcessDataDyn& data) noexcept final override;
void handleHiseEvent(HiseEvent& e) final override;
WrapperType wrapper;
};
#if 0
struct ParameterNodeBase : public ModulationSourceNode
{
ParameterNodeBase(DspNetwork* n, ValueTree d) :
ModulationSourceNode(n, d)
{};
void timerCallback() override
{
getParameterHolder()->updateUI();
}
bool isUsingNormalisedRange() const override
{
return true;
}
void reset()
{
}
void prepare(PrepareSpecs ps) final override
{
}
void processFrame(NodeBase::FrameType& data) final override
{
}
void processMonoFrame(MonoFrameType& data) final override
{
}
void processStereoFrame(StereoFrameType& data) final override
{
}
void process(ProcessDataDyn& data) noexcept final override
{
}
void handleHiseEvent(HiseEvent& e) final override
{}
virtual parameter::dynamic_base_holder* getParameterHolder() = 0;
};
struct ParameterMultiplyAddNode : public ParameterNodeBase
{
ParameterMultiplyAddNode(DspNetwork* n, ValueTree d) :
ParameterNodeBase(n, d)
{
ParameterDataList pData;
obj.createParameters(pData);
initParameterData(pData);
};
parameter::dynamic_base_holder* getParameterHolder() override
{
return &obj.getParameter();
}
static Identifier getStaticId() { RETURN_STATIC_IDENTIFIER("pma"); };
void* getObjectPtr() override
{
return &obj;
};
static NodeBase* createNode(DspNetwork* n, ValueTree d)
{
auto node = new ParameterMultiplyAddNode(n, d);
node->extraComponentFunction = CombinedParameterDisplay::createExtraComponent;
return node;
};
ParameterDataList createInternalParameterList() override
{
ParameterDataList pData;
obj.createParameters(pData);
return pData;
}
core::pma<parameter::dynamic_base_holder, 1> obj;
};
#endif
namespace parameter
{
struct dynamic_list;
}
struct NewHero : public ModulationSourceNode,
public InterpretedNodeBase<OpaqueNode>
{
using Base = InterpretedNodeBase<OpaqueNode>;
NewHero(DspNetwork* n, ValueTree d) :
ModulationSourceNode(n, d),
Base()
{
};
template <typename T, typename ComponentType, bool AddDataOffsetToUIPtr> static NodeBase* createNode(DspNetwork* n, ValueTree d)
{
constexpr bool isBaseOfDynamicParameterHolder = std::is_base_of<control::pimpl::parameter_node_base<parameter::dynamic_base_holder>, typename T::WrappedObjectType>();
static_assert(std::is_base_of<control::pimpl::no_processing, typename T::WrappedObjectType>(), "not a base of no_processing");
auto mn = new NewHero(n, d);
if constexpr (isBaseOfDynamicParameterHolder)
mn->getParameterFunction = NewHero::getParameterFunctionStatic<T>;
else
{
constexpr bool isBaseOfDynamicList = std::is_base_of<control::pimpl::parameter_node_base<parameter::dynamic_list>, typename T::WrappedObjectType>();
static_assert(isBaseOfDynamicList, "not a base of dynamic holder or list");
mn->getParameterFunction = nullptr;
}
mn->init<T, AddDataOffsetToUIPtr>();
mn->extraComponentFunction = ComponentType::createExtraComponent;
return mn;
};
void* getObjectPtr() override
{
return getObjectPtrFromWrapper();
}
ParameterDataList createInternalParameterList() override
{
return createInternalParameterListFromWrapper();
}
parameter::dynamic_base_holder* getParameterHolder() override
{
if(getParameterFunction)
return getParameterFunction(getObjectPtr());
return nullptr;
}
void process(ProcessDataDyn& data) final override
{
}
void reset() final override
{
}
void timerCallback() override
{
if(auto p = getParameterHolder())
p->updateUI();
}
bool isUsingNormalisedRange() const override
{
return this->obj.getWrappedObject().isNormalised;
}
void prepare(PrepareSpecs ps) final override;
void processFrame(FrameType& data) final override
{
}
void handleHiseEvent(HiseEvent& e) final override
{
this->obj.handleHiseEvent(e);
}
private:
typedef parameter::dynamic_base_holder*(*getParamFunc)(void*);
template <class Derived> static parameter::dynamic_base_holder* getParameterFunctionStatic(void* b)
{
using BaseClass = control::pimpl::parameter_node_base<parameter::dynamic_base_holder>;
static_assert(std::is_base_of<BaseClass, typename Derived::WrappedObjectType>());
auto typed = static_cast<Derived*>(b);
return &typed->getWrappedObject().getParameter();
};
getParamFunc getParameterFunction;
};
class RestorableNode
{
public:
virtual ~RestorableNode()
{
}
virtual String getSnippetText() const { return ""; }
};
#if OLD_SCRIPTNODE_CPP
template<int... Indexes> using NodePath = std::integer_sequence<int, Indexes...>;
template <class T> static auto& findNode(T& t, NodePath<> empty)
{
ignoreUnused(empty);
return t.getObject();
}
template <class T, int Index, int... Indexes> static auto& findNode(T& t, NodePath<Index, Indexes...> )
{
auto& obj = t.template get<Index>().getObject();
NodePath<Indexes...> seq;
return findNode(obj, seq);
}
#define FIND_NODE(obj, ...) &findNode(obj.getObject(), NodePath<__VA_ARGS__>())
class HardcodedNode : public RestorableNode
{
public:
virtual ~HardcodedNode()
{
combinedParameterValues.clear();
};
struct ParameterInitValue
{
ParameterInitValue(const char* id_, double v) :
id(id_),
value(v)
{};
String id;
double value;
};
struct CombinedParameterValue
{
CombinedParameterValue(const HiseDspBase::ParameterData& p):
id(p.id),
callback(p.dbNew),
lastValue(p.defaultValue)
{
}
bool matches(const HiseDspBase::ParameterData& p) const
{
return id == p.id;
}
void SetValue(double newValue)
{
lastValue = newValue;
update();
}
void Add(double newValue)
{
addValue = newValue;
update();
}
void Multiply(double newValue)
{
mulValue = newValue;
update();
}
void updateRangeForOpType(Identifier opType, NormalisableRange<double> newRange)
{
if (opType == OperatorIds::Add)
{
addRange = newRange;
useAddRange = !RangeHelpers::isIdentity(newRange);
}
if (opType == OperatorIds::SetValue)
{
setRange = newRange;
useSetRange = !RangeHelpers::isIdentity(newRange);
}
if (opType == OperatorIds::Multiply)
{
mulRange = newRange;
useMulRange = !RangeHelpers::isIdentity(newRange);
}
}
void addConversion(Identifier converterId, Identifier opType)
{
if (opType == OperatorIds::SetValue)
setConverter = DspHelpers::ConverterFunctions::getFunction(converterId);
if(opType == OperatorIds::Multiply)
mulConverter = DspHelpers::ConverterFunctions::getFunction(converterId);
if(opType == OperatorIds::Add)
addConverter = DspHelpers::ConverterFunctions::getFunction(converterId);
}
private:
void update()
{
auto newValue = getSet() * getMul() + getAdd();
callback(newValue);
}
std::function<void(double)> callback;
double getSet() const
{
return useSetRange ? setRange.convertFrom0to1(getSetConverted()) : getSetConverted();
}
double getMul() const
{
return useMulRange ? mulRange.convertFrom0to1(getMullConverted()) : getMullConverted();
}
double getAdd() const
{
return useAddRange ? addRange.convertFrom0to1(getAddConverted()) : getAddConverted();
}
double getSetConverted() const
{
return setConverter ? setConverter(lastValue) : lastValue;
}
double getAddConverted() const
{
return addConverter ? addConverter(addValue) : addValue;
}
double getMullConverted() const
{
return mulConverter ? mulConverter(mulValue) : mulValue;
}
String id;
double lastValue = 0.0;
double mulValue = 1.0;
double addValue = 0.0;
NormalisableRange<double> mulRange;
NormalisableRange<double> setRange;
NormalisableRange<double> addRange;
std::function<double(double)> setConverter;
std::function<double(double)> mulConverter;
std::function<double(double)> addConverter;
bool useSetRange = false;
bool useMulRange = false;
bool useAddRange = false;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CombinedParameterValue);
};
CombinedParameterValue* getCombinedParameter(const String& id, NormalisableRange<double> range, Identifier opType);
static constexpr int ExtraHeight = 0;
static ParameterDataList createParametersT(ParameterHolder* d, const String& prefix)
{
ParameterDataList data;
d->createParameters(data);
if (prefix.isNotEmpty())
{
for (auto& c : data)
c.id = prefix + "." + c.id;
}
return data;
}
void fillInternalParameterList(ParameterHolder* obj, const String& name)
{
internalParameterList.addArray(createParametersT(obj, name));
}
template <class T> void setInternalModulationParameter(T* modObject, const DspHelpers::ParameterCallback& f)
{
modObject->setCallback(f);
}
void setNodeProperty(const String& id, const var& newValue, bool isPublic);
var getNodeProperty(const String& id, const var& defaultReturnValue) const;
void setParameterDefault(const String& parameterId, double value);
ParameterDataList internalParameterList;
Array<ParameterInitValue> initValues;
OwnedArray<CombinedParameterValue> combinedParameterValues;
HiseDspBase::ParameterData getParameter(const String& id);
HiseDspBase::ParameterData getParameter(const String& id, NormalisableRange<double> d);
String getNodeId(const HiseDspBase* internalNode) const;
HiseDspBase* getNode(const String& id) const;
template <class T> void registerNode(T* obj, const String& id)
{
if (auto typed = dynamic_cast<HiseDspBase*>(&obj->getObject()))
{
internalNodes.add({ typed, id });
fillInternalParameterList(typed, id);
}
}
void addPublicComponent(const String& nodeId)
{
nodesWithPublicComponent.add(nodeId);
}
protected:
StringArray getNodeIdsWithPublicComponent()
{
return nodesWithPublicComponent;
}
ValueTree nodeData;
UndoManager* um = nullptr;
private:
StringArray nodesWithPublicComponent;
ValueTree getNodePropertyTree(const String& id) const;
struct InternalNode
{
HiseDspBase* node = nullptr;
String id;
};
Array<InternalNode> internalNodes;
};
struct hc
{
static constexpr int no_modulation = 1;
static constexpr int with_modulation = 2;
};
#define DEF_CONSTRUCTOR instance(); ~instance();
#define DEF_PIMPL struct Impl; Impl* pimpl;
#define DEF_PREPARE_PIMPL void prepare(PrepareSpecs ps);
#define DEF_INIT_PIMPL void initialise(NodeBase* n);
#define DEF_HANDLE_MOD_PIMPL bool handleModulation(double& value);
#define DEF_HANDLE_EVENT_PIMPL void handleHiseEvent(HiseEvent& e);
#define DEF_PROCESS_PIMPL void process(ProcessData& data) noexcept;
#define DEF_RESET_PIMPL void reset();
#define DEF_PROCESS_SINGLE_PIMPL void processFrame(float* frameData, int numChannels) noexcept;
#define DEFINE_DSP_METHODS_PIMPL DEF_CONSTRUCTOR; DEF_PIMPL; DEF_PREPARE_PIMPL; DEF_INIT_PIMPL; DEF_HANDLE_MOD_PIMPL; DEF_HANDLE_EVENT_PIMPL; DEF_PROCESS_PIMPL; DEF_RESET_PIMPL; DEF_PROCESS_SINGLE_PIMPL;
#define DEFINE_PIMPL_CLASS(NodeType) struct instance::Impl : public NodeType { };
#define DEFINE_CONSTRUCTOR instance::instance() { pimpl = new Impl(); }
#define DEFINE_DESTRUCTOR instance::~instance() { delete pimpl; }
#define PREPARE_PIMPL void instance::prepare(PrepareSpecs ps) { pimpl->prepare(ps); }
#define INIT_PIMPL void instance::initialise(NodeBase* n) { pimpl->initialise(n); nodeData = n->getValueTree(); um = n->getUndoManager(); }
#define HANDLE_MOD_PIMPL bool instance::handleModulation(double& value) { return pimpl->handleModulation(value); }
#define HANDLE_EVENT_PIMPL void instance::handleHiseEvent(HiseEvent& e) { pimpl->handleHiseEvent(e); }
#define PROCESS_PIMPL void instance::process(ProcessData& data) noexcept { pimpl->process(data); }
#define RESET_PIMPL void instance::reset() { pimpl->reset(); }
#define PROCESS_SINGLE_PIMPL void instance::processFrame(float* frameData, int numChannels) noexcept { pimpl->processFrame(frameData, numChannels); }
#define DSP_METHODS_PIMPL_IMPL(NodeType) DEFINE_PIMPL_CLASS(NodeType); DEFINE_CONSTRUCTOR; DEFINE_DESTRUCTOR; PREPARE_PIMPL; INIT_PIMPL; HANDLE_MOD_PIMPL; HANDLE_EVENT_PIMPL; PROCESS_PIMPL; RESET_PIMPL; PROCESS_SINGLE_PIMPL;
struct HardcodedNodeComponent : public Component
{
public:
HardcodedNodeComponent(HardcodedNode* hc, const StringArray& nodeIds, PooledUIUpdater* updater)
{
int w = 256;
int h = 0;
#if RE
for (auto nId : nodeIds)
{
if (auto node = hc->getNode(nId))
{
auto newComponent = node->createExtraComponent(updater);
newComponent->setSize(w, newComponent->getHeight());
components.add(newComponent);
addAndMakeVisible(newComponent);
h += newComponent->getHeight();
}
}
#endif
setSize(w, h);
}
void resized() override
{
int y = 0;
for (auto c : components)
{
c->setTopLeftPosition(0, y);
y += c->getHeight();
}
}
OwnedArray<Component> components;
};
#endif
#if HISE_INCLUDE_SNEX
#define SET_HISE_BLOCK_CALLBACK(s) static constexpr int BlockCallback = CallbackTypes::s;
#define SET_HISE_FRAME_CALLBACK(s) static constexpr int FrameCallback = CallbackTypes::s;
struct jit_base : public RestorableNode
{
struct Parameter
{
String id;
std::function<void(double)> f;
};
virtual ~jit_base() {};
struct ConsoleDummy
{
template <typename T> void print(const T& value)
{
DBG(value);
}
} Console;
virtual void createParameters()
{
}
void addParameter(String name, const std::function<void(double)>& f)
{
parameters.add({ name, f });
}
Array<Parameter> parameters;
snex::hmath Math;
};
#endif
#if OLD_SCRIPTNODE_CPP
struct hardcoded_base : public HiseDspBase,
public HardcodedNode
{
virtual ~hardcoded_base() {};
int extraHeight = -1;
int extraWidth = -1;
};
#endif
#if OLD_SCRIPTNODE_CPP
struct hardcoded_pimpl : public hardcoded_base
{
virtual ~hardcoded_pimpl() {};
};
template <class DspProcessorType> struct hardcoded : hardcoded_base
{
public:
virtual ~hardcoded() {};
void initialise(NodeBase* n) override
{
obj.initialise(n);
nodeData = n->getValueTree();
um = n->getUndoManager();
}
void prepare(PrepareSpecs ps) {
obj.prepare(ps);
}
bool handleModulation(double& value)
{
return obj.handleModulation(value);
}
void handleHiseEvent(HiseEvent& e) final override
{
obj.handleHiseEvent(e);
}
template <typename ProcessDataType> void process(ProcessDataType& data) noexcept
{
this->obj.process(data);
}
void reset()
{
obj.reset();
}
template <typename FrameDataType> void processFrame(FrameDataType& data) noexcept
{
this->obj.processFrame(data);
}
DspProcessorType obj;
};
#endif
#define SCRIPTNODE_FACTORY(x, id) static NodeBase* createNode(DspNetwork* n, ValueTree d) { return new x(n, d); }; \
static Identifier getStaticId() { return Identifier(id); };
#if 0
struct FilterTestNode : public snex::Types::SnexNodeBase
{
FilterTestNode(const snex::Types::SnexTypeConstructData& cd_) :
SnexNodeBase(cd_)
{
}
template <typename ObjectType> void init()
{
cd.id = cd.id.getChildId(ObjectType::getStaticId());
cd.c.registerExternalComplexType(this);
functionCreator = DefaultFunctionClass(&obj);
}
snex::Types::OpaqueSnexParameter::List getParameterList() override
{
ParameterDataList data;
obj.createParameters(data);
OpaqueSnexParameter::List l;
for (auto& p : data)
{
OpaqueSnexParameter osp;
osp.function = p.dbNew.getFunction();
osp.data.id = p.id;
l.add(osp);
}
return l;
}
/** Override this and return the size of the object. It will be used by the allocator to create the memory. */
size_t getRequiredByteSize() const override
{
return sizeof(obj);
}
Result initialise(InitData d) override
{
memcpy(d.dataPointer, &obj, getRequiredByteSize());
reinterpret_cast<ObjectType*>(d.dataPointer)->initialise(reinterpret_cast<NodeBase*>(cd.nodeParent));
return Result::ok();
}
};
#endif
/** This namespace contains functions that initialise nodes.
It's been put here so that it can acccess the NodeBase type.
*/
namespace init
{
}
struct NodeFactory
{
using CreateCallback = std::function<NodeBase*(DspNetwork*, ValueTree)>;
protected:
struct Item
{
CreateCallback cb;
Identifier id;
};
public:
NodeFactory(DspNetwork* n) :
network(n)
{};
virtual ~NodeFactory() {};
StringArray getModuleList() const
{
StringArray sa;
String prefix = getId().toString() + ".";
for (const auto& item : monoNodes)
{
sa.add(prefix + item.id.toString());
}
return sa;
}
template <class MonoT, class PolyT> void registerPolyNodeRaw()