void CPitchBendEventRenderer::Draw( const CEvent &ev, bool shadowed) const { CDestination *dest = Editor()->TrackWindow()->Document()->FindDestination(ev.GetVChannel()); BRect r; if (shadowed) Editor()->SetDrawingMode( B_OP_BLEND ); Editor()->SetHighColor(dest->Color()); if ((ev.Duration() > 0) && (ev.pitchBend.updatePeriod > 0)) { Editor()->BeginLineArray(ev.Duration() / ev.pitchBend.updatePeriod); for (int i = ev.pitchBend.updatePeriod; i < ev.Duration(); i += ev.pitchBend.updatePeriod) { long v = ev.pitchBend.startBend - 0x2000 + ((ev.pitchBend.targetBend - ev.pitchBend.startBend) * i / ev.Duration()); BPoint point(Editor()->TimeToViewCoords(ev.Start() + i), Editor()->ValueToViewCoords(v)); Editor()->AddLine(point, point, Editor()->HighColor()); } Editor()->EndLineArray(); r.left = Editor()->TimeToViewCoords(ev.Stop() ) - 2.0; r.top = Editor()->ValueToViewCoords(ev.pitchBend.targetBend - 0x2000) - 2.0; r.right = r.left + 4.0; r.bottom = r.top + 4.0; Editor()->FillEllipse(r); r.InsetBy(-1.0, -1.0); if (ev.IsSelected() && !shadowed && Editor()->IsSelectionVisible()) Editor()->SetHighColor(0, 0, 255); else Editor()->SetHighColor(0, 0, 0); Editor()->StrokeEllipse(r); } r.left = Editor()->TimeToViewCoords(ev.Start()) - 2.0; r.top = Editor()->ValueToViewCoords(ev.pitchBend.startBend - 0x2000) - 2.0; r.right = r.left + 4.0; r.bottom = r.top + 4.0; Editor()->SetHighColor(dest->Color()); Editor()->FillEllipse(r); if (ev.IsSelected() && !shadowed && Editor()->IsSelectionVisible()) Editor()->SetHighColor(0, 0, 255); else Editor()->SetHighColor(0, 0, 0); r.InsetBy(-1.0, -1.0); Editor()->StrokeEllipse(r); }
long CPitchBendEventRenderer::Pick( const CEvent &ev, BPoint pickPt, short &partCode) const { if (ev.Duration() > 0) { BPoint start(Editor()->TimeToViewCoords(ev.Start()), Editor()->ValueToViewCoords(ev.pitchBend.startBend - 0x2000)); BPoint stop(Editor()->TimeToViewCoords(ev.Stop()), Editor()->ValueToViewCoords(ev.pitchBend.targetBend - 0x2000)); float best = MAX(fabs(pickPt.x - stop.x), fabs(pickPt.y - stop.y)); float dist = MAX(fabs(pickPt.x - start.x), fabs(pickPt.y - start.y)); partCode = Part_End; if (dist < best) { best = dist; partCode = Part_Start; } if (best > 3.0) { dist = MathUtils::DistanceFromPointToLine(pickPt, start, stop); if (dist < best) { best = dist + 2.0; partCode = Part_Whole; } } if (best > 8.0) return LONG_MAX; return static_cast<long>(best); } else { BPoint diff(pickPt.x - Editor()->TimeToViewCoords(ev.Start()), pickPt.y - Editor()->ValueToViewCoords(ev.pitchBend.startBend - 0x2000)); if ((diff.y > 8) || (diff.y < -8) || (diff.x > 10) || (diff.x < -8)) return LONG_MAX; if (diff.x >= 3.0) partCode = Part_End; else partCode = Part_Whole; return static_cast<long>(MAX(fabs(diff.x), fabs(diff.y))); } }
BRect CPitchBendEventRenderer::Extent( const CEvent &ev) const { float yStart = Editor()->ValueToViewCoords(ev.pitchBend.startBend - 0x2000); float yStop = Editor()->ValueToViewCoords(ev.pitchBend.targetBend - 0x2000); BRect r; r.left = Editor()->TimeToViewCoords(ev.Start()) - 5.0; r.right = Editor()->TimeToViewCoords(ev.Stop()) + 5.0; r.bottom = MAX(yStart, yStop) + 5.0; r.top = MIN(yStart, yStop) - 5.0; return r; }
void CPlaybackTaskGroup::_executeEvent( CEvent &ev, TimeState &tState) { D_INTERNAL(("CPlaybackTaskGroup::_executeEvent(%s)\n", ev.NameText())); switch (ev.Command()) { case EvtType_TaskMarker: { if (ev.task.taskPtr->flags & CPlaybackTask::Task_Finished) { delete ev.task.taskPtr; if (tasks.Empty()) { BMessage message(Player_ChangeTransportState); be_app->PostMessage(&message); } } else { ev.task.taskPtr->Play(); } return; } case EvtType_Interpolate: { // I was originally supposed to have executed at ev.Start() + timeStep, // but I may be a bit later than that -- take the difference into account. // Here's how much time has elapsed since I was dispatched... int32 elapsed = tState.time - ev.Start() + ev.interpolate.timeStep; // If we went past the end, then clip the time. if ((unsigned long)elapsed > ev.interpolate.duration) elapsed = ev.interpolate.duration; CDestination *dest = ev.common.destination; if (dest != NULL) { if (dest->ReadLock(500)) { dest->Interpolate(ev, tState.stack, system_time(), elapsed); dest->ReadUnlock(); } } return; } } CDestination *dest = ev.common.destination; if (dest != NULL) { if (dest->ReadLock(500)) { dest->Execute(ev, system_time()); dest->ReadUnlock(); } } }