# ABCjs integration now available

Update: ABCjs is now enabled on the main site as well. If there are any problems, please report them the usual way - in a new post tagged . Thanks, and enjoy!

Y'all asked for ABCjs integration earlier, and I'm happy to announce that we have something ready to test out here.

First of all, no delimiters are needed - any code block that matches the ABC format should be replaced with the rendered version once ABCjs loads.

It looks like the ABC spec says tunes should start with X:, and have a key defined by K:, so this is what we're currently looking for within the code blocks.

I've tested this some, but I'm sure y'all will have better examples, so please use this post to try out ABC blocks as well as jTab blocks to make sure that everything works correctly and, more importantly, addresses the use cases you have in practice.

And, of course, let me know what's broken. Barring any major issues, my plan is to flip this on on the main site in a couple days.

• Is jtab also enabled on the meta? Last time I checked it wasn't.
– Dom Mod
Jul 12 '16 at 18:35
• @Dom It is now by virtue of abcjs needing Raphael, which is also part of jtab.
Jul 12 '16 at 18:43
• Adam, hi! This is a great addition to the site. Is there a plan to support MIDI creation on-the-fly / ability to listen to the snippet score inline? Sep 18 '16 at 12:20
• @xnakos Not at the moment, no.
Sep 18 '16 at 23:47
• Adam, can this be added to the Markdown help page please? Specifically, is there any particular formatting required to get it to work? Should code be automatically interpreted on the fly in the answer preview on a post? (It doesn't appear to be: is that expected?) Feb 7 '17 at 17:26
• @AndrewLeach Unfortunately we don't really have a way to do that (hence the lack of jTab documentation on the Markdown page as well). But to your question, no, it's not supposed to work live in the preview. It's also an unfortunate limitation at the moment.
Feb 7 '17 at 22:50
• Although this is now implemented (which is great!), I feel that we still need support for simple inline formatting of symbols like asked for here to support simple access to sharps and flats etc (♭ ♮ ♯)
– awe
May 29 '17 at 9:43
• I have tried to start a "documentation page here. Would be nice if this could be source of help page for ABCjs. Maybe tag it as faq?
– awe
May 29 '17 at 10:38
• Only when I was linked with the abc documentation page, did I know this feature is possible.... A time saver! Note how music theory discussions suffer from unclear ASCII description of chord symbols... Jun 7 '17 at 16:06
• Any chance you could create a bookmarklet, like the Mathematics chatrooms now use for LaTeX (math rendering)? Aug 22 '17 at 15:47
• The editor on this site doesn't offer live previews, but you can use the demo page on abcjs.net for composing your snippets. Nov 25 '17 at 7:02

Here's what a post might look like with sheet music embedded in it:

X: 1
T: Cooley's
M: 4/4
L: 1/8
R: reel
K: Emin
EBBA B2 EB|B2 AB defg|afe^c dBAF|DEFD E2:|
|:gf|eB B2 efge|eB B2 gedB|A2 FA DAFA|A2 FA defg|
eB B2 eBgB|eB B2 defg|afe^c dBAF|DEFD E2:|


Note that refreshing the page is required (same as with jTab), so if you edit posts with the inline editor, you'll need to refresh after submitting to see the changes.

• hey... I know that piece..! obligatory +1 Jul 14 '16 at 4:28
• Nice! That looks really good. Thanks! Jul 19 '16 at 17:32
• Yes, plus one and thank you, this looks useful. So, could the theoreticians get asciimath to render analyses? \overbrace{\rm \Large{Fr^{{^{+6}}} \ I}^{_6 \atop _4} \ V _{__} I}^{\LARGE{typical}} or can this be done with ABCjs. Dec 9 '18 at 20:33
• @RichardBarber I'm not 100% sure what you're referring to. We have MathJax enabled on math-related sites, though: math.stackexchange.com/help/notation.
Dec 10 '18 at 19:05
• Was actually referring to that MathJax capability on the math exchange. I can type roman numeral analysis with Math Jax but I haven't figured out how to achieve that in ABCjs yet. Dec 10 '18 at 19:16
• @RichardBarber ABCjs is designed to display musical notation, so I wouldn't be surprised if numeral analysis isn't possible. I'm not that familiar with the syntax though, I just hooked it up to the site here. :)
Dec 10 '18 at 20:16

Thanks for the playground! let's seee...

X:1
C: J.S. Bach
T: BWV 1005 Largo extract
M: C
L: 1/16
K: Dm
([FA]Bc)"1"f (ge)(f"0"A) ("3"[dE]B)c2 z "4"B("4"~A~G) |
([DF]ED)F (G"0"A)(Bd) ("1"T[CEB]A)"4"A2 z "0"A(~B~c) |


Wow, this is actually great. I can pretty much do everything I can think of to express how to actually play the music!

minor

Apparently the engine breaks when trying to do a chord with a rest, [zF]. This may sound silly, but it actually is important to transmit the musical intention of different voices from composer to interpret.

It would be great to be able to write fingerings to all notes, not only the top one using the guitar chord notation.

The tildes would actually be tenuto markings.

reaaaaaally picky

It would be like heaven to be able to decide each notes beam direction. For exemple with a two notes chord, that the top one be pointed up and the bottom one down.

These things seem completely not related to SE's work in this, I'll head to the github repo and roam through documentation.

• Yeah, unfortunately we don't really have any control over the notation and the parsing itself. That's all up to the abcjs folks.
Jul 14 '16 at 17:26

Let's see if it works for the kind of short snippets that are so interesting for posts on this site...

X: 1
M: C
K: Gmaj
L: 1/4
|G2FG|A2FA|Bcde|e2d2|


Nnnope. Ok, I see, you require T: in addition to X:...

X: 1
T: Ex2
M: C
K: Gmaj
L: 1/4
|G2FG|A2FA|Bcde|e2d2|


That really shouldn't be necessary. Snippets without title are certainly no problem for ABC, and titles won't usually be needed here.

But apart from that... it seems to work – thanks a lot!

Of course, it's a bit of a pity that you need to refresh to see the rendered output. With MathJax on the science SE sites, the quick feedback is really nice (especially for newbies), and for ABC this would be at least as helpful. I think it ought to be possible too, at least drawthedots.com renders immediately.
But this is not such a big deal.

Furthermore (even less critical) – I was never a fan of the way jtab just uses normal code blocks, since it interferes if you actually want to post verbatim source code. I reckon the ABC addition won't make this any more of an issue, but as was already discussed, I would prefer it if both ABC and jtab got dedicated delimiters and code blocks would become just code blocks again.

• I hesitate to introduce delimiters since that just adds a lot of complexity. For one, now suddenly a single code block could contain multiple notation sections, and we would have a hard time rendering that sanely. For another, we could do some sort of $abc$ thing for abc.js since we trigger rendering manually and could strip it out of the input, but we don't have that level of control over jTab readily available, and I'd rather not have the two behave differently.
Jul 13 '16 at 22:43
• I'm pushing a change that won't require the title to be specified, and I'll see what I can do about not needing a refresh to edit... not sure how involved that's gonna be, though, so no promises there. (As a side note, at least for abc, posting verbatim code is relatively easy since all you need to do is omit the X: line :))
Jul 13 '16 at 22:59
• Well, I suppose the solution with code blocks starting with X: really will be just fine. I've just found it a bit annoying in the past when I wanted to post some monospace code and jTab would kick in and display some complete nonsense. But I've gotten rather used to it; literal code blocks aren't so important on this site and as you say, using the 4-space indent also for ABC won't exacerbate the issue further if it needs X:. (My personal choice would be to just ditch jTab – who needs tabs when you have notation? – and use  for ABC, but that opinion clearly isn't representative.) Jul 13 '16 at 23:03
• By the way, thanks for trying this out and leaving your feedback. I appreciate it!
Jul 13 '16 at 23:04
• "Who needs tabs when you have notation?" Answer: 90% of those asking questions with the guitar tag. :-/ Jul 19 '16 at 17:34

I have found ways to break it, I think. First thing is it seems to be unhappy with too small an excerpt (this is supposed to be one measure of Bs):

X: 1
K: C
M: 4/4
L: 1/8
B2 B2 B2 B2 |]


