1
+ // Copyright Epic Games, Inc. All Rights Reserved.
2
+
3
+ #include " CoreMinimal.h"
4
+ #include " MetasoundExecutableOperator.h"
5
+ #include " MetasoundFacade.h"
6
+ #include " MetasoundNodeInterface.h"
7
+ #include " MetasoundParamHelper.h"
8
+ #include " MetasoundSampleCounter.h"
9
+ #include " MetasoundStandardNodesCategories.h"
10
+ #include " MetasoundVertex.h"
11
+
12
+ #include " HarmonixMetasound/DataTypes/MidiStream.h"
13
+ #include " HarmonixMetasound/DataTypes/MusicTransport.h"
14
+ // #include "MidiStreamTrackIsolatorNode.h"
15
+
16
+ #include " SfizzSynthNode.h"
17
+ // #include "MidiTrackIsolator.h"
18
+
19
+ #define LOCTEXT_NAMESPACE " Sfizz4Unreal_SfizzSyntNode"
20
+
21
+ namespace Sfizz4Unreal ::SfizzSynthNode
22
+ {
23
+ using namespace Metasound ;
24
+ using namespace HarmonixMetasound ;
25
+
26
+ const FNodeClassName& GetClassName ()
27
+ {
28
+ static FNodeClassName ClassName
29
+ {
30
+ " Sfizz" ,
31
+ " SfizzSynth" ,
32
+ " "
33
+ };
34
+ return ClassName;
35
+ }
36
+
37
+ int32 GetCurrentMajorVersion ()
38
+ {
39
+ return 1 ;
40
+ }
41
+
42
+ namespace Inputs
43
+ {
44
+ DEFINE_INPUT_METASOUND_PARAM (Enable, " Enable" , " Enable" );
45
+ DEFINE_INPUT_METASOUND_PARAM (MidiStream, " MidiStream" , " MidiStream" );
46
+ DEFINE_INPUT_METASOUND_PARAM (MinTrackIndex, " Track Index" , " Track" );
47
+ DEFINE_INPUT_METASOUND_PARAM (MaxTrackIndex, " Channel Index" , " Channel" );
48
+ DEFINE_INPUT_METASOUND_PARAM (MidiDeviceName, " Midi Device Name" , " The name of the midi input device we want to receive with this node" )
49
+ // DEFINE_INPUT_METASOUND_PARAM(IncludeConductorTrack, "Include Conductor Track", "Enable to include the conductor track (AKA track 0)");
50
+ }
51
+
52
+ namespace Outputs
53
+ {
54
+ DEFINE_OUTPUT_METASOUND_PARAM (MidiStream, " MidiStream" , " MidiStream" );
55
+ }
56
+
57
+ class FSfizzSynthMetasoundOperator final : public TExecutableOperator<FSfizzSynthMetasoundOperator>
58
+ {
59
+ public:
60
+ static const FNodeClassMetadata& GetNodeInfo ()
61
+ {
62
+ auto InitNodeInfo = []() -> FNodeClassMetadata
63
+ {
64
+ FNodeClassMetadata Info;
65
+ Info.ClassName = GetClassName ();
66
+ Info.MajorVersion = 1 ;
67
+ Info.MinorVersion = 0 ;
68
+ Info.DisplayName = INVTEXT (" Sfizz Sampler" );
69
+ Info.Description = INVTEXT (" Renders MIDI Stream to audio data using Sfizz" );
70
+ Info.Author = PluginAuthor;
71
+ Info.PromptIfMissing = PluginNodeMissingPrompt;
72
+ Info.DefaultInterface = GetVertexInterface ();
73
+ Info.CategoryHierarchy = { INVTEXT (" Sfizz" ), NodeCategories::Music };
74
+ return Info;
75
+ };
76
+
77
+ static const FNodeClassMetadata Info = InitNodeInfo ();
78
+
79
+ return Info;
80
+ }
81
+
82
+ static const FVertexInterface& GetVertexInterface ()
83
+ {
84
+ static const FVertexInterface Interface (
85
+ FInputVertexInterface (
86
+ TInputDataVertex<bool >(METASOUND_GET_PARAM_NAME_AND_METADATA (Inputs::Enable), true ),
87
+ TInputDataVertex<FMidiStream>(METASOUND_GET_PARAM_NAME_AND_METADATA (Inputs::MidiStream)),
88
+ TInputDataVertex<int32>(METASOUND_GET_PARAM_NAME_AND_METADATA (Inputs::MinTrackIndex), 0 ),
89
+ TInputDataVertex<int32>(METASOUND_GET_PARAM_NAME_AND_METADATA (Inputs::MaxTrackIndex), 0 ),
90
+ TInputDataVertex<FString>(METASOUND_GET_PARAM_NAME_AND_METADATA (Inputs::MidiDeviceName))
91
+ // TInputDataVertex<bool>(METASOUND_GET_PARAM_NAME_AND_METADATA(Inputs::IncludeConductorTrack), false)
92
+ ),
93
+ FOutputVertexInterface (
94
+ TOutputDataVertex<FMidiStream>(METASOUND_GET_PARAM_NAME_AND_METADATA (Outputs::MidiStream))
95
+ )
96
+ );
97
+
98
+ return Interface;
99
+ }
100
+
101
+ struct FInputs
102
+ {
103
+ FBoolReadRef Enabled;
104
+ FMidiStreamReadRef MidiStream;
105
+ FInt32ReadRef MinTrackIndex;
106
+ FInt32ReadRef MaxTrackIndex;
107
+ FStringReadRef MidiDeviceName;
108
+ // FBoolReadRef IncludeConductorTrack;
109
+ };
110
+
111
+ struct FOutputs
112
+ {
113
+ FMidiStreamWriteRef MidiStream;
114
+ };
115
+
116
+ static TUniquePtr<IOperator> CreateOperator (const FBuildOperatorParams& InParams, FBuildResults& OutResults)
117
+ {
118
+ const FInputVertexInterfaceData& InputData = InParams.InputData ;
119
+
120
+ FInputs Inputs
121
+ {
122
+ InputData.GetOrCreateDefaultDataReadReference <bool >(Inputs::EnableName, InParams.OperatorSettings ),
123
+ InputData.GetOrConstructDataReadReference <FMidiStream>(Inputs::MidiStreamName),
124
+ InputData.GetOrCreateDefaultDataReadReference <int32>(Inputs::MinTrackIndexName, InParams.OperatorSettings ),
125
+ InputData.GetOrCreateDefaultDataReadReference <int32>(Inputs::MaxTrackIndexName, InParams.OperatorSettings ),
126
+ InputData.GetOrCreateDefaultDataReadReference <FString>(Inputs::MidiDeviceNameName, InParams.OperatorSettings )
127
+ // InputData.GetOrCreateDefaultDataReadReference<bool>(Inputs::IncludeConductorTrackName, InParams.OperatorSettings)
128
+ };
129
+
130
+ FOutputs Outputs
131
+ {
132
+ FMidiStreamWriteRef::CreateNew ()
133
+ };
134
+
135
+ return MakeUnique<FSfizzSynthMetasoundOperator>(InParams, MoveTemp (Inputs), MoveTemp (Outputs));
136
+ }
137
+
138
+ FSfizzSynthMetasoundOperator (const FBuildOperatorParams& InParams, FInputs&& InInputs, FOutputs&& InOutputs)
139
+ : Inputs(MoveTemp(InInputs))
140
+ , Outputs(MoveTemp(InOutputs))
141
+ {
142
+ Reset (InParams);
143
+ }
144
+
145
+ virtual void BindInputs (FInputVertexInterfaceData& InVertexData) override
146
+ {
147
+ InVertexData.BindReadVertex (Inputs::EnableName, Inputs.Enabled );
148
+ InVertexData.BindReadVertex (Inputs::MidiStreamName, Inputs.MidiStream );
149
+ InVertexData.BindReadVertex (Inputs::MinTrackIndexName, Inputs.MinTrackIndex );
150
+ InVertexData.BindReadVertex (Inputs::MaxTrackIndexName, Inputs.MaxTrackIndex );
151
+ InVertexData.BindReadVertex (Inputs::MidiDeviceNameName, Inputs.MidiDeviceName );
152
+ // InVertexData.BindReadVertex(Inputs::IncludeConductorTrackName, Inputs.IncludeConductorTrack);
153
+ }
154
+
155
+ virtual void BindOutputs (FOutputVertexInterfaceData& InVertexData) override
156
+ {
157
+ InVertexData.BindReadVertex (Outputs::MidiStreamName, Outputs.MidiStream );
158
+ }
159
+
160
+ void Reset (const FResetParams&)
161
+ {
162
+
163
+ }
164
+
165
+
166
+ // destructor
167
+ virtual ~FSfizzSynthMetasoundOperator ()
168
+ {
169
+ UE_LOG (LogTemp, Log, TEXT (" Sfizz Synth Node Destructor" ));
170
+
171
+ }
172
+
173
+
174
+ void Execute ()
175
+ {
176
+ // Filter.SetFilterValues(*Inputs.MinTrackIndex, *Inputs.MaxTrackIndex, false);
177
+
178
+ Outputs.MidiStream ->PrepareBlock ();
179
+
180
+ if (*Inputs.Enabled )
181
+ {
182
+ // stream current tick?
183
+ // int32 CurrentTick = Inputs.MidiStream->GetClock()->GetCurrentMidiTick();
184
+ // Inputs.MidiStream->Add
185
+
186
+ PendingMessages.Empty ();
187
+ // Filter.Process(*Inputs.MidiStream, *Outputs.MidiStream);
188
+ }
189
+ }
190
+ private:
191
+ FInputs Inputs;
192
+ FOutputs Outputs;
193
+
194
+ FDelegateHandle RawEventDelegateHandle;
195
+ int32 TickOffset = 0 ; // in theory we can start when the stream tick is different from the device tick, we'll see
196
+ TArray<TTuple<int32, FMidiMsg>> PendingMessages;
197
+ // unDAWMetasounds::TrackIsolatorOP::FMidiTrackIsolator Filter;
198
+ };
199
+
200
+ class FSfizzSynthNode final : public FNodeFacade
201
+ {
202
+ public:
203
+ explicit FSfizzSynthNode (const FNodeInitData& InInitData)
204
+ : FNodeFacade(InInitData.InstanceName, InInitData.InstanceID, TFacadeOperatorClass<FSfizzSynthMetasoundOperator>())
205
+ {}
206
+ virtual ~FSfizzSynthNode () override = default ;
207
+ };
208
+
209
+ METASOUND_REGISTER_NODE (FSfizzSynthNode)
210
+ }
211
+
212
+ #undef LOCTEXT_NAMESPACE // "HarmonixMetaSound"
0 commit comments