Forums Instiki

How to develop an ABC music plugin for Instiki?

Subscribe to How to develop an ABC music plugin for Instiki? 6 posts, 2 voices

tanzer 36 posts

edited almost 10 years ago

I’m interested in using Instiki for a wiki that includes sheet music. I like the ABC notation, which is a pure ASCII format, with a defined standard, that’s widely used.

For example, see this link for a sample of the format, the output it renders. (It’s also a really nice Balkan song, Jovano Jovanke.) The ABC converters also generally produce MIDI also, but this is of secondary interest to me.

I realize that this request is out of the context of a math-focused wiki, so potentially the only developer for this would be me. Not sure if I’m up for making the leap to Ruby / rails development, but possibly…

As a starting point, I’m interested in discussing here how one might go about implementing this as an extension / plugin to Instiki.

For reference, PmWIki implements an ABC plugin, here.

But I want to stick with – Instiki.

Still it would be interesting to see how they accomplish it.

A long time ago I wrote an ABC plugin for MediaWiki. I piggybacked on a script abc2ly which is distributed with LilyPond (GPL music typesetting program). This script takes an ABC file as input, and generates a PDF file. My extension was simple but heavy-handed – it called the script, cached up the generated PDF file, and then included it on the page. (Many years later they archived this extension, for being unsupported and a security risk.

Another source of ideas could be from the Traditional Tune Archive, which uses Semantic MediaWiki, and has an ABC plugin. That page has a link to an open source javascript component for rendering ABC notation. However, when I clicked on the link for the actual wiki, it took me to a page with some music and text on it, and then…froze completely. Which led me to wonder whether that whole rig is half-baked.

tanzer 36 posts

Does Instiki have a general interface / API designed for writing plugins?

distler Moderator 123 posts

There is a hierarchy of processing of inputs in Instiki

  • The chunk handler processes various bits of “Wiki Syntax.” It is extensible, by writing new handlers and including them, by name, in lib/wiki_content.rb.
  • A content engine (Markdown, by default, but Textile and RDoc are also available). New content engines can be added in lib/chunks/engines.rb.
  • Within one of the Markdown content engines, itextomml handles equations.

Maruku (our Markdown processor) has an extension mechanism. Math support is implemented as an extension. But so is the div syntax, as are fenced codeblocks and citations.

Presumably, what you want is an ABC extension for Maruku. That would be much easier to create, if there were a Rubygem implementation of ABC notation. But there doesn’t seem to be one.

Is there a good library in Python/Perl/… that might be worth porting to Ruby?

tanzer 36 posts

Thanks for the good information.

All I’ve worked with is the script, which comes with Liliypond. It parses ABC pretty well – though not perfectly. It’s fairly simple, in that it generates a Lilypond script. Then the “fat” app Lilypond does the heavy lifting, when given this script as input, it produces a PDF with beautifully typeset music notation.

So a klunky solution would be to have a Maruku ABC extension that just calls this script, then fires off a Lilypond process, and stores the pdf somewhere in the file area. It would be good to employ some sort of caching scheme for the rendered files, so that this bloated process would only be run once for each exact instance of an ABC source file on a given page. To spell out the idea here more specifically, a crude implementation could be achieved by having a directory for each instiki page, which would contain the source text for all ABC snippets on that page, along with their associated rendered PDF files. When a page is reprocessed, it would match the new ABC snippets against the stored ones, and use the rendered PDF files if there was an exact match. Of course there are nicer ways to do this, but what I just said does define the idea.

If the Maruku filter generates PDF, can that be embedded in the Instiki output in a nice way?

This solution is klunky in the sense that it shells out to some heavy processes, and requires them to be installed on the server. On the other hand, there is a coding minimalism to it – music typesetting is a huge challenge, especially to do well – in that the whole buck gets passed to Lilypond.

This could be a default approach in the absence of something nice that would be more integrated with the Wiki.

distler Moderator 123 posts

The Markdown+Blahtex engine works similarly: shelling out to Blahtex to produce png images for the equations (which are cached on the server.

So you might look closely at the Blahtex Math Extension in (my version of) Maruku.

Forums Instiki