Re: How to generate notes in a scale

2008-04-21 Thread Peter Chubb

 Mats == Mats Bengtsson [EMAIL PROTECTED] writes:

Mats Isn't it possible to obtain the same result in a simpler way by
Mats just transposing a hard coded template in C major into the
Mats current key? 

You'ld need a different template for each degree of each kind of
scale, I think.  And for flatted and sharpened turns.  The number of
templates multiplies fast.  If you have a general rule for going one
step up, one step down from any note given the current key, then you
can do any turn; you just need to handle the alteration.

Mats Information on the current key signature is
Mats available in the keySignature context property (see the internal
Mats reference documentation for Key-engraver), but perhaps not in a
Mats very useful way.

Hmmm.  How does one get at that from a music function?
ly:context-property ??

Mats  Also, don't forget about the instrumentTransposition property
Mats (which is set by the \transposition command) if you want to
Mats handle transposing instruments correctly.

That shouldn't matter.



Here's what I have so far, anyway.  It mostly works, and handles
ordinary turns.  I'm not happy about tenuto (a note marked tenuto
should be lengthened slightly and steal time from the next note on),
nor about the handling of grace notes.  And there are lots of
ornaments I haven't handled yet.

The resulting Midi sounds reasonable, but needs more work.  In
particular, it sounds (for clarinet) as if slurred notes are being
tongued (I don't know enough about Midi yet, but suspect that when a
EndNote event and a StartNote event are adjacent, one should omit
the EndNote.)  And there are lots of tempo markings to handle.

I wish that Director Musices were implemented in scheme not common lisp...

---articulate.ly

#(define ac:staccatoFactor '(1 . 8))
#(define ac:tenutoFactor '(1 . 1))
#(define ac:normalFactor '(7 . 8))

% assume start in C major
#(define ac:current-key (make-music
  'KeyChangeEvent
  'tonic
  (ly:make-pitch -1 0 0)
  'pitch-alist
  (list (cons 0 0)
(cons 1 0)
(cons 2 0)
(cons 3 0)
(cons 4 0)
(cons 5 0)
(cons 6 0

#(define ac:currentDuration (ly:make-duration 0 0))

#(define (ac:up note)
  (let* ((pitch (ly:music-property note 'pitch))
 (notename (ly:pitch-notename pitch))
 (new-notename (if (eq? notename 6) 0 (+ 1 notename)))
 (alterations (ly:music-property ac:current-key 'pitch-alist))
 (new-alteration (cdr (assq new-notename alterations)))
 (new-octave (if (eq? new-notename 0) (+ 1 (ly:pitch-octave pitch))
  (ly:pitch-octave pitch)))
   )
   (set! (ly:music-property note 'pitch)(ly:make-pitch new-octave new-notename 
new-alteration

#(use-modules (ice-9 debug))

#(define (ac:down note)
  (begin
  (let* ((pitch (ly:music-property note 'pitch))
 (notename (ly:pitch-notename pitch))
 (new-notename (if (eq? notename 0) 6 (- notename 1)))
 (alterations (ly:music-property ac:current-key 'pitch-alist))
 (new-alteration (cdr (assq new-notename alterations)))
 (new-octave (if (eq? new-notename 6) (- (ly:pitch-octave pitch) 1)
  (ly:pitch-octave pitch)))
   )
   (set! (ly:music-property note 'pitch)(ly:make-pitch new-octave new-notename 
new-alteration
)

#(define (ac:articulate-one-note m fraction)
  Replace m with m*fraction rest*(1-fraction)
  (if  (eq? 'NoteEvent (ly:music-property m 'name))
   (let*
((dur (ly:music-property m 'duration))
 (l (ly:duration-log dur))
 (d (ly:duration-dot-count dur))
 (factor (ly:duration-factor dur))
 (num (car fraction))
 (denom (cdr fraction)))
(begin
 (set! ac:currentDuration dur)
 (set! (ly:music-property m 'duration)
  (ly:make-duration l d
   (* num (car factor))
   (* denom (cdr factor))
   m))

#(define ac:inSlur #f)
#(define ac:inPhrasingSlur #f)

% If there's an articulation, use it.
% If in a slur, use tenutoFactor instead.
% What to do about phrasing slurs?
% Expect an EventChord
% trills, turns., ornaments pralls etc.
% are also treated as Articulations.
% How should they be handled???
#(define (ac:getactions:elements es actions)
  (let* ((factor ac:normalFactor)
 (e (car es))
 (tail (cdr es)))
   (case (ly:music-property e 'name)
((SkipEvent)
 (set! factor (cons 1 1)))
((RestEvent)
 (set! factor (cons 1 1)))
((ArticulationEvent)
 (let ((articname (ly:music-property e 'articulation-type)))
  (cond 
   ((string= articname staccato)
(set! factor ac:staccatoFactor))
   ((string= articname tenuto)
(set! factor ac:tenutoFactor))
   ((string= articname mordent)
(set! actions (list 'mordent)))
   ((string= articname prall)
(set! actions (list 'trill)))
   ((string= articname trill)
(set! actions (list 'trill)))
   

Re: How to generate notes in a scale

2008-04-20 Thread Peter Chubb
OK, here's how I did it in the end.  Is there a better way???

#(define ac:current-key (make-music
  'KeyChangeEvent
  'tonic
  (ly:make-pitch -1 0 0)
  'pitch-alist
  (list (cons 0 0)
(cons 1 0)
(cons 2 0)
(cons 3 0)
(cons 4 0)
(cons 5 0)
(cons 6 0

#(define (ac:up note)
Given a NoteEvent, replace its pitch with the next one 
 up in the current scale.
 Doesn't cope too well with melodic minors
  (let* ((pitch (ly:music-property note 'pitch))
 (notename (ly:pitch-notename pitch))
 (new-notename (if (eq? notename 6) 0 (+ 1 notename)))
 (alterations (ly:music-property ac:current-key 'pitch-alist))
 (new-alteration (cdr (assq new-notename alterations)))
 (new-octave (if (eq? new-notename 0) (+ 1 (ly:pitch-octave pitch))
  (ly:pitch-octave pitch)))
   )
   (set! 
(ly:music-property note 'pitch)
(ly:make-pitch new-octave new-notename new-alteration

(ac:down is analogous to ac:up)

Whenever I see a KeyChangeEvent in the rest of the program I update
ac:current-key.

Is there a better way?  Does Lilypond keep track of the current key
signature for me?

--
Dr Peter Chubb  http://www.gelato.unsw.edu.au  peterc AT gelato.unsw.edu.au
http://www.ertos.nicta.com.au   ERTOS within National ICT Australia


___
lilypond-user mailing list
lilypond-user@gnu.org
http://lists.gnu.org/mailman/listinfo/lilypond-user


How to generate notes in a scale

2008-04-18 Thread Peter Chubb

Hi,
I'm currently trying to get improved MIDI output.  I have a
scheme function that processes articulations like staccato, tenuto,
etc., working now.  But for turns and trills, I need to generate the
notes around a note in the current key.

Has anyone written a scheme function to do this yet?  for
example, given e return fis (if the current key is g), or given e return f (if
the current key is c)?  I'm a bit stuck, as I can't even work out how 
to get at the current key within a music-function.
--
Dr Peter Chubb  http://www.gelato.unsw.edu.au  peterc AT gelato.unsw.edu.au
http://www.ertos.nicta.com.au   ERTOS within National ICT Australia


___
lilypond-user mailing list
lilypond-user@gnu.org
http://lists.gnu.org/mailman/listinfo/lilypond-user