Thanks, David.
@Vaughan
For a short test ... this compiles, but I can't listen to the resulting
pan in midi ....
I changed the PropertySet to ApplyContext with a lambda. This should
work in variables, as it returns an applyContext expression.
As with the previous solution, you have to care about the order autopan
is called.
It might be a good idea to either use a performer (engraver in midi
context) and/or to track context id's, so that each context is counted once.

HTH, Jan-Peter


On 27.01.2014 15:15, David Kastrup wrote:
> Jan-Peter Voigt <jp.vo...@gmx.de> writes:
>
>> Hi Vaughan,
>>
>> if global is a music-function calling autopan, it will evaluate it
>> everytime. If global is a variable, its value is set, once it is assigned.
>> So if you have to wrap it in music-function. If you always have a
>> variable "global" containing all you need, you can wrap that in a function:
> I'd recommend putting this into an \applyContext call.  That way, you
> get a call for each use in a different context.
>

\version "2.18.0"

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%{

   Auto panner

   Spreads voices evenly from -1 (LEFT) to 1 (RIGHT)

   Usage:

   \include "autopanner.ly"
   \SetTotalAutopanStaves #2 % or \SetTotalAutopanVoices

   \score {
   <<
   \new Staff <<
   \set Staff.midiInstrument = #"violin"
   \autopan
   { ... music here }
   >>
   \new Staff <<
   \set Staff.midiInstrument = #"cello"
   \autopan
   { ... music here }
   >>
   >>
   }

%}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


#(define autopan-total-voices 2.0)

#(define autopan-current-voice -1.0)

#(define autopan-staff-or-voice 'Staff)

ResetAutoPanning =
#(define-void-function
  (parser location)
  ()
  (set! autopan-current-voice -1.0)
  )

SetTotalAutopanVoices =
#(define-void-function
  (parser location total-voices)
  (number?)
  (begin
   (set! autopan-total-voices total-voices)
   (set! autopan-current-voice -1.0)
   (set! autopan-staff-or-voice 'Voice)
   )
  )

SetTotalAutopanStaves =
#(define-void-function
  (parser location total-voices)
  (number?)
  (begin
   (set! autopan-total-voices total-voices)
   (set! autopan-current-voice -1.0)
   (set! autopan-staff-or-voice 'Staff)
   )
  )


autopan =
#(define-scheme-function (parser location)()
   (begin
    (set! autopan-current-voice (+ autopan-current-voice 1.0))
    (make-music
     'ApplyContext
     'procedure
     (lambda (context)
       (let ((ctx (ly:context-find context autopan-staff-or-voice)))
         (if (not (ly:context? ctx)) (set! ctx context))
         ;(ly:message "context ~A" ctx)
         (ly:context-set-property! ctx 'midiPanPosition
           (+ -1.0
             (* autopan-current-voice
               (/ 2.0
                 (- autopan-total-voices 1.0)
                 )
               )
             )))
       ))
     ))

_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to