C++ API Reference RNBO: src/RNBO_CoreObject.h Source File

RNBO: src/RNBO_CoreObject.h Source File

1 #ifndef _RNBO_CoreObject_h_
2 #define _RNBO_CoreObject_h_
3 
4 #if defined(USE_DYNAMIC_COMPILATION)
5 #include <memory>
6 #endif
7 
8 #include "RNBO_Types.h"
9 #include "RNBO_BaseInterface.h"
10 #include "RNBO_ProbingInterface.h"
11 #include "RNBO_ParameterEventInterface.h"
12 #include "RNBO_EventVariant.h"
13 #include "RNBO_List.h"
14 #include "RNBO_Array.h"
15 #include "RNBO_ExternalData.h"
16 #include "RNBO_DataRef.h"
17 #include "RNBO_AudioBufferConverter.h"
18 #include "RNBO_EventList.h"
19 #include "RNBO_Presets.h"
20 #include "RNBO_PresetList.h"
21 #include "RNBO_DataRefList.h"
22 
23 //#define RNBO_SIMPLEENGINE
24 
25 namespace RNBO {
26 
27  class FileChangeWatcher;
28 #ifdef RNBO_SIMPLEENGINE
29  class EngineCore;
30 #else
31  class Engine;
32 #endif
33  class EventHandler;
34  class PatcherChangedHandler;
35 
42  class CoreObject : public BaseInterface, public ProbingInterface {
43 
44  public:
45 
54  CoreObject(EventHandler* handler = nullptr);
55 
65  CoreObject(UniquePtr<PatcherInterface> patcher, EventHandler* handler = nullptr);
66  virtual ~CoreObject();
67 
68  CoreObject(const CoreObject& other) = delete;
69  CoreObject& operator=(const CoreObject& other) = delete;
70 
71  CoreObject(CoreObject&& other) = default;
72  CoreObject& operator=(CoreObject&& other) = default;
73 
74 
75  /* Parameter Interface */
76 
86  ParameterIndex getNumParameters() const override;
87 
95 
110 
117  void getParameterInfo(ParameterIndex index, ParameterInfo* info) const override;
118 
124 
132  void setParameterValue(ParameterIndex index, ParameterValue value, MillisecondTime time = RNBOTimeNow) override;
133 
141  void setParameterValueNormalized(ParameterIndex index, ParameterValue normalizedValue, MillisecondTime time = RNBOTimeNow) override;
142 
151 
160 
171 
188 
199  void scheduleEvent(EventVariant event);
200 
214  void sendMessage(MessageTag tag, number payload, MessageTag objectId = 0, MillisecondTime eventTime = RNBOTimeNow);
215 
232  void sendMessage(MessageTag tag, UniqueListPtr payload, MessageTag objectId = 0, MillisecondTime eventTime = RNBOTimeNow);
233 
246  void sendMessage(MessageTag tag, MessageTag objectId = 0, MillisecondTime eventTime = RNBOTimeNow);
247 
255 
260 
268 
272  Index getNumMidiInputPorts() const override;
273 
277  Index getNumMidiOutputPorts() const override;
278 
279  /* External Data Interface */
280 
281  // use the below functions to iterate through the list of external memory references (for example after you received a
282  // patcher changed notification) - be aware that the indices will only stay valid until the next patcher rebuild
283 
292 
302 
312 
335  void setExternalData(ExternalDataId memoryId, char *data, size_t sizeInBytes, DataType type, ReleaseCallback callback = nullptr);
336 
347 
360 
361 
362  /* Processing Interface */
363 
368 
373 
388  bool prepareToProcess(number sampleRate, Index maxBlockSize, bool force = false);
389 
398 
410 
423  void process(const SampleValue* const * audioInputs, Index numInputs,
424  SampleValue* const * audioOutputs, Index numOutputs,
425  Index sampleFrames,
426  const MidiEventList* midiInput = nullptr, MidiEventList* midiOutput = nullptr);
427 
445  template <typename I, typename O>
446  void process(I audioInputs, Index numInputs,
447  O audioOutputs, Index numOutputs,
448  Index sampleFrames,
449  const MidiEventList* midiInput = nullptr,
450  MidiEventList* midiOutput = nullptr)
451  {
452  AudioInBufferConverter<I> audioInBuffer(audioInputs, numInputs, sampleFrames, &_audioInData);
453  AudioOutBufferConverter<O> audioOutBuffer(audioOutputs, numOutputs, sampleFrames, &_audioOutData);
454 
455  process(audioInBuffer.getReadBuffers(), numInputs,
456  audioOutBuffer.getWriteBuffers(), numOutputs,
457  sampleFrames,
458  midiInput, midiOutput);
459  }
460 
461 
465  Index getNumInputChannels() const override;
466 
470  Index getNumOutputChannels() const override;
471 
480 
489 
490 
491  /* Setting a new patcher */
492 
500  bool setPatcher();
501 
511 
518 
527 
536  void getPreset(PresetCallback callback);
537 
546 
547 #ifndef RNBO_FEATURE_NO_SETPATCHER
548 
557 #endif
558 
559 
560  // Probing interface
561 
569 
578  Index getProbingChannels(MessageTag outletId) const override;
579 
580  protected:
581 
582  void initializeEngine(EventHandler* handler);
583 
584 #ifdef RNBO_SIMPLEENGINE
585  UniquePtr<EngineCore> _engine;
586 #else
587  UniquePtr<Engine> _engine;
588 #endif
589 
590  private:
591  ParameterEventInterfaceUniquePtr _parameterInterface;
592 #ifdef USE_DYNAMIC_COMPILATION
593  void initializeFileWatcher(const char* fullPathToCPPSource);
594  void fileChanged();
595  std::unique_ptr<FileChangeWatcher> _fileWatcher;
596 #endif
597 
598  AudioBufferConverterData _audioInData;
599  AudioBufferConverterData _audioOutData;
600  };
601 
603  {
604  public:
605  virtual ~PatcherChangedHandler() {}
606 
607  virtual void patcherChanged() = 0;
608  };
609 
610 } // namespace RNBO
611 
612 #endif // #ifndef _RNBO_CoreObject_h_