/
juce_AudioProcessor.h
1601 lines (1225 loc) · 74.9 KB
/
juce_AudioProcessor.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 the JUCE library.
Copyright (c) 2017 - ROLI Ltd.
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 5 End-User License
Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
27th April 2017).
End User License Agreement: www.juce.com/juce-5-licence
Privacy Policy: www.juce.com/juce-5-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
#pragma once
struct PluginBusUtilities;
//==============================================================================
/**
Base class for audio processing filters or plugins.
This is intended to act as a base class of audio filter that is general enough to
be wrapped as a VST, AU, RTAS, etc, or used internally.
It is also used by the plugin hosting code as the wrapper around an instance
of a loaded plugin.
Derive your filter class from this base class, and if you're building a plugin,
you should implement a global function called createPluginFilter() which creates
and returns a new instance of your subclass.
*/
class JUCE_API AudioProcessor
{
protected:
struct BusesProperties;
//==============================================================================
/** Constructor.
This constructor will create a main input and output bus which are diabled
by default. If you need more fine grain control then use the other
constructors.
*/
AudioProcessor();
/** Constructor for multibus AudioProcessors
If your AudioProcessor supports multiple buses than use this constructor
to initialise the bus layouts and bus names of your plug-in.
*/
AudioProcessor (const BusesProperties& ioLayouts);
/** Constructor for AudioProcessors which use layout maps
If your AudioProcessor uses layout maps then use this constructor.
*/
#if JUCE_COMPILER_SUPPORTS_INITIALIZER_LISTS
AudioProcessor (const std::initializer_list<const short[2]>& channelLayoutList)
{
initialise (busesPropertiesFromLayoutArray (layoutListToArray (channelLayoutList)));
}
#else
template <int numLayouts>
AudioProcessor (const short (&channelLayoutList) [numLayouts][2])
{
initialise (busesPropertiesFromLayoutArray (layoutListToArray (channelLayoutList)));
}
#endif
public:
//==============================================================================
enum ProcessingPrecision
{
singlePrecision,
doublePrecision
};
//==============================================================================
/** Destructor. */
virtual ~AudioProcessor();
//==============================================================================
/** Returns the name of this processor. */
virtual const String getName() const = 0;
/** Returns a list of alternative names to use for this processor.
Some hosts truncate the name of your AudioProcessor when there isn't enough
space in the GUI to show the full name. Overriding this method, allows the host
to choose an alternative name (such as an abbreviation) to better fit the
available space.
*/
virtual StringArray getAlternateDisplayNames() const;
//==============================================================================
/** Called before playback starts, to let the filter prepare itself.
The sample rate is the target sample rate, and will remain constant until
playback stops.
You can call getTotalNumInputChannels and getTotalNumOutputChannels
or query the busLayout member variable to find out the number of
channels your processBlock callback must process.
The maximumExpectedSamplesPerBlock value is a strong hint about the maximum
number of samples that will be provided in each block. You may want to use
this value to resize internal buffers. You should program defensively in
case a buggy host exceeds this value. The actual block sizes that the host
uses may be different each time the callback happens: completely variable
block sizes can be expected from some hosts.
@see busLayout, getTotalNumInputChannels, getTotalNumOutputChannels
*/
virtual void prepareToPlay (double sampleRate,
int maximumExpectedSamplesPerBlock) = 0;
/** Called after playback has stopped, to let the filter free up any resources it
no longer needs.
*/
virtual void releaseResources() = 0;
/** Renders the next block.
When this method is called, the buffer contains a number of channels which is
at least as great as the maximum number of input and output channels that
this filter is using. It will be filled with the filter's input data and
should be replaced with the filter's output.
So for example if your filter has a total of 2 input channels and 4 output
channels, then the buffer will contain 4 channels, the first two being filled
with the input data. Your filter should read these, do its processing, and
replace the contents of all 4 channels with its output.
Or if your filter has a total of 5 inputs and 2 outputs, the buffer will have 5
channels, all filled with data, and your filter should overwrite the first 2 of
these with its output. But be VERY careful not to write anything to the last 3
channels, as these might be mapped to memory that the host assumes is read-only!
If your plug-in has more than one input or output buses then the buffer passed
to the processBlock methods will contain a bundle of all channels of each bus.
Use AudiobusLayout::getBusBuffer to obtain an audio buffer for a
particular bus.
Note that if you have more outputs than inputs, then only those channels that
correspond to an input channel are guaranteed to contain sensible data - e.g.
in the case of 2 inputs and 4 outputs, the first two channels contain the input,
but the last two channels may contain garbage, so you should be careful not to
let this pass through without being overwritten or cleared.
Also note that the buffer may have more channels than are strictly necessary,
but you should only read/write from the ones that your filter is supposed to
be using.
The number of samples in these buffers is NOT guaranteed to be the same for every
callback, and may be more or less than the estimated value given to prepareToPlay().
Your code must be able to cope with variable-sized blocks, or you're going to get
clicks and crashes!
Also note that some hosts will occasionally decide to pass a buffer containing
zero samples, so make sure that your algorithm can deal with that!
If the filter is receiving a midi input, then the midiMessages array will be filled
with the midi messages for this block. Each message's timestamp will indicate the
message's time, as a number of samples from the start of the block.
Any messages left in the midi buffer when this method has finished are assumed to
be the filter's midi output. This means that your filter should be careful to
clear any incoming messages from the array if it doesn't want them to be passed-on.
Be very careful about what you do in this callback - it's going to be called by
the audio thread, so any kind of interaction with the UI is absolutely
out of the question. If you change a parameter in here and need to tell your UI to
update itself, the best way is probably to inherit from a ChangeBroadcaster, let
the UI components register as listeners, and then call sendChangeMessage() inside the
processBlock() method to send out an asynchronous message. You could also use
the AsyncUpdater class in a similar way.
@see AudiobusLayout::getBusBuffer
*/
virtual void processBlock (AudioBuffer<float>& buffer,
MidiBuffer& midiMessages) = 0;
/** Renders the next block.
When this method is called, the buffer contains a number of channels which is
at least as great as the maximum number of input and output channels that
this filter is using. It will be filled with the filter's input data and
should be replaced with the filter's output.
So for example if your filter has a combined total of 2 input channels and
4 output channels, then the buffer will contain 4 channels, the first two
being filled with the input data. Your filter should read these, do its
processing, and replace the contents of all 4 channels with its output.
Or if your filter has 5 inputs and 2 outputs, the buffer will have 5 channels,
all filled with data, and your filter should overwrite the first 2 of these
with its output. But be VERY careful not to write anything to the last 3
channels, as these might be mapped to memory that the host assumes is read-only!
If your plug-in has more than one input or output buses then the buffer passed
to the processBlock methods will contain a bundle of all channels of
each bus. Use AudiobusLayout::getBusBuffer to obtain a audio buffer
for a particular bus.
Note that if you have more outputs than inputs, then only those channels that
correspond to an input channel are guaranteed to contain sensible data - e.g.
in the case of 2 inputs and 4 outputs, the first two channels contain the input,
but the last two channels may contain garbage, so you should be careful not to
let this pass through without being overwritten or cleared.
Also note that the buffer may have more channels than are strictly necessary,
but you should only read/write from the ones that your filter is supposed to
be using.
If your plugin uses buses, then you should use AudiobusLayout::getBusBuffer()
or AudiobusLayout::getChannelIndexInProcessBlockBuffer() to find out which
of the input and output channels correspond to which of the buses.
The number of samples in these buffers is NOT guaranteed to be the same for every
callback, and may be more or less than the estimated value given to prepareToPlay().
Your code must be able to cope with variable-sized blocks, or you're going to get
clicks and crashes!
Also note that some hosts will occasionally decide to pass a buffer containing
zero samples, so make sure that your algorithm can deal with that!
If the filter is receiving a midi input, then the midiMessages array will be filled
with the midi messages for this block. Each message's timestamp will indicate the
message's time, as a number of samples from the start of the block.
Any messages left in the midi buffer when this method has finished are assumed to
be the filter's midi output. This means that your filter should be careful to
clear any incoming messages from the array if it doesn't want them to be passed-on.
Be very careful about what you do in this callback - it's going to be called by
the audio thread, so any kind of interaction with the UI is absolutely
out of the question. If you change a parameter in here and need to tell your UI to
update itself, the best way is probably to inherit from a ChangeBroadcaster, let
the UI components register as listeners, and then call sendChangeMessage() inside the
processBlock() method to send out an asynchronous message. You could also use
the AsyncUpdater class in a similar way.
@see AudiobusLayout::getBusBuffer
*/
virtual void processBlock (AudioBuffer<double>& buffer,
MidiBuffer& midiMessages);
/** Renders the next block when the processor is being bypassed.
The default implementation of this method will pass-through any incoming audio, but
you may override this method e.g. to add latency compensation to the data to match
the processor's latency characteristics. This will avoid situations where bypassing
will shift the signal forward in time, possibly creating pre-echo effects and odd timings.
Another use for this method would be to cross-fade or morph between the wet (not bypassed)
and dry (bypassed) signals.
*/
virtual void processBlockBypassed (AudioBuffer<float>& buffer,
MidiBuffer& midiMessages);
/** Renders the next block when the processor is being bypassed.
The default implementation of this method will pass-through any incoming audio, but
you may override this method e.g. to add latency compensation to the data to match
the processor's latency characteristics. This will avoid situations where bypassing
will shift the signal forward in time, possibly creating pre-echo effects and odd timings.
Another use for this method would be to cross-fade or morph between the wet (not bypassed)
and dry (bypassed) signals.
*/
virtual void processBlockBypassed (AudioBuffer<double>& buffer,
MidiBuffer& midiMessages);
//==============================================================================
/**
Represents the bus layout state of a plug-in
*/
struct BusesLayout
{
/** An array containing the list of input buses that this processor supports. */
Array<AudioChannelSet> inputBuses;
/** An array containing the list of output buses that this processor supports. */
Array<AudioChannelSet> outputBuses;
/** Get the number of channels of a particular bus */
int getNumChannels (bool isInput, int busIndex) const noexcept
{
const Array<AudioChannelSet>& bus = (isInput ? inputBuses : outputBuses);
return isPositiveAndBelow (busIndex, bus.size()) ? bus.getReference (busIndex).size() : 0;
}
/** Get the channel set of a particular bus */
AudioChannelSet& getChannelSet (bool isInput, int busIndex)
{
return (isInput ? inputBuses : outputBuses).getReference (busIndex);
}
/** Get the channel set of a particular bus */
AudioChannelSet getChannelSet (bool isInput, int busIndex) const noexcept
{
return (isInput ? inputBuses : outputBuses) [busIndex];
}
/** Get the input channel layout on the main bus. */
AudioChannelSet getMainInputChannelSet() const noexcept { return getChannelSet (true, 0); }
/** Get the output channel layout on the main bus. */
AudioChannelSet getMainOutputChannelSet() const noexcept { return getChannelSet (false, 0); }
/** Get the number of input channels on the main bus. */
int getMainInputChannels() const noexcept { return getNumChannels (true, 0); }
/** Get the number of output channels on the main bus. */
int getMainOutputChannels() const noexcept { return getNumChannels (false, 0); }
bool operator== (const BusesLayout& other) const noexcept { return inputBuses == other.inputBuses && outputBuses == other.outputBuses; }
bool operator!= (const BusesLayout& other) const noexcept { return inputBuses != other.inputBuses || outputBuses != other.outputBuses; }
};
//==============================================================================
/**
Describes the layout and properties of an audio bus.
Effectively a bus description is a named set of channel types.
@see AudioChannelSet, AudioProcessor::addBus
*/
class Bus
{
public:
/** Returns true if this bus is an input bus. */
bool isInput() const;
/** Returns the index of this bus. */
int getBusIndex() const;
/** Returns true if the current bus is the main input or output bus. */
bool isMain() const { return getBusIndex() == 0; }
//==============================================================================
/** The bus's name. */
const String &getName() const noexcept { return name; }
/** Get the default layout of this bus.
@see AudioChannelSet
*/
const AudioChannelSet& getDefaultLayout() const noexcept { return dfltLayout; }
//==============================================================================
/** The bus's current layout. This will be AudioChannelSet::disabled() if the current
layout is dfisabled.
@see AudioChannelSet
*/
const AudioChannelSet& getCurrentLayout() const noexcept { return layout; }
/** Return the bus's last active channel layout.
If the bus is currently enabled then the result will be identical to getCurrentLayout
otherwise it will return the last enabled layout.
@see AudioChannelSet
*/
const AudioChannelSet& getLastEnabledLayout() const noexcept { return lastLayout; }
/** Sets the bus's current layout.
If the AudioProcessor does not support this layout then this will return false.
@see AudioChannelSet
*/
bool setCurrentLayout (const AudioChannelSet& layout);
/** Sets the bus's current layout without changing the enabled state.
If the AudioProcessor does not support this layout then this will return false.
@see AudioChannelSet
*/
bool setCurrentLayoutWithoutEnabling (const AudioChannelSet& layout);
/** Return the number of channels of the current bus. */
inline int getNumberOfChannels() const noexcept { return cachedChannelCount; }
/** Set the number of channles of this bus. This will return false if the AudioProcessor
does not support this layout.
*/
bool setNumberOfChannels (int channels);
//==============================================================================
/** Checks if a particular layout is supported.
@param set The AudioChannelSet which is to be probed.
@param currentLayout If non-null, pretend that the current layout of the AudioProcessor is
currentLayout. On exit, currentLayout will be modified to
to represent the buses layouts of the AudioProcessor as if the layout
of the reciever had been succesfully changed. This is useful as changing
the layout of the reciever may change the bus layout of other buses.
@see AudioChannelSet
*/
bool isLayoutSupported (const AudioChannelSet& set, BusesLayout* currentLayout = nullptr) const;
/** Checks if this bus can support a given number of channels. */
bool isNumberOfChannelsSupported (int channels) const;
/** Returns a ChannelSet that the bus supports with a given number of channels. */
AudioChannelSet supportedLayoutWithChannels (int channels) const;
/** Returns the maximum number of channels that this bus can support.
@param limit The maximum value to return.
*/
int getMaxSupportedChannels (int limit = AudioChannelSet::maxChannelsOfNamedLayout) const;
/** Returns the resulting layouts of all buses after changing the layout of this bus.
Changing an individual layout of a bus may also change the layout of all the other
buses. This method returns what the layouts of all the buses of the audio processor
would be, if you were to change the layout of this bus to the given layout. If there
is no way to support the given layout then this method will return the next best
layout.
*/
BusesLayout getBusesLayoutForLayoutChangeOfBus (const AudioChannelSet& set) const;
//==============================================================================
/** Returns true if the current bus is enabled. */
bool isEnabled() const noexcept { return ! layout.isDisabled(); }
/** Enable or disable this bus. This will return false if the AudioProcessor
does not support disabling this bus. */
bool enable (bool shouldEnable = true);
/** Returns if this bus is enabled by default. */
bool isEnabledByDefault() const noexcept { return enabledByDefault; }
//==============================================================================
/** Returns the position of a bus's channels within the processBlock buffer.
This can be called in processBlock to figure out which channel of the master AudioSampleBuffer
maps onto a specific bus's channel.
*/
int getChannelIndexInProcessBlockBuffer (int channelIndex) const noexcept;
/** Returns an AudioBuffer containing a set of channel pointers for a specific bus.
This can be called in processBlock to get a buffer containing a sub-group of the master
AudioSampleBuffer which contains all the plugin channels.
*/
template <typename FloatType>
AudioBuffer<FloatType> getBusBuffer (AudioBuffer<FloatType>& processBlockBuffer) const
{
bool isIn;
int busIdx;
busDirAndIndex (isIn, busIdx);
return owner.getBusBuffer (processBlockBuffer, isIn, busIdx);
}
private:
friend class AudioProcessor;
Bus (AudioProcessor&, const String&, const AudioChannelSet&, bool);
void busDirAndIndex (bool&, int&) const noexcept;
void updateChannelCount() noexcept;
AudioProcessor& owner;
String name;
AudioChannelSet layout, dfltLayout, lastLayout;
bool enabledByDefault;
int cachedChannelCount;
JUCE_DECLARE_NON_COPYABLE (Bus)
};
//==============================================================================
/** Returns the number of buses on the input or output side */
int getBusCount (bool isInput) const noexcept { return (isInput ? inputBuses : outputBuses).size(); }
/** Returns the audio bus with a given index and direction.
If busIdx is invalid then this method will return a nullptr.
*/
Bus* getBus (bool isInput, int busIdx) noexcept { return (isInput ? inputBuses : outputBuses)[busIdx]; }
/** Returns the audio bus with a given index and direction.
If busIdx is invalid then this method will return a nullptr.
*/
const Bus* getBus (bool isInput, int busIdx) const noexcept { return const_cast<AudioProcessor*> (this)->getBus (isInput, busIdx); }
//==============================================================================
/** Callback to query if a bus can currently be added.
This callback probes if a bus can currently be added. You should override
this callback if you want to support dynamically adding/removing buses by
the host. This is useful for mixer audio processors.
The default implementation will always return false.
@see addBus
*/
virtual bool canAddBus (bool isInput) const { ignoreUnused (isInput); return false; }
/** Callback to query if the last bus can currently be removed.
This callback probes if the last bus can currently be removed. You should
override this callback if you want to support dynamically adding/removing
buses by the host. This is useful for mixer audio processors.
If you return true in this callback then the AudioProcessor will go ahead
and delete the bus.
The default implementation will always return false.
*/
virtual bool canRemoveBus (bool isInput) const { ignoreUnused (isInput); return false; }
/** Dynamically request an additional bus.
Request an additional bus from the audio processor. If the audio processor
does not support adding additional buses then this method will return false.
Most audio processors will not allow you to dynamically add/remove
audio buses and will return false.
This method will invoke the canApplyBusCountChange callback to probe
if a bus can be added and, if yes, will use the supplied bus properties
of the canApplyBusCountChange callback to create a new bus.
@see canApplyBusCountChange, removeBus
*/
bool addBus (bool isInput);
/** Dynamically remove the latest added bus.
Request the removal of the last bus from the audio processor. If the
audio processor does not support removing buses then this method will
return false.
Most audio processors will not allow you to dynamically add/remove
audio buses and will return false.
The default implementation will return false.
This method will invoke the canApplyBusCountChange callback to probe if
a bus can currently be removed and, if yes, will go ahead and remove it.
@see addBus, canRemoveBus
*/
bool removeBus (bool isInput);
//==============================================================================
/** Set the channel layouts of this audio processor.
If the layout is not supported by this audio processor then
this method will return false. You can use the checkBusesLayoutSupported
and getNextBestLayout methods to probe which layouts this audio
processor supports.
*/
bool setBusesLayout (const BusesLayout&);
/** Set the channel layouts of this audio processor without changing the
enablement state of the buses.
If the layout is not supported by this audio processor then
this method will return false. You can use the checkBusesLayoutSupported
methods to probe which layouts this audio processor supports.
*/
bool setBusesLayoutWithoutEnabling (const BusesLayout&);
/** Provides the current channel layouts of this audio processor. */
BusesLayout getBusesLayout() const;
/** Provides the channel layout of the bus with a given index and direction.
If the index, direction combination is invalid then this will return an
AudioChannelSet with no channels.
*/
AudioChannelSet getChannelLayoutOfBus (bool isInput, int busIndex) const noexcept;
/** Set the channel layout of the bus with a given index and direction.
If the index, direction combination is invalid or the layout is not
supported by the audio processor then this method will return false.
*/
bool setChannelLayoutOfBus (bool isInput, int busIdx, const AudioChannelSet& layout);
/** Provides the number of channels of the bus with a given index and direction.
If the index, direction combination is invalid then this will return zero.
*/
inline int getChannelCountOfBus (bool isInput, int busIdx) const noexcept
{
if (const Bus* bus = getBus (isInput, busIdx))
return bus->getNumberOfChannels();
return 0;
}
/** Enables all buses */
bool enableAllBuses();
/** Disables all non-main buses (aux and sidechains). */
bool disableNonMainBuses();
//==============================================================================
/** Returns the position of a bus's channels within the processBlock buffer.
This can be called in processBlock to figure out which channel of the master AudioSampleBuffer
maps onto a specific bus's channel.
*/
int getChannelIndexInProcessBlockBuffer (bool isInput, int busIndex, int channelIndex) const noexcept;
/** Returns the offset in a bus's buffer from an absolute channel indes.
This method returns the offset in a bus's buffer given an absolute channel index.
It also provides the bus index. For example, this method would return one
for a processor with two stereo buses when given the absolute channel index.
*/
int getOffsetInBusBufferForAbsoluteChannelIndex (bool isInput, int absoluteChannelIndex, /*out*/ int& busIdx) const noexcept;
/** Returns an AudioBuffer containing a set of channel pointers for a specific bus.
This can be called in processBlock to get a buffer containing a sub-group of the master
AudioSampleBuffer which contains all the plugin channels.
*/
template <typename FloatType>
AudioBuffer<FloatType> getBusBuffer (AudioBuffer<FloatType>& processBlockBuffer, bool isInput, int busIndex) const
{
const int busNumChannels = getChannelCountOfBus (isInput, busIndex);
const int channelOffset = getChannelIndexInProcessBlockBuffer (isInput, busIndex, 0);
return AudioBuffer<FloatType> (processBlockBuffer.getArrayOfWritePointers() + channelOffset,
busNumChannels, processBlockBuffer.getNumSamples());
}
//==============================================================================
/** Returns true if the Audio processor is likely to support a given layout.
This can be called regardless if the processor is currently running.
*/
bool checkBusesLayoutSupported (const BusesLayout&) const;
//==============================================================================
/** Returns true if the Audio processor supports double precision floating point processing.
The default implementation will always return false.
If you return true here then you must override the double precision versions
of processBlock. Additionally, you must call getProcessingPrecision() in
your prepareToPlay method to determine the precision with which you need to
allocate your internal buffers.
@see getProcessingPrecision, setProcessingPrecision
*/
virtual bool supportsDoublePrecisionProcessing() const;
/** Returns the precision-mode of the processor.
Depending on the result of this method you MUST call the corresponding version
of processBlock. The default processing precision is single precision.
@see setProcessingPrecision, supportsDoublePrecisionProcessing
*/
ProcessingPrecision getProcessingPrecision() const noexcept { return processingPrecision; }
/** Returns true if the current precision is set to doublePrecision. */
bool isUsingDoublePrecision() const noexcept { return processingPrecision == doublePrecision; }
/** Changes the processing precision of the receiver. A client of the AudioProcessor
calls this function to indicate which version of processBlock (single or double
precision) it intends to call. The client MUST call this function before calling
the prepareToPlay method so that the receiver can do any necessary allocations
in the prepareToPlay() method. An implementation of prepareToPlay() should call
getProcessingPrecision() to determine with which precision it should allocate
it's internal buffers.
Note that setting the processing precision to double floating point precision
on a receiver which does not support double precision processing (i.e.
supportsDoublePrecisionProcessing() returns false) will result in an assertion.
@see getProcessingPrecision, supportsDoublePrecisionProcessing
*/
void setProcessingPrecision (ProcessingPrecision newPrecision) noexcept;
//==============================================================================
/** Returns the current AudioPlayHead object that should be used to find
out the state and position of the playhead.
You can ONLY call this from your processBlock() method! Calling it at other
times will produce undefined behaviour, as the host may not have any context
in which a time would make sense, and some hosts will almost certainly have
multithreading issues if it's not called on the audio thread.
The AudioPlayHead object that is returned can be used to get the details about
the time of the start of the block currently being processed. But do not
store this pointer or use it outside of the current audio callback, because
the host may delete or re-use it.
If the host can't or won't provide any time info, this will return nullptr.
*/
AudioPlayHead* getPlayHead() const noexcept { return playHead; }
//==============================================================================
/** Returns the total number of input channels.
This method will return the total number of input channels by accumulating
the number of channels on each input bus. The number of channels of the
buffer passed to your processBlock callback will be equivalent to either
getTotalNumInputChannels or getTotalNumOutputChannels - which ever
is greater.
Note that getTotalNumInputChannels is equivalent to
getMainBusNumInputChannels if your processor does not have any sidechains
or aux buses.
*/
int getTotalNumInputChannels() const noexcept { return cachedTotalIns; }
/** Returns the total number of output channels.
This method will return the total number of output channels by accumulating
the number of channels on each output bus. The number of channels of the
buffer passed to your processBlock callback will be equivalent to either
getTotalNumInputChannels or getTotalNumOutputChannels - which ever
is greater.
Note that getTotalNumOutputChannels is equivalent to
getMainBusNumOutputChannels if your processor does not have any sidechains
or aux buses.
*/
int getTotalNumOutputChannels() const noexcept { return cachedTotalOuts; }
/** Returns the number of input channels on the main bus. */
inline int getMainBusNumInputChannels() const noexcept { return getChannelCountOfBus (true, 0); }
/** Returns the number of output channels on the main bus. */
inline int getMainBusNumOutputChannels() const noexcept { return getChannelCountOfBus (false, 0); }
//==============================================================================
/** Returns true if the channel layout map contains a certain layout.
You can use this method to help you implement the checkBusesLayoutSupported
method. For example
@code
bool checkBusesLayoutSupported (const BusesLayout& layouts) override
{
return containsLayout (layouts, {{1,1},{2,2}});
}
@endcode
*/
#if JUCE_COMPILER_SUPPORTS_INITIALIZER_LISTS
static bool containsLayout (const BusesLayout& layouts, const std::initializer_list<const short[2]>& channelLayoutList)
{
return containsLayout (layouts, layoutListToArray (channelLayoutList));
}
#endif
template <int numLayouts>
static bool containsLayout (const BusesLayout& layouts, const short (&channelLayoutList) [numLayouts][2])
{
return containsLayout (layouts, layoutListToArray (channelLayoutList));
}
/** Returns the next best layout which is contained in a channel layout map.
You can use this mehtod to help you implement getNextBestLayout. For example:
@code
BusesLayout getNextBestLayout (const BusesLayout& layouts) override
{
return getNextBestLayoutInLayoutList (layouts, {{1,1},{2,2}});
}
@endcode
*/
template <int numLayouts>
BusesLayout getNextBestLayoutInLayoutList (const BusesLayout& layouts,
const short (&channelLayoutList) [numLayouts][2])
{
return getNextBestLayoutInList (layouts, layoutListToArray (channelLayoutList));
}
//==============================================================================
/** Returns the current sample rate.
This can be called from your processBlock() method - it's not guaranteed
to be valid at any other time, and may return 0 if it's unknown.
*/
double getSampleRate() const noexcept { return currentSampleRate; }
/** Returns the current typical block size that is being used.
This can be called from your processBlock() method - it's not guaranteed
to be valid at any other time.
Remember it's not the ONLY block size that may be used when calling
processBlock, it's just the normal one. The actual block sizes used may be
larger or smaller than this, and will vary between successive calls.
*/
int getBlockSize() const noexcept { return blockSize; }
//==============================================================================
/** This returns the number of samples delay that the filter imposes on the audio
passing through it.
The host will call this to find the latency - the filter itself should set this value
by calling setLatencySamples() as soon as it can during its initialisation.
*/
int getLatencySamples() const noexcept { return latencySamples; }
/** The filter should call this to set the number of samples delay that it introduces.
The filter should call this as soon as it can during initialisation, and can call it
later if the value changes.
*/
void setLatencySamples (int newLatency);
/** Returns the length of the filter's tail, in seconds. */
virtual double getTailLengthSeconds() const = 0;
/** Returns true if the processor wants midi messages. */
virtual bool acceptsMidi() const = 0;
/** Returns true if the processor produces midi messages. */
virtual bool producesMidi() const = 0;
/** Returns true if the processor supports MPE. */
virtual bool supportsMPE() const { return false; }
/** Returns true if this is a midi effect plug-in and does no audio processing. */
virtual bool isMidiEffect() const { return false; }
//==============================================================================
/** This returns a critical section that will automatically be locked while the host
is calling the processBlock() method.
Use it from your UI or other threads to lock access to variables that are used
by the process callback, but obviously be careful not to keep it locked for
too long, because that could cause stuttering playback. If you need to do something
that'll take a long time and need the processing to stop while it happens, use the
suspendProcessing() method instead.
@see suspendProcessing
*/
const CriticalSection& getCallbackLock() const noexcept { return callbackLock; }
/** Enables and disables the processing callback.
If you need to do something time-consuming on a thread and would like to make sure
the audio processing callback doesn't happen until you've finished, use this
to disable the callback and re-enable it again afterwards.
E.g.
@code
void loadNewPatch()
{
suspendProcessing (true);
..do something that takes ages..
suspendProcessing (false);
}
@endcode
If the host tries to make an audio callback while processing is suspended, the
filter will return an empty buffer, but won't block the audio thread like it would
do if you use the getCallbackLock() critical section to synchronise access.
Any code that calls processBlock() should call isSuspended() before doing so, and
if the processor is suspended, it should avoid the call and emit silence or
whatever is appropriate.
@see getCallbackLock
*/
void suspendProcessing (bool shouldBeSuspended);
/** Returns true if processing is currently suspended.
@see suspendProcessing
*/
bool isSuspended() const noexcept { return suspended; }
/** A plugin can override this to be told when it should reset any playing voices.
The default implementation does nothing, but a host may call this to tell the
plugin that it should stop any tails or sounds that have been left running.
*/
virtual void reset();
//==============================================================================
/** Returns true if the processor is being run in an offline mode for rendering.
If the processor is being run live on realtime signals, this returns false.
If the mode is unknown, this will assume it's realtime and return false.
This value may be unreliable until the prepareToPlay() method has been called,
and could change each time prepareToPlay() is called.
@see setNonRealtime()
*/
bool isNonRealtime() const noexcept { return nonRealtime; }
/** Called by the host to tell this processor whether it's being used in a non-realtime
capacity for offline rendering or bouncing.
*/
virtual void setNonRealtime (bool isNonRealtime) noexcept;
//==============================================================================
/** Creates the filter's UI.
This can return nullptr if you want a UI-less filter, in which case the host may create
a generic UI that lets the user twiddle the parameters directly.
If you do want to pass back a component, the component should be created and set to
the correct size before returning it. If you implement this method, you must
also implement the hasEditor() method and make it return true.
Remember not to do anything silly like allowing your filter to keep a pointer to
the component that gets created - it could be deleted later without any warning, which
would make your pointer into a dangler. Use the getActiveEditor() method instead.
The correct way to handle the connection between an editor component and its
filter is to use something like a ChangeBroadcaster so that the editor can
register itself as a listener, and be told when a change occurs. This lets them
safely unregister themselves when they are deleted.
Here are a few things to bear in mind when writing an editor:
- Initially there won't be an editor, until the user opens one, or they might
not open one at all. Your filter mustn't rely on it being there.
- An editor object may be deleted and a replacement one created again at any time.
- It's safe to assume that an editor will be deleted before its filter.
@see hasEditor
*/
virtual AudioProcessorEditor* createEditor() = 0;
/** Your filter must override this and return true if it can create an editor component.
@see createEditor
*/
virtual bool hasEditor() const = 0;
//==============================================================================
/** Returns the active editor, if there is one.
Bear in mind this can return nullptr, even if an editor has previously been opened.
*/
AudioProcessorEditor* getActiveEditor() const noexcept { return activeEditor; }
/** Returns the active editor, or if there isn't one, it will create one.
This may call createEditor() internally to create the component.
*/
AudioProcessorEditor* createEditorIfNeeded();
//==============================================================================
/** This must return the correct value immediately after the object has been
created, and mustn't change the number of parameters later.
NOTE! This method will eventually be deprecated! It's recommended that you use the
AudioProcessorParameter class instead to manage your parameters.
*/
virtual int getNumParameters();
/** Returns the name of a particular parameter.
NOTE! This method will eventually be deprecated! It's recommended that you use the
AudioProcessorParameter class instead to manage your parameters.
*/
virtual const String getParameterName (int parameterIndex);
/** Returns the ID of a particular parameter.
The ID is used to communicate the value or mapping of a particular parameter with
the host. By default this method will simply return a string representation of
index.
NOTE! This method will eventually be deprecated! It's recommended that you use the
AudioProcessorParameterWithID class instead to manage your parameters.
*/
virtual String getParameterID (int index);
/** Called by the host to find out the value of one of the filter's parameters.
The host will expect the value returned to be between 0 and 1.0.
This could be called quite frequently, so try to make your code efficient.
It's also likely to be called by non-UI threads, so the code in here should
be thread-aware.
NOTE! This method will eventually be deprecated! It's recommended that you use the
AudioProcessorParameter class instead to manage your parameters.
*/
virtual float getParameter (int parameterIndex);
/** Returns the name of a parameter as a text string with a preferred maximum length.
If you want to provide customised short versions of your parameter names that
will look better in constrained spaces (e.g. the displays on hardware controller
devices or mixing desks) then you should implement this method.
If you don't override it, the default implementation will call getParameterName(int),
and truncate the result.
NOTE! This method will eventually be deprecated! It's recommended that you use
AudioProcessorParameter::getName() instead.