Also padding with rests doesn't necessarily work:

X: 2
M: 4/4
K: C
L: 1/4
|B2-.Bz|F2-!>!F-F|FGAB| z8 |]


This is a test to play around with ABC.js features and see how they look. Since it's a CW, feel free to edit it yourself!

X:2
T:Bonjour, le monde!
C:µeta
M:6/16
L:1/16
R:Gigue Français
K:Gm
I:linebreak @
[DG][D^F]!style=rhythm!!marcato!_GBAB | gfggab | GFGBAB | d3AFD |
G/2F/2G/2B/2A/2B/2G/2F/2G/2B/2A/2B/2 | gfggab | age edB |1 dBA AFD :|2 dBA ABd |:
|: efe edB | dBA ABd | efe edB | gdB ABd |
efe edB | d2d def | gfe edB |1 dBA ABd :|2 dBA AFD |]


A test for the pianists:

X:1
T:test
K:Am
M:3/8
L:1/16
V:1 clef=treble
z ee' zz ^d | e2 z ^ded |
V:2 clef=treble
e) zz ^de z | z ^de z z2 |

• Yay! Thanks for implementing this, I think it will be extremely useful.
– Bacs
Jul 28 '16 at 8:58

Oh, let me try…

MML → MusicXML → MuseScore → (edit) → MusicXML → xml2abc.js → prepend four spaces → here:

