Sorted elements in ccEvents
This commit is contained in:
parent
0f4c32b5a8
commit
e2f0ca754e
3 changed files with 47 additions and 7 deletions
|
|
@ -53,8 +53,8 @@ void sfz::MidiState::advanceTime(int numSamples) noexcept
|
|||
internalClock += numSamples;
|
||||
for (auto& ccEvents: cc) {
|
||||
ASSERT(!ccEvents.empty()); // CC event vectors should never be empty
|
||||
ccEvents.front().second = ccEvents.back().second;
|
||||
ccEvents.front().first = 0;
|
||||
ccEvents.front().value = ccEvents.back().value;
|
||||
ccEvents.front().delay = 0;
|
||||
ccEvents.resize(1);
|
||||
}
|
||||
}
|
||||
|
|
@ -104,15 +104,15 @@ int sfz::MidiState::getPitchBend() const noexcept
|
|||
void sfz::MidiState::ccEvent(int delay, int ccNumber, float ccValue) noexcept
|
||||
{
|
||||
ASSERT(ccValue >= 0.0 && ccValue <= 1.0);
|
||||
|
||||
cc[ccNumber].emplace_back(delay, ccValue);
|
||||
const auto insertionPoint = absl::c_upper_bound(cc[ccNumber], delay, MidiEventComparator{});
|
||||
cc[ccNumber].insert(insertionPoint, { delay, ccValue });
|
||||
}
|
||||
|
||||
float sfz::MidiState::getCCValue(int ccNumber) const noexcept
|
||||
{
|
||||
ASSERT(ccNumber >= 0 && ccNumber < config::numCCs);
|
||||
|
||||
return cc[ccNumber].back().second;
|
||||
return cc[ccNumber].back().value;
|
||||
}
|
||||
|
||||
void sfz::MidiState::reset() noexcept
|
||||
|
|
@ -122,7 +122,7 @@ void sfz::MidiState::reset() noexcept
|
|||
|
||||
for (auto& ccEvents: cc) {
|
||||
ccEvents.clear();
|
||||
ccEvents.emplace_back(0, 0.0f);
|
||||
ccEvents.push_back({ 0, 0.0f });
|
||||
}
|
||||
|
||||
pitchBend = 0;
|
||||
|
|
|
|||
|
|
@ -144,7 +144,6 @@ public:
|
|||
private:
|
||||
template<class T>
|
||||
using MidiNoteArray = std::array<T, 128>;
|
||||
using MidiEvent = std::pair<int, float>;
|
||||
using EventVector = std::vector<MidiEvent>;
|
||||
int activeNotes { 0 };
|
||||
|
||||
|
|
|
|||
|
|
@ -62,6 +62,47 @@ struct CCValuePairComparator<ValueType, true> {
|
|||
}
|
||||
};
|
||||
|
||||
struct MidiEvent {
|
||||
int delay;
|
||||
float value;
|
||||
};
|
||||
|
||||
template<bool CompareValue = false>
|
||||
struct MidiEventComparator {
|
||||
bool operator()(const MidiEvent& event, const int& delay)
|
||||
{
|
||||
return (event.delay < delay);
|
||||
}
|
||||
|
||||
bool operator()(const int& delay, const MidiEvent& event)
|
||||
{
|
||||
return (delay < event.delay);
|
||||
}
|
||||
|
||||
bool operator()(const MidiEvent& lhs, const MidiEvent& rhs)
|
||||
{
|
||||
return (lhs.delay < rhs.delay);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct MidiEventComparator<true> {
|
||||
bool operator()(const MidiEvent& event, const float& value)
|
||||
{
|
||||
return (event.value < value);
|
||||
}
|
||||
|
||||
bool operator()(const float& value, const MidiEvent& event)
|
||||
{
|
||||
return (value < event.value);
|
||||
}
|
||||
|
||||
bool operator()(const MidiEvent& lhs, const MidiEvent& rhs)
|
||||
{
|
||||
return (lhs.value < rhs.value);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Converts cents to a pitch ratio
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue