iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
SynthVoice.h
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the iPlug 2 library. Copyright (C) the iPlug 2 developers.
5
6 See LICENSE.txt for more info.
7
8 ==============================================================================
9 */
10
11#pragma once
12
18#include <array>
19#include <vector>
20#include <stdint.h>
21
22#include "ptrlist.h"
23
24#include "IPlugConstants.h"
25#include "IPlugMidi.h"
26#include "IPlugLogger.h"
27
28#include "IPlugQueue.h"
29#include "ControlRamp.h"
30
31BEGIN_IPLUG_NAMESPACE
32
35{
38 {
39 kVoiceControlGate = 0,
40 kVoiceControlPitch,
41 kVoiceControlPitchBend,
42 kVoiceControlPressure,
43 kVoiceControlTimbre,
44 kNumVoiceControlRamps
45 };
46}
47
48using namespace voiceControlNames;
49
50using VoiceInputs = ControlRamp::RampArray<kNumVoiceControlRamps>;
51
52#pragma mark - Voice class
53
55{
56public:
57
58 virtual ~SynthVoice() {};
59
61 virtual bool GetBusy() const = 0;
62
66 virtual void Trigger(double level, bool isRetrigger) {};
67
69 virtual void Release() {};
70
78 virtual void ProcessSamplesAccumulating(sample** inputs, sample** outputs, int nInputs, int nOutputs, int startIdx, int nFrames)
79 {
80 for (auto c = 0; c < nOutputs; c++)
81 {
82 for (auto s = startIdx; s < startIdx + nFrames; s++)
83 {
84 outputs[c][s] += 0.; // if you are following this no-op example, remember you need to accumulate the output of all the different voices
85 }
86 }
87 }
88
92 virtual void SetSampleRateAndBlockSize(double sampleRate, int blockSize) {};
93
96 virtual void SetProgramNumber(int pgm) {};
97
102 virtual void SetControl(int controlNumber, float value) {};
103
104protected:
105 VoiceInputs mInputs;
106 int64_t mLastTriggeredTime{-1};
107 uint8_t mVoiceNumber{0};
108 uint8_t mZone{0};
109 uint8_t mChannel{0};
110 uint8_t mKey{0};
111 double mBasePitch{0.};
112 double mGain{0.}; // used by voice allocator to hard-kill voices.
113
114 friend class MidiSynth;
115 friend class VoiceAllocator;
116};
117
118END_IPLUG_NAMESPACE
IPlug Constant definitions, Types, magic numbers.
IPlug logging a.k.a tracing functionality.
MIDI and sysex structs/utilites.
A monophonic/polyphonic synthesiser base class which can be supplied with a custom voice.
Definition: MidiSynth.h:38
virtual void ProcessSamplesAccumulating(sample **inputs, sample **outputs, int nInputs, int nOutputs, int startIdx, int nFrames)
Process a block of audio data for the voice.
Definition: SynthVoice.h:78
virtual void Trigger(double level, bool isRetrigger)
Trigger is called by the VoiceAllocator when a new voice should start, or if the voice limit has been...
Definition: SynthVoice.h:66
virtual void Release()
As with Trigger, called to do optional tasks when a voice is released.
Definition: SynthVoice.h:69
virtual void SetControl(int controlNumber, float value)
Implement this to respond to control numbers for which there are not ramps.
Definition: SynthVoice.h:102
virtual bool GetBusy() const =0
virtual void SetProgramNumber(int pgm)
Implement this to allow picking a sound program from an integer index, as with MIDI.
Definition: SynthVoice.h:96
virtual void SetSampleRateAndBlockSize(double sampleRate, int blockSize)
Implement this if you need to do work when the sample rate or block size changes.
Definition: SynthVoice.h:92
A generic synthesizer voice to be controlled by a voice allocator.
Definition: SynthVoice.h:35
eControlNames
This enum names the control ramps by which we connect a controller to a synth voice.
Definition: SynthVoice.h:38