X:1
T:Loreley
C:Ph. Friedrich Silcher (1789–1860), 1837
Z:Heinrich Heine (1797–1856), 1824
Z:MML encoding & arrangement © 2016 mirabilos, published under The MirOS Licence; copyright for text, music, and piano arrangement has expired; music engraving by MuseScore
%%scale 0.83
%%pagewidth 21.01cm
%%leftmargin 1.00cm
%%rightmargin 1.00cm
%%score { ( 1 2 ) | ( 3 4 ) }
L:1/8
Q:1/4=76.00
M:6/8
I:linebreak $K:C V:1 treble nm="Piano" V:2 treble V:3 bass V:4 bass V:1 "^Andante"!mf! G | ([EG]>[FA])[EG]!>(! ([F-c][FB])[FA] | [EG]3!>)! [DF]2 [DF] | %3 w: 1.~Ich|weiß nicht, was soll es be-|deu- ten, daß| w: 2.~Die|schön- * ste Jung- * frau|si- tzet dort| w: 3.~Den|Schif- * fer im klei- nen|Schif- fe- *| [CE]3/2 [CE]/ [CE] [B,D][A,C][B,D] | [CE]3- [CE] z G |$ ([EG]>[FA])[EG] ([F-c][FB])[FA] | %6
w: ich _ so trau- * rig|bin? _ Ein|Mähr- chen aus al- * ten|
w: o- * ben wun- * der-|bar, _ ihr|gold’- nes Ge- schmei- * de|
w: greift es mit wil- * dem|Weh, _ er|schaut nicht die Fel- * sen-|
[EG]3 [DF]2 [DF] | [CE]3/2 [CE]/ [CE] [B,G][B,F][B,D] | C3- C z!mf! E |$%9 w: Zei- ten, das|kommt _ mir nicht aus dem|Sinn. _ Die| w: bli- tzet, sie|kämmt _ ihr gol- de- nes|Haar. _ Sie| w: rif- fe, er|schaut nur hin- auf in die|Höh’. _ Ich| ([B,D]>[CE])[B,D] [B,DG][B,D][B,D] | [DGB]3 [CEA]2 [CEA] | [B,DG]2 [DG] [A,^F][B,G][CA] | %12 w: Luft _ ist kühl und es|dun- kelt und|ru- hig fließt _ der| w: kämmt es mit gol- de- nem|Kam- me und|singt ein Lied _ da-| w: glau- be die Wel- len ver-|schlin- gen am|En- de Schif- fer und| G3- G2 [FG] |$ [EG]>[FA]!<(![EG] ([F-c][FB])[FA] | (([EG]2 [Ge]))!<)! [Fd]2!>(! [Fd] | %15
w: Rhein; _ der|Gi- pfel des Ber- * ges|fun- * kelt im|
w: bei; _ das|hat ei- ne wun- * der-|sa- * me, ge-|
w: Kahn, _ und|das hat mit ih- * rem|Sin- * gen die|
[Fc]3/2 [Fc]/ [Fc] ([F-B][FA])[FB] | [Ec]3-!>)! [Ec] z |] %17
w: A- * bend- son- * nen-|schein. _|
w: wal- ti- ge Me- * lo-|dei. _|
w: Lo- * re- ley _ ge-|than. _|
V:2
x | x6 | x6 | x6 | x6 |$x6 | x6 | x6 | x6 |$ x6 | x6 | x6 | (B,DE =FED) |$x6 | x6 | x6 | x5 |] %17 V:3 z | (C,/G,/CG,) (C,/A,/DB,) | (C,/G,/CG,) (F,,/F,/A,F,) | (G,,/E,/G,E,) [G,,G,]2 [G,,G,] | %4 ([C,G,]G,,E,, C,,2) z |$ (C,/G,/CG,) (C,/A,/DB,) | (C,/G,/CG,) (F,,/F,/A,F,) | %7
G,,G,C, [G,,D,][G,,D,][G,,F,] | ([C,E,]E,,G,, C,,2) z |$(G,,D,G,) (G,,D,G,) | %10 (G,,D,G,) (C,,E,A,) | (D,,D,B,) z2 [D,^F,] | D,3- D,2 G, |$ (C,/G,/CG,) (C,/A,/DB,) | %14
(C,/G,/C/) z/ z (F,,/A,/D/) z/ z | (G,,/G,/C/) z/ z [G,D][G,C][G,D] | ([C,G,]E,G, C,) z |] %17
V:4
x | x6 | x6 | x6 | x6 |$x6 | x6 | x6 | x6 |$ x6 | x6 | x6 | (G,,B,,C, D,C,B,,) |$x6 | x6 | x6 | %16 x5 |] %17  Hm, seems to not quite work yet for more complex pieces… let’s see what happens if I remove V:2 and V:4… […]  Not quite, either; it seems to confuse physical line breaks (LF) with logical ones (|$). Let’s make the physical breaks all the same (manually editing the auto-converted score):

