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))); } }
void DualBendOffsetOp::operator()( CEvent &ev, TClockType clockType) { if (ev.Command() == EvtType_PitchBend) { if (ev.Duration() > 0) { ev.pitchBend.startBend = (uint16)CLAMP(0, ((int16)ev.pitchBend.startBend) + delta, 0x3fff ); ev.pitchBend.targetBend = (uint16)CLAMP(0, ((int16)ev.pitchBend.targetBend) + delta, 0x3fff); } else { ev.pitchBend.startBend = ev.pitchBend.targetBend = (uint16)CLAMP(0, ((int16)ev.pitchBend.targetBend) + delta, 0x3fff ); } } }