ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Henning Hraban Ramm <texml@fiee.net>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: filter module: call function before calling the filter command?
Date: Wed, 12 Oct 2016 11:11:34 +0200	[thread overview]
Message-ID: <E50A730F-EF80-4088-99F3-6EF9EFE018BA@fiee.net> (raw)

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
___________________________________________________________________________________

             reply	other threads:[~2016-10-12  9:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-12  9:11 Henning Hraban Ramm [this message]
2016-10-13 22:41 ` Aditya Mahajan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E50A730F-EF80-4088-99F3-6EF9EFE018BA@fiee.net \
    --to=texml@fiee.net \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).