Skip to content

Commit

Permalink
Refactor the messaging system
Browse files Browse the repository at this point in the history
Trading off complexity when parsing/replying to the messages for complexity
in some templated and overloaded code blocks.
  • Loading branch information
paulfd committed Jan 2, 2024
1 parent 49699de commit 685bbe4
Show file tree
Hide file tree
Showing 7 changed files with 989 additions and 1,939 deletions.
45 changes: 45 additions & 0 deletions src/sfizz/Defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,51 @@ struct OpcodeSpec
}

operator T() const { return normalizeInput(defaultInputValue); }


/**
* @brief Demormalizes an input as needed for the spec
*
* @tparam U
* @param input
* @return U
*/
template<class U=T>
typename std::enable_if<IsNormalizable<U>::value, U>::type denormalizeInput(U input) const
{
constexpr int needsOperation {
kNormalizePercent |
kNormalizeMidi |
kNormalizeBend |
kDb2Mag
};

if (!(flags & needsOperation))
return input;
else if (flags & kNormalizePercent)
return static_cast<U>(input * U(100));
else if (flags & kNormalizeMidi)
return static_cast<U>(input * U(127));
else if (flags & kNormalizeBend)
return static_cast<U>(input * U(8191));
else if (flags & kDb2Mag)
return static_cast<U>(mag2db(input));

return input;
}

/**
* @brief Normalizes an input as needed for the spec
*
* @tparam U
* @param input
* @return U
*/
template<class U=T>
typename std::enable_if<!IsNormalizable<U>::value, U>::type denormalizeInput(U input) const
{
return input;
}
};

namespace Default
Expand Down
43 changes: 43 additions & 0 deletions src/sfizz/RegionSpecs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#pragma once
#include "Region.h"
#include "Defaults.h"
#include <tuple>

namespace sfz
{
template<class T, class Member>
constexpr auto spec(Member member)
{
switch (member)
{
case &Region::defaultSwitch: return Default::key;
case &Region::delay: return Default::delay;
case &Region::delayRandom: return Default::delayRandom;
case &Region::delayCC: return Default::delayMod;
case &Region::offset: return Default::offset;
case &Region::offsetRandom: return Default::offsetRandom;
case &Region::offsetCC: return Default::offsetMod;
case &Region::sampleEnd: return Default::sampleEnd;
case &Region::sampleCount: return Default::sampleCount;
case &Region::loopMode: return Default::loopMode;
case &Region::loopRange: return std::make_pair(Default::loopStart, Default::loopEnd);
case &Region::endCC: return Default::sampleEndMod;
case &Region::loopStartCC:
case &Region::loopEndCC: return Default::loopMod;
case &Region::keyRange: return std::make_pair(Default::loKey, Default::hiKey);
case &Region::velocityRange: return std::make_pair(Default::loVel, Default::hiVel);
case &Region::randRange: return std::make_pair(Default::loNormalized, Default::hiNormalized);
case &EGDescription::ccAttack:
case &EGDescription::ccDecay:
case &EGDescription::ccDelay:
case &EGDescription::ccHold:
case &EGDescription::ccRelease:
return Default::egTimeMod;
case &EGDescription::ccStart:
case &EGDescription::ccSustain:
return Default::egPercentMod;
}
}


}
2 changes: 1 addition & 1 deletion src/sfizz/Synth.h
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,8 @@ class Synth final {
*/
void setBroadcastCallback(sfizz_receive_t* broadcast, void* data);

private:
struct Impl;
private:
std::unique_ptr<Impl> impl_;

LEAK_DETECTOR(Synth);
Expand Down
Loading

0 comments on commit 685bbe4

Please sign in to comment.