2323
2424import org .audiveris .omr .constant .Constant ;
2525import org .audiveris .omr .constant .ConstantSet ;
26+ import org .audiveris .omr .glyph .Glyph ;
2627import org .audiveris .omr .glyph .Shape ;
2728import org .audiveris .omr .math .GeoOrder ;
2829import org .audiveris .omr .math .PointUtil ;
3132import org .audiveris .omr .sheet .Sheet ;
3233import org .audiveris .omr .sheet .Staff ;
3334import org .audiveris .omr .sheet .SystemInfo ;
35+ import org .audiveris .omr .sheet .curve .Curves ;
3436import org .audiveris .omr .sheet .rhythm .Measure ;
3537import org .audiveris .omr .sheet .rhythm .MeasureStack ;
3638import org .audiveris .omr .sheet .ui .ObjectUIModel ;
@@ -611,6 +613,32 @@ public void setNumber (String number)
611613 this .number = number ;
612614 }
613615
616+ //----------//
617+ // setGlyph //
618+ //----------//
619+ @ Override
620+ public void setGlyph (Glyph glyph )
621+ {
622+ super .setGlyph (glyph );
623+
624+ if (glyph != null ) {
625+ if (line == null ) {
626+ // Case of manual ending: we compute the lines based on glyph bounds
627+ // We use the half of standard line thickness to refine coordinates
628+ final int half = (int ) Math .rint (Curves .DEFAULT_THICKNESS / 2 );
629+ final Rectangle b = glyph .getBounds ();
630+ b .grow (-half , -half );
631+
632+ line = new Line2D .Double (b .x , b .y , b .x + b .width , b .y );
633+ leftLeg = new Line2D .Double (b .x , b .y , b .x , b .y + b .height );
634+
635+ if (shape == Shape .ENDING_WRL ) {
636+ rightLeg = new Line2D .Double (b .x + b .width , b .y , b .x + b .width , b .y + b .height );
637+ }
638+ }
639+ }
640+ }
641+
614642 //-----------------//
615643 // upgradeOldStuff //
616644 //-----------------//
@@ -647,11 +675,13 @@ private static class Constants
647675 /**
648676 * User editor for an ending.
649677 * <p>
650- * For an ending, there are 3 handles:
678+ * For an ending, there can be between 3 to 5 handles:
651679 * <ul>
652680 * <li>Left handle, moving only horizontally (with its related leg if any)
681+ * <li>Bottom left handle, moving only vertically (if there is a left leg)
653682 * <li>Top middle handle, moving the whole inter in any direction
654683 * <li>Right handle, moving only horizontally (with its related leg if any)
684+ * <li>Bottom right handle, moving only vertically (if there is a right leg)
655685 * </ul>
656686 */
657687 private static class Editor
@@ -667,6 +697,10 @@ private static class Editor
667697
668698 private final Point2D midRight ;
669699
700+ private final Point2D bottomLeft ;
701+
702+ private final Point2D bottomRight ;
703+
670704 public Editor (final EndingInter ending )
671705 {
672706 super (ending );
@@ -681,18 +715,22 @@ public Editor (final EndingInter ending)
681715 if (ending .leftLeg != null ) {
682716 originalModel .bottomLeft = ending .leftLeg .getP2 ();
683717 model .bottomLeft = ending .leftLeg .getP2 ();
718+ bottomLeft = model .bottomLeft ;
684719 midLeft = PointUtil .middle (ending .leftLeg );
685720 } else {
686721 midLeft = null ;
722+ bottomLeft = null ;
687723 }
688724
689725 if (ending .rightLeg != null ) {
690726 originalModel .bottomRight = ending .rightLeg .getP2 ();
691727 model .bottomRight = ending .rightLeg .getP2 ();
728+ bottomRight = model .bottomRight ;
692729
693730 midRight = PointUtil .middle (ending .rightLeg );
694731 } else {
695732 midRight = null ;
733+ bottomRight = null ;
696734 }
697735
698736 // Global move: move all points
@@ -720,8 +758,8 @@ public boolean move (int dx,
720758 }
721759 });
722760
723- // Left handle: move horizontally only
724761 if (ending .leftLeg != null ) {
762+ // Left handle: move horizontally only
725763 handles .add (new InterEditor .Handle (midLeft )
726764 {
727765 @ Override
@@ -735,12 +773,31 @@ public boolean move (int dx,
735773 PointUtil .add (model .topLeft , dx , 0 );
736774 PointUtil .add (midLeft , dx , 0 );
737775 PointUtil .add (model .bottomLeft , dx , 0 );
738- PointUtil .add (midTop , dx / 2 , 0 );
776+ PointUtil .add (midTop , dx / 2.0 , 0 );
777+
778+ return true ;
779+ }
780+ });
781+
782+ // BottomLeft handle: move vertically only
783+ handles .add (new InterEditor .Handle (bottomLeft )
784+ {
785+ @ Override
786+ public boolean move (int dx ,
787+ int dy )
788+ {
789+ if (dy == 0 ) {
790+ return false ;
791+ }
792+
793+ PointUtil .add (midLeft , 0 , dy / 2.0 );
794+ PointUtil .add (model .bottomLeft , 0 , dy );
739795
740796 return true ;
741797 }
742798 });
743799 } else {
800+ // Left handle: move horizontally only
744801 handles .add (new InterEditor .Handle (model .topLeft )
745802 {
746803 @ Override
@@ -752,15 +809,15 @@ public boolean move (int dx,
752809 }
753810
754811 PointUtil .add (model .topLeft , dx , 0 );
755- PointUtil .add (midTop , dx / 2 , 0 );
812+ PointUtil .add (midTop , dx / 2.0 , 0 );
756813
757814 return true ;
758815 }
759816 });
760817 }
761818
762- // Right handle: move horizontally only
763819 if (ending .rightLeg != null ) {
820+ // Right handle: move horizontally only
764821 handles .add (new InterEditor .Handle (midRight )
765822 {
766823 @ Override
@@ -774,11 +831,30 @@ public boolean move (int dx,
774831 PointUtil .add (model .topRight , dx , 0 );
775832 PointUtil .add (midRight , dx , 0 );
776833 PointUtil .add (model .bottomRight , dx , 0 );
777- PointUtil .add (midTop , dx / 2 , 0 );
834+ PointUtil .add (midTop , dx / 2.0 , 0 );
835+
836+ return true ;
837+ }
838+ });
839+
840+ // BottomRight handle: move vertically only
841+ handles .add (new InterEditor .Handle (bottomRight )
842+ {
843+ @ Override
844+ public boolean move (int dx ,
845+ int dy )
846+ {
847+ if (dy == 0 ) {
848+ return false ;
849+ }
850+
851+ PointUtil .add (midRight , 0 , dy / 2.0 );
852+ PointUtil .add (model .bottomRight , 0 , dy );
778853
779854 return true ;
780855 }
781856 });
857+
782858 } else {
783859 handles .add (new InterEditor .Handle (model .topRight )
784860 {
@@ -791,7 +867,7 @@ public boolean move (int dx,
791867 }
792868
793869 PointUtil .add (model .topRight , dx , 0 );
794- PointUtil .add (midTop , dx / 2 , 0 );
870+ PointUtil .add (midTop , dx / 2.0 , 0 );
795871
796872 return true ;
797873 }
@@ -845,11 +921,9 @@ public void undo ()
845921 public static class Impacts
846922 extends GradeImpacts
847923 {
848- private static final String [] NAMES = new String []
849- { "straight" , "slope" , "length" };
924+ private static final String [] NAMES = new String [] { "straight" , "slope" , "length" };
850925
851- private static final double [] WEIGHTS = new double []
852- { 1 , 1 , 1 };
926+ private static final double [] WEIGHTS = new double [] { 1 , 1 , 1 };
853927
854928 public Impacts (double straight ,
855929 double slope ,
0 commit comments