Re: [NTG-context] filter module: call function before calling the filter command?

2016-10-13 Thread Aditya Mahajan

On Wed, 12 Oct 2016, Henning Hraban Ramm wrote:

Now, I’d like to overwrite "texsettings.ly", containing the setting of 
ConTeXt’s text width, each time before I call LilyPond, to adapt its 
note line width to the current text width. That would automate the line 
width adaption to e.g. columns.


In the module’s documentation under "Dealing with expansion" I found the 
example of creating the filter command in a macro.
Can I use this to call a Lua function first and then LilyPond? Or is there a 
better way?


There is an internal option: filtersetups that may be useful for what you 
have in mind.


You can create a lua function, say lilypond.initialize(...), that does all 
the initializations, and then write


\startsetups lilypond:initialize
  \ctxlua{lilypond.initialize()}
\stopsetups

\defineexternalfilter[...]
  [ ...
   filtersetups=lilypond:initialize,
   ...
  ]

This is untested, but it should work.

Aditya___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___

[NTG-context] filter module: call function before calling the filter command?

2016-10-12 Thread Henning Hraban Ramm
Ahoi!

As you probably know ;), I’m using the filter module with LilyPond, setup see 
below.

Now, I’d like to overwrite "texsettings.ly", containing the setting of 
ConTeXt’s text width, each time before I call LilyPond, to adapt its note line 
width to the current text width. That would automate the line width adaption to 
e.g. columns.

In the module’s documentation under "Dealing with expansion" I found the 
example of creating the filter command in a macro.
Can I use this to call a Lua function first and then LilyPond? Or is there a 
better way?


-

\usemodule[filter]

\startbuffer[lilypond::settings]
\include "../lilysettings.ly" % file must be in same folder as text, not in 
lilytemp
\include "texsettings.ly"
\stopbuffer

\def\LILYTEMP{lilytemp} % name of folder for LilyPond/buffer files

\def\ParseLilypondFile#1% #1 is the name of the output file
  {\ctxlua{thirddata.parselilypondfile("#1")}}

\startluacode

 thirddata = thirddata or {}
 
 -- create temp folder if missing
 if not lfs.isdir("\LILYTEMP") then
   lfs.mkdir("\LILYTEMP")
 end

 -- write text width to include file
 io.savedata("\LILYTEMP/texsettings.ly", "\\paper { line-width = " .. 
string.gsub(number.topoints(tex.dimen.textwidth),"pt","\\pt") .. " } 
\n")
 
 function thirddata.parselilypondfile(name)
   -- include all systems (pages)
   -- name is like \LILYTEMP/mainfile-temp-lilypond-21.pdf
   logs.report("LILYPOND","name='" .. name .. "'")
   local scname = string.gsub(name, '%.pdf$', '-systems.count')
   local syco = tonumber(io.loaddata(scname)) or 0
   
   for nr = 1, syco do
 logs.report("LILYPOND","including system no." .. nr)
 context("\\externalfigure[" .. string.gsub(name, '%.pdf$', '-' .. nr) .. 
"]")
   end
 end
\stopluacode

\defineexternalfilter[lilypond]
[continue=yes,
cache=yes,
%purge=no,
readcommand=\ParseLilypondFile,
bufferbefore={lilypond::settings},
directory=\LILYTEMP/,
output={\externalfilterbasefile.pdf},
filtercommand={lilypond -dbackend=eps -dinclude-eps-fonts 
-dno-gs-load-fonts -o"\LILYTEMP/\externalfilterbasefile" 
"\externalfilterinputfile"}]

\starttext

-



Greetlings, Hraban
---
http://www.fiee.net
http://wiki.contextgarden.net
https://www.cacert.org (I'm an assurer)
GPG Key ID 1C9B22FD

___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___