OpenShot Audio Library | OpenShotAudio: juce_MPESynthesiserBase.cpp Source File

OpenShot Audio Library | OpenShotAudio 0.3.2

Loading...
Searching...
No Matches
juce_MPESynthesiserBase.cpp
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2017 - ROLI Ltd.
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
26MPESynthesiserBase::MPESynthesiserBase()
27 : instrument (new MPEInstrument)
28{
29 instrument->addListener (this);
30}
31
32 MPESynthesiserBase::MPESynthesiserBase (MPEInstrument* inst)
33 : instrument (inst)
34{
35 jassert (instrument != nullptr);
36 instrument->addListener (this);
37}
38
39//==============================================================================
40 MPEZoneLayout MPESynthesiserBase::getZoneLayout() const noexcept
41{
42 return instrument->getZoneLayout();
43}
44
45 void MPESynthesiserBase::setZoneLayout (MPEZoneLayout newLayout)
46{
47 instrument->setZoneLayout (newLayout);
48}
49
50//==============================================================================
51 void MPESynthesiserBase::enableLegacyMode (int pitchbendRange, Range<int> channelRange)
52{
53 instrument->enableLegacyMode (pitchbendRange, channelRange);
54}
55
56 bool MPESynthesiserBase::isLegacyModeEnabled() const noexcept
57{
58 return instrument->isLegacyModeEnabled();
59}
60
61 Range<int> MPESynthesiserBase::getLegacyModeChannelRange() const noexcept
62{
63 return instrument->getLegacyModeChannelRange();
64}
65
66 void MPESynthesiserBase::setLegacyModeChannelRange (Range<int> channelRange)
67{
68 instrument->setLegacyModeChannelRange (channelRange);
69}
70
71 int MPESynthesiserBase::getLegacyModePitchbendRange() const noexcept
72{
73 return instrument->getLegacyModePitchbendRange();
74}
75
76 void MPESynthesiserBase::setLegacyModePitchbendRange (int pitchbendRange)
77{
78 instrument->setLegacyModePitchbendRange (pitchbendRange);
79}
80
81//==============================================================================
82 void MPESynthesiserBase::setPressureTrackingMode (TrackingMode modeToUse)
83{
84 instrument->setPressureTrackingMode (modeToUse);
85}
86
87 void MPESynthesiserBase::setPitchbendTrackingMode (TrackingMode modeToUse)
88{
89 instrument->setPitchbendTrackingMode (modeToUse);
90}
91
92 void MPESynthesiserBase::setTimbreTrackingMode (TrackingMode modeToUse)
93{
94 instrument->setTimbreTrackingMode (modeToUse);
95}
96
97//==============================================================================
98 void MPESynthesiserBase::handleMidiEvent (const MidiMessage& m)
99{
100 instrument->processNextMidiEvent (m);
101}
102
103//==============================================================================
104template <typename floatType>
105 void MPESynthesiserBase::renderNextBlock (AudioBuffer<floatType>& outputAudio,
106 const MidiBuffer& inputMidi,
107 int startSample,
108 int numSamples)
109{
110 // you must set the sample rate before using this!
111 jassert (sampleRate != 0);
112
113 MidiBuffer::Iterator midiIterator (inputMidi);
114 midiIterator.setNextSamplePosition (startSample);
115
116 bool firstEvent = true;
117 int midiEventPos;
118 MidiMessage m;
119
120 const ScopedLock sl (noteStateLock);
121
122 while (numSamples > 0)
123 {
124 if (! midiIterator.getNextEvent (m, midiEventPos))
125 {
126 renderNextSubBlock (outputAudio, startSample, numSamples);
127 return;
128 }
129
130 auto samplesToNextMidiMessage = midiEventPos - startSample;
131
132 if (samplesToNextMidiMessage >= numSamples)
133 {
134 renderNextSubBlock (outputAudio, startSample, numSamples);
135 handleMidiEvent (m);
136 break;
137 }
138
139 if (samplesToNextMidiMessage < ((firstEvent && ! subBlockSubdivisionIsStrict) ? 1 : minimumSubBlockSize))
140 {
141 handleMidiEvent (m);
142 continue;
143 }
144
145 firstEvent = false;
146
147 renderNextSubBlock (outputAudio, startSample, samplesToNextMidiMessage);
148 handleMidiEvent (m);
149 startSample += samplesToNextMidiMessage;
150 numSamples -= samplesToNextMidiMessage;
151 }
152
153 while (midiIterator.getNextEvent (m, midiEventPos))
154 handleMidiEvent (m);
155}
156
157// explicit instantiation for supported float types:
158template void MPESynthesiserBase::renderNextBlock<float> (AudioBuffer<float>&, const MidiBuffer&, int, int);
159template void MPESynthesiserBase::renderNextBlock<double> (AudioBuffer<double>&, const MidiBuffer&, int, int);
160
161//==============================================================================
162 void MPESynthesiserBase::setCurrentPlaybackSampleRate (const double newRate)
163{
164 if (sampleRate != newRate)
165 {
166 const ScopedLock sl (noteStateLock);
167 instrument->releaseAllNotes();
168 sampleRate = newRate;
169 }
170}
171
172//==============================================================================
173 void MPESynthesiserBase::setMinimumRenderingSubdivisionSize (int numSamples, bool shouldBeStrict) noexcept
174{
175 jassert (numSamples > 0); // it wouldn't make much sense for this to be less than 1
176 minimumSubBlockSize = numSamples;
177 subBlockSubdivisionIsStrict = shouldBeStrict;
178}
179
180} // namespace juce
juce::AudioBuffer
Definition: juce_AudioSampleBuffer.h:34
juce::GenericScopedLock
Definition: juce_ScopedLock.h:55
juce::MPEInstrument
Definition: juce_MPEInstrument.h:56
juce::MPEInstrument::TrackingMode
TrackingMode
Definition: juce_MPEInstrument.h:119
juce::MPEZoneLayout
Definition: juce_MPEZoneLayout.h:45
juce::MidiBuffer::Iterator
Definition: juce_MidiBuffer.h:171
juce::MidiBuffer::Iterator::setNextSamplePosition
void setNextSamplePosition(int samplePosition) noexcept
Definition: juce_MidiBuffer.cpp:196
juce::MidiBuffer::Iterator::getNextEvent
bool getNextEvent(MidiMessage &result, int &samplePosition) noexcept
Definition: juce_MidiBuffer.cpp:219
juce::MidiBuffer
Definition: juce_MidiBuffer.h:43
juce::MidiMessage
Definition: juce_MidiMessage.h:35
juce::Range
Definition: juce_Range.h:40
juce::MPESynthesiserBase::setPitchbendTrackingMode
void setPitchbendTrackingMode(TrackingMode modeToUse)
Definition: juce_MPESynthesiserBase.cpp:87
juce::MPESynthesiserBase::handleMidiEvent
virtual void handleMidiEvent(const MidiMessage &)
Definition: juce_MPESynthesiserBase.cpp:98
juce::MPESynthesiserBase::isLegacyModeEnabled
bool isLegacyModeEnabled() const noexcept
Definition: juce_MPESynthesiserBase.cpp:56
juce::MPESynthesiserBase::getZoneLayout
MPEZoneLayout getZoneLayout() const noexcept
Definition: juce_MPESynthesiserBase.cpp:40
juce::MPESynthesiserBase::setZoneLayout
void setZoneLayout(MPEZoneLayout newLayout)
Definition: juce_MPESynthesiserBase.cpp:45
juce::MPESynthesiserBase::getLegacyModePitchbendRange
int getLegacyModePitchbendRange() const noexcept
Definition: juce_MPESynthesiserBase.cpp:71
juce::MPESynthesiserBase::setLegacyModeChannelRange
void setLegacyModeChannelRange(Range< int > channelRange)
Definition: juce_MPESynthesiserBase.cpp:66
juce::MPESynthesiserBase::setLegacyModePitchbendRange
void setLegacyModePitchbendRange(int pitchbendRange)
Definition: juce_MPESynthesiserBase.cpp:76
juce::MPESynthesiserBase::enableLegacyMode
void enableLegacyMode(int pitchbendRange=2, Range< int > channelRange=Range< int >(1, 17))
Definition: juce_MPESynthesiserBase.cpp:51
juce::MPESynthesiserBase::setTimbreTrackingMode
void setTimbreTrackingMode(TrackingMode modeToUse)
Definition: juce_MPESynthesiserBase.cpp:92
juce::MPESynthesiserBase::instrument
std::unique_ptr< MPEInstrument > instrument
Definition: juce_MPESynthesiserBase.h:198
juce::MPESynthesiserBase::setPressureTrackingMode
void setPressureTrackingMode(TrackingMode modeToUse)
Definition: juce_MPESynthesiserBase.cpp:82
juce::MPESynthesiserBase::getLegacyModeChannelRange
Range< int > getLegacyModeChannelRange() const noexcept
Definition: juce_MPESynthesiserBase.cpp:61
juce::MPESynthesiserBase::setCurrentPlaybackSampleRate
virtual void setCurrentPlaybackSampleRate(double sampleRate)
Definition: juce_MPESynthesiserBase.cpp:162
juce::MPESynthesiserBase::renderNextBlock
void renderNextBlock(AudioBuffer< floatType > &outputAudio, const MidiBuffer &inputMidi, int startSample, int numSamples)
Definition: juce_MPESynthesiserBase.cpp:105
juce::MPESynthesiserBase::setMinimumRenderingSubdivisionSize
void setMinimumRenderingSubdivisionSize(int numSamples, bool shouldBeStrict=false) noexcept
Definition: juce_MPESynthesiserBase.cpp:173
juce::MPESynthesiserBase::renderNextSubBlock
virtual void renderNextSubBlock(AudioBuffer< float > &outputAudio, int startSample, int numSamples)=0
juce::MPESynthesiserBase::MPESynthesiserBase
MPESynthesiserBase()
Definition: juce_MPESynthesiserBase.cpp:26