OpenShot Audio Library | OpenShotAudio 0.4.0
 
Loading...
Searching...
No Matches
juce_Sampler.h
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
29//==============================================================================
43class JUCE_API SamplerSound : public SynthesiserSound
44{
45public:
46 //==============================================================================
65 SamplerSound (const String& name,
66 AudioFormatReader& source,
67 const BigInteger& midiNotes,
68 int midiNoteForNormalPitch,
69 double attackTimeSecs,
70 double releaseTimeSecs,
71 double maxSampleLengthSeconds);
72
74 ~SamplerSound() override;
75
76 //==============================================================================
78 const String& getName() const noexcept { return name; }
79
83 AudioBuffer<float>* getAudioData() const noexcept { return data.get(); }
84
85 //==============================================================================
87 void setEnvelopeParameters (ADSR::Parameters parametersToUse) { params = parametersToUse; }
88
89 //==============================================================================
90 bool appliesToNote (int midiNoteNumber) override;
91 bool appliesToChannel (int midiChannel) override;
92
93private:
94 //==============================================================================
95 friend class SamplerVoice;
96
97 String name;
98 std::unique_ptr<AudioBuffer<float>> data;
99 double sourceSampleRate;
100 BigInteger midiNotes;
101 int length = 0, midiRootNote = 0;
102
103 ADSR::Parameters params;
104
105 JUCE_LEAK_DETECTOR (SamplerSound)
106};
107
108
109//==============================================================================
120class JUCE_API SamplerVoice : public SynthesiserVoice
121{
122public:
123 //==============================================================================
125 SamplerVoice();
126
128 ~SamplerVoice() override;
129
130 //==============================================================================
131 bool canPlaySound (SynthesiserSound*) override;
132
133 void startNote (int midiNoteNumber, float velocity, SynthesiserSound*, int pitchWheel) override;
134 void stopNote (float velocity, bool allowTailOff) override;
135
136 void pitchWheelMoved (int newValue) override;
137 void controllerMoved (int controllerNumber, int newValue) override;
138
139 void renderNextBlock (AudioBuffer<float>&, int startSample, int numSamples) override;
141
142private:
143 //==============================================================================
144 double pitchRatio = 0;
145 double sourceSamplePosition = 0;
146 float lgain = 0, rgain = 0;
147
148 ADSR adsr;
149
150 JUCE_LEAK_DETECTOR (SamplerVoice)
151};
152
153} // namespace juce
SamplerSound(const String &name, AudioFormatReader &source, const BigInteger &midiNotes, int midiNoteForNormalPitch, double attackTimeSecs, double releaseTimeSecs, double maxSampleLengthSeconds)
AudioBuffer< float > * getAudioData() const noexcept
void setEnvelopeParameters(ADSR::Parameters parametersToUse)
const String & getName() const noexcept
void startNote(int midiNoteNumber, float velocity, SynthesiserSound *, int pitchWheel) override
void controllerMoved(int controllerNumber, int newValue) override
bool canPlaySound(SynthesiserSound *) override
void renderNextBlock(AudioBuffer< float > &, int startSample, int numSamples) override
void pitchWheelMoved(int newValue) override
void stopNote(float velocity, bool allowTailOff) override
virtual void renderNextBlock(AudioBuffer< float > &outputBuffer, int startSample, int numSamples)=0