On Wed, 2026-01-21 at 14:57 +0000, Richard Shann wrote:
> On Mon, 2026-01-19 at 20:25 +0100, Andreas Schneider wrote:
> > Am 19.01.26 um 18:35 schrieb Richard Shann:
> > > The rebar command I mentioned is very complex; I've created a
> > > script
> > > that adjusts the Denemo bars to match the LilyPond default
> > > barring
> > > from
> > > the cursor onwards for the current staff.
> > > Richard
> > > ;;;;;;;;;ReBarFromCursor
> > > (let ((MaxTicks (* 1536 (GetPrevailingTimeSig #t)))) ;ticks in
> > > full
> > > measure
> > >   (d-PushPosition)
> > >   (define (LastObjectInMeasure?)
> > >         (if (d-NextObjectInMeasure)
> > >                 (begin
> > >                         (d-PrevObjectInMeasure)
> > >                         #f)
> > >                 #t))
> > >   (let nextMeasure ()
> > >         (if (not (None?))
> > >                 (let nextObject ()
> > >                         (if (TupletClose?)
> > >                                 (d-MoveCursorRight))
> > >                         (if (Timesignature?)
> > >                                 (begin
> > >                                         (d-MoveCursorRight)
> > >                                         (set! MaxTicks (* 1536
> > > (GetPrevailingTimeSig #t)))))
> > >                         (if (d-GetStartTick)
> > >                                 (begin
> > >                         
> > >                                         (if (>= (d-GetStartTick)
> > > MaxTicks)
> > >                                                         (d-
> > > SplitMeasure))
> > >                                         (if (d-GetStartTick)
> > >                                                 (begin
> > >                                                         (if (and
> > > (<
> > > (d-GetStartTick) MaxTicks) (LastObjectInMeasure?) (not
> > > (LastMeasure?)))
> > >                                                                 (
> > > d-
> > > MergeWithNextMeasure))
> > >                                                         (disp
> > > "after any split merge start tick " (d-GetStartTick)  "max "
> > > MaxTicks)    
> > >                                                         (disp
> > > "Measure " (d-GetMeasure))        
> > >                                                         ;(d-
> > > WarningDialog "merge?")
> > >                                                         (if (d-
> > > NextObjectInMeasure)
> > >                                                                 (
> > > ne
> > > xtObject))))))))
> > >         (if (d-MoveToMeasureRight)
> > >                 (nextMeasure)))
> > >    (d-PopPosition))
> > > ;;;;;;;;;;;;;;;;;;;
> > 
> > Thanks a lot for this script. It come much closer to what I want
> > than
> > the rebar command. What it does not do is compensating overfull
> > bars 
> > like lilypond, see attached screenshot.
> 
> Here is a complete re-write, not much tested...
> 
> ;;ReBarFromCursor
> (let ((MaxTicks (* 1536 (GetPrevailingTimeSig #t)))(carry 0))
>  (d-PushPosition)
>  (define (LastObjectInMeasure?)
>         (if (d-NextObjectInMeasure)
>                 (begin
>                         (d-PrevObjectInMeasure)
>                         #f)
>                 #t))
>  (define (LastMeasure?)
>                 (= (d-GetMeasure) (d-GetMeasuresInStaff)))
>                 
>  (let loop ()
>  (disp "At " (GetPosition) " carry " carry)
>         (if (Timesignature?)
>                                                 (begin
>                                                         (d-
> MoveCursorRight)
>                                                         (set!
> MaxTicks (* 1536 (GetPrevailingTimeSig #t)))))
>         (if (MeasureEmpty?)
>                 (if (d-MoveToMeasureRight)
>                         (loop))
>                 (if (< (+ carry (d-GetEndTick)) MaxTicks) ;;; too
> little to fill the bar?
>                         (begin (disp "too little")
>                                 (if (not (LastObjectInMeasure?))
>                                         (begin
>                                                 (d-MoveCursorRight)
>                                                                 (loop
> ))
>                                         (begin ;;on the last object
> and too little
>                                                 (if (not
> (LastMeasure?))
>                                                         (begin
>                                                                 (d-
> MergeWithNextMeasure)
>                                                                 (loop
> ))))))
>                                                                 
>                         (begin ;;; not too little to fill bar
>                                 (if (= (+ carry (d-GetEndTick))
> MaxTicks) ;;; if note completes bar
>                                         (begin (disp "just right")
>                                                 (set! carry 0)
>                                                 (if (not
> (LastMeasure?))
>                                                                 (begi
> n
>                                                                      
>    (if (LastObjectInMeasure?)
>                                                                      
>            (begin
>                                                                      
>                    (d-MoveToMeasureRight)
>                                                                      
>                    (loop))
>                                                                      
>            (begin
>                                                                      
>                    (d-MoveCursorRight)
>                                                                      
>                    (d-SplitMeasure)
>                                                                      
>                    (d-MergeWithNextMeasure)
>                                                                      
>                    (loop))))
>                                                                 (begi
> n ;;is last measure, are there more notes?
>                                                                      
>    (if (not (LastObjectInMeasure?))
>                                                                      
>            (begin
>                                                                      
>                    (set! carry (- MaxTicks (+ carry (d-GetEndTick))))
>                                                                      
>                    (d-MoveCursorRight)
>                                                                      
>                    (d-SplitMeasure)
>                                                                      
>                    (d-MergeWithNextMeasure)
>                                                                      
>                    (loop))
>                                                                      
>            (begin
>                                                                      
>                    (d-WarningDialog "It is the last measure and last
> note and the note completes the bar"))))))
>                                                                      
>                    
>                                                 (begin (disp "too
> much") ;;;note exceeds bar
>                                                         (if (> (+
> carry (d-GetEndTick)) MaxTicks) 
>                                                                 (begi
> n
>                                                                      
>    (set! carry (- (+ carry (d-GetEndTick)) MaxTicks))
>                                                                      
>    (d-MoveCursorRight)
>                                                                      
>    (d-SplitMeasure)
>                                                                      
>    (d-MergeWithNextMeasure)
>                                                                      
>    (loop)))))))))))

I've tidied this up a bit and fixed the repositioning of the cursor at
the end so I attach this more polished version.
Richard

;;ReBarFromCursor
(let ((MaxTicks (* 1536 (GetPrevailingTimeSig #t)))(carry 0))
 (d-PushPosition)
 (define (LastObjectInMeasure?)
	(if (d-NextObjectInMeasure)
		(begin
			(d-PrevObjectInMeasure)
			#f)
		#t))
 (define (LastMeasure?)
		(= (d-GetMeasure) (d-GetMeasuresInStaff)))
		
 (let loop ()
 ;(disp "At " (GetPosition) " carry " carry)
	(if (Timesignature?)
						(begin
							(d-MoveCursorRight)
							(set! MaxTicks (* 1536 (GetPrevailingTimeSig #t)))))
	(if (MeasureEmpty?)
		(if (d-MoveToMeasureRight)
			(loop))
		(if (< (+ carry (d-GetEndTick)) MaxTicks) ;;; too little to fill the bar?
			(begin ;(disp "too little")
				(if (not (LastObjectInMeasure?))
					(begin
						(d-MoveCursorRight)
								(loop))
					(begin ;;on the last object and too little
						(if (not (LastMeasure?))
							(begin
								(d-MergeWithNextMeasure)
								(loop))))))
								
			(begin ;;; not too little to fill bar
				(if (= (+ carry (d-GetEndTick)) MaxTicks) ;;; if note completes bar
					(begin ;(disp "just right")
						(set! carry 0)
						(if (not (LastMeasure?))
								(begin
									(if (LastObjectInMeasure?)
										(begin
											(d-MoveToMeasureRight)
											(loop))
										(begin
											(d-MoveCursorRight)
											(d-SplitMeasure)
											(d-MergeWithNextMeasure)
											(loop))))
								(begin ;;is last measure, are there more notes?
									(if (not (LastObjectInMeasure?))
										(begin
											(set! carry (- MaxTicks (+ carry (d-GetEndTick))))
											(d-MoveCursorRight)
											(d-SplitMeasure)
											(d-MergeWithNextMeasure)
											(loop)))))))
											
						(begin ;(disp "too much") ;;;note exceeds bar
							(if (> (+ carry (d-GetEndTick)) MaxTicks) 
								(begin
									(set! carry (- (+ carry (d-GetEndTick)) MaxTicks))
									(d-MoveCursorRight)
									(d-SplitMeasure)
									(d-MergeWithNextMeasure)
									(loop))))))))
	(d-PopPosition))

Reply via email to