ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* LilyPond module for LilyPond 2.9.x
@ 2006-09-26 18:34 Henning Hraban Ramm
  2006-09-26 20:12 ` Henning Hraban Ramm
  2006-09-26 21:41 ` Willi Egger
  0 siblings, 2 replies; 11+ messages in thread
From: Henning Hraban Ramm @ 2006-09-26 18:34 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 505 bytes --]

Yeah, I finally got it working with recent versions of LilyPond!
(The most important change was from "linewidth" to "line-width", and  
I overlooked that far too long...)

The module still has lots of issues (e.g. paths for external command  
like lilypond are hardcoded), but it does what I want it to do. ;-)

Could someone please exchange the module in the garden?

Greetlings from Lake Constance!
Hraban
---
http://www.fiee.net/texnique/
http://contextgarden.net
http://www.cacert.org (I'm an assurer)

[-- Attachment #2: t-lilypond.tex --]
[-- Type: application/octet-stream, Size: 8940 bytes --]

%D \module
%D   [       file=t-lilypond,
%D        version=2006.09.26,
%D          title=\CONTEXT\ User Modules,
%D       subtitle=Lilypond Connections (Music Typesetting),
%D         author=Christopher Creutzig \& Henning Hraban Ramm,
%D           date=\currentdate,
%D      copyright=Christopher Creutzig]

%M \usemodule[lilypond]

%D This module serves to include lilypond music directly in the
%D \CONTEXT\ source, just as \METAPOST\ code can be.  Before starting
%D with the implementation, one or two examples are in order.
%D \startbuffer[sample]
%D \startlilypond
%D % Telemann, TWV 40:11
%D \version "2.9.18"
%D 
%D \relative c' {
%D \set Staff.instrumentName = flute
%D \key fis \minor
%D \time 3/4
%D \partial 4
%D 
%D    r8 fis'8 | fis4. cis8 a cis | fis, a cis fis a fis |
%D    b, d fis b d b | eis,, gis cis eis gis b, |
%D    a fis' gis, fis' cis eis | fis,4 r8
%D    a' gis fis | e gis, a e' fis cis |
%D    d fis, gis b e d | cis4 \trill r8
%D    cis b a | b dis e gis cis, b |
%D    a e' dis fis b, a | gis4 \trill r8
%D }
%D \stoplilypond
%D \stopbuffer
%D
%D The input
%D
%D \typebuffer[sample]
%D
%D is typeset as
%D
%D \getbuffer[sample]
%D
%D \type{\startlilypond} accepts options, as in\crlf
%D \type{\startlilypond[staffsize=24, linewidth=14cm, indent=5cm, time=no]}:
%D 
%D \nobreak
%D \startlilypond[staffsize=24,linewidth=14cm,indent=5cm,time=no]
%D \version "2.9.18"
%D \relative c' {
%D \set Staff.instrumentName = flute
%D \key fis \minor
%D \time 3/4
%D \partial 4
%D    r8 fis'8 | fis4. cis8 a cis | fis, a cis fis a fis |
%D    b, d fis b d b | eis,, gis cis eis gis b, |
%D    a fis' gis, fis' cis eis | fis,4 r8
%D    a' gis fis | e gis, a e' fis cis |
%D    d fis, gis b e d | cis4 \trill r8
%D    cis b a | b dis e gis cis, b |
%D    a e' dis fis b, a | gis4 \trill r8
%D }
%D \stoplilypond
%D
%D It is also possible to mix text and music:
%D \lower 8.2pt\hbox{\lilypond[fragment=true,staffsize=16,time=no]{g'}} is a g.
%D
%D TODO: Complete list of options.
%D
%D  staffsize=20,
%D  indent=0pt,
%D  time=yes,
%D  align=?,% default depends on fragment=...
%D  fragment=no,
%D  barnumbers=no,
%D
%D
%D TODO: The \type{\lower} in the example above should not be necessary.
%D
%D TODO: Switches to turn off the clef etc.
%D
%D TODO: Proper support for multipage results.
%D
%D TODO: lilypond -> \CONTEXT.
%D
%D \page
%D Now for the implementation.  As usual, we use a prefix for buffers,
%D \type{\getparameters} etc.:

\unprotect
\def\??lily{lilypond-}

%D Define the text snippets to be placed around fragments.
%D Since lilypond uses similar syntax to \TeX, we must do some catcode fiddling.
\bgroup
\catcode`\/=\@@escape
/catcode`/\=/@@other
/catcode`/#=/@@other
/catcode`/<=/@@begingroup
/catcode`/>=/@@endgroup
/catcode`/{=/@@other
/catcode`/}=/@@other
/catcode`/%=/@@other
/gdef/lily!fragmentprefix<
/string^^J
/string^^J
{/string^^J
% ly snippet contents follows:/string^^J
>

/gdef/lily!fragmentsuffix</string^^J
% end ly snippet/string^^J
}/string^^J
>

/gdef/lily!prefix</string^^J
%#(set! toplevel-score-handler print-score-with-defaults)/string^^J
%#(set! toplevel-music-handler 
  (lambda (p m) 
   (if (not (eq? (ly:music-property m 'void) #t)) 
        (print-score-with-defaults 
         p (scorify-music m p)))))/string^^J
/string^^J
#(ly:set-option (quote no-point-and-click))/string^^J
/string^^J
%#(define version-seen #t)/string^^J
\version "2.9.18"/string^^J
/iflily!time/else
% switch off time signature/string^^J
\layout {
  ragged-last = ##t
  \context {
   \Score
    timing = ##f
  }/string^^J
  \context {
   \Staff
    \remove "Time_signature_engraver"
  }
}/string^^J
/fi
/iflily!barnumbers/else
% switch off bar numbers/string^^J
\layout {
 \context {
  \Score
   \remove "Bar_number_engraver"
 }
}/string^^J
/fi
\paper {/string^^J
  #(define dump-extents #t)/string^^J
  ragged-right = /iflily!align ##f/else ##t/fi/string^^J
  indent = /withoutpt/the/lily!indent\pt/string^^J
  line-width = /withoutpt/the/lily!linewidth\pt/string^^J
  vsize = /withoutpt/the/lily!vsize\pt/string^^J
  printpagenumber = ##f/string^^J
  oddFooterMarkup=##f/string^^J
  oddHeaderMarkup=##f/string^^J
  bookTitleMarkup = ##f/string^^J
  scoreTitleMarkup = ##f/string^^J
}/string^^J
>

/gdef/lily!hash<#>
/egroup

\newdimen\lily!linewidth
\newdimen\lily!vsize
\newdimen\lily!indent
\newif\iflily!align
\newif\iflily!time
\newif\iflily!barnumbers

\newcount\lily!figures

%D Again, as usual, there is a \type{\setuplilypond} command
%D that accepts the same parameters as \type{\lilypond} and
%D \type{\startlilypond} do in their optional argument:
\def\setuplilypond{\dosingleempty\dosetuplilypond}

\def\dosetuplilypond[#1]{%
   \getparameters[\??lily][#1]%
}

%D We set the following defaults:
\setuplilypond
  [staffsize=20,
   indent=0pt,
   time=\v!yes,
   align=?,% default depends on fragment=...
   fragment=\v!no,
   barnumbers=\v!no,
   ]

%D \type{\startlilypond} is a multistage implementation, because
%D end-of-line characters must be treated specially in the
%D \type{\startlilypond}\textellipsis\type{\stoplilypond} range.
\def\startlilypond{\dosingleempty\dostartlilypond}

\def\dostartlilypond[#1]{%
   \bgroup
   \obeylines
   \dodostartlilypond[{#1}]%
}

\long\def\dodostartlilypond[#1]#2\stoplilypond{%
   \egroup% from \dostartlilypond
   \bgroup%
%D The default of the \type{linewidth} parameter is the local
%D \type{\hsize}.
   \setlocalhsize
   \getparameters[\??lily][linewidth=\the\localhsize,height=\the\textheight,#1]%
   \lily!linewidth\dimexpr\getvalue{\??lily linewidth}\relax
   \lily!vsize\dimexpr\getvalue{\??lily height}\relax
   \lily!indent\dimexpr\getvalue{\??lily indent}\relax
%D The default of \type{align} depends on whether we typeset a fragment:
   \@EAEAEA\doifelse\getvalue{\??lily align}{\v!yes}%
      \lily!aligntrue\lily!alignfalse
   \@EAEAEA\doif\getvalue{\??lily fragment}{\v!no}{%
     \@EAEAEA\doif\getvalue{\??lily align}?
        \lily!aligntrue
   }%
   \@EAEAEA\doifelse\getvalue{\??lily time}\v!yes
      \lily!timetrue\lily!timefalse
%D We are using a counter to keep the different lilypond pieces
%D separate.  This allows to typeset them only once, during the
%D first run.
%D
%D TODO: This won't work any longer once we pass the remaining
%D vertical space to lilypond.
   \global\advance\lily!figures\plusone
   \startmode[*\v!first]% 
   \def\obeyedlines{\string^^J}%
   \convertargument#2\to\ascii
   \expanded{%
   \setbuffer[lilypond-\the\lily!figures]%
   \lily!prefix
   \lily!hash(set-global-staff-size \getvalue{\??lily staffsize})\string^^J%
   \ifundefined{\??lily fragment}\else\lily!fragmentprefix\fi
   %% TODO: Option "packed"
   \ascii%
   \ifundefined{\??lily fragment}\else\lily!fragmentsuffix\fi
   }%
   \endbuffer%
%D Generating a pdf directly always creates a whole page, so we generate eps first.
%D If \type{\ifeof18} creates an error for you, your pdfetex is too old.
%D just change it to \iftrue then.  (\type{\ifeof18} checks whether \type{\write18}
%D is disabled.)
	\def\LP{/usr/local/bin/lilypond -b eps -f eps -dno-gs-load-fonts -dinclude-eps-fonts }
	\def\TU{/usr/local/teTeX/bin/powerpc-apple-darwin-current/texutil }
	\def\toPDF{/usr/local/teTeX/bin/powerpc-apple-darwin-current/epstopdf }
	%\def\toPDF{\TU --figures --epstopdf } % not yet in Ruby version
	
   \ifeof18
   	\installprogram{\LP \bufferprefix lilypond-\the\lily!figures.tmp}%
   \else
      \executesystemcommand{\LP \bufferprefix lilypond-\the\lily!figures.tmp}%
      %\executesystemcommand{rm \bufferprefix lilypond-\the\lily!figures-systems.tex}
      %\executesystemcommand{rm \bufferprefix lilypond-\the\lily!figures-systems.texi}
   \fi
   \doif\jobsuffix{pdf}{%
      \executesystemcommand{\toPDF \bufferprefix lilypond-\the\lily!figures.eps}%
      %\executesystemcommand{rm \bufferprefix lilypond-\the\lily!figures.eps}
   }%
   \stopmode% only first run
   \doifelse\jobsuffix{pdf}
     {\edef\lily!img{\bufferprefix lilypond-\the\lily!figures.pdf}}%
     {\edef\lily!img{\bufferprefix lilypond-\the\lily!figures.eps}}%
%D
%D TODO: Get the relevant dimension directly from lilypond,
%D to place the instrument name into the left margin for
%D short snippets as well.
%D If we are not in the middle of some text, we have to check
%D whether lilypond created an image that is wider than requested:
%D It places the instrument names in the left margin.
   \ifvmode
      \getfiguredimensions[\bufferprefix lilypond-\the\lily!figures.pdf]%
      \leavevmode%
      \newdimen\FigWidth
      \FigWidth=\figurewidth
      \ifdim\FigWidth>\localhsize
        \!!dimena=\localhsize
        \advance\!!dimena by-\FigWidth
        \noindent\hskip\!!dimena
      \fi
   \fi
   \externalfigure[\lily!img]%
   \egroup%
}%

%D For short snippets, we define an inline alternative to
%D our start/stop pair:
\def\lilypond{\dosingleempty\dolilypond}

\def\dolilypond[#1]#2{\startlilypond[#1]#2\stoplilypond}

\protect
%D End of file

[-- Attachment #3: Type: text/plain, Size: 1 bytes --]



[-- Attachment #4: Type: text/plain, Size: 139 bytes --]

_______________________________________________
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: LilyPond module for LilyPond 2.9.x
  2006-09-26 18:34 LilyPond module for LilyPond 2.9.x Henning Hraban Ramm
@ 2006-09-26 20:12 ` Henning Hraban Ramm
  2006-09-26 20:23   ` Hans Hagen
  2006-09-26 21:41 ` Willi Egger
  1 sibling, 1 reply; 11+ messages in thread
From: Henning Hraban Ramm @ 2006-09-26 20:12 UTC (permalink / raw)


Am 2006-09-26 um 20:34 schrieb Henning Hraban Ramm:

> Yeah, I finally got it working with recent versions of LilyPond!

No, it doesn't. :-(
And it's strange: the external command for lilypond gets called, but  
not that for epstopdf:

% I tried different methods to convert the LilyPond EPS to PDF:
	\def\LP{/usr/local/bin/lilypond -b eps -f eps -dno-gs-load-fonts - 
dinclude-eps-fonts }
	%\def\TU{/usr/local/teTeX/bin/powerpc-apple-darwin-current/texutil }
	\def\TU{perl /usr/local/teTeX/share/texmf.local/scripts/context/perl/ 
texutil.pl }
	%\def\PDF{/usr/local/teTeX/bin/powerpc-apple-darwin-current/epstopdf }
	\def\PDF{\TU --figures --epstopdf } % --figures  not yet in Ruby  
version
	
    \ifeof18
    	\installprogram{\LP \bufferprefix lilypond-\the\lily!figures.tmp}%
	   \doif\jobsuffix{pdf}{%
	      \installprogram{\PDF \bufferprefix lilypond-\the\lily! 
figures.eps}%
	   }%
    \else
       \executesystemcommand{\LP \bufferprefix lilypond-\the\lily! 
figures.tmp}%
       \doif\jobsuffix{pdf}{%
	\executesystemcommand{\PDF \bufferprefix lilypond-\the\lily! 
figures.eps}%
	}%
    \fi


I thought it would work, because I already had a PDF of my score EPS  
from a previous test.
If I call one of the above epstopdf commands manually, it works, i.e.  
the notes appear in my PDF after the next texexec run.

Somewhere in the output it says "system commands are disabled" - but  
the LilyPond call works, and write18 is enabled in my texexec.ini

Greetlings from Lake Constance!
Hraban
---
http://www.fiee.net/texnique/
http://contextgarden.net
http://www.cacert.org (I'm an assurer)

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: LilyPond module for LilyPond 2.9.x
  2006-09-26 20:12 ` Henning Hraban Ramm
@ 2006-09-26 20:23   ` Hans Hagen
  2006-09-26 20:52     ` Henning Hraban Ramm
  0 siblings, 1 reply; 11+ messages in thread
From: Hans Hagen @ 2006-09-26 20:23 UTC (permalink / raw)


Henning Hraban Ramm wrote:
>   
> % I tried different methods to convert the LilyPond EPS to PDF:
> 	\def\LP{/usr/local/bin/lilypond -b eps -f eps -dno-gs-load-fonts - 
> dinclude-eps-fonts }
> 	%\def\TU{/usr/local/teTeX/bin/powerpc-apple-darwin-current/texutil }
> 	\def\TU{perl /usr/local/teTeX/share/texmf.local/scripts/context/perl/ 
> texutil.pl }
> 	%\def\PDF{/usr/local/teTeX/bin/powerpc-apple-darwin-current/epstopdf }
> 	\def\PDF{\TU --figures --epstopdf } % --figures  not yet in Ruby  
> version
> 	
>   

use texmfstart!

texmfstart whateverscript whateverargs

will free you from adding the path

lilypond -b eps -f eps -dno-gs-load-fonts -dinclude-eps-fonts

or texmfstart bin:lilypond .... 

conversion to pdf: 

texmfstart pdftops somefile.eps 

if may be worth using the -ifchanged cum suis features so that you don't get more runs than needed

Hans  


-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
                                             | www.pragma-pod.nl
-----------------------------------------------------------------

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: LilyPond module for LilyPond 2.9.x
  2006-09-26 20:23   ` Hans Hagen
@ 2006-09-26 20:52     ` Henning Hraban Ramm
  2006-09-27  7:55       ` Hans Hagen
  0 siblings, 1 reply; 11+ messages in thread
From: Henning Hraban Ramm @ 2006-09-26 20:52 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 907 bytes --]

Am 2006-09-26 um 22:23 schrieb Hans Hagen:
> use texmfstart!
>
> texmfstart whateverscript whateverargs
>
> will free you from adding the path
>
> lilypond -b eps -f eps -dno-gs-load-fonts -dinclude-eps-fonts
>
> or texmfstart bin:lilypond ....
>
> conversion to pdf:
>
> texmfstart pdftops somefile.eps
>
> if may be worth using the -ifchanged cum suis features so that you  
> don't get more runs than needed

Thank you very much, that works! Now I have:
\def\LP{texmfstart --exec bin:lilypond -b eps -dno-gs-load-fonts - 
dinclude-eps-fonts }
\def\PDF{texmfstart --ifchanged pstopdf }
with \executesystemcommand or \installprogram

If I add --ifchanged to the lilypond call, it never does anything;  
without it's called twice (like before, I couldn't find out why).

Greetlings from Lake Constance!
Hraban
---
http://www.fiee.net/texnique/
http://contextgarden.net
http://www.cacert.org (I'm an assurer)

[-- Attachment #2: t-lilypond.tex --]
[-- Type: application/octet-stream, Size: 8629 bytes --]

%D \module
%D   [       file=t-lilypond,
%D        version=2006.09.26,
%D          title=\CONTEXT\ User Modules,
%D       subtitle=Lilypond Connections (Music Typesetting),
%D         author=Christopher Creutzig \& Henning Hraban Ramm,
%D           date=\currentdate,
%D      copyright=Christopher Creutzig]

%M \usemodule[lilypond]

%D This module serves to include lilypond music directly in the
%D \CONTEXT\ source, just as \METAPOST\ code can be.  Before starting
%D with the implementation, one or two examples are in order.
%D \startbuffer[sample]
%D \startlilypond
%D % Telemann, TWV 40:11
%D \version "2.9.18"
%D 
%D \relative c' {
%D \set Staff.instrumentName = flute
%D \key fis \minor
%D \time 3/4
%D \partial 4
%D 
%D    r8 fis'8 | fis4. cis8 a cis | fis, a cis fis a fis |
%D    b, d fis b d b | eis,, gis cis eis gis b, |
%D    a fis' gis, fis' cis eis | fis,4 r8
%D    a' gis fis | e gis, a e' fis cis |
%D    d fis, gis b e d | cis4 \trill r8
%D    cis b a | b dis e gis cis, b |
%D    a e' dis fis b, a | gis4 \trill r8
%D }
%D \stoplilypond
%D \stopbuffer
%D
%D The input
%D
%D \typebuffer[sample]
%D
%D is typeset as
%D
%D \getbuffer[sample]
%D
%D \type{\startlilypond} accepts options, as in\crlf
%D \type{\startlilypond[staffsize=24, linewidth=14cm, indent=5cm, time=no]}:
%D 
%D \nobreak
%D \startlilypond[staffsize=24,linewidth=14cm,indent=5cm,time=no]
%D \version "2.9.18"
%D \relative c' {
%D \set Staff.instrumentName = flute
%D \key fis \minor
%D \time 3/4
%D \partial 4
%D    r8 fis'8 | fis4. cis8 a cis | fis, a cis fis a fis |
%D    b, d fis b d b | eis,, gis cis eis gis b, |
%D    a fis' gis, fis' cis eis | fis,4 r8
%D    a' gis fis | e gis, a e' fis cis |
%D    d fis, gis b e d | cis4 \trill r8
%D    cis b a | b dis e gis cis, b |
%D    a e' dis fis b, a | gis4 \trill r8
%D }
%D \stoplilypond
%D
%D It is also possible to mix text and music:
%D \lower 8.2pt\hbox{\lilypond[fragment=true,staffsize=16,time=no]{g'}} is a g.
%D
%D TODO: Complete list of options.
%D
%D  staffsize=20,
%D  indent=0pt,
%D  time=yes,
%D  align=?,% default depends on fragment=...
%D  fragment=no,
%D  barnumbers=no,
%D
%D
%D TODO: The \type{\lower} in the example above should not be necessary.
%D
%D TODO: Switches to turn off the clef etc.
%D
%D TODO: Proper support for multipage results.
%D
%D TODO: lilypond -> \CONTEXT.
%D
%D \page
%D Now for the implementation.  As usual, we use a prefix for buffers,
%D \type{\getparameters} etc.:

\unprotect
\def\??lily{lilypond-}

%D Define the text snippets to be placed around fragments.
%D Since lilypond uses similar syntax to \TeX, we must do some catcode fiddling.
\bgroup
\catcode`\/=\@@escape
/catcode`/\=/@@other
/catcode`/#=/@@other
/catcode`/<=/@@begingroup
/catcode`/>=/@@endgroup
/catcode`/{=/@@other
/catcode`/}=/@@other
/catcode`/%=/@@other
/gdef/lily!fragmentprefix<
/string^^J
/string^^J
{/string^^J
% ly snippet contents follows:/string^^J
>

/gdef/lily!fragmentsuffix</string^^J
% end ly snippet/string^^J
}/string^^J
>

/gdef/lily!prefix</string^^J
%#(set! toplevel-score-handler print-score-with-defaults)/string^^J
%#(set! toplevel-music-handler 
  (lambda (p m) 
   (if (not (eq? (ly:music-property m 'void) #t)) 
        (print-score-with-defaults 
         p (scorify-music m p)))))/string^^J
/string^^J
#(ly:set-option (quote no-point-and-click))/string^^J
/string^^J
#(define version-seen #t)/string^^J
%\version "2.9.18"/string^^J
/iflily!time/else
% switch off time signature/string^^J
\layout {
  ragged-last = ##t
  \context {
   \Score
    timing = ##f
  }/string^^J
  \context {
   \Staff
    \remove "Time_signature_engraver"
  }
}/string^^J
/fi
/iflily!barnumbers/else
% switch off bar numbers/string^^J
\layout {
 \context {
  \Score
   \remove "Bar_number_engraver"
 }
}/string^^J
/fi
\paper {/string^^J
  #(define dump-extents #t)/string^^J
  ragged-right = /iflily!align ##f/else ##t/fi/string^^J
  indent = /withoutpt/the/lily!indent\pt/string^^J
  line-width = /withoutpt/the/lily!linewidth\pt/string^^J
  vsize = /withoutpt/the/lily!vsize\pt/string^^J
  printpagenumber = ##f/string^^J
  oddFooterMarkup=##f/string^^J
  oddHeaderMarkup=##f/string^^J
  bookTitleMarkup = ##f/string^^J
  scoreTitleMarkup = ##f/string^^J
}/string^^J
>

/gdef/lily!hash<#>
/egroup

\newdimen\lily!linewidth
\newdimen\lily!vsize
\newdimen\lily!indent
\newif\iflily!align
\newif\iflily!time
\newif\iflily!barnumbers

\newcount\lily!figures

%D Again, as usual, there is a \type{\setuplilypond} command
%D that accepts the same parameters as \type{\lilypond} and
%D \type{\startlilypond} do in their optional argument:
\def\setuplilypond{\dosingleempty\dosetuplilypond}

\def\dosetuplilypond[#1]{%
   \getparameters[\??lily][#1]%
}

%D We set the following defaults:
\setuplilypond
  [staffsize=20,
   indent=0pt,
   time=\v!yes,
   align=?,% default depends on fragment=...
   fragment=\v!no,
   barnumbers=\v!no,
   ]

%D \type{\startlilypond} is a multistage implementation, because
%D end-of-line characters must be treated specially in the
%D \type{\startlilypond}\textellipsis\type{\stoplilypond} range.
\def\startlilypond{\dosingleempty\dostartlilypond}

\def\dostartlilypond[#1]{%
   \bgroup
   \obeylines
   \dodostartlilypond[{#1}]%
}

\long\def\dodostartlilypond[#1]#2\stoplilypond{%
   \egroup% from \dostartlilypond
   \bgroup%
%D The default of the \type{linewidth} parameter is the local
%D \type{\hsize}.
   \setlocalhsize
   \getparameters[\??lily][linewidth=\the\localhsize,height=\the\textheight,#1]%
   \lily!linewidth\dimexpr\getvalue{\??lily linewidth}\relax
   \lily!vsize\dimexpr\getvalue{\??lily height}\relax
   \lily!indent\dimexpr\getvalue{\??lily indent}\relax
%D The default of \type{align} depends on whether we typeset a fragment:
   \@EAEAEA\doifelse\getvalue{\??lily align}{\v!yes}%
      \lily!aligntrue\lily!alignfalse
   \@EAEAEA\doif\getvalue{\??lily fragment}{\v!no}{%
     \@EAEAEA\doif\getvalue{\??lily align}?
        \lily!aligntrue
   }%
   \@EAEAEA\doifelse\getvalue{\??lily time}\v!yes
      \lily!timetrue\lily!timefalse
%D We are using a counter to keep the different lilypond pieces
%D separate.  This allows to typeset them only once, during the
%D first run.
%D
%D TODO: This won't work any longer once we pass the remaining
%D vertical space to lilypond.
   \global\advance\lily!figures\plusone
   \startmode[*\v!first]% 
   \def\obeyedlines{\string^^J}%
   \convertargument#2\to\ascii
   \expanded{%
   \setbuffer[lilypond-\the\lily!figures]%
   \lily!prefix
   \lily!hash(set-global-staff-size \getvalue{\??lily staffsize})\string^^J%
   \ifundefined{\??lily fragment}\else\lily!fragmentprefix\fi
   %% TODO: Option "packed"
   \ascii%
   \ifundefined{\??lily fragment}\else\lily!fragmentsuffix\fi
   }%
   \endbuffer%
%D Generating a pdf directly always creates a whole page, so we generate eps first.
%D If \type{\ifeof18} creates an error for you, your pdfetex is too old.
%D just change it to \iftrue then.  (\type{\ifeof18} checks whether \type{\write18}
%D is disabled.)
	\def\LP{texmfstart --exec bin:lilypond -b eps -dno-gs-load-fonts -dinclude-eps-fonts }
	\def\PDF{texmfstart --ifchanged pstopdf }
	
   \ifeof18
   	\installprogram{\LP \bufferprefix lilypond-\the\lily!figures.tmp}%
	 \doif\jobsuffix{pdf}{%
	      \installprogram{\PDF \bufferprefix lilypond-\the\lily!figures.eps}%
	  }%
   \else
      \executesystemcommand{\LP \bufferprefix lilypond-\the\lily!figures.tmp}%
      \doif\jobsuffix{pdf}{%
	\executesystemcommand{\PDF \bufferprefix lilypond-\the\lily!figures.eps}%
      }%
   \fi
   \stopmode% only first run
   \doifelse\jobsuffix{pdf}
     {\edef\lily!img{\bufferprefix lilypond-\the\lily!figures.pdf}}%
     {\edef\lily!img{\bufferprefix lilypond-\the\lily!figures.eps}}%
%D
%D TODO: Get the relevant dimension directly from lilypond,
%D to place the instrument name into the left margin for
%D short snippets as well.
%D If we are not in the middle of some text, we have to check
%D whether lilypond created an image that is wider than requested:
%D It places the instrument names in the left margin.
   \ifvmode
      \getfiguredimensions[\bufferprefix lilypond-\the\lily!figures.pdf]%
      \leavevmode%
      \newdimen\FigWidth
      \FigWidth=\figurewidth
      \ifdim\FigWidth>\localhsize
        \!!dimena=\localhsize
        \advance\!!dimena by-\FigWidth
        \noindent\hskip\!!dimena
      \fi
   \fi
   \externalfigure[\lily!img]%
   \egroup%
}%

%D For short snippets, we define an inline alternative to
%D our start/stop pair:
\def\lilypond{\dosingleempty\dolilypond}

\def\dolilypond[#1]#2{\startlilypond[#1]#2\stoplilypond}

\protect
%D End of file

[-- Attachment #3: Type: text/plain, Size: 1 bytes --]



[-- Attachment #4: Type: text/plain, Size: 139 bytes --]

_______________________________________________
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: LilyPond module for LilyPond 2.9.x
  2006-09-26 18:34 LilyPond module for LilyPond 2.9.x Henning Hraban Ramm
  2006-09-26 20:12 ` Henning Hraban Ramm
@ 2006-09-26 21:41 ` Willi Egger
  1 sibling, 0 replies; 11+ messages in thread
From: Willi Egger @ 2006-09-26 21:41 UTC (permalink / raw)


Hi Hraban!

This is great! Recently I was trying Lilypond again and thought, that 
this music-typesetting environment should be used within ConTeXt. - Your 
module worked, after adapting the three path-defs under Windows!

Thanks  Hraban and Chritopher!

Willi

Henning Hraban Ramm wrote:
> Yeah, I finally got it working with recent versions of LilyPond!
> (The most important change was from "linewidth" to "line-width", and I 
> overlooked that far too long...)
>
> The module still has lots of issues (e.g. paths for external command 
> like lilypond are hardcoded), but it does what I want it to do. ;-)
>
> Could someone please exchange the module in the garden?
>
> Greetlings from Lake Constance!
> Hraban
> ---
> http://www.fiee.net/texnique/
> http://contextgarden.net
> http://www.cacert.org (I'm an assurer)
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> ntg-context mailing list
> ntg-context@ntg.nl
> http://www.ntg.nl/mailman/listinfo/ntg-context
>   

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: LilyPond module for LilyPond 2.9.x
  2006-09-26 20:52     ` Henning Hraban Ramm
@ 2006-09-27  7:55       ` Hans Hagen
  2006-09-27 20:26         ` Henning Hraban Ramm
  0 siblings, 1 reply; 11+ messages in thread
From: Hans Hagen @ 2006-09-27  7:55 UTC (permalink / raw)


Henning Hraban Ramm wrote:
> Am 2006-09-26 um 22:23 schrieb Hans Hagen:
>> use texmfstart!
>>
>> texmfstart whateverscript whateverargs
>>
>> will free you from adding the path
>>
>> lilypond -b eps -f eps -dno-gs-load-fonts -dinclude-eps-fonts
>>
>> or texmfstart bin:lilypond ....
>>
>> conversion to pdf:
>>
>> texmfstart pdftops somefile.eps
>>
>> if may be worth using the -ifchanged cum suis features so that you 
>> don't get more runs than needed
>
> Thank you very much, that works! Now I have:
> \def\LP{texmfstart --exec bin:lilypond -b eps -dno-gs-load-fonts 
> -dinclude-eps-fonts }
> \def\PDF{texmfstart --ifchanged pstopdf }
> with \executesystemcommand or \installprogram
>
> If I add --ifchanged to the lilypond call, it never does anything; 
> without it's called twice (like before, I couldn't find out why).
>
--ifchanged=filename

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: LilyPond module for LilyPond 2.9.x
  2006-09-27  7:55       ` Hans Hagen
@ 2006-09-27 20:26         ` Henning Hraban Ramm
  2006-09-27 22:22           ` Henning Hraban Ramm
  0 siblings, 1 reply; 11+ messages in thread
From: Henning Hraban Ramm @ 2006-09-27 20:26 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 508 bytes --]

Am 2006-09-27 um 09:55 schrieb Hans Hagen:

>> If I add --ifchanged to the lilypond call, it never does anything;
>> without it's called twice (like before, I couldn't find out why).
> --ifchanged=filename

Ah, great!
Here's the new version again (Willi, please try this, no need for  
patching any more!).
I also updated the wiki: http://wiki.contextgarden.net/LilyPond

Greetlings from Lake Constance!
Hraban
---
http://www.fiee.net/texnique/
http://contextgarden.net
http://www.cacert.org (I'm an assurer)

[-- Attachment #2: t-lilypond.tex --]
[-- Type: application/octet-stream, Size: 8622 bytes --]

%D \module
%D   [       file=t-lilypond,
%D        version=2006.09.27,
%D          title=\CONTEXT\ User Modules,
%D       subtitle=Lilypond Connections (Music Typesetting),
%D         author=Christopher Creutzig \& Henning Hraban Ramm,
%D           date=\currentdate,
%D      copyright=Christopher Creutzig]

%M \usemodule[lilypond]

%D This module serves to include lilypond music directly in the
%D \CONTEXT\ source, just as \METAPOST\ code can be.  Before starting
%D with the implementation, one or two examples are in order.
%D \startbuffer[sample]
%D \startlilypond
%D % Telemann, TWV 40:11
%D \version "2.9.18"
%D 
%D \relative c' {
%D \set Staff.instrumentName = flute
%D \key fis \minor
%D \time 3/4
%D \partial 4
%D 
%D    r8 fis'8 | fis4. cis8 a cis | fis, a cis fis a fis |
%D    b, d fis b d b | eis,, gis cis eis gis b, |
%D    a fis' gis, fis' cis eis | fis,4 r8
%D    a' gis fis | e gis, a e' fis cis |
%D    d fis, gis b e d | cis4 \trill r8
%D    cis b a | b dis e gis cis, b |
%D    a e' dis fis b, a | gis4 \trill r8
%D }
%D \stoplilypond
%D \stopbuffer
%D
%D The input
%D
%D \typebuffer[sample]
%D
%D is typeset as
%D
%D \getbuffer[sample]
%D
%D \type{\startlilypond} accepts options, as in\crlf
%D \type{\startlilypond[staffsize=24, linewidth=14cm, indent=5cm, time=no]}:
%D 
%D \nobreak
%D \startlilypond[staffsize=24,linewidth=14cm,indent=5cm,time=no]
%D \version "2.9.18"
%D \relative c' {
%D \set Staff.instrumentName = flute
%D \key fis \minor
%D \time 3/4
%D \partial 4
%D    r8 fis'8 | fis4. cis8 a cis | fis, a cis fis a fis |
%D    b, d fis b d b | eis,, gis cis eis gis b, |
%D    a fis' gis, fis' cis eis | fis,4 r8
%D    a' gis fis | e gis, a e' fis cis |
%D    d fis, gis b e d | cis4 \trill r8
%D    cis b a | b dis e gis cis, b |
%D    a e' dis fis b, a | gis4 \trill r8
%D }
%D \stoplilypond
%D
%D It is also possible to mix text and music:
%D \lower 8.2pt\hbox{\lilypond[fragment=true,staffsize=16,time=no]{g'}} is a g.
%D
%D TODO: Complete list of options.
%D
%D \startlines
%D  staffsize=20,
%D  indent=0pt,
%D  time=yes,
%D  align=?, % default depends on fragment=...
%D  fragment=no,
%D  barnumbers=no,
%D \stoplines
%D
%D TODO: The \type{\lower} in the example above should not be necessary.
%D
%D TODO: Switches to turn off the clef etc.
%D
%D TODO: Proper support for multipage results.
%D
%D TODO: lilypond -> \CONTEXT.
%D
%D \page
%D Now for the implementation.  As usual, we use a prefix for buffers,
%D \type{\getparameters} etc.:

\unprotect
\def\??lily{lilypond-}

%D Define the text snippets to be placed around fragments.
%D Since lilypond uses similar syntax to \TeX, we must do some catcode fiddling.
\bgroup
\catcode`\/=\@@escape
/catcode`/\=/@@other
/catcode`/#=/@@other
/catcode`/<=/@@begingroup
/catcode`/>=/@@endgroup
/catcode`/{=/@@other
/catcode`/}=/@@other
/catcode`/%=/@@other
/gdef/lily!fragmentprefix<
/string^^J
/string^^J
{/string^^J
% ly snippet contents follows:/string^^J
>

/gdef/lily!fragmentsuffix</string^^J
% end ly snippet/string^^J
}/string^^J
>

/gdef/lily!prefix</string^^J
%#(set! toplevel-score-handler print-score-with-defaults)/string^^J
%#(set! toplevel-music-handler 
  (lambda (p m) 
   (if (not (eq? (ly:music-property m 'void) #t)) 
        (print-score-with-defaults 
         p (scorify-music m p)))))/string^^J
/string^^J
#(ly:set-option (quote no-point-and-click))/string^^J
/string^^J
#(define version-seen #t)/string^^J
%\version "2.9.18"/string^^J
/iflily!time/else
% switch off time signature/string^^J
\layout {
  ragged-last = ##t
  \context {
   \Score
    timing = ##f
  }/string^^J
  \context {
   \Staff
    \remove "Time_signature_engraver"
  }
}/string^^J
/fi
/iflily!barnumbers/else
% switch off bar numbers/string^^J
\layout {
 \context {
  \Score
   \remove "Bar_number_engraver"
 }
}/string^^J
/fi
\paper {/string^^J
  #(define dump-extents #t)/string^^J
  ragged-right = /iflily!align ##f/else ##t/fi/string^^J
  indent = /withoutpt/the/lily!indent\pt/string^^J
  line-width = /withoutpt/the/lily!linewidth\pt/string^^J
  vsize = /withoutpt/the/lily!vsize\pt/string^^J
  printpagenumber = ##f/string^^J
  oddFooterMarkup=##f/string^^J
  oddHeaderMarkup=##f/string^^J
  bookTitleMarkup = ##f/string^^J
  scoreTitleMarkup = ##f/string^^J
}/string^^J
>

/gdef/lily!hash<#>
/egroup

\newdimen\lily!linewidth
\newdimen\lily!vsize
\newdimen\lily!indent
\newif\iflily!align
\newif\iflily!time
\newif\iflily!barnumbers

\newcount\lily!figures

%D Again, as usual, there is a \type{\setuplilypond} command
%D that accepts the same parameters as \type{\lilypond} and
%D \type{\startlilypond} do in their optional argument:
\def\setuplilypond{\dosingleempty\dosetuplilypond}

\def\dosetuplilypond[#1]{%
   \getparameters[\??lily][#1]%
}

%D We set the following defaults:
\setuplilypond
  [staffsize=20,
   indent=0pt,
   time=\v!yes,
   align=?,% default depends on fragment=...
   fragment=\v!no,
   barnumbers=\v!no,
   ]

%D \type{\startlilypond} is a multistage implementation, because
%D end-of-line characters must be treated specially in the
%D \type{\startlilypond}\textellipsis\type{\stoplilypond} range.
\def\startlilypond{\dosingleempty\dostartlilypond}

\def\dostartlilypond[#1]{%
   \bgroup
   \obeylines
   \dodostartlilypond[{#1}]%
}

\long\def\dodostartlilypond[#1]#2\stoplilypond{%
   \egroup% from \dostartlilypond
   \bgroup%
%D The default of the \type{linewidth} parameter is the local
%D \type{\hsize}.
   \setlocalhsize
   \getparameters[\??lily][linewidth=\the\localhsize,height=\the\textheight,#1]%
   \lily!linewidth\dimexpr\getvalue{\??lily linewidth}\relax
   \lily!vsize\dimexpr\getvalue{\??lily height}\relax
   \lily!indent\dimexpr\getvalue{\??lily indent}\relax
%D The default of \type{align} depends on whether we typeset a fragment:
   \@EAEAEA\doifelse\getvalue{\??lily align}{\v!yes}%
      \lily!aligntrue\lily!alignfalse
   \@EAEAEA\doif\getvalue{\??lily fragment}{\v!no}{%
     \@EAEAEA\doif\getvalue{\??lily align}?
        \lily!aligntrue
   }%
   \@EAEAEA\doifelse\getvalue{\??lily time}\v!yes
      \lily!timetrue\lily!timefalse
%D We are using a counter to keep the different lilypond pieces
%D separate.  This allows to typeset them only once, during the
%D first run.
%D
%D TODO: This won't work any longer once we pass the remaining
%D vertical space to lilypond.
   \global\advance\lily!figures\plusone
   \startmode[*\v!first]% 
   \def\obeyedlines{\string^^J}%
   \convertargument#2\to\ascii
   \expanded{%
   \setbuffer[lilypond-\the\lily!figures]%
   \lily!prefix
   \lily!hash(set-global-staff-size \getvalue{\??lily staffsize})\string^^J%
   \ifundefined{\??lily fragment}\else\lily!fragmentprefix\fi
   %% TODO: Option "packed"
   \ascii%
   \ifundefined{\??lily fragment}\else\lily!fragmentsuffix\fi
   }%
   \endbuffer%
%D Generating a pdf directly always creates a whole page, so we generate eps first.
%D If \type{\ifeof18} creates an error for you, your pdfetex is too old.
%D just change it to \iftrue then.  (\type{\ifeof18} checks whether \type{\write18}
%D is disabled.)
	\def\LP{texmfstart --ifchanged=\bufferprefix lilypond-\the\lily!figures.tmp --exec bin:lilypond -b eps -dno-gs-load-fonts -dinclude-eps-fonts \bufferprefix lilypond-\the\lily!figures.tmp}
	\def\PDF{texmfstart --ifchanged pstopdf  \bufferprefix lilypond-\the\lily!figures.eps}
	
   \ifeof18
   	\installprogram{\LP}%
	 \doif\jobsuffix{pdf}{%
	      \installprogram{\PDF}%
	  }%
   \else
      \executesystemcommand{\LP}%
      \doif\jobsuffix{pdf}{%
	\executesystemcommand{\PDF}%
      }%
   \fi
   \stopmode% only first run
   \doifelse\jobsuffix{pdf}
     {\edef\lily!img{\bufferprefix lilypond-\the\lily!figures.pdf}}%
     {\edef\lily!img{\bufferprefix lilypond-\the\lily!figures.eps}}%
%D
%D TODO: Get the relevant dimension directly from lilypond,
%D to place the instrument name into the left margin for
%D short snippets as well.
%D If we are not in the middle of some text, we have to check
%D whether lilypond created an image that is wider than requested:
%D It places the instrument names in the left margin.
   \ifvmode
      \getfiguredimensions[\bufferprefix lilypond-\the\lily!figures.pdf]%
      \leavevmode%
      \newdimen\FigWidth
      \FigWidth=\figurewidth
      \ifdim\FigWidth>\localhsize
        \!!dimena=\localhsize
        \advance\!!dimena by-\FigWidth
        \noindent\hskip\!!dimena
      \fi
   \fi
   \externalfigure[\lily!img]%
   \egroup%
}%

%D For short snippets, we define an inline alternative to
%D our start/stop pair:
\def\lilypond{\dosingleempty\dolilypond}

\def\dolilypond[#1]#2{\startlilypond[#1]#2\stoplilypond}

\protect
%D End of file

[-- Attachment #3: Type: text/plain, Size: 1 bytes --]



[-- Attachment #4: Type: text/plain, Size: 139 bytes --]

_______________________________________________
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: LilyPond module for LilyPond 2.9.x
  2006-09-27 20:26         ` Henning Hraban Ramm
@ 2006-09-27 22:22           ` Henning Hraban Ramm
  2006-10-03 21:37             ` Henning Hraban Ramm
  0 siblings, 1 reply; 11+ messages in thread
From: Henning Hraban Ramm @ 2006-09-27 22:22 UTC (permalink / raw)


Aaargh! It still doesn't work right; I should have tested with more  
than one LilyPond snippet.

\lily!figures is the "image" counter; if I use it in the definition  
of the command, it stays 1.
If I use it like below, I get "! Use of \LP doesn't match its  
definition."

--- code ---

\def\LP#1{texmfstart --exec bin:lilypond -b eps -dno-gs-load-fonts - 
dinclude-eps-fonts \bufferprefix lilypond-#1.tmp}
\def\PDF#1{texmfstart --ifchanged=\bufferprefix lilypond-#1.eps  
pstopdf  \bufferprefix lilypond-#1.eps}
	
\ifeof18
	\installprogram{\LP{\the\lily!figures}}%
	\doif\jobsuffix{pdf}{%
		\installprogram{\PDF{\the\lily!figures}}%
	}%
\else
	\executesystemcommand{\LP{\the\lily!figures}}%
	\doif\jobsuffix{pdf}{%
		\executesystemcommand{\PDF{\the\lily!figures}}%
	}%
\fi

--- error ---

! Use of \LP doesn't match its definition.
<write> e p {\LP {
                   \the \lily!figures }}
<inserted text>
                 }\endwrite
\installprogram ...mmediatewriteutility {e p {#1}}

\dodostartlilypond ... {\LP {\the \lily!figures }}
                                                   \doif \jobsuffix  
{pdf}{\in...
l.71 \stoplilypond

--- end ---

Maybe the problem has nothing to do with this section.
Would you please have a look at the file I posted before?

Greetlings from Lake Constance!
Hraban
---
http://www.fiee.net/texnique/
http://contextgarden.net
http://www.cacert.org (I'm an assurer)

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: LilyPond module for LilyPond 2.9.x
  2006-09-27 22:22           ` Henning Hraban Ramm
@ 2006-10-03 21:37             ` Henning Hraban Ramm
  2006-10-03 21:59               ` Mojca Miklavec
  0 siblings, 1 reply; 11+ messages in thread
From: Henning Hraban Ramm @ 2006-10-03 21:37 UTC (permalink / raw)



[-- Attachment #1.1: Type: text/plain, Size: 2529 bytes --]

Hello again, I'm still stuck with the counter problem, unfortunately  
I got no response...

ConTeXts writes out all the LilyPond pieces as "myfile-lilypond- 
#.tmp", sequential numbered.
Then it should run LilyPond and epstopdf on the snippets, but runs  
them always only on no.1
I.e. the counter doesn't behave like it should. Why?

I think, these are the regarding code snippets (sorry, can't think of  
a minimal example for I don't understand the code by Christopher):

\unprotect
\def\??lily{lilypond-}
%...
\newcount\lily!figures
%...
\long\def\dodostartlilypond[#1]#2\stoplilypond{%
    \egroup% from \dostartlilypond
    \bgroup%
%...
    \global\advance\lily!figures\plusone
    \startmode[*\v!first]%
    \def\obeyedlines{\string^^J}%
    \convertargument#2\to\ascii
    \expanded{%
    \setbuffer[lilypond-\the\lily!figures]%
%>> here it works, all buffers are numbered
% ...
    \ascii%
    \ifundefined{\??lily fragment}\else\lily!fragmentsuffix\fi
    }% expanded
    \endbuffer%

    \def\LP{texmfstart --exec bin:lilypond -b eps -dno-gs-load-fonts - 
dinclude-eps-fonts }
    \def\PDF{texmfstart --ifchanged=}

%>> here the counter is always 1	
    \ifeof18
       \installprogram{\LP\bufferprefix lilypond-\the\lily!figures.tmp}%
%>> can someone explain this "installprogram"?
       \doif\jobsuffix{pdf}{%
          \installprogram{\PDF\bufferprefix lilypond-\the\lily! 
figures.eps pstopdf  \bufferprefix lilypond-\the\lily!figures.eps}%
       }%
    \else
       \executesystemcommand{\LP\bufferprefix lilypond-\the\lily! 
figures.tmp}%
       \doif\jobsuffix{pdf}{%
          \executesystemcommand{\PDF\bufferprefix lilypond-\the\lily! 
figures.eps pstopdf  \bufferprefix lilypond-\the\lily!figures.eps}%
       }%
    \fi
    \stopmode% only first run
    \doifelse\jobsuffix{pdf}
       {\edef\lily!img{\bufferprefix lilypond-\the\lily!figures.pdf}}%
       {\edef\lily!img{\bufferprefix lilypond-\the\lily!figures.eps}}%

    \ifvmode
       \getfiguredimensions[\bufferprefix lilypond-\the\lily! 
figures.pdf]%
%>> here it works again, image no.# is not found (besides no.1)
       \leavevmode%
       \newdimen\FigWidth
       \FigWidth=\figurewidth
       \ifdim\FigWidth>\localhsize
          \!!dimena=\localhsize
          \advance\!!dimena by-\FigWidth
          \noindent\hskip\!!dimena
       \fi
    \fi
    \externalfigure[\lily!img]%
    \egroup%
}%


Greetlings from Lake Constance!
Hraban
---
http://www.fiee.net/texnique/
http://contextgarden.net
http://www.cacert.org (I'm an assurer)


[-- Attachment #1.2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 3574 bytes --]

[-- Attachment #2: Type: text/plain, Size: 139 bytes --]

_______________________________________________
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: LilyPond module for LilyPond 2.9.x
  2006-10-03 21:37             ` Henning Hraban Ramm
@ 2006-10-03 21:59               ` Mojca Miklavec
  2006-10-04  0:18                 ` Henning Hraban Ramm
  0 siblings, 1 reply; 11+ messages in thread
From: Mojca Miklavec @ 2006-10-03 21:59 UTC (permalink / raw)


On 10/3/06, Henning Hraban Ramm wrote:
> Hello again, I'm still stuck with the counter problem, unfortunately
> I got no response...
>
> ConTeXts writes out all the LilyPond pieces as "myfile-lilypond-
> #.tmp", sequential numbered.
> Then it should run LilyPond and epstopdf on the snippets, but runs
> them always only on no.1
> I.e. the counter doesn't behave like it should. Why?
>
> I think, these are the regarding code snippets (sorry, can't think of
> a minimal example for I don't understand the code by Christopher):
>
> \unprotect
> \def\??lily{lilypond-}
> %...
> \newcount\lily!figures
> %...
> \long\def\dodostartlilypond[#1]#2\stoplilypond{%
>     \egroup% from \dostartlilypond
>     \bgroup%
> %...
>     \global\advance\lily!figures\plusone
>     \startmode[*\v!first]%
>     \def\obeyedlines{\string^^J}%
>     \convertargument#2\to\ascii
>     \expanded{%
>     \setbuffer[lilypond-\the\lily!figures]%
> %>> here it works, all buffers are numbered
> % ...
>     \ascii%
>     \ifundefined{\??lily fragment}\else\lily!fragmentsuffix\fi
>     }% expanded
>     \endbuffer%
>
>     \def\LP{texmfstart --exec bin:lilypond -b eps -dno-gs-load-fonts -
> dinclude-eps-fonts }
>     \def\PDF{texmfstart --ifchanged=}
>
> %>> here the counter is always 1
>     \ifeof18
>        \installprogram{\LP\bufferprefix lilypond-\the\lily!figures.tmp}%
> %>> can someone explain this "installprogram"?
>        \doif\jobsuffix{pdf}{%
>           \installprogram{\PDF\bufferprefix lilypond-\the\lily!
> figures.eps pstopdf  \bufferprefix lilypond-\the\lily!figures.eps}%
>        }%
>     \else
>        \executesystemcommand{\LP\bufferprefix lilypond-\the\lily!
> figures.tmp}%
>        \doif\jobsuffix{pdf}{%
>           \executesystemcommand{\PDF\bufferprefix lilypond-\the\lily!
> figures.eps pstopdf  \bufferprefix lilypond-\the\lily!figures.eps}%
>        }%
>     \fi
>     \stopmode% only first run
>     \doifelse\jobsuffix{pdf}
>        {\edef\lily!img{\bufferprefix lilypond-\the\lily!figures.pdf}}%
>        {\edef\lily!img{\bufferprefix lilypond-\the\lily!figures.eps}}%
>
>     \ifvmode
>        \getfiguredimensions[\bufferprefix lilypond-\the\lily!
> figures.pdf]%
> %>> here it works again, image no.# is not found (besides no.1)
>        \leavevmode%
>        \newdimen\FigWidth
>        \FigWidth=\figurewidth
>        \ifdim\FigWidth>\localhsize
>           \!!dimena=\localhsize
>           \advance\!!dimena by-\FigWidth
>           \noindent\hskip\!!dimena
>        \fi
>     \fi
>     \externalfigure[\lily!img]%
>     \egroup%
> }%

I cannot test since lilypond is not working properly on my computer,
but I get the proper numbers.

Here's an excerpt from the log file (I changed lilypond to echo):

systems         : begin file test1 at line 2
<test1-lilypond-1.tmp>
system(echo test1-lilypond-1.tmp)...executed.

system(epstopdf test1-lilypond-1.eps)...executed.

 (C:\Programi\MikTeX\tex\context\base\pdfr-ec.tex)
figures         : figure test1-lilypond-1 can not be found
color           : mpcmyk color space is supported
color           : mpspot color space is supported
color           : system rgb is local activated
<test1-lilypond-2.tmp>
system(echo test1-lilypond-2.tmp)...executed.

system(epstopdf test1-lilypond-2.eps)...executed.


Mojca

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: LilyPond module for LilyPond 2.9.x
  2006-10-03 21:59               ` Mojca Miklavec
@ 2006-10-04  0:18                 ` Henning Hraban Ramm
  0 siblings, 0 replies; 11+ messages in thread
From: Henning Hraban Ramm @ 2006-10-04  0:18 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 2770 bytes --]

Am 2006-10-03 um 23:59 schrieb Mojca Miklavec:

> I cannot test since lilypond is not working properly on my computer,
> but I get the proper numbers.
>
> Here's an excerpt from the log file (I changed lilypond to echo):
>
> systems         : begin file test1 at line 2
> <test1-lilypond-1.tmp>
> system(echo test1-lilypond-1.tmp)...executed.
>
> system(epstopdf test1-lilypond-1.eps)...executed.
>
>  (C:\Programi\MikTeX\tex\context\base\pdfr-ec.tex)
> figures         : figure test1-lilypond-1 can not be found
> color           : mpcmyk color space is supported
> color           : mpspot color space is supported
> color           : system rgb is local activated
> <test1-lilypond-2.tmp>
> system(echo test1-lilypond-2.tmp)...executed.
>
> system(epstopdf test1-lilypond-2.eps)...executed.

I just updated my whole installation, but it's still the same:

structure       : begin of sectionblock bodymatter
systems         : begin file c_weihgeist at line 32
(./c_weihgeist.tex
Titel           : - Kom|m| nun|,| weihnachtlicher Geis|t.|
<prd_winternacht-lilypond-1.tmp>
figures         : figure prd_winternacht-lilypond-1.pdf can not be found
<prd_winternacht-lilypond-2.tmp>
figures         : figure prd_winternacht-lilypond-2.pdf can not be found
)
systems         : end file c_weihgeist at line 32
systems         : begin file c_ansingen at line 33
(./c_ansingen.tex [3.1]
Titel           : - Winteransingen
<prd_winternacht-lilypond-3.tmp>
figures         : figure prd_winternacht-lilypond-3.pdf can not be found
)

...

TeXUtil | running texmfstart --ifchanged=prd_winternacht- 
lilypond-1.tmp --exec bin:lilypond -b eps -dno-gs-load-fonts - 
dinclude-eps-fonts prd_winternacht-lilypond-1.tmp
GNU LilyPond 2.9.18
Processing `prd_winternacht-lilypond-1.tmp'
Parsing...
Interpreting music... [8][13]
Preprocessing graphical objects...
Writing prd_winternacht-lilypond-1-systems.tex...
Writing prd_winternacht-lilypond-1-systems.texi...
Layout output to `prd_winternacht-lilypond-1-1.eps'...
Converting to `prd_winternacht-lilypond-1-1.pdf'...
Layout output to `prd_winternacht-lilypond-1.eps'...
Converting to `prd_winternacht-lilypond-1.pdf'...
TeXUtil | running texmfstart --ifchanged=prd_winternacht- 
lilypond-1.tmp --exec bin:lilypond -b eps -dno-gs-load-fonts - 
dinclude-eps-fonts prd_winternacht-lilypond-1.tmp
TeXUtil | running texmfstart --ifchanged=prd_winternacht- 
lilypond-1.tmp --exec bin:lilypond -b eps -dno-gs-load-fonts - 
dinclude-eps-fonts prd_winternacht-lilypond-1.tmp
...


My songbook has 24 songs at the moment, but the counter stays at 1  
for the lilypond run (works with the tmp, as you can see).


Greetlings from Lake Constance!
Hraban
---
http://www.fiee.net/texnique/
http://contextgarden.net
http://www.cacert.org (I'm an assurer)

[-- Attachment #2: t-lilypond.tex --]
[-- Type: application/octet-stream, Size: 8472 bytes --]

%D \module
%D	[		 file=t-lilypond,
%D			version=2006.10.03,
%D			 title=\CONTEXT\ User Modules,
%D		 subtitle=Lilypond Connections (Music Typesetting),
%D			author=Christopher Creutzig \& Henning Hraban Ramm,
%D				date=\currentdate,
%D		copyright=Christopher Creutzig]

%M \usemodule[lilypond]

%D This module serves to include LilyPond music directly in the
%D \CONTEXT\ source, just as \METAPOST\ code can be.
%D It should work from LilyPond version 2.8.
%D Before starting with the implementation, one or two examples are in order.
%D
%D \startbuffer[sample]
%D \startlilypond
%D % Telemann, TWV 40:11
%D \version "2.9.18"
%D 
%D \relative c' {
%D \set Staff.instrumentName = flute
%D \key fis \minor
%D \time 3/4
%D \partial 4
%D 
%D	 r8 fis'8 | fis4. cis8 a cis | fis, a cis fis a fis |
%D	 b, d fis b d b | eis,, gis cis eis gis b, |
%D	 a fis' gis, fis' cis eis | fis,4 r8
%D	 a' gis fis | e gis, a e' fis cis |
%D	 d fis, gis b e d | cis4 \trill r8
%D	 cis b a | b dis e gis cis, b |
%D	 a e' dis fis b, a | gis4 \trill r8
%D }
%D \stoplilypond
%D \stopbuffer
%D
%D The input
%D
%D \typebuffer[sample]
%D
%D is typeset as
%D
%D \getbuffer[sample]
%D
%D \type{\startlilypond} accepts options, as in\crlf
%D \type{\startlilypond[staffsize=24, linewidth=14cm, indent=5cm, time=no]}:
%D 
%D \nobreak
%D \startlilypond[staffsize=24,linewidth=14cm,indent=5cm,time=no]
%D \version "2.9.18"
%D \relative c' {
%D \set Staff.instrumentName = flute
%D \key fis \minor
%D \time 3/4
%D \partial 4
%D	 r8 fis'8 | fis4. cis8 a cis | fis, a cis fis a fis |
%D	 b, d fis b d b | eis,, gis cis eis gis b, |
%D	 a fis' gis, fis' cis eis | fis,4 r8
%D	 a' gis fis | e gis, a e' fis cis |
%D	 d fis, gis b e d | cis4 \trill r8
%D	 cis b a | b dis e gis cis, b |
%D	 a e' dis fis b, a | gis4 \trill r8
%D }
%D \stoplilypond
%D
%D It is also possible to mix text and music:
%D \lower 8.2pt\hbox{\lilypond[fragment=true,staffsize=16,time=no]{g'}} is a g.
%D
%D TODO: Complete list of options.
%D
%D \startlines
%D	staffsize=20,
%D	indent=0pt,
%D	time=yes,
%D	align=?, % default depends on fragment=...
%D	fragment=no,
%D	barnumbers=no,
%D \stoplines
%D
%D TODO: The \type{\lower} in the example above should not be necessary.
%D
%D TODO: Switches to turn off the clef etc.
%D
%D TODO: Proper support for multipage results.
%D
%D TODO: lilypond -> \CONTEXT.
%D
%D TODO: enable LilyPond variables (Scheme code)
%D
%D \page
%D Now for the implementation.	As usual, we use a prefix for buffers,
%D \type{\getparameters} etc.:

\unprotect
\def\??lily{lilypond-}

%D Define the text snippets to be placed around fragments.
%D Since lilypond uses similar syntax to \TeX, we must do some catcode fiddling.
\bgroup
\catcode`\/=\@@escape
/catcode`/\=/@@other
/catcode`/#=/@@other
/catcode`/<=/@@begingroup
/catcode`/>=/@@endgroup
/catcode`/{=/@@other
/catcode`/}=/@@other
/catcode`/%=/@@other
/gdef/lily!fragmentprefix<
/string^^J
/string^^J
{/string^^J
% ly snippet contents follows:/string^^J
>

/gdef/lily!fragmentsuffix</string^^J
% end ly snippet/string^^J
}/string^^J
>

/gdef/lily!prefix</string^^J
%#(set! toplevel-score-handler print-score-with-defaults)/string^^J
%#(set! toplevel-music-handler 
	(lambda (p m) 
	(if (not (eq? (ly:music-property m 'void) #t)) 
			(print-score-with-defaults 
			p (scorify-music m p)))))/string^^J
/string^^J
#(ly:set-option (quote no-point-and-click))/string^^J
/string^^J
#(define version-seen #t)/string^^J
%\version "2.9.18"/string^^J
/iflily!time/else
% switch off time signature/string^^J
\layout {
	ragged-last = ##t
	\context {
		\Score
		 timing = ##f
	}/string^^J
	\context {
		\Staff
		 \remove "Time_signature_engraver"
	}
}/string^^J
/fi
/iflily!barnumbers/else
% switch off bar numbers/string^^J
\layout {
	\context {
		\Score
		\remove "Bar_number_engraver"
	}
}/string^^J
/fi
\paper {/string^^J
	#(define dump-extents #t)/string^^J
	ragged-right = /iflily!align ##f/else ##t/fi/string^^J
	indent = /withoutpt/the/lily!indent\pt/string^^J
	line-width = /withoutpt/the/lily!linewidth\pt/string^^J
	vsize = /withoutpt/the/lily!vsize\pt/string^^J
	printpagenumber = ##f/string^^J
	oddFooterMarkup=##f/string^^J
	oddHeaderMarkup=##f/string^^J
	bookTitleMarkup = ##f/string^^J
	scoreTitleMarkup = ##f/string^^J
}/string^^J
>

/gdef/lily!hash<#>
/egroup

\newdimen\lily!linewidth
\newdimen\lily!vsize
\newdimen\lily!indent
\newif\iflily!align
\newif\iflily!time
\newif\iflily!barnumbers

\newcount\lily!figures

%D Again, as usual, there is a \type{\setuplilypond} command
%D that accepts the same parameters as \type{\lilypond} and
%D \type{\startlilypond} do in their optional argument:
\def\setuplilypond{\dosingleempty\dosetuplilypond}

\def\dosetuplilypond[#1]{%
	\getparameters[\??lily][#1]%
}

%D We set the following defaults:
\setuplilypond
	[staffsize=20,
	indent=0pt,
	time=\v!yes,
	align=?,% default depends on fragment=...
	fragment=\v!no,
	barnumbers=\v!no,
	]

%D \type{\startlilypond} is a multistage implementation, because
%D end-of-line characters must be treated specially in the
%D \type{\startlilypond}\textellipsis\type{\stoplilypond} range.
\def\startlilypond{\dosingleempty\dostartlilypond}

\def\dostartlilypond[#1]{%
	\bgroup
	\obeylines
	\dodostartlilypond[{#1}]%
}

\long\def\dodostartlilypond[#1]#2\stoplilypond{%
	\egroup% from \dostartlilypond
	\bgroup%
%D The default of the \type{linewidth} parameter is the local
%D \type{\hsize}.
	\setlocalhsize
	\getparameters[\??lily][linewidth=\the\localhsize,height=\the\textheight,#1]%
	\lily!linewidth\dimexpr\getvalue{\??lily linewidth}\relax
	\lily!vsize\dimexpr\getvalue{\??lily height}\relax
	\lily!indent\dimexpr\getvalue{\??lily indent}\relax
%D The default of \type{align} depends on whether we typeset a fragment:
	\@EAEAEA\doifelse\getvalue{\??lily align}{\v!yes}%
		\lily!aligntrue\lily!alignfalse
	\@EAEAEA\doif\getvalue{\??lily fragment}{\v!no}{%
		\@EAEAEA\doif\getvalue{\??lily align}?
			\lily!aligntrue
	}%
	\@EAEAEA\doifelse\getvalue{\??lily time}\v!yes
		\lily!timetrue\lily!timefalse
%D We are using a counter to keep the different lilypond pieces
%D separate.	This allows to typeset them only once, during the
%D first run.
%D
%D TODO: This won't work any longer once we pass the remaining
%D vertical space to lilypond.
	\global\advance\lily!figures\plusone
	\edef\lily!filename{\bufferprefix lilypond-\the\lily!figures}
	%\startmode[*\v!first]% 
	\def\obeyedlines{\string^^J}%
	\convertargument#2\to\ascii
	\expanded{%
	\setbuffer[lilypond-\the\lily!figures]%
	\lily!prefix
	\lily!hash(set-global-staff-size \getvalue{\??lily staffsize})\string^^J%
	\ifundefined{\??lily fragment}\else\lily!fragmentprefix\fi
	%% TODO: Option "packed"
	\ascii%
	\ifundefined{\??lily fragment}\else\lily!fragmentsuffix\fi
	}% expanded
	\endbuffer%
%D Generating a pdf directly always creates a whole page, so we generate eps first.
%D If \type{\ifeof18} creates an error for you, your pdfetex is too old.
%D just change it to \iftrue then.	(\type{\ifeof18} checks whether \type{\write18}
%D is disabled.)
	
	%\def\LP{echo LILYPOND \lily!filename.tmp}
	%\def\PDF{echo PStoPDF \lily!filename.eps}
	\def\LP{texmfstart --ifchanged=\lily!filename.tmp --exec bin:lilypond -b eps -dno-gs-load-fonts -dinclude-eps-fonts \lily!filename.tmp}
	\def\PDF{texmfstart --ifchanged=\lily!filename.eps pstopdf \lily!filename.eps}
	\ifeof18
		\installprogram{\LP}%
		\doif\jobsuffix{pdf}{%
			\installprogram{\PDF}%
		}%
	\else
		\executesystemcommand{\LP}%
		\doif\jobsuffix{pdf}{%
			\executesystemcommand{\PDF}%
		}%
	\fi
	%\stopmode% only first run
	\doifelse\jobsuffix{pdf}
		{\edef\lily!img{\lily!filename.pdf}}%
		{\edef\lily!img{\lily!filename.eps}}%
%D
%D TODO: Get the relevant dimension directly from lilypond,
%D to place the instrument name into the left margin for
%D short snippets as well.
%D If we are not in the middle of some text, we have to check
%D whether lilypond created an image that is wider than requested:
%D It places the instrument names in the left margin.
%D
	\ifvmode
		\getfiguredimensions[\lily!filename.pdf]%
		\leavevmode%
		\newdimen\FigWidth
		\FigWidth=\figurewidth
		\ifdim\FigWidth>\localhsize
			\!!dimena=\localhsize
			\advance\!!dimena by-\FigWidth
			\noindent\hskip\!!dimena
		\fi
	\fi
	\externalfigure[\lily!img]%
	\egroup%
}%

%D For short snippets, we define an inline alternative to
%D our start/stop pair:
\def\lilypond{\dosingleempty\dolilypond}

\def\dolilypond[#1]#2{\startlilypond[#1]#2\stoplilypond}

\protect
%D End of file

[-- Attachment #3: Type: text/plain, Size: 1 bytes --]



[-- Attachment #4: Type: text/plain, Size: 139 bytes --]

_______________________________________________
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2006-10-04  0:18 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-09-26 18:34 LilyPond module for LilyPond 2.9.x Henning Hraban Ramm
2006-09-26 20:12 ` Henning Hraban Ramm
2006-09-26 20:23   ` Hans Hagen
2006-09-26 20:52     ` Henning Hraban Ramm
2006-09-27  7:55       ` Hans Hagen
2006-09-27 20:26         ` Henning Hraban Ramm
2006-09-27 22:22           ` Henning Hraban Ramm
2006-10-03 21:37             ` Henning Hraban Ramm
2006-10-03 21:59               ` Mojca Miklavec
2006-10-04  0:18                 ` Henning Hraban Ramm
2006-09-26 21:41 ` Willi Egger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).