Js::ImplicitCallFlags JITTimeProfileInfo::GetLoopImplicitCallFlags(uint loopNum) const { // TODO: michhol OOP JIT, investigate vaibility of reenabling this assert // Assert(Js::DynamicProfileInfo::EnableImplicitCallFlags(functionBody)); Assert(loopNum < GetLoopCount()); // Mask out the dispose implicit call. We would bailout on reentrant dispose, // but it shouldn't affect optimization. return (Js::ImplicitCallFlags)(m_profileData.loopImplicitCallFlags[loopNum] & Js::ImplicitCall_All); }
double GetOriginalPpqPos (MediaItem_Take* take, double ppqPos, bool* loopedItem, double* posVisInsertStartPpq, double* posVisInsertEndPpq) { double returnPos = 0; MediaItem* item = GetMediaItemTake_Item(take); if (!take || !item || !IsMidi(take, NULL)) { WritePtr(loopedItem, false); WritePtr(posVisInsertStartPpq, 0.0); WritePtr(posVisInsertEndPpq, 0.0); } else { double itemStart = GetMediaItemInfo_Value(item, "D_POSITION"); double itemEnd = itemStart + GetMediaItemInfo_Value(item, "D_LENGTH"); if (GetMediaItemInfo_Value(item, "B_LOOPSRC") == 0) { WritePtr(loopedItem, false); WritePtr(posVisInsertStartPpq, MIDI_GetPPQPosFromProjTime(take, itemStart)); WritePtr(posVisInsertEndPpq, MIDI_GetPPQPosFromProjTime(take, itemEnd)); returnPos = ppqPos; } else { WritePtr(loopedItem, true); double visibleItemStartPpq = MIDI_GetPPQPosFromProjTime(take, itemStart); double visibleItemEndPpq = MIDI_GetPPQPosFromProjTime(take, itemEnd); double sourceLenPpq = GetMidiSourceLengthPPQ(take, true); // Deduct take offset to get correct current loop iteration double itemStartPpq = MIDI_GetPPQPosFromProjTime(take, itemStart - GetMediaItemTakeInfo_Value(take, "D_STARTOFFS")); int currentLoop; int loopCount = GetLoopCount(take, MIDI_GetProjTimeFromPPQPos(take, ppqPos), ¤tLoop); returnPos = (ppqPos >= visibleItemStartPpq) ? (ppqPos - (currentLoop * sourceLenPpq)) : ppqPos; if (ppqPos > visibleItemEndPpq) // position after item end { WritePtr(posVisInsertStartPpq, 0.0); WritePtr(posVisInsertEndPpq, 0.0); } else if (ppqPos < visibleItemStartPpq || currentLoop == 0) // position in first loop iteration or before it { WritePtr(posVisInsertStartPpq, visibleItemStartPpq); WritePtr(posVisInsertEndPpq, (visibleItemEndPpq - visibleItemStartPpq >= sourceLenPpq) ? itemStartPpq + sourceLenPpq : visibleItemEndPpq); } else if (currentLoop == loopCount) // position in last loop iteration { WritePtr(posVisInsertStartPpq, itemStartPpq); WritePtr(posVisInsertEndPpq, itemStartPpq + (visibleItemEndPpq - (currentLoop * sourceLenPpq))); } else // position in other loop iterations { WritePtr(posVisInsertStartPpq, itemStartPpq); WritePtr(posVisInsertEndPpq, itemStartPpq + sourceLenPpq); } } } return returnPos; }
double EffectiveMidiTakeStart (MediaItem_Take* take, bool ignoreMutedEvents, bool ignoreTextEvents, bool ignoreEventsOutsideItemBoundaries) { int noteCount, ccCount, sysCount; if (take && MIDI_CountEvts(take, ¬eCount, &ccCount, &sysCount)) { MediaItem* item = GetMediaItemTake_Item(take); double itemStart = GetMediaItemInfo_Value(item, "D_POSITION"); double itemStartPPQ = MIDI_GetPPQPosFromProjTime(take, itemStart); double itemEndPPQ = (!ignoreEventsOutsideItemBoundaries) ? 0 : MIDI_GetPPQPosFromProjTime(take, GetMediaItemInfo_Value(item, "D_LENGTH") + itemStart); int loopCount = (!ignoreEventsOutsideItemBoundaries) ? 0 : GetLoopCount(take, 0, NULL); double sourceLenPPQ = (!ignoreEventsOutsideItemBoundaries) ? 0 : GetMidiSourceLengthPPQ(take, true); bool validNote = false, validCC = false, validSys = false; double noteStart, ccStart, sysStart; double loopOffset = 0; for (int i = 0; i < noteCount; ++i) { bool muted; double start, end; MIDI_GetNote(take, i, NULL, &muted, &start, &end, NULL, NULL, NULL); if ((ignoreMutedEvents && !muted) || !ignoreMutedEvents) { if (!ignoreEventsOutsideItemBoundaries) { noteStart = start; validNote = true; break; } else { start += loopOffset; end += loopOffset; if (AreOverlapped(start, end, itemStartPPQ, itemEndPPQ)) { if (itemStartPPQ > start) start = itemStartPPQ; noteStart = start; validNote = true; break; } } } if (ignoreEventsOutsideItemBoundaries && loopCount > 0 && i == noteCount - 1) { if (sourceLenPPQ > 0 && loopOffset == 0) { loopOffset = sourceLenPPQ; i = -1; } } } loopOffset = 0; for (int i = 0; i < ccCount; ++i) { bool muted; double pos; MIDI_GetCC(take, i, NULL, &muted, &pos, NULL, NULL, NULL, NULL); if ((ignoreMutedEvents && !muted) || !ignoreMutedEvents) { if (!ignoreEventsOutsideItemBoundaries) { ccStart = pos; validCC = true; break; } else { pos += loopOffset; if (CheckBounds(pos, itemStartPPQ, itemEndPPQ)) { ccStart = pos; validCC = true; break; } } } if (ignoreEventsOutsideItemBoundaries && loopCount > 0 && i == ccCount - 1) { if (sourceLenPPQ > 0 && loopOffset == 0) { loopOffset = sourceLenPPQ; i = -1; } } } for (int i = 0; i < sysCount; ++i) { bool muted; double pos; int type; MIDI_GetTextSysexEvt(take, i, NULL, &muted, &pos, &type, NULL, NULL); if (((ignoreMutedEvents && !muted) || !ignoreMutedEvents) && ((ignoreTextEvents && type == -1) || !ignoreTextEvents)) { if (!ignoreEventsOutsideItemBoundaries) { sysStart = pos; validSys = true; break; } else { pos += loopOffset; if (CheckBounds(pos, itemStartPPQ, itemEndPPQ)) { sysStart = pos; validSys = true; break; } } } if (ignoreEventsOutsideItemBoundaries && loopCount > 0 && i == sysCount - 1) { if (sourceLenPPQ > 0 && loopOffset == 0) { loopOffset = sourceLenPPQ; i = -1; } } } if (validNote || validCC || validSys) { if (!validNote) noteStart = (validSys) ? sysStart : ccStart; if (!validCC) ccStart = (validSys) ? sysStart : noteStart; if (!validSys) sysStart = (ccStart) ? ccStart : noteStart; return MIDI_GetProjTimeFromPPQPos(take, min(min(noteStart, ccStart), sysStart)); } else { return GetMediaItemInfo_Value(item, "D_POSITION"); } } else { return GetMediaItemInfo_Value(GetMediaItemTake_Item(take), "D_POSITION"); } }
double EffectiveMidiTakeEnd (MediaItem_Take* take, bool ignoreMutedEvents, bool ignoreTextEvents, bool ignoreEventsOutsideItemBoundaries) { int noteCount, ccCount, sysCount; if (take && MIDI_CountEvts(take, ¬eCount, &ccCount, &sysCount)) { MediaItem* item = GetMediaItemTake_Item(take); double itemStart = GetMediaItemInfo_Value(item, "D_POSITION"); double itemStartPPQ = MIDI_GetPPQPosFromProjTime(take, itemStart); double itemEndPPQ = (!ignoreEventsOutsideItemBoundaries) ? 0 : MIDI_GetPPQPosFromProjTime(take, GetMediaItemInfo_Value(item, "D_LENGTH") + itemStart); int loopCount = GetLoopCount(take, 0, NULL); double sourceLenPPQ = GetMidiSourceLengthPPQ(take, true); double effectiveTakeEndPPQ = -1; for (int i = 0; i < noteCount; ++i) { bool muted; double noteStart, noteEnd; MIDI_GetNote(take, i, NULL, &muted, ¬eStart, ¬eEnd, NULL, NULL, NULL); if (((ignoreMutedEvents && !muted) || !ignoreMutedEvents)) { noteEnd += loopCount*sourceLenPPQ; if (!ignoreEventsOutsideItemBoundaries) { if (noteEnd > effectiveTakeEndPPQ) effectiveTakeEndPPQ = noteEnd; } else { noteStart += loopCount*sourceLenPPQ; if (CheckBounds(noteStart, itemStartPPQ, itemEndPPQ)) { if (noteEnd > itemEndPPQ) noteEnd = itemEndPPQ; if (noteEnd > effectiveTakeEndPPQ) effectiveTakeEndPPQ = noteEnd; } else if (loopCount > 0) { noteStart -= sourceLenPPQ; if (CheckBounds(noteStart, itemStartPPQ, itemEndPPQ)) { noteEnd -= sourceLenPPQ; if (noteEnd > itemEndPPQ) noteEnd = itemEndPPQ; if (noteEnd > effectiveTakeEndPPQ) effectiveTakeEndPPQ = noteEnd; } } } } } for (int i = ccCount - 1; i >= 0; --i) { bool muted; double pos; MIDI_GetCC(take, i, NULL, &muted, &pos, NULL, NULL, NULL, NULL); if ((ignoreMutedEvents && !muted) || !ignoreMutedEvents) { pos += loopCount*sourceLenPPQ; if (!ignoreEventsOutsideItemBoundaries) { if (pos > effectiveTakeEndPPQ) effectiveTakeEndPPQ = pos + 1; // add 1 ppq so length definitely includes that last event break; } else { if (CheckBounds(pos, itemStartPPQ, itemEndPPQ)) { if (pos > effectiveTakeEndPPQ) { effectiveTakeEndPPQ = pos + 1; break; } } else if (loopCount > 0) { pos -= sourceLenPPQ; if (CheckBounds(pos, itemStartPPQ, itemEndPPQ)) { if (pos > effectiveTakeEndPPQ) { effectiveTakeEndPPQ = pos + 1; break; } } } } } } for (int i = 0; i < sysCount; ++i) { bool muted; double pos; int type; MIDI_GetTextSysexEvt(take, i, NULL, &muted, &pos, &type, NULL, NULL); if (((ignoreMutedEvents && !muted) || !ignoreMutedEvents) && ((ignoreTextEvents && type == -1) || !ignoreTextEvents)) { pos += loopCount*sourceLenPPQ; if (!ignoreEventsOutsideItemBoundaries) { if (pos > effectiveTakeEndPPQ) effectiveTakeEndPPQ = pos + 1; // add 1 ppq so length definitely includes that last event } else { if (CheckBounds(pos, itemStartPPQ, itemEndPPQ)) { if (pos > effectiveTakeEndPPQ) effectiveTakeEndPPQ = pos + 1; } else if (loopCount > 0) { pos -= sourceLenPPQ; if (CheckBounds(pos, itemStartPPQ, itemEndPPQ)) { if (pos > effectiveTakeEndPPQ) effectiveTakeEndPPQ = pos + 1; } } } } } return (effectiveTakeEndPPQ == -1) ? itemStart : MIDI_GetProjTimeFromPPQPos(take, effectiveTakeEndPPQ); } return 0; }