Browse Source

Fix a build error and some warnings when building the SamplerPluginDemo example on Windows

tags/2021-05-28
ed 8 years ago
parent
commit
563869300e
1 changed files with 70 additions and 68 deletions
  1. +70
    -68
      examples/Plugins/SamplerPluginDemo.h

+ 70
- 68
examples/Plugins/SamplerPluginDemo.h View File

@@ -56,6 +56,7 @@
#include <iomanip> #include <iomanip>
#include <sstream> #include <sstream>
#include <functional> #include <functional>
#include <mutex>
namespace IDs namespace IDs
{ {
@@ -350,9 +351,9 @@ private:
auto invAlpha = 1.0f - alpha; auto invAlpha = 1.0f - alpha;
// just using a very simple linear interpolation here.. // just using a very simple linear interpolation here..
auto l = currentLevel * (inL[pos] * invAlpha + inL[nextPos] * alpha);
auto r = (inR != nullptr) ? currentLevel * (inR[pos] * invAlpha + inR[nextPos] * alpha)
: l;
auto l = static_cast<float> (currentLevel * (inL[pos] * invAlpha + inL[nextPos] * alpha));
auto r = static_cast<float> ((inR != nullptr) ? currentLevel * (inR[pos] * invAlpha + inR[nextPos] * alpha)
: l);
if (outR != nullptr) if (outR != nullptr)
{ {
@@ -360,7 +361,9 @@ private:
outR[writePos] += r; outR[writePos] += r;
} }
else else
{
outL[writePos] += (l + r) * 0.5f; outL[writePos] += (l + r) * 0.5f;
}
std::tie (currentSamplePos, currentDirection) = getNextState (currentFrequency, std::tie (currentSamplePos, currentDirection) = getNextState (currentFrequency,
currentLoopBegin, currentLoopBegin,
@@ -394,11 +397,11 @@ private:
backward backward
}; };
std::tuple<double, Direction> getNextState (double frequency,
double loopBegin,
double loopEnd) const
std::tuple<double, Direction> getNextState (double freq,
double begin,
double end) const
{ {
auto nextPitchRatio = frequency / samplerSound->getCentreFrequencyInHz();
auto nextPitchRatio = freq / samplerSound->getCentreFrequencyInHz();
auto nextSamplePos = currentSamplePos; auto nextSamplePos = currentSamplePos;
auto nextDirection = currentDirection; auto nextDirection = currentDirection;
@@ -418,9 +421,9 @@ private:
// Update current sample position, taking loop mode into account // Update current sample position, taking loop mode into account
// If the loop mode was changed while we were travelling backwards, deal // If the loop mode was changed while we were travelling backwards, deal
// with it gracefully. // with it gracefully.
if (nextDirection == Direction::backward && nextSamplePos < loopBegin)
if (nextDirection == Direction::backward && nextSamplePos < begin)
{ {
nextSamplePos = loopBegin;
nextSamplePos = begin;
nextDirection = Direction::forward; nextDirection = Direction::forward;
return { nextSamplePos, nextDirection }; return { nextSamplePos, nextDirection };
@@ -429,13 +432,13 @@ private:
if (samplerSound->getLoopMode() == LoopMode::none) if (samplerSound->getLoopMode() == LoopMode::none)
return { nextSamplePos, nextDirection }; return { nextSamplePos, nextDirection };
if (nextDirection == Direction::forward && loopEnd < nextSamplePos && !isTailingOff())
if (nextDirection == Direction::forward && end < nextSamplePos && !isTailingOff())
{ {
if (samplerSound->getLoopMode() == LoopMode::forward) if (samplerSound->getLoopMode() == LoopMode::forward)
nextSamplePos = loopBegin;
nextSamplePos = begin;
else if (samplerSound->getLoopMode() == LoopMode::pingpong) else if (samplerSound->getLoopMode() == LoopMode::pingpong)
{ {
nextSamplePos = loopEnd;
nextSamplePos = end;
nextDirection = Direction::backward; nextDirection = Direction::backward;
} }
} }
@@ -625,8 +628,8 @@ public:
{ {
public: public:
virtual ~Listener() noexcept = default; virtual ~Listener() noexcept = default;
virtual void totalRangeChanged (Range<double> value) {}
virtual void visibleRangeChanged (Range<double> value) {}
virtual void totalRangeChanged (Range<double>) {}
virtual void visibleRangeChanged (Range<double>) {}
}; };
VisibleRangeDataModel() VisibleRangeDataModel()
@@ -691,8 +694,7 @@ public:
} }
private: private:
void valueTreePropertyChanged (ValueTree &treeWhosePropertyHasChanged,
const Identifier &property) override
void valueTreePropertyChanged (ValueTree &, const Identifier &property) override
{ {
if (property == IDs::totalRange) if (property == IDs::totalRange)
{ {
@@ -727,13 +729,13 @@ public:
{ {
public: public:
virtual ~Listener() noexcept = default; virtual ~Listener() noexcept = default;
virtual void synthVoicesChanged (int value) {}
virtual void voiceStealingEnabledChanged (bool value) {}
virtual void legacyModeEnabledChanged (bool value) {}
virtual void mpeZoneLayoutChanged (const MPEZoneLayout& value) {}
virtual void legacyFirstChannelChanged (int value) {}
virtual void legacyLastChannelChanged (int value) {}
virtual void legacyPitchbendRangeChanged (int value) {}
virtual void synthVoicesChanged (int) {}
virtual void voiceStealingEnabledChanged (bool) {}
virtual void legacyModeEnabledChanged (bool) {}
virtual void mpeZoneLayoutChanged (const MPEZoneLayout&) {}
virtual void legacyFirstChannelChanged (int) {}
virtual void legacyLastChannelChanged (int) {}
virtual void legacyPitchbendRangeChanged (int) {}
}; };
MPESettingsDataModel() MPESettingsDataModel()
@@ -852,8 +854,7 @@ public:
} }
private: private:
void valueTreePropertyChanged (ValueTree &treeWhosePropertyHasChanged,
const Identifier &property) override
void valueTreePropertyChanged (ValueTree&, const Identifier &property) override
{ {
if (property == IDs::synthVoices) if (property == IDs::synthVoices)
{ {
@@ -918,10 +919,10 @@ public:
{ {
public: public:
virtual ~Listener() noexcept = default; virtual ~Listener() noexcept = default;
virtual void sampleReaderChanged (std::shared_ptr<AudioFormatReaderFactory> value) {}
virtual void centreFrequencyHzChanged (double value) {}
virtual void loopModeChanged (LoopMode value) {}
virtual void loopPointsSecondsChanged (Range<double> value) {}
virtual void sampleReaderChanged (std::shared_ptr<AudioFormatReaderFactory>) {}
virtual void centreFrequencyHzChanged (double) {}
virtual void loopModeChanged (LoopMode) {}
virtual void loopPointsSecondsChanged (Range<double>) {}
}; };
explicit DataModel (AudioFormatManager& audioFormatManager) explicit DataModel (AudioFormatManager& audioFormatManager)
@@ -966,8 +967,8 @@ public:
double getSampleLengthSeconds() const double getSampleLengthSeconds() const
{ {
if (auto sampleReader = getSampleReader())
return sampleReader->lengthInSamples / sampleReader->sampleRate;
if (auto r = getSampleReader())
return r->lengthInSamples / r->sampleRate;
return 1.0; return 1.0;
} }
@@ -1031,8 +1032,7 @@ public:
} }
private: private:
void valueTreePropertyChanged (ValueTree &treeWhosePropertyHasChanged,
const Identifier &property) override
void valueTreePropertyChanged (ValueTree&, const Identifier& property) override
{ {
if (property == IDs::sampleReader) if (property == IDs::sampleReader)
{ {
@@ -1438,7 +1438,8 @@ private:
newPath.startNewSubPath (bounds.getBottomLeft().toFloat()); newPath.startNewSubPath (bounds.getBottomLeft().toFloat());
newPath.lineTo (bounds.getBottomRight().toFloat()); newPath.lineTo (bounds.getBottomRight().toFloat());
Point<float> apex (bounds.getX() + (bounds.getWidth() / 2), bounds.getBottom() - triHeight);
Point<float> apex (static_cast<float> (bounds.getX() + (bounds.getWidth() / 2)),
static_cast<float> (bounds.getBottom() - triHeight));
newPath.lineTo (apex); newPath.lineTo (apex);
newPath.closeSubPath(); newPath.closeSubPath();
@@ -1459,7 +1460,7 @@ private:
bool hitTest (int x, int y) override bool hitTest (int x, int y) override
{ {
return path.contains (x, y);
return path.contains ((float) x, (float) y);
} }
void mouseDown (const MouseEvent& e) override void mouseDown (const MouseEvent& e) override
@@ -1511,14 +1512,14 @@ private:
0, 0,
bg.darker(), bg.darker(),
0, 0,
getHeight(),
(float) getHeight(),
false)); false));
g.fillAll(); g.fillAll();
g.setColour (bg.brighter()); g.setColour (bg.brighter());
g.drawHorizontalLine (0, 0, getWidth());
g.drawHorizontalLine (0, 0.0f, (float) getWidth());
g.setColour (bg.darker()); g.setColour (bg.darker());
g.drawHorizontalLine (1, 0, getWidth());
g.drawHorizontalLine (1, 0.0f, (float) getWidth());
g.setColour (Colours::lightgrey); g.setColour (Colours::lightgrey);
auto minLog = std::ceil (std::log10 (visibleRange.getVisibleRange().getLength() / maxDivisions)); auto minLog = std::ceil (std::log10 (visibleRange.getVisibleRange().getLength() / maxDivisions));
@@ -1533,15 +1534,15 @@ private:
/ visibleRange.getVisibleRange().getLength(); / visibleRange.getVisibleRange().getLength();
std::ostringstream out_stream; std::ostringstream out_stream;
out_stream << std::setprecision (precision) << time;
out_stream << std::setprecision (roundToInt (precision)) << roundToInt (time);
g.drawText (out_stream.str(), g.drawText (out_stream.str(),
Rectangle<int> (Point<int> (xPos + 3, 0),
Point<int> (xPos + minDivisionWidth, getHeight())),
Rectangle<int> (Point<int> (roundToInt (xPos) + 3, 0),
Point<int> (roundToInt (xPos + minDivisionWidth), getHeight())),
Justification::centredLeft, Justification::centredLeft,
false); false);
g.drawVerticalLine (xPos, 2, getHeight());
g.drawVerticalLine (roundToInt (xPos), 2.0f, (float) getHeight());
} }
} }
@@ -1566,7 +1567,7 @@ private:
visibleRange.setVisibleRange (range, nullptr); visibleRange.setVisibleRange (range, nullptr);
} }
void visibleRangeChanged (Range<double> value) override
void visibleRangeChanged (Range<double>) override
{ {
repaint(); repaint();
} }
@@ -1610,7 +1611,7 @@ private:
positionLoopPointMarkers(); positionLoopPointMarkers();
} }
void loopPointMouseDown (LoopPointMarker& marker, const MouseEvent& e)
void loopPointMouseDown (LoopPointMarker&, const MouseEvent&)
{ {
loopPointsOnMouseDown = dataModel.getLoopPointsSeconds(); loopPointsOnMouseDown = dataModel.getLoopPointsSeconds();
undoManager->beginNewTransaction(); undoManager->beginNewTransaction();
@@ -1634,12 +1635,12 @@ private:
dataModel.setLoopPointsSeconds (newLoopRange, undoManager); dataModel.setLoopPointsSeconds (newLoopRange, undoManager);
} }
void loopPointsSecondsChanged (Range<double> value) override
void loopPointsSecondsChanged (Range<double>) override
{ {
positionLoopPointMarkers(); positionLoopPointMarkers();
} }
void visibleRangeChanged (Range<double> value) override
void visibleRangeChanged (Range<double>) override
{ {
positionLoopPointMarkers(); positionLoopPointMarkers();
} }
@@ -1666,7 +1667,7 @@ private:
auto ptr = std::get<0> (tup); auto ptr = std::get<0> (tup);
auto time = std::get<1> (tup); auto time = std::get<1> (tup);
ptr->setSize (halfMarkerWidth * 2, getHeight()); ptr->setSize (halfMarkerWidth * 2, getHeight());
ptr->setTopLeftPosition (timeToXPosition (time) - halfMarkerWidth, 0);
ptr->setTopLeftPosition (roundToInt (timeToXPosition (time) - halfMarkerWidth), 0);
} }
} }
@@ -1700,7 +1701,7 @@ private:
for (auto position : provider()) for (auto position : provider())
{ {
g.drawVerticalLine (timeToXPosition (position), 0, getHeight());
g.drawVerticalLine (roundToInt (timeToXPosition (position)), 0.0f, (float) getHeight());
} }
} }
@@ -1753,7 +1754,7 @@ private:
if (numChannels == 0) if (numChannels == 0)
{ {
g.setColour (Colours::white); g.setColour (Colours::white);
g.drawFittedText ("No File Loaded", getLocalBounds(), Justification::centred, 1.0f);
g.drawFittedText ("No File Loaded", getLocalBounds(), Justification::centred, 1);
return; return;
} }
@@ -2085,7 +2086,7 @@ public:
synthesiser.addVoice (new MPESamplerVoice (sound)); synthesiser.addVoice (new MPESamplerVoice (sound));
} }
void prepareToPlay (double sampleRate, int samplesPerBlock) override
void prepareToPlay (double sampleRate, int) override
{ {
synthesiser.setCurrentPlaybackSampleRate (sampleRate); synthesiser.setCurrentPlaybackSampleRate (sampleRate);
} }
@@ -2180,25 +2181,26 @@ public:
// Update the current playback positions // Update the current playback positions
for (auto i = 0; i != maxVoices; ++i) for (auto i = 0; i != maxVoices; ++i)
{ {
MPESamplerVoice* voicePtr = nullptr;
playbackPositions[i] = (i < numVoices && (voicePtr = dynamic_cast<MPESamplerVoice*> (synthesiser.getVoice (i))))
? voicePtr->getCurrentSamplePosition() / loadedSamplerSound->getSample()->getSampleRate()
: 0;
auto* voicePtr = dynamic_cast<MPESamplerVoice*> (synthesiser.getVoice (i));
if (i < numVoices && voicePtr != nullptr)
playbackPositions[i] = static_cast<float> (voicePtr->getCurrentSamplePosition() / loadedSamplerSound->getSample()->getSampleRate());
else
playbackPositions[i] = 0.0f;
} }
} }
// These should be called from the GUI thread, and will block until the // These should be called from the GUI thread, and will block until the
// command buffer has enough room to accept a command. // command buffer has enough room to accept a command.
void setSample (std::unique_ptr<AudioFormatReaderFactory> readerFactory,
AudioFormatManager& formatManager)
void setSample (std::unique_ptr<AudioFormatReaderFactory> fact, AudioFormatManager& formatManager)
{ {
class SetSampleCommand class SetSampleCommand
{ {
public: public:
SetSampleCommand (std::unique_ptr<AudioFormatReaderFactory> readerFactory,
SetSampleCommand (std::unique_ptr<AudioFormatReaderFactory> r,
std::unique_ptr<Sample> sample, std::unique_ptr<Sample> sample,
std::vector<std::unique_ptr<MPESamplerVoice>> newVoices) std::vector<std::unique_ptr<MPESamplerVoice>> newVoices)
: readerFactory (move (readerFactory)),
: readerFactory (move (r)),
sample (move (sample)), sample (move (sample)),
newVoices (move (newVoices)) newVoices (move (newVoices))
{} {}
@@ -2232,16 +2234,16 @@ public:
for (auto i = 0; i != maxVoices; ++i) for (auto i = 0; i != maxVoices; ++i)
newSamplerVoices.emplace_back (new MPESamplerVoice (loadedSamplerSound)); newSamplerVoices.emplace_back (new MPESamplerVoice (loadedSamplerSound));
if (readerFactory == nullptr)
if (fact == nullptr)
{ {
pushCommand (SetSampleCommand (move (readerFactory),
pushCommand (SetSampleCommand (move (fact),
nullptr, nullptr,
move (newSamplerVoices))); move (newSamplerVoices)));
} }
else else
{ {
auto reader = readerFactory->make (formatManager);
pushCommand (SetSampleCommand (move (readerFactory),
auto reader = fact->make (formatManager);
pushCommand (SetSampleCommand (move (fact),
std::unique_ptr<Sample> (new Sample (*reader, 10.0)), std::unique_ptr<Sample> (new Sample (*reader, 10.0)),
move (newSamplerVoices))); move (newSamplerVoices)));
} }
@@ -2448,8 +2450,8 @@ private:
{ {
jassert (files.size() == 1); jassert (files.size() == 1);
undoManager.beginNewTransaction(); undoManager.beginNewTransaction();
auto readerFactory = new FileAudioFormatReaderFactory (files[0]);
dataModel.setSampleReader (std::unique_ptr<AudioFormatReaderFactory> (readerFactory),
auto r = new FileAudioFormatReaderFactory (files[0]);
dataModel.setSampleReader (std::unique_ptr<AudioFormatReaderFactory> (r),
&undoManager); &undoManager);
} }
@@ -2493,22 +2495,22 @@ private:
setProcessorMPEMode(); setProcessorMPEMode();
} }
void mpeZoneLayoutChanged (const MPEZoneLayout& value) override
void mpeZoneLayoutChanged (const MPEZoneLayout&) override
{ {
setProcessorMPEMode(); setProcessorMPEMode();
} }
void legacyFirstChannelChanged (int value) override
void legacyFirstChannelChanged (int) override
{ {
setProcessorLegacyMode(); setProcessorLegacyMode();
} }
void legacyLastChannelChanged (int value) override
void legacyLastChannelChanged (int) override
{ {
setProcessorLegacyMode(); setProcessorLegacyMode();
} }
void legacyPitchbendRangeChanged (int value) override
void legacyPitchbendRangeChanged (int) override
{ {
setProcessorLegacyMode(); setProcessorLegacyMode();
} }


Loading…
Cancel
Save