MCPcopy Create free account
hub / github.com/BespokeSynth/BespokeSynth / ClipNotes

Method ClipNotes

Source/NoteCanvas.cpp:488–538  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

486}
487
488void NoteCanvas::ClipNotes()
489{
490 bool anyHighlighted = false;
491 float earliest = FLT_MAX;
492 float latest = 0;
493 std::vector<CanvasElement*> toDelete;
494 for (auto* element : mCanvas->GetElements())
495 {
496 if (element->GetHighlighted())
497 {
498 anyHighlighted = true;
499 if (element->GetStart() < earliest)
500 earliest = element->GetStart();
501 if (element->GetEnd() > latest)
502 latest = element->GetEnd();
503 }
504 else
505 {
506 toDelete.push_back(element);
507 }
508 }
509
510 if (anyHighlighted)
511 {
512 for (auto* remove : toDelete)
513 mCanvas->RemoveElement(remove);
514
515 int earliestMeasure = int(earliest * mNumMeasures);
516 int latestMeasure = int(latest * mNumMeasures) + 1;
517 int clipStart = 0;
518 int clipEnd = mNumMeasures;
519
520 while (earliestMeasure - clipStart >= (clipEnd - clipStart) / 2 ||
521 clipEnd - latestMeasure >= (clipEnd - clipStart) / 2)
522 {
523 if (earliestMeasure - clipStart >= (clipEnd - clipStart) / 2)
524 clipStart += (clipEnd - clipStart) / 2;
525 if (clipEnd - latestMeasure >= (clipEnd - clipStart) / 2)
526 clipEnd -= (clipEnd - clipStart) / 2;
527 }
528
529 SetNumMeasures(clipEnd - clipStart);
530
531 ofLog() << earliest << " " << latest << " " << clipStart << " " << clipEnd;
532
533 int shift = -clipStart;
534
535 for (auto* element : mCanvas->GetElements())
536 element->SetStart(element->GetStart() + float(shift) / mNumMeasures, true);
537 }
538}
539
540void NoteCanvas::QuantizeNotes()
541{

Callers

nothing calls this directly

Calls 6

ofLogClass · 0.85
GetHighlightedMethod · 0.80
GetStartMethod · 0.80
GetEndMethod · 0.80
RemoveElementMethod · 0.80
SetStartMethod · 0.80

Tested by

no test coverage detected