Am Montag, 11. September 2006 14:49 schrieb Helge Hafting:
> Helge Hafting wrote:
> 
> Attached v.3 of the lilypond external inset.
> (The patch to preferences and the script is unchanged.)

This is the complete patch I'd like to apply. Instead of the script I 
changed the preview conversion script to change to the temporary 
directory, since that has the added benefit that the byprodcuts lilypond 
produces get deleted when LyX is closed.
I also had to remove the $$o parameter, my lilypond 2.6.5 did not like it.

Helge, does this work for you? The patch is against 1.5 but should also 
apply to 1.4.


Georg
Index: src/graphics/GraphicsConverter.C
===================================================================
--- src/graphics/GraphicsConverter.C	(Revision 15193)
+++ src/graphics/GraphicsConverter.C	(Arbeitskopie)
@@ -332,6 +332,13 @@ void build_script(string const & from_fi
 	          "outfile = " << quoteName(outfile, quote_python) << "\n"
 	          "shutil.copy(infile, outfile)\n";
 
+	// Some converters (e.g. lilypond) can only output files to the
+	// current directory, so we need to change the current directory.
+	// This has the added benefit that all other files that may be
+	// generated by the converter are deleted when LyX closes and do not
+	// clutter the real working directory.
+	script << "os.chdir(" << quoteName(onlyPath(outfile)) << ")\n";
+
 	if (edgepath.empty()) {
 		// Either from_format is unknown or we don't have a
 		// converter path from from_format to to_format, so we use
Index: src/converter.C
===================================================================
--- src/converter.C	(Revision 15193)
+++ src/converter.C	(Arbeitskopie)
@@ -326,8 +326,15 @@ bool Converters::convert(Buffer const * 
 	}
 	OutputParams runparams;
 	runparams.flavor = getFlavor(edgepath);
+
+	// Some converters (e.g. lilypond) can only output files to the
+	// current directory, so we need to change the current directory.
+	// This has the added benefit that all other files that may be
+	// generated by the converter are deleted when LyX closes and do not
+	// clutter the real working directory.
 	string path = onlyPath(from_file);
 	Path p(path);
+
 	// empty the error list before any new conversion takes place.
 	errorList.clear();
 
Index: lib/external_templates
===================================================================
--- lib/external_templates	(Revision 15193)
+++ lib/external_templates	(Arbeitskopie)
@@ -33,7 +33,6 @@ PreambleDef InputOrWarn
 	        \IfFileExists{#1}{\input{#1}}{\warnNotFound{#1}}}
 PreambleDefEnd
 
-
 Template RasterImage
 	# By default, InsetExternal is displayed as a grey button
 	# containing this text.
@@ -196,6 +195,55 @@ Template ChessDiagram
 TemplateEnd
 
 
+Template LilyPond
+	GuiName "Lilypond typeset music"
+	HelpText
+		Sheet music typeset by GNU LilyPond,
+		converted to .pdf or .eps for inclusion
+		Using .eps requires at least lilypond 2.6
+		Using .pdf requires at least lilypond 2.9
+	HelpTextEnd
+	InputFormat "lilypond"
+	FileFilter "*.ly"
+	AutomaticProduction true
+	Transform Rotate
+	Transform Resize
+	Transform Clip
+	Transform Extra
+	Format LaTeX
+		TransformOption Rotate RotationLatexOption
+		TransformOption Resize ResizeLatexOption
+		TransformOption Clip   ClipLatexOption
+		TransformOption Extra  ExtraOption
+		Option Arg "[$$Extra,$$Rotate,$$Resize,$$Clip]"
+		Product "\\includegraphics$$Arg{$$AbsOrRelPathMaster$$Basename}"
+		UpdateFormat eps
+		UpdateResult "$$AbsPath$$Basename.eps"
+		Requirement "graphicx"
+		ReferencedFile latex "$$AbsPath$$Basename.eps"
+		ReferencedFile dvi   "$$AbsPath$$Basename.eps"
+	FormatEnd
+	Format PDFLaTeX
+		TransformOption Rotate RotationLatexOption
+		TransformOption Resize ResizeLatexOption
+		TransformOption Clip   ClipLatexOption
+		TransformOption Extra  ExtraOption
+		Option Arg "[$$Extra,$$Rotate,$$Resize,$$Clip]"
+		Product "\\includegraphics$$Arg{$$AbsOrRelPathMaster$$Basename}"
+		UpdateFormat pdf
+		UpdateResult "$$AbsPath$$Basename.pdf"
+		Requirement "graphicx"
+		ReferencedFile pdflatex "$$AbsPath$$Basename.pdf"
+	FormatEnd
+	Format Ascii
+		Product "[LilyPond: $$FName]"
+	FormatEnd
+	Format DocBook
+		Product "[LilyPond: $$FName]"
+	FormatEnd
+TemplateEnd
+
+
 Template Date
 	GuiName "Date"
 	HelpText
Index: lib/configure.py
===================================================================
--- lib/configure.py	(Revision 15193)
+++ lib/configure.py	(Arbeitskopie)
@@ -254,6 +254,7 @@ def checkFormatEntries():  
 \Format docbook    sgml    DocBook                B  ""	"%%"	"document"
 \Format docbook-xml xml   "Docbook (XML)"         "" ""	"%%"	"document"
 \Format literate   nw      NoWeb                  N  ""	"%%"	"document"
+\Format lilypond   ly     "LilyPond music"        "" ""	"%%"	""
 \Format latex      tex    "LaTeX (plain)"         L  ""	"%%"	"document"
 \Format linuxdoc   sgml    LinuxDoc               x  ""	"%%"	"document"
 \Format pdflatex   tex    "LaTeX (pdflatex)"      "" ""	"%%"	"document"
@@ -408,6 +409,23 @@ def checkConverterEntries():
         'latex2html -no_subdir -split 0 -show_section_numbers $$i', 'hevea -s $$i'],
         rc_entry = [ r'\converter latex      html       "%%"	"originaldir,needaux"' ])
     #
+    path, lilypond = checkProg('a LilyPond -> ESP/PDF/PNG converter', ['lilypond'])
+    if (lilypond != ''):
+        version_string = cmdOutput("lilypond --version")
+        match = re.match('GNU LilyPond (\S+)', version_string)
+        if match:
+            version_number = match.groups()[0]
+            version = version_number.split('.')
+            if int(version[0]) > 2 or (len(version) > 1 and int(version[0]) == 2 and int(version[1]) >= 6):
+                addToRC(r'''\converter lilypond   eps        "lilypond -b eps --ps $$i"	""
+\converter lilypond   pdf        "lilypond -b eps --pdf $$i"	""
+\converter lilypond   png        "lilypond -b eps --png $$i"	""''')
+                print '+  found LilyPond version %s.' % version_number
+            else:
+                print '+  found LilyPond, but version %s is too old.' % version_number
+        else:
+            print '+  found LilyPond, but could not extract version number.'
+    #
     # FIXME: no rc_entry? comment it out
     # checkProg('Image converter', ['convert $$i $$o'])
     #

Reply via email to