| 56 | } |
| 57 | |
| 58 | void AudioParamTimeline::insertEvent(const ParamEvent & event) |
| 59 | { |
| 60 | // Sanity check the event. Be super careful we're not getting infected with NaN or Inf. |
| 61 | bool isValid = event.type() < ParamEvent::LastType |
| 62 | && isValidNumber(event.value()) |
| 63 | && isValidNumber(event.time()) |
| 64 | && isValidNumber(event.timeConstant()) |
| 65 | && isValidNumber(event.duration()) |
| 66 | && event.duration() >= 0; |
| 67 | |
| 68 | ASSERT(isValid); |
| 69 | |
| 70 | if (!isValid) |
| 71 | return; |
| 72 | |
| 73 | std::lock_guard<std::mutex> lock(m_eventsMutex); |
| 74 | |
| 75 | unsigned i = 0; |
| 76 | float insertTime = event.time(); |
| 77 | |
| 78 | for (i = 0; i < m_events.size(); ++i) |
| 79 | { |
| 80 | |
| 81 | if (event.type() == ParamEvent::SetValueCurve) |
| 82 | { |
| 83 | // If this event is a SetValueCurve, make sure it doesn't overlap any existing |
| 84 | // event. It's ok if the SetValueCurve starts at the same time as the end of some other |
| 85 | // duration. |
| 86 | double endTime = event.time() + event.duration(); |
| 87 | if (m_events[i].time() > event.time() && m_events[i].time() < endTime) |
| 88 | { |
| 89 | throw std::runtime_error("ParamEvent::SetValueCurve overlaps existing"); |
| 90 | } |
| 91 | } |
| 92 | else |
| 93 | { |
| 94 | // Otherwise, make sure this event doesn't overlap any existing SetValueCurve event. |
| 95 | if (m_events[i].type() == ParamEvent::SetValueCurve) |
| 96 | { |
| 97 | double endTime = m_events[i].time() + m_events[i].duration(); |
| 98 | if (event.time() >= m_events[i].time() && event.time() < endTime) |
| 99 | { |
| 100 | throw std::runtime_error("ParamEvent::SetValueCurve overlaps existing"); |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | // Overwrite same event type and time. |
| 106 | if (m_events[i].time() == insertTime && m_events[i].type() == event.type()) |
| 107 | { |
| 108 | m_events[i] = event; |
| 109 | return; |
| 110 | } |
| 111 | |
| 112 | if (m_events[i].time() > insertTime) |
| 113 | { |
| 114 | break; |
| 115 | } |
nothing calls this directly
no test coverage detected