[…]


This is only really useful if auto-conversion from MusicXML works, though :|

OK, next attempt: conversion with python xml2abc_v63/xml2abc.py -x -b 4 .MuseScore2/Scores/Loreley.xml >Loreley.abc:

X:1
T:Loreley
C:Ph. Friedrich Silcher (1789–1860), 1837
Z:Heinrich Heine (1797–1856), 1824
Z:MML encoding & arrangement © 2016 mirabilos, published under The MirOS Licence; copyright for text, music, and piano arrangement has expired; music engraving by MuseScore
%%score { ( 1 2 ) | ( 3 4 ) }
L:1/8
Q:1/4=76.00
M:6/8
I:linebreak \$
K:C
V:1 treble nm="Piano"
V:2 treble
V:3 bass
V:4 bass
V:1
"^Andante"!mf! G | ([EG]>[FA])[EG]!>(! ([F-c][FB])[FA] | [EG]3!>)! [DF]2 [DF] | [CE]3/2 [CE]/ [CE] [B,D][A,C][B,D] | %4
w: 1.~Ich|weiß nicht, was soll es be-|deu- ten, daß|ich _ so trau- * rig|
w: 2.~Die|schön- * ste Jung- * frau|si- tzet dort|o- * ben wun- * der-|
w: 3.~Den|Schif- * fer im klei- nen|Schif- fe- *|greift es mit wil- * dem|
[CE]3- [CE] z G | ([EG]>[FA])[EG] ([F-c][FB])[FA] | [EG]3 [DF]2 [DF] | [CE]3/2 [CE]/ [CE] [B,G][B,F][B,D] | %8
w: bin? _ Ein|Mähr- chen aus al- * ten|Zei- ten, das|kommt _ mir nicht aus dem|
w: bar, _ ihr|gold’- nes Ge- schmei- * de|bli- tzet, sie|kämmt _ ihr gol- de- nes|
w: Weh, _ er|schaut nicht die Fel- * sen-|rif- fe, er|schaut nur hin- auf in die|
C3- C z!mf! E | ([B,D]>[CE])[B,D] [B,DG][B,D][B,D] | [DGB]3 [CEA]2 [CEA] | [B,DG]2 [DG] [A,^F][B,G][CA] | %12
w: Sinn. _ Die|Luft _ ist kühl und es|dun- kelt und|ru- hig fließt _ der|
w: Haar. _ Sie|kämmt es mit gol- de- nem|Kam- me und|singt ein Lied _ da-|
w: Höh’. _ Ich|glau- be die Wel- len ver-|schlin- gen am|En- de Schif- fer und|
G3- G2 [FG] | [EG]>[FA]!<(![EG] ([F-c][FB])[FA] | (([EG]2 [Ge]))!<)! [Fd]2!>(! [Fd] | [Fc]3/2 [Fc]/ [Fc] ([F-B][FA])[FB] | %16
w: Rhein; _ der|Gi- pfel des Ber- * ges|fun- * kelt im|A- * bend- son- * nen-|
w: bei; _ das|hat ei- ne wun- * der-|sa- * me, ge-|wal- ti- ge Me- * lo-|
w: Kahn, _ und|das hat mit ih- * rem|Sin- * gen die|Lo- * re- ley _ ge-|
[Ec]3-!>)! [Ec] z |] %17
w: schein. _|
w: dei. _|
w: than. _|
V:2
x | x6 | x6 | x6 | %4
x6 | x6 | x6 | x6 | %8
x6 | x6 | x6 | x6 | %12
(B,DE =FED) | x6 | x6 | x6 | %16
x5 |] %17
V:3
z | (C,/G,/CG,) (C,/A,/DB,) | (C,/G,/CG,) (F,,/F,/A,F,) | (G,,/E,/G,E,) [G,,G,]2 [G,,G,] | %4
([C,G,]G,,E,, C,,2) z | (C,/G,/CG,) (C,/A,/DB,) | (C,/G,/CG,) (F,,/F,/A,F,) | G,,G,C, [G,,D,][G,,D,][G,,F,] | %8
([C,E,]E,,G,, C,,2) z | (G,,D,G,) (G,,D,G,) | (G,,D,G,) (C,,E,A,) | (D,,D,B,) z2 [D,^F,] | %12
D,3- D,2 G, | (C,/G,/CG,) (C,/A,/DB,) | (C,/G,/C/) z/ z (F,,/A,/D/) z/ z | (G,,/G,/C/) z/ z [G,D][G,C][G,D] | %16
([C,G,]E,G, C,) z |] %17
V:4
x | x6 | x6 | x6 | %4
x6 | x6 | x6 | x6 | %8
x6 | x6 | x6 | x6 | %12
(G,,B,,C, D,C,B,,) | x6 | x6 | x6 | %16
x5 |] %17


Just a quick test, if that's OK

X: 1
T: Test
O: Akiva
M: 4/4
L: 1/8
K: C
[| [^F6A6d6] [F^Ad]([EGc] | [E8G8c8]) | [_E6G6_B6] [_EG_B]([^CEA] | [C8E8A8]) |
| [^F6A6d6] [F^Ad]([EGc] | [E8G8c8]) | [D6G6B6] [DGB]([EA^c]|[EAc]) |]


asdfasdf

X:1
T:test
K:Am
M:3/8
L:1/16
V:1 clef=treble
z ee' zz ^d | e2 z ^ded |
V:2 clef=treble
e) zz ^de z | z ^de z z2 |


asdfasdf df sdfvsd sds

Test

X:2
T:Exercise 1
M:4/4
L:1/8
K:G
| "heh"G "heh"G "teh"G "teh"G "teh"G4 | G/"etc"G/G/G/