24

This is a post that would act as documentation for the ABCjs syntax, which would be a good reference site for help on basic syntax.

Please add aswers here with basic examples for ABCjs syntax to make it easier to get into the world of writing music snippets on Music.SE.

Minimal requirement is to start the code block with X: and also specify key with K: before starting write the notes. I also recommend specifying standard note lenght using L:. Default is eights that would be noted like this: L: 1/8.

Example:

Code:

X: 1  
K: C  
L: 1/4   
ABc

Output:

X: 1
K: C
L: 1/4
ABc

Links to ABCjs references:

We also have the formatting sandbox, which you can use to try out things for yourself:

jTab and ABCjs Formatting Sandbox

ABCjs integration now available

1

8 Answers 8

9
X:1
T:Notes
M:C
L:1/4
K:C
C, D, E, F,|G, A, B, C|D E F G|A B c d|e f g a|b c' d' e'|f' g' a' b'|]
X:1
T:Notes
M:C
L:1/4
K:C
C, D, E, F,|G, A, B, C|D E F G|A B c d|e f g a|b c' d' e'|f' g' a' b'|]
9
X:1
T:Rests
M:C
K:C
L:1/4
A z G z/2 G/2 | A2 z2 | z3 G | z4 |]
X:1
T:Rests
M:C
K:C
L:1/4
A z G z/2 G/2 | A2 z2 | z3 G | z4 |]
9

Sharps, flats and naturals

To sharpen a note precede it with the circumflex or caret ^
^c

To flatten a note precede it with an underscore _
_B

Double sharps are shown as ^^ and double flats as __

To naturalise a note precede it with an equals sign =
=c

So a scale of G major could be notated as GABcde^fg

X: 1  
K: C  
L: 1/4 
GABcde^fg

And a scale of G minor as GA_Bcd_efg

X: 1  
K: C  
L: 1/4 
GA_Bcd_efg

Key

However: Just as standard Western musical notation has the key signature, so that the player automatically knows to (for example) play all F's as F♯ in the key of G, the same thing exists in abc, with the K: field.

Example in the key of B major with a B natural accident:

X: 1  
K: _B  
L: 1/4 
GA=BAGFED
X: 1  
K: _B  
L: 1/4 
GA=Bcdefg
9
X:1
T:Note lengths and default note length
M:C
K:C
L:1/16
A/2 A/ A A2 A3 A4 A6 A7 A8 A12 A15 A16|]
L:1/8
A/4 A/2 A/ A A2 A3 A4 A6 A7 A8 A12 A15|]
L:1/4
A/8 A/4 A/2 A/ A A2 A3 A4 A6 A7|]
L:1/16
A2A2 (3 A2A2A2 (5 AAAAA (7 AAAAAAA |]
X:1
T:Note lengths and default note length
M:C
K:C
L:1/16
A/2 A/ A A2 A3 A4 A6 A7 A8 A12 A15 A16|]
L:1/8
A/4 A/2 A/ A A2 A3 A4 A6 A7 A8 A12 A15|]
L:1/4
A/8 A/4 A/2 A/ A A2 A3 A4 A6 A7|]
L:1/16
A2A2 (3 A2A2A2 (5 AAAAA (7 AAAAAAA |]
8

Voices

Systems and clefs

To have multiple systems with parallel-running voices, first declare each system with a statement of the form V:Vᴏɪᴄᴇ clef=Cʟᴇꜰ. Then, when writing out the score, prefix each line with a reference to the voice it belongs to, in the form [V:Vᴏɪᴄᴇ].

X:1
K:C
V:V1 clef=treble
V:V2 clef=treble
V:Va clef=alto
V:Vc clef=bass
[V:V1] c
[V:V2] E
[V:Va] G,
[V:Vc] C,
    X:1
    K:C
    V:V1 clef=treble
    V:V2 clef=treble
    V:Va clef=alto
    V:Vc clef=bass
    [V:V1] c
    [V:V2] E
    [V:Va] G,
    [V:Vc] C,

Multiple voices in a system

You can also have indepent voices within a single system. That requires, in addition to the declaration of voices with their clefs (which must in this case match!) a grouping-declaration in the form %%score (Vᴏɪᴄᴇ₁ Vᴏɪᴄᴇ₂).

X:1
K:Am
%%score (T1 T2)
V:T1 clef=treble
V:T2 clef=treble
[V:T1] c3  B c
[V:T2] AG FG A
    X:1
    K:Am
    %%score (T1 T2)
    V:T1 clef=treble
    V:T2 clef=treble
    [V:T1] c3  B c
    [V:T2] AG FG A

Chords within a single voice

To just write simultaneous notes of the same length, which needn't be considered as belonging to individual voices, you can put those notes in square brackets. Note length can be specified after the closing bracket and will hold for all notes in the chord.

X:1
K:C
G [GB] [EAc]2 [GB] [FBd] [Ec]2
    X:1
    K:C
    G [GB] [EAc]2 [GB] [FBd] [Ec]2
2

CHANGING KEY SIGNATURE

X:0
K:C
CDEFGAB | [K:Cmin] C'BAGFED | C
X:0
K:C
CDEFGAB | [K:Cmin] C'BAGFED | C
1
  • Note that you must use the bracket notation.
    – Aaron
    Commented Jul 29, 2020 at 6:27
1
X:1
T: Example Tie vs Dots
M:C
K:C
L:1/64
A63 A| A32-A16-A8-A4-A2-AA]
X:1
T: Example Tie vs Dots
M:C
K:C
L:1/64
A63 A| A32-A16-A8-A4-A2-AA]
0

IRRATIONAL TIME SIGNATURES

X:0
K:none
M:3/5
L:1/4
A B c | [M:3+2/7] A B c B2 |
X:0
K:none
M:3/5
L:1/4
A B c | [M:3+2/7] A B c B2 |
4
  • I would note that these time signatures are not irrational, but rather their denominators are not powers of two.
    – phoog
    Commented Nov 27, 2020 at 16:45
  • @phoog The term "irrational time signature" is separate from "irrational numbers". In the time signature case, it refers to any non-power-of-two time signature. See, for example, Unusual time signatures?. The situation would be much improved had the theorist who coined the term consulted with one of us first.
    – Aaron
    Commented Nov 27, 2020 at 18:06
  • This example doesn't seem right. It's showing up as 4/4 in my browser. Commented Jan 5 at 19:56
  • @A.R. That's likely due to a long-standing problem with ABCjs on the site. Try doing a hard refresh of your browser.
    – Aaron
    Commented Jan 5 at 20:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .