Re: Get the pitch as number

2011-02-15 Thread Gilles THIBAULT



I see now what the problem was. however, I'm not quite sure yet how to
avoid doing similar mistakes in the future, but maybe I'll get used to
it (For example, how do I know that I should start looking for
EventChord rather than NoteEvents?)


You can start looking for NoteEvent but remenber you cannot add a markup to 
a NoteEvent.

c-hello %% allowed ( equivalent to c-hello )
c-hello %% not allowed



What I want to do is to map a 43-tone scale (octave divided
in 43-tones) to the first 43 tones of the chromatic scale so it is
important that I can tell middle C from C in the first octave.
ly:pitch-semitones seemed to be an appropriate method.


+1 (didn't understantood that. Sorry)

Gilles 




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


Re: Get the pitch as number

2011-02-14 Thread Henrik Frisk
On Fri, Feb 11, 2011 at 3:10 PM, Gilles THIBAULT
gilles.thiba...@free.fr wrote:

 It appears to me that I'm getting a list rather than an integer, but if I
 run (get-text texts (ly:pitch-semitones (ly:make-pitch 0 1 0)))

 So get-pitch was probably the culprit ...


 NB
 You use : ly:pitch-semitones. You'll get first only a number from a note
 above the middle C, then your texts list will be very extensive. Are you
 sure you
 don't want ly:pitch-notename instead ?

Thanks Gilles,

I see now what the problem was. however, I'm not quite sure yet how to
avoid doing similar mistakes in the future, but maybe I'll get used to
it (For example, how do I know that I should start looking for
EventChord rather than NoteEvents?)

I'm not sure I understand your comment about using ly:pitch-notename
instead, but the method for getting the pitch is not necessarily
important. What I want to do is to map a 43-tone scale (octave divided
in 43-tones) to the first 43 tones of the chromatic scale so it is
important that I can tell middle C from C in the first octave.
ly:pitch-semitones seemed to be an appropriate method.

best,

/Henrik

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


Re: Get the pitch as number

2011-02-11 Thread Gilles THIBAULT



It appears to me that I'm getting a list rather than an integer, but if I
run (get-text texts (ly:pitch-semitones (ly:make-pitch 0 1 0)))

So get-pitch was probably the culprit ...

%
#(define (make-text-script x)
(make-music 'TextScriptEvent
   'direction DOWN
   'text (get-text texts x)))

#(define (add-text-script m)
 (if (equal? (ly:music-property m 'name) 'EventChord)
 (ly:music-set-property! m 'elements
   (cons (make-text-script (get-pitch m))
 (ly:music-property m 'elements)))
 (let ((es (ly:music-property m 'elements))
(e (ly:music-property m 'element)))
   (if (pair? es)(ly:music-set-property! m 'elements
  (map add-text-script es)))
   (if (ly:music? e)(ly:music-set-property! m 'element
  (add-text-script e)
 m)

#(define (get-text ls n)
 (if (or ( n 0)(= n (length ls)))
   
   (list-ref ls n)))

#(define (get-pitch music)  %% music as a eventChord
 (let* ((es (ly:music-property music 'elements))
(p  (ly:music-property (car es) 'pitch)))
;(display \npitch : )(ly:pitch-semitones p)(newline)
(if (ly:pitch? p)(ly:pitch-semitones p) -1)))
%%(if (ly:pitch? p)(ly:pitch-notename p) -1)))

#(define texts '(zero one two three four))
%%#(define texts '(zero one two three four))%% with use of
ly:pitch-notename

addText = #(define-music-function(parser location m)(ly:music?)
(add-text-script m))

music = \relative c' { b c cis d dis e f r}
%% music = \relative c' { b c d e f g a r} %% with use of ly:pitch-notename

\score {
  \new Staff \addText \music
}


NB
You use : ly:pitch-semitones. You'll get first only a number from a note
above the middle C, then your texts list will be very extensive. Are you 
sure you

don't want ly:pitch-notename instead ?

Gilles



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


Get the pitch as number

2011-02-09 Thread Henrik Frisk
Hi all,

I'm trying to write a couple of functions that will attach a given
text script to a note depending on the pitch. In the example below I
get the first item in the list, as expected if I run (get-text 1). If
I run (get-pitch msc) I get ((0)) and if I try to compile the file or
run (add-text-script) I get

transformer.ly:23:44: In procedure - in expression (- n 1):
transformer.ly:23:44: Wrong type argument in position 1: (0)

I'm a beginner in Scheme so I'm probably doing something stupid here.
It appears to me that I'm getting a list rather than an integer, but
if I run (get-text texts (ly:pitch-semitones (ly:make-pitch 0 1 0))) I
get the expected output. Why am I not getting an integer in my example
and/or how can I access the integer value in my call to
(ly:pitch-semitones)?

Thanks for any input!

/Henrik

\version 2.12.3

#(define (make-text-script x)
(make-music 'TextScriptEvent
'direction DOWN
'text (get-text texts x)))

#(define (add-text-script m)
(if (equal? (ly:music-property m 'name) 'EventChord)
(set! (ly:music-property m 'elements)
  (cons (make-text-script (get-pitch m))
(ly:music-property m 'elements)))
(let ((es (ly:music-property m 'elements))
  (e (ly:music-property m 'element)))
  (map (lambda (y) (add-text-script y)) es)
  (if (ly:music? e)
  (add-text-script e
m)

#(define get-text (lambda (ls n)
(if (eq? n 1)
(car ls)
(get-text (cdr ls) (- n 1)

#(define (get-pitch music)

   (let ((es (ly:music-property music 'elements))
 (e (ly:music-property music 'element))
 (p (ly:music-property music 'pitch)))
   (cond
   ((ly:pitch? p)
(ly:pitch-semitones p))
   ((pair? es)
   (map (lambda (x) (get-pitch x)) es))
   ((ly:music? e)
   (get-pitch e)

#(define texts '(one two three four))

#(define msc (make-music
  'SequentialMusic
  'elements
  (list (make-music
  'EventChord
  'elements
  (list (make-music
  'NoteEvent
  'duration
  (ly:make-duration 2 0 1 1)
  'pitch
  (ly:make-pitch 0 0 0)))

addText = #(define-music-function
 (parser location m)
 (ly:music?) (add-text-script m))

music = \relative c' { d }

\score {
\new Staff  {
\addText { \music }
} 
}

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