Abcplus En
Abcplus En
Abc 2
Making Music with Abc 2 (formerly, Making Music with Abc Plus)
Version: June 2022
Copyleft © Guido Gonzato, PhD, 2003–2022
Image cover by Vera Kratochvil, via http://www.publicdomainpictures.net
Typeset with LATEX, with the help of the Jed editor and LATEX4Jed.
This manual is released under the terms of the GNU Free Documentation License 1.3:
http://www.gnu.org/licenses/fdl.html
2 Melody 15
2.1 Notes and Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.1.1 Manual or Automatic Formatting? . . . . . . . . . . . . . . . . . . . 15
2.1.2 Note Pitch: A-G a-g ,' . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.1.3 Note Length: L: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.1.4 Rests and Spacing: z Z x y . . . . . . . . . . . . . . . . . . . . . . . 18
2.1.5 Accidentals: ^ = . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.1.6 Dotted Notes: < > . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.1.7 Ties, Slurs, Staccato: - () . . . . . . . . . . . . . . . . . . . . . . . 20
2.1.8 Tuplets: (n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.1.9 Chords: [] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.1.10 Grace Notes: ~ {} . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.1.11 Inline Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.2 Music Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
v
2.2.1 Key signatures and Clefs: K: . . . . . . . . . . . . . . . . . . . . . . 23
Key Signatures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Clefs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Changing the Clef: I:clef . . . . . . . . . . . . . . . . . . . . . . . 27
Bass and Alto Clefs Compatibility Issues . . . . . . . . . . . . . . . . 27
2.2.2 Time Signature: M: . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
2.2.3 Bars, Repeats, Endings: | / : [ ] . . . . . . . . . . . . . . . . . . . 28
2.2.4 Title, Composer, Tempo: T: C: Q: . . . . . . . . . . . . . . . . . . 30
2.2.5 Lyrics: W: w: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
2.2.6 Text and Foreign Characters . . . . . . . . . . . . . . . . . . . . . . . 34
2.2.7 UTF-8 Characters and Symbols . . . . . . . . . . . . . . . . . . . . . 34
2.2.8 Parts: P: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
2.2.9 Accompaniment Chords: "" . . . . . . . . . . . . . . . . . . . . . . . 37
2.2.10 Text Annotations: "^ <>@" . . . . . . . . . . . . . . . . . . . . . . 38
Courtesy Accidentals . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
2.2.11 Decorations: !symbol! . . . . . . . . . . . . . . . . . . . . . . . . . 40
2.2.12 Symbol Lines: s: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Figured Bass . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
2.2.13 Redefinable Symbols: U: . . . . . . . . . . . . . . . . . . . . . . . . . 44
3 Harmony 45
3.1 Polyphony in Abc 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
3.1.1 Voices and Systems: V: . . . . . . . . . . . . . . . . . . . . . . . . . 45
3.1.2 Positioning Voices: %%score . . . . . . . . . . . . . . . . . . . . . . 49
3.1.3 Reductions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
3.1.4 Voice Overlay: & . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
3.1.5 Writing Clean Sources . . . . . . . . . . . . . . . . . . . . . . . . . . 56
4 Formatting 59
4.1 Formatting Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
4.1.1 How Directives Work . . . . . . . . . . . . . . . . . . . . . . . . . . 60
4.1.2 Using Format and Header Files . . . . . . . . . . . . . . . . . . . . . 62
4.1.3 Changing Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
4.1.4 Directives as I: Fields . . . . . . . . . . . . . . . . . . . . . . . . . . 63
4.1.5 Using Fonts and Text . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
4.1.6 Line, Staff, Tune, and Page Breaks . . . . . . . . . . . . . . . . . . . . 69
4.1.7 Avoiding Line Breaks . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
4.1.8 Controlling Measures . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
4.1.9 Voice Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
4.1.10 Repeated Sequences (Simile) . . . . . . . . . . . . . . . . . . . . . . . 72
4.1.11 The Grand Staff . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
4.1.12 Change of System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Blank Sheet Music . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
4.1.13 Positioning Music Elements . . . . . . . . . . . . . . . . . . . . . . . 76
4.1.14 Customising Slurs, Beams, Stems, and Flags . . . . . . . . . . . . . . 77
4.1.15 Customising Accompaniment Chords . . . . . . . . . . . . . . . . . . 78
4.1.16 Customising Tuplets . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
4.1.17 Customising Volta Brackets . . . . . . . . . . . . . . . . . . . . . . . 80
vi
4.1.18 Combining Voices . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
4.1.19 Colours . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
4.1.20 Multi-column Output . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
4.1.21 Customising Titles . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
4.1.22 Headers and Footers . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
4.1.23 Inserting Graphics Files (abcm2ps) . . . . . . . . . . . . . . . . . . . 85
4.1.24 Numbering Measures and Pages . . . . . . . . . . . . . . . . . . . . . 86
4.1.25 Staff Gaps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
4.1.26 Ambitus (abc2svg) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
4.1.27 Embedding XHTML (abc2svg) . . . . . . . . . . . . . . . . . . . . . 87
4.1.28 Saving Space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
4.2 Transposition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
4.2.1 Using %%transpose . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
4.2.2 K: and V: Modifiers (abc2svg) . . . . . . . . . . . . . . . . . . . . . 90
6 Tune Collections 97
6.1 Index Number: X: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
6.2 Information Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
6.3 Including Abc Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
6.4 Songbooks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
6.5 Selecting Tunes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
6.6 Incipits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
7 Playing 105
7.1 MIDI Conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
7.1.1 A Software MIDI Player: TiMidity++ . . . . . . . . . . . . . . . . . . 106
7.1.2 Our First Midi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
7.1.3 Example: How To Make a Ringtone . . . . . . . . . . . . . . . . . . . 107
7.1.4 Supported Decorations . . . . . . . . . . . . . . . . . . . . . . . . . . 108
7.1.5 %%MIDI Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
7.1.6 Avoiding abcm2ps Extensions . . . . . . . . . . . . . . . . . . . . . . 109
7.1.7 Voices and Instruments . . . . . . . . . . . . . . . . . . . . . . . . . . 109
7.1.8 MIDI Transposition . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
7.1.9 Changing Instruments in Repeats . . . . . . . . . . . . . . . . . . . . 111
7.1.10 Accompaniment Chords . . . . . . . . . . . . . . . . . . . . . . . . . 111
7.1.11 New Accompaniment Chords . . . . . . . . . . . . . . . . . . . . . . 113
7.1.12 Customising Beats . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
7.1.13 Arpeggios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
7.1.14 Broken Rhythm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
7.1.15 Drum Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
7.1.16 Percussion Instruments and Drum Mapping . . . . . . . . . . . . . . 117
7.1.17 Portamento . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
vii
7.1.18 Drone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
7.1.19 Global Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
7.2 Differences and Incompatibilities . . . . . . . . . . . . . . . . . . . . . . . . . 120
viii
A Bits & Pieces 159
A.1 Web Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
A.2 Abc Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
A.3 ABC Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
A.4 Common Errors and Bad Practices . . . . . . . . . . . . . . . . . . . . . . . . 164
A.4.1 Syntax Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
A.4.2 Character Encoding . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
A.4.3 Missing L: and Q: Fields . . . . . . . . . . . . . . . . . . . . . . . . . 164
A.4.4 Lines Too Long . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
A.4.5 X: Number in Titles . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
A.4.6 Ties vs. Slurs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
A.4.7 Outdated Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Q: Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
! as End of Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
+ for Decorations and Chords . . . . . . . . . . . . . . . . . . . . . . 165
\ in w: Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
middle= Specifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
A.5 Formatting Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
A.5.1 Page Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
A.5.2 Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
A.5.3 Fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
A.5.4 Spacing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
A.5.5 Other Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
A.5.6 Deprecated Directives . . . . . . . . . . . . . . . . . . . . . . . . . . 177
A.6 PostScript Fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
A.7 abcMIDI Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
A.8 MIDI Instruments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
A.8.1 Standard instruments . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
A.8.2 Percussion Instruments . . . . . . . . . . . . . . . . . . . . . . . . . 184
ix
x
List of Tables
xi
xii
List of Figures
xiii
xiv
About This Guide
T his manual explains how to make beautiful sheet music and MIDI files using a computer,
some free and open source software, and the Abc 2 music notation. It is aimed at musi-
cians with some computer expertise who don’t want to spend a lot of money on commercial
music software. Music teachers, students, amateur and professional musicians may benefit
greatly from this guide and from the software it describes.
This manual comes in printed and electronic versions; the latter is accompanied by a few
audio files. Just like the software that is used to make the music, this manual is free and open
source, and can be freely copied and shared.
I hope you will find my work useful and enjoyable.
Cheers,
xv
xvi
Chapter 1
1.1 Introduction
M usicians who can also use a computer are very lucky people. First of all, because they
are musicians; secondly, because the computer is an excellent tool for writing and ma-
naging music. Lots of programs are available.
Most music notation programs have a visual (or WYSIWYG) approach: one or more staves
are displayed on the screen, and the user drags and drops notes and symbols using the mouse.
An alternative approach is writing music using a text-based notation. This is a non-visual
mode that represents notes and other symbols using characters. A specialised program then
translates the notation into printable sheet music in some electronic format (e.g. in PDF)
and/or into a MIDI file. Visual programs are easier for beginners and are probably more
intuitive, but text-based notations make for faster transcription and have other advantages.
Many text-based notations have been invented. The Abc notation was introduced by Chris
Walshaw in 1993, and is one of the best available: being simple, easy to learn yet very pow-
erful, it has gained widespread popularity. Thousands of tunes written in Abc are available
on the Internet: in fact, this notation is the de facto standard among folk musicians. For more
information, please refer to the official Abc home page: http://abcnotation.com.
Abc was later expanded to provide multiple voices (polyphony), page layout details, and
MIDI commands. This major release of the Abc notation is called Abc 2.
A few programs implement most Abc 2 features and provide some extensions, which
in turn may become part of the Abc 2 standard in the future. The purpose of this guide is to
introduce the reader to Abc 2 and the most important features of its related programs. Ideally,
people who could benefit from Abc 2 are:
• folk musicians who would like to learn as little Abc as necessary to understand the files
they find on the net. These people can skip the part about harmony, and probably do
not need to study this guide thoroughly;
• classically trained musicians who would like to use Abc 2 for typesetting their scores.
In both cases, if you wish to print sheet music for your choir or band, or make a song book,
or even teach music, you have found the right tool. As an additional bonus, all programs are
free and open source.
The unofficial Abc 2 home page was created to provide ready to use software and docu-
mentation: http://abcplus.sourceforge.net.
1
2 CHAPTER 1. MUSIC ON THE COMPUTER WITH ABC 2
A Few Words About “Standards”. Although Abc 2 is formally defined, what you get
using software differs slightly from the theoretical standard. This guide will concentrate on
practical implementations of Abc 2, rather than theoretical features.
To avoid confusion, deprecated syntax variations of old Abc releases will not be explained,
or even mentioned unless strictly necessary. The following chapters will cover most features
and options of the best available programs.
In conclusion: for the sake of simplicity, in the following I shall simply write “Abc” instead
of “Abc 2”.
1.1.1 Requirements
I assume that you have a PC with Windows, macOS, GNU/Linux or other Unix variants, and
that you are reasonably familiar with computers. An Android tablet, or even a phone, is a
viable alternative.
Expertise in the Windows or Unix command line interface is not required. It is required,
however, that you can read music: the treble clef and two octaves starting at middle C should
suffice.
1.1.2 Software
First of all, I would like to stress that Abc is not tied to a specific program. Abc is a musical
notation that can be typeset, i.e. turned to music printed on paper or displayed in web pages.
It can also be played and/or turned to sound files by several applications, each of which is
just an Abc implementation.
The state of the art of Abc implementation is currently represented by a few great little
programs: the abcm2ps and abc2svg scorewriters, the MIDI creator abc2midi, the Abc/Mu-
sicXML translators abc2xml.py and xml2abc.py, and the TradMusician player. All these
programs are free an open source software, released under the GNU GPL license.
abcm2ps, written by Jean-François Moine, reads Abc files and converts them to PostScript.
This is a file format closely related to PDF, and it can be viewed and printed with another free
program called Ghostscript. This application converts PostScript files into several formats,
PDF being the most important.
A twin program to abcm2ps is abc2svg, which is basically abcm2ps rewritten in Java-
script. abc2svg can be integrated in web pages to provide an Abc editor, viewer, and player
that works in any web browser.
abc2midi converts Abc files to MIDI. It is part of the abcMIDI package, written by James
Allwright and currently maintained by Seymour Shlien. abcMIDI includes other utilities that
convert Abc and MIDI files in several ways.
As their names suggest, the abc2xml.py and xml2abc.py translators, written by Willem
Vree, convert music written from Abc to MusicXML and the reverse. MusicXML is an open
format for exchanging digital sheet music, and is supported by many professional applica-
tions.
Last but not least: TradMusician, written by Nicolas Jouve, is a complete Abc player and
viewer for Android.
Please note that abcm2ps, abc2svg, abcMIDI, the Abc/MusicXML tools, and TradMusi-
cian are not completely compatible with each other: each program supports extensions to the
Abc standard and/or lacks some features. Usually, this is not a problem; besides, one should
expect minor differences, as applications target different musical aspects. For instance, music
1.1. INTRODUCTION 3
elements that only make sense in a printed score (e.g. a text annotation) are not supposed to
produce playback. In the following chapters, these differences will be highlighted.
Since Abc files are plain text files, an essential tool for writing them is a good text editor.
Countless free editors exist, some of which have specialised facilities for editing Abc files. In
general, any application that can be used to write text can also be used to write Abc files.
It’s important to stress that abcm2ps, abc2midi, part of abc2svg, and the abc2xml-
.py/xml2abc.py translators are command-line programs: in short, you cannot start them
double-clicking on their icons, or selecting them from a menu. To use these programs, you
will have to open a command shell (Windows Command Prompt, Unix or Android terminal)
and type commands.
People with limited computer expertise need not worry. First of all, using the programs in
the command line is trivial. Besides, there are applications, and even web pages, that gather
all relevant pieces of software in a single integrated environment. Currently, one of the most
popular is EasyABC, a free and multiplatform application that displays and plays the music
using the command-line programs internally. More fine software options are listed at the
Abc 2 and Abc home pages.
text only: the importance of this feature can’t be emphasised enough. Being simple text,
Abc music can be read, written and stored by any computer system on the Earth; it
can be used by visually impaired people, emailed, texted by phone, scribbled down on
beermats, etc.
One of the most important aims of abc notation, and one that distinguishes
it from most computer-based musical languages is that it can also be read
easily by humans. In other words, with a little practice, it is possible to play
a tune directly from the abc notation without having to process and print it
out. The resulting compactness—each tune is about the same as a paragraph
of text—and clarity makes it very easy to notate tunes.
features: Abc supports nearly all features of Western music including multiple voices and
staves, symbols, dynamics, lyrics, text annotations, and much more;
indexing: Abc allows for easy creation, searching and indexing of tune books and music
archives, many of which are freely available on the web;
scalability: with Abc you can create scores from very simple to highly sophisticated;
ease of use: Abc is easy to learn, and after a little practice it becomes very intuitive;
quality: using abcm2ps or abc2svg, Abc produces publication quality sheet music;
4 CHAPTER 1. MUSIC ON THE COMPUTER WITH ABC 2
price: while commercial software is often expensive, nearly all programs for making Abc
music are free, and can be freely copied and shared with your friends or students;
openness: Abc is an open standard and it has no owner, so it can be freely implemented by
everyone royalty-free;
low resources: Abc programs are very light on resources and can run on old computers, or
even tablets and smartphones;
portability: music is created as SVG or PDF and MIDI files instead of proprietary file for-
mats. Open formats let you share your music with everybody, not only people who
have the software to produce it;
multiple formats: Abc programs make music that can be printed on paper, or viewed on
computer screens, or managed with tablets and phones;
speed: writing music in Abc is much faster than using any graphical program;
learning value: if you teach music, Abc in an invaluable tool that facilitates the learning of
music theory.
learning curve: while a graphical program may allow you to get started right away (at least
in theory), Abc requires that you take your time and study the syntax before you can
get started;
file conversion: if your work environment forces you to use a specific commercial program,
you may find it difficult or impossible to convert existing music files to Abc and vice
versa;
limitations: Abc can’t do everything. Currently, it can’t deal with Gregorian chant, con-
temporary music notation, and non-European music;
compatibility: some Abc programs provide extensions to the standard (e.g. tablatures and
guitar diagrams) that other programs can’t deal with.
To overcome the first hurdle, this guide is hopefully a good start; but I also recommend
that you look at some scores to see real-life examples of Abc in action. The Abc home page
has many links to Abc collections; on the Abc 2 page you will find more complex choral
scores.
1. using a text editor, write the tune using the Abc syntax;
1.2. GETTING STARTED 5
If the music you write is free from copyright, please consider sharing it on the web for
others to enjoy.
Ready-to-run packages for Windows, GNU/Linux, macOS, and Android are available from
the Abc 2 web site. Besides, all GNU/Linux distributions include Ghostscript and a document
viewer that reads PostScript. SVG output can be viewed with any web browser.
At the moment, Android has no Ghostscript support and only SVG output is usable.
abcm2ps
abcm2ps typesets music in PostScript, which used to be the best option for printing on paper.
It also produces SVG output, but abc2svg is better at that.
abcm2ps can typeset files containing thousands of tunes without even a hiccup, and it’s
incredibly fast. It gives the user full control of page layout and output options; many Abc
applications use abcm2ps internally to display the music. Unfortunately, abcm2ps is no longer
being developed, as its author is concentrating on abc2svg; new Abc features will not be
implemented. In its current state, though, abcm2ps is a very capable scorewriter.
If you want to manage big tune collections, or if you need precise page layout customisa-
tion, or if you use a program that runs abcm2ps internally, then abcm2ps is the best program
for you.
abc2svg
abc2svg typesets music in SVG/HTML, which is meant to be displayed in web pages. Output
can also be converted to PDF.
abc2svg can be integrated in web-based Abc editors that make it very easy to use. In
addition to displaying the score, web-based abc2svg can also play the music and highlight the
notes being played. abc2svg is updated frequently, and includes the latest Abc improvements
and extensions.
The main disadvantage of abc2svg is its lack of fine control on PDF output. Printing,
in fact, is delegated to external tools, which may produce slightly different PDF files. Fur-
thermore, when it is integrated in browser-based editors abc2svg cannot handle large tune
collections, which can make it very slow or even hang it completely.
If you are a beginner, or if you need to display music in web pages, or if you want to use
the latest Abc features, then abc2svg is the best program for you.
abcMIDI
The abcMIDI suite focuses on MIDI output, and it also performs manipulations such as trans-
position and reformatting. Like abcm2ps, many Abc applications use abc2midi internally to
play the music.
You will need abcMIDI programs if you want MIDI output.
Abc/MusicXML Translators
The Abc/MusicXML translators are the bridge between Abc and other music applications.
These tools are essential if you want to typeset and play Abc music with MusicXML-
enabled programs. Some of these are renowned professional applications, like Sibelius® and
Finale® , which may produce better output than abcm2ps/abc2svg and abc2midi. In addi-
tion, the Abc/MusicXML translators provide useful extensions to Abc such as tablatures and
percussion notes.
Unfortunately, the conversion from/to MusicXML and Abc cannot be perfect, and some
features may be lost. In particular, Abc tune collections cannot be converted as a single file,
because the MusicXML file format has currently no notion of tune collection.
Use the Abc/MusicXML translators if you want to insert Abc music in MusicXML appli-
cations, or if you want to use Abc extensions.
1.2. GETTING STARTED 7
TradMusician
TradMusician is a complete Abc player and viewer for Android that also manages tune col-
lections. It lets the user browse and select tunes, display them in standard notation, and play
them at adjustable speed.
TradMusician is free and available on Google Play; it’s probably the best choice for the
Android platform.
Other Programs
As already explained, there are many other Abc applications. A number of them, like the
aforementioned EasyABC, use abcm2ps and abc2midi internally to display and play the
music. These applications are quite popular and are very easy to use, but there’s a catch.
Users often ignore or forget that the real work is done under the hood by abcm2ps and
abc2midi, possibly bundled with the application. Often, these are old versions that should be
upgraded to fix errors and/or add new features. Further, the application that employs abcm-
2ps and abc2midi may introduce its own errors. If you use such an application, take all this
into account.
Please let me stress this point: the most reliable way to make music in Abc is by using the
latest versions of the command line programs, directly in the command line. It’s not difficult:
command line usage will be explained in Section 1.2.5, page 9.
• accidentals, ties, slurs etc. are written with characters like = - ( ) and so on;
• expression symbols are notated with words called decorations, like !fff!, !fermata!,
!tenuto!, . . .
• the metre, clef, title, and other tune properties are written in words called fields, like
M:, K:, T:;
• low-level details (that is, formatting parameters or MIDI commands) are written using
directives like %%titlefont or %%MIDI program 19.
Strictly speaking, directives for low-level details are not part of the notation. In fact, Abc
was designed for a high-level description of musical pieces, with no special instructions for
typesetting or playback. That said, Abc 2 does provide directives for specifying such details;
these will be examined in Chapter 4 (page 59).
If you don’t have a US keyboard, some important characters may be missing. To obtain
these characters in Windows, turn the numeric keypad on, keep the Alt key pressed and type
some digits:
GNU/Linux and macOS users will have to find out how to type these characters.
Avoid mistakes!
do not use file names containing spaces!
That is: instead of, say, my music file.abc, you must use my music file.abc or My-
MusicFile.abc. This is very important, because command line programs cannot easily use
file names containing spaces. Besides, file names containing spaces are not web-friendly ei-
ther.
You can use abc2svg online, visiting the page http://moinejf.free.fr/js/edit-1.xhtml, or
offline, using the portable abc2svg that you can download at the Abc 2 page. Start it the way
you prefer.
The screen is split in two; the left-hand side is a large text input area with a menu on the
top; the right-hand side is blank, apart from the “(void)” string. This is the area where the
score will be displayed (Figure 1.1).
Click on the text input area and type (or copy and paste) this source verbatim:
X: 1 % start of header
K: C % scale: C major
C D E F G A B c | c d e f g a b c' |
1.2. GETTING STARTED 9
When you are done, wait two seconds and you should see this score:
To save the source for later use, select File/Save file and input the file name scale1.abc.
To listen to the tune, right click on the right-hand side and select Play/Tune from the popup
menu; notes will be highlighted as they are played.
To convert the music to PDF, open the browser menu and select Print…. From the follow-
ing dialog, change the Destination to Save as PDF, then click on Save and insert the name of
the PDF file.
Now, let us make a mistake on purpose: insert the # character instead of the first bar | .
An error message will be printed in red near the menu; click on it and an explanation will be
displayed:
noname.abc:3:17 Error: Bad character '#'
Fix the error in the source, wait two seconds, and the error message will disappear.
Windows
Start the cmd program. A black window will pop up showing a line that reads something like:
C:\Users\Guido>_
Let’s check whether abcm2ps and abcMIDI were installed correctly. Type the following:
C:\Users\Guido>abcm2ps -V
abcm2ps-8.14.13 (2022-01-29)
Options: A4_FORMAT PANGO
Default format directory: /usr/share/abcm2ps
C:\Users\Guido>abc2midi -ver
4.74 June 14 2022 abc2midi
C:\Users\Guido>_
10 CHAPTER 1. MUSIC ON THE COMPUTER WITH ABC 2
If you don’t see the above output messages, there’s an installation problem you will have
to fix; please refer to the programs’ documentation. Otherwise, you can proceed.
The first time, and only the first time you use the command prompt, type this command:
C:\Users\Guido>md abcmusic
and press the Enter key. This command creates a directory (that is, a “folder”), called abc-
music, where we will save our Abc files. Now, let’s enter the directory:
C:\Users\Guido>cd abcmusic
C:\Users\Guido\abcmusic>_
This command is equivalent to a double click on the folder icon. Note that the command
prompt changed to confirm that you’ve moved to that folder. Always move to the abcmusic
folder before writing tunes.
Let’s now run the notepad editor. In our example, we’ll use the file name scale1.abc.
C:\Users\Guido\abcmusic>notepad scale1.abc
Clic on “Yes” to create a new file, then copy this source verbatim:
X: 1 % start of header
K: C % scale: C major
C D E F G A B c | c d e f g a b c' |
A bit of explanation may be helpful. -c -O= are options that tell abcm2ps to perform
automatic line breaks and to give the PostScript output file the same name as the input file,
but with a .ps extension.
To display the PostScript output, launch Sumatra and open the scale1.ps file that you’ll
find in C:\Users\YOURNAME\abcmusic. The score will look like this:
To convert the score to PDF, select File/Save As. . . from Sumatra’s menu, then select PDF
documents in Save as Type.
Now, let us make a mistake on purpose: insert the # character instead of the first bar | .
Save and try to convert; you will get this error message:
1.2. GETTING STARTED 11
Fix the error in the source, save it and convert it again. Finally, let’s make a MIDI file:
C:\Users\user\abcmusic>abc2midi scale1.abc
4.74 June 14 2022 abc2midi
Warning in line-char 2-0 : No M: in header, using default
writing MIDI file scale11.mid
C:\Users\user\abcmusic>_
GNU/Linux, macOS
Open a terminal window (Ubuntu: Applications/Accessories; Mac OS X: Applications/Utilities).
Let’s check whether abcm2ps and abcMIDI were installed correctly. Type the following:
$ abcm2ps -V
abcm2ps-8.14.13 (2022-01-29)
Options: A4_FORMAT PANGO
Default format directory: /usr/share/abcm2ps
$ abc2midi -ver
4.74 June 14 2022 abc2midi
$ _
If you don’t see the above output messages, there’s an installation problem you will have
to fix; please refer to the programs’ documentation. Otherwise, you can proceed.
The first time, and only the first time you use the command prompt, type this command:
$ mkdir abcmusic
and press the Enter key. This command creates a directory (that is, a “folder”), called abcmusic,
where we will save our Abc files. Now, let’s enter the directory:
˜$ cd abcmusic
˜/abcmusic$ _
This command is equivalent to a double click on the folder icon. The command prompt
should change to confirm that you’ve moved to that folder. Always move to the abcmusic
folder before writing tunes.
Now let’s start an editor. In GNU/Linux systems, the default editor should be one of the
following: xed, gedit, pluma, kate, mousepad, leafpad. If it is not, please find out. In ma-
cOS, the default editor is TextEdit; from Preferences, select Plain Text in the Format section.
The file name we are about to create is scale1.abc.
12 CHAPTER 1. MUSIC ON THE COMPUTER WITH ABC 2
Don’t forget the ampersand & at the end of the line. Copy this source verbatim:
X: 1 % start of header
K: C % scale: C major
C D E F G A B c | c d e f g a b c' |
Save it, then switch back to the command prompt. We are ready to make the PostScript
output using abcm2ps:
A bit of explanation may be helpful. -c -O= are options that tell abcm2ps to perform
automatic line breaks and to give the PostScript output file the same name as the input file,
but with a .ps extension.
To display the PostScript output, GNU/Linux users have a wide choice of viewers; use
xdg-open if you’re in doubt. macOS has a Preview utility that will automatically open scale1.ps
and convert it into PDF format; in the command line, use open.
Fix the error in the source, save it and convert it again. Finally, let’s make a MIDI file:
1.2. GETTING STARTED 13
Note the -X switch: it tells abcm2ps to produce SVG output embedded in a file called
scale1.xhtml. To view this file, just open it with a web browser.
Finally, let’s make a MIDI file:
Tap on the MIDI file to listen to it; you may have to install additional software.
X: 1 % start of header
K: C % scale: C major
C D E F G A B c | c d e f g a b c' |
14 CHAPTER 1. MUSIC ON THE COMPUTER WITH ABC 2
It starts with two header fields: X:, index, and K:, key; both upper-case. These are the
only obligatory fields. X: is always followed by a number, which is used to identify the tunes
written in a file. The % character begins a comment; everything that follows % till the end
of the line is ignored.
Fields may contain spaces. X:1 and X: 1 are equivalent. However, field lines must not
begin with spaces, and spaces are not allowed between the field letter and the : character.
The K: field specifies the tune key; C means “C major”. In many countries, notes are
written as “do (ut) re mi fa sol la si (ti)”; if you live in such a country, you may want to
consult Table 1.1 that compares notes written in English and in Latin notation.
English note C D E F G A B
Latin note Do Re Mi Fa Sol La Si
The X: field must be the first in the header, while the K: field must be the last. Other fields
may be inserted in any order between X: and K:.
The next line in the source starts the body of the tune, containing the notes. Upper-case
letters correspond to the central octave, while lower-case letters one octave higher. The |
character inserts a measure bar, which can be entered at any position. That is, you may write
measures of variable length, more than or less than the value specified by the metre.
The last c is followed by a single quote, which denotes an octave higher. Note that abcm-
2ps, by default, automatically set the metre as four quarters, and the note length as eighths.
It wasn’t difficult, was it? We are now ready to study all the details that will enable us to
typeset beautiful scores.
Homework time. Try and write some Abc files as an exercise. Type random notes if you
wish, but get used to writing, saving, converting, and viewing tunes. I strongly suggest that
you do your exercises at the end of each of the following sections.
If you use “do re mi. . . ”, the main hurdle is getting used to “C D E. . . ” A trick I used was
memorizing the notes as “doC”, “reD”, “miE”, “faF”, “solG”, “laA”, “siB” and the reverse.
Chapter 2
Melody
T his part of the manual deals with basic characteristics of notes: pitch, length, accidentals,
dots, ties, slurs, tuplets, chords, grace notes, and expression symbols. But before we
begin, we have an important topic to examine.
15
16 CHAPTER 2. MELODY
X: 1
K: C treble
% C major, four octaves:
C, D, E, F, G, A, B, C | C D E F G A B c |
c d e f g a b c' | c' e' g' c'' |
The rule is: if a note is followed by one or more commas, it goes down one or more octaves;
if it is followed by one or more single quotes, it goes up one or more octaves. Experts will
notice some resemblance to the Helmholtz pitch notation, shifted two octaves upwards.
It is important to note that we wrote two lines of Abc notes, which produced two lines of
music. This is one of the basic rules of the Abc notation; a new line in the source starts a new
line in the score. However, automatic line breaks may be preferable. In the above example, for
instance, note spacing is too wide; a single line would probably look better.
We can instruct abcm2ps and abc2svg to typeset the score with automatic formatting.
This is done inserting the following line:
%%linebreak <none>
at the top of the source. This line is one of the many directives available that let us fine-tune
the appearance of the score; we will study them in Chapter 4, page 59.
Converting the new source:
%%linebreak <none>
X: 1
K: C treble
% C major, four octaves:
C, D, E, F, G, A, B, C | C D E F G A B c |
c d e f g a b c' | c' e' g' c'' |
we obtain this score:
%%linebreak <none>
X: 1
L: 1/8
K: C
%
C,, D,, E,, F,, G,, A,, B,, C, | C, D, E, F, G, A, B, C|
C D E F G A B c | c d e f g a b c' |
To sum up, these are the note names in the bass and treble clef:
...
E,, F,, G,, A,, B,, C, D,
E, F, G, A, B,
C
B,,, C,, D,,
A,,,
c''
d'
e'
c
g
b
f
B a
e
A
d
G
C D E F c ... ...
X: 1
L: 1/4
K: C
% 16/4 8/4 4/4 2/4 2/4 1/4 1/4 1/4 1/8 1/8
C16 | C8 | C4 | D2 D2 | E0 E E F/ F/|
% 3/4 1/16 1/16 1/32 1/32 1/64 1/64 1/64 1/64
G3 G// G/4 G/8 G/8 G/16 G/16 G/16 G/16|
18 CHAPTER 2. MELODY
Note that abcm2ps and abc2svg support notes that are longer than a whole note! The first
note in the above example is called a longa, and its length is four whole notes. The second
note is a brevis, equal to two whole notes. The spacing between notes is proportional to their
length. (We shall see in Section 4.1 (page 59) how to make the spacing of notes constant
instead of proportional.)
Another weird note is the first E in measure 5. The trailing 0 denotes a stemless quarter
note, which is sometimes found in early music.
Spaces between notes and measure bars can be freely inserted when the notes are longer
than one eighth, and are used to improve the legibility of the source. But spaces between notes
that are equal or lesser than one eighth are not optional. If these notes are not separated by
spaces, they will be grouped under a beam:
X: 1
K: C
%
C D E F CD EF | C D E F C/D/E/F/ G/A/B/c/ |
c/B/A/G/ F/E/D/C/ CC/C/ C z |
Commonly, notes are beamed “by beat”: each group of eigth (or less) notes corresponds
to a beat in the measure. Unbeamed notes may be used in vocal music; see Section 2.2.5, page
30.
X: 1
L: 1/4
K: C
Z12 | z16 | z8 | z4 | C2 z2 | C z C z |
C z/ z/ C z//z//z///z///z///z////z//// |
The characters x and y denote, respectively, invisible rests and additional spacing:
2.1. NOTES AND SYMBOLS 19
X: 1
L: 1/4
K: C
C D E/E/E/E/ F/F/F/F/ | C D E/E/E/yyE/ F/yF/yF/yF/ yyyy | xxxG |
The y character can be followed by a width in points; default is 20 points. This unit of
measurement is widely used in typography; a “point” (PostScript point) is 0.353 mm.
Invisible rests are often used for transcribing piano music; examples will be shown in
Section 3.1.2 (page 49).
2.1.5 Accidentals: ^ =
Sharp ] is denoted by a caret ^ before the note, flat [ by an underscore and natural \ by an
equal sign = . Spaces between the accidental and the note are not allowed. Double accidentals
are indicated doubling the special character: double sharp by ^^ and double flat by :
X: 1
L: 1/4
K: C
C ^C D ^D | E F ^F G | ^G A ^A B | c^c=cz |
c B _B A | _A G _G F | E _E D _D | C_C=Cz |
C ^^C __C z |
Quarter tone accidentals (microtones) are also available. That is, 1/4 and 3/4 sharps and
flats can be obtained adding / after the caret or the underscore, while 3/4 are obtained adding
3/2:
X: 1
L: 1/8
K: C
G ^/G ^G ^3/2G A4 | A _/A _A _3/2A G4 | G3 ^G A4 | A3 _A G4 |]
X: 1
L: 1/4
K: C
C3 D | E3/2 F//G// A B | c3/2 B//A// G>F | E D C z |
C C3/2 C7/4 C15/8 |
Please note the three last dotted notes: we specified 3/2, 7/4, and 15/8 to obtain one,
two, or three dots. Admittedly, this notation is not very handy, but isolated dotted notes are
not very common. More often, one note is dotted and the following is halved; or vice versa.
In this case, we are talking of broken rhythm. It is obtained using the characters > or <
between two notes.
When we use > , the first note is dotted (that is, its duration increases by half) and the
following note is halved. The opposite with < . To indicate a note followed by two or three
dots, use >> or >>> .
X: 1
L: 1/4
K: C
CEGc | C > E G >> c | C < E G < c | C/>E/ C/ > E/ C/<E/ C/ < E/ |
X: 1
L: 1/4
K: C
.C/ .C/ D- D .E/ .E/ | EF-FG | (C/E/G/c/) (c/G/E/C/-) | C2 z2 |]
Avoid mistakes!
Although ties and slurs are graphically very similar, they have a completely different
musical meaning. Do not use ties to connect notes of different pitch: MIDI output (see
Section 7.1, page 105) would be wrong!
2.1. NOTES AND SYMBOLS 21
Dashed slurs and ties are indicated by a dot before the open parentheses or hyphen char-
acter. Further, the slur and tie direction may be specified adding a ’ (above) or , (below)
before the open parenthesis:
X: 1
L: 1/4
K: C
.C/ .C/ D.- D .E/ .E/ | EF-'FG | .('C/E/G/c/) .(c/G/E/C/-) | C2 z2 |]
2.1.8 Tuplets: (n
Triplets, quadruplets, etc. are coded with an open left parenthesis, immediately followed by
the number of notes, then by the notes.
More precisely, the notation is:
The notes in a tuplet must have the same length. If the tune metre is compound, that is
6/8, 9/8, 12/8 etc., hni is 3; otherwise, it is 2.
More complex tuplets are coded using the extended notation (hni:hti:hxi, which means:
put hni notes into the time of hti for the next hxi notes. The first parameter is the number
printed over the tuplet. Extended tuplets are used to include notes of different lengths in a
tuplet.
If the second parameter is omitted, the syntax is equivalent to that of simple tuplets. If
the third parameter is omitted, it is assumed to be equal to the first. To make things more
interesting, nested tuplets are also possible. In fact, one of the notes can be replaced by a
tuplet:
X: 1
L: 1/8
K: C
(3cde e2 | (6cegczg (3czg |
(3:2:2G4c2 | (3:2:4G2A2Bc | (3:2:6(3GGGA2Bc |]
22 CHAPTER 2. MELODY
3
3 3
3
3 3
6
To fine-grain the printing of tuplet indications, please see Section 4.1.16 (page 79).
Warning
abcMIDI and the Abc/MusicXML translators do not support nested tuplets.
2.1.9 Chords: []
Chords are written enclosing notes in square brackets; spaces between brackets and notes are
not allowed. A chord behaves as a single note when it comes to adding dots, slurs, etc. That
is, a chord can be preceded by a dot for staccato, or by a symbol, and so on. The same holds
for chord length: instead of specifying the length of each note in the chord, we can simply
add a number after the closing bracket.
X: 1
L: 1/4
K: C
CE [C2G] c | .[CEGc] ([C/E/G/c/][E/G/c/e/]) [C2D2G2c2] |
[CEGc] > [CEGc] [CEGc] > [CEGc]| [C2-E2-G2-][CEG]2 |
Note the chord in the first measure. While abcm2ps and abc2svg typeset chords contain-
ing unequal notes as they are, abcMIDI extends shorter notes to match the longer ones.
Avoid mistakes!
Do not mistake chords for something completely different! If you want to obtain some-
thing like this:
you should be aware that these are not chords, but different voices on the same staff.
Voices will be the subject of Section 3.1 (page 45).
A grace note length can also be specified. (Music theorists need not apply. . . .) The grace
note length does not depend on L:; it is always 1/8 for a single grace note, 1/16 for two or
more, and 1/32 in bagpipe tunes. (Yup, abcm2ps and abc2svg support keys and directives for
Great Highland Bagpipe music.)
Chords can also be specified instead of a single grace note. However, abc2midi can’t play
these “grace chords” correctly.
X: 1
L: 1/4
K: C
~c2 {/d}c {c2d2}c | {d/c/d/}c {ede}c {fef}c c |
c/{[ceg][gc]}c/c/c/ c/c/{gfedc}c/c/ | c2 c {cBAGFED}C |
To remove the slur joining grace notes to the main note, we use the -G option of abcm2ps,
or a formatting parameter that we’ll see later on. (For the curious: %%graceslurs.)
X: 1
L: 1/4
K: C
CDEF | GABc | [r:this is a remark][K:D][L:1/8] DEFG ABcd |
The new r: field, as you might have guessed, is used to include remarks within the music.
Key Signatures
K: must be followed by a note name in upper case, followed by m or min when the mode
is minor. Accidentals are written as # for ] and b for [; e.g. Bb, or F#m. When there are no
24 CHAPTER 2. MELODY
Explicit accidentals can also be specified by appending them to the key signature. For
example, K:D exp =c ^g would set the key of D major but mark every C as natural, and
every G as sharp. (The keyword exp may be omitted, but since abc2midi needs it, don’t leave
it out if you need MIDI output.) Lower case letters must be used, separated by spaces. When
present, explicit accidentals always override the accidentals in the key signature.
The keyword none, meaning “no accidentals”, can also be used; e.g. K:G none.
Since many people don’t have formal music training, I suggest that a comment be added
after the K: field to indicate the number of accidentals: K:AMix % 2 sharps
Clefs
As we saw in Section 2.1.2 (page 15), the clef is automatically set by abcm2ps and abc2svg
depending on the notes pitch. For example, if we start a tune with notes much below the staff
(notes with commas), abcm2ps or abc2svg will select the bass clef. However, we can set the
clef with the K: field at the start of the tune; we can also opt to have no clef at all. This is
accomplished with key modifiers.
The complete syntax of the K: field is:
2.2. MUSIC PROPERTIES 25
• [clef=] may be omitted before the clef type when it is not none;
• [line number] indicates the staff line on which the clef is drawn;
• [ˆ8] and [ 8] print 8 above or below the clef, and perform octave transposition;
• [cue=hon/offi] sets the music scale to 0.7 (on) or 1.0 (off). The staff scale is unchanged.
To sum up, available clefs and their respective fields are listed in Table 2.2 and in the
following example (the w: lines will be explained in Section 2.2.5):
X: 1
L: 1/4
K: C clef=none
CEGc | [K:C treble] CEGc | [K:Cm bass]C,E,G,C |
w: none | treble | bass |
[K:C bass3]C,E,G,C | [K:Cm alto4]CEGc | [K:C alto]CEGc |
w: baritone | tenor | alto |
[K:Cm alto2]CEGc | [K:C alto1]CEGc | [K:perc] cdef |]
w: mezzosoprano | soprano | percussions |
26 CHAPTER 2. MELODY
Clef Field
Treble K:treble (default)
Treble, 1 octave below K:treble-8
Treble, 1 octave above K:treble+8
Bass K:bass
Baritone K:bass3
Tenor K:alto4
Alto K:alto
Mezzosoprano K:alto2
Soprano K:alto1
no clef K:clef=none
percussions K:perc
none treble bass baritone tenor
alto mezzosoprano soprano percussions
Note the difference between the +8/-8 and ^/ 8 in clefs indications. The latter prints 8
above or below the clef, and also transposes the notes one octave lower or higher:
X: 1
L: 1/4
K: C
[K:C treble+8] CEGc | [K:C treble-8] CEGc |
w: +octave\ indication | \-octave\ indication |
[K:C treble^8] CEGc | [K:C treble_8] CEGc |
w: +octave\ and\ transposition * | \-octave\ and\ transposition * |
+octave indication -octave indication +octave and transposition -octave and transposition
The \ characters in the example above are used to insert the next character literally,
avoiding its special meaning; for example, \- will not produce a new syllable. (More details
in Section 2.2.5, page 30.)
The following example shows how the very same notes can be set in different clefs using
the octave= option:
X: 1
L: 1/4
K: C treble
2.2. MUSIC PROPERTIES 27
%
CDEF|GABc||
K:C clef=bass octave=-2
CDEF|GABc||
K:C clef=alto octave=-1
CDEF|GABc||
K:C clef=G octave=1
CDEF|GABc||
K:C clef=bass
I:clef bass
which can also used inline. Note that we did not write = . Clefs types are the ones listed in
Table 2.2 (page 26).
K: C clef=bass
to:
28 CHAPTER 2. MELODY
K: C clef=bass octave=-2
The same method can be used to transpose music for a different clef. For instance, let’s
suppose we wanted to transpose some music from the treble to the alto clef; that is, we
transpose music from violin to viola. We can do that by changing the K: field, from
K:D
to:
• as a fraction, i.e. M:4/4 or M:3/4. Complex indications can be used, such as M:5/4
(2/4+3/4) or M:7/8 (3+2+2). No spaces are allowed between digits and the + char-
acter;
• as a textual indication: M:C or M:C| denote the metre of 4/4 and cut time (“alla breve”).
Ancient metre indications are also supported: M:o (perfect minor), M:o. (perfect major),
M:c (imperfect minor), M:c. (imperfect major);
Needless to say, the metre can change in the middle of a tune. In this case, we insert an
inline M: field in the body:
X: 1
M: C
K: C
L: 1/4
C D E F | [M: 3/4] G A B | [M: 2/4] c c |
[M:7/8 (3+2+2/8)] [L:1/8] CDE FG AB | c2 z4 z |
The recommended order of fields related to note length is M:, L:, and Q:.
X: 1
L: 1/4
K: C
CDEF .| GFED [| CDEF |: GFED :|CDEF :: GFED ||
CDEF [|] GFED CDEF |[| GFED :::|] CDEF : GFED |]
Note that [|] doesn’t typeset anything: it is an invisible bar, and it can be used as a
placeholder for a decoration. The same can be accomplished using []. Also, note that : is the
same as .|.
To indicate that a section has two (or more) different endings, use the symbols [1, [2, . . .
as in the following example. When repeats symbols are close to a bar, they can be shortened
using |1, |2, . . . The end of the last repeat is set with ||, or |] if at the end of the tune.
X: 1
L: 1/4
K: C
|: C D E F | G F E D |[1 C2 G2 :|2 C2 C2|| c3 z |]
1 2
abcm2ps and abc2svg also support other types of repeats. Not only digits, but also dots,
commas, hyphen signs and text in double quotes can be used:
X: 1
L: 1/4
K: C
|: C D E F |1-3 c d e f :|4,5 C2 G2 :|["last time" C G C z |]
1-3
4,5 last time
Most commonly, the start repeat bar |: is left out. This is not a problem in printed music,
but abcMIDI is a bit more restrictive and expects to find it. In Section 2.2.11 (page 40) we will
see how to include |: in the source, but hide it in printed output.
Warning
Unfortunately, repeats are one of the features that make abcm2ps/abc2svg and abcMI-
DI not compatible with each other. In the latter,
• to repeat a run of notes three times, |:: ::| will not work. A simple workaround
30 CHAPTER 2. MELODY
• text indications in repeat bars (as "last time" above) are not recognised.
X: 1
T: Happy Birthday To You % title
T: (Good Morning To All) % subtitle
C: Patty Hill, Mildred J. Hill % composer
M: 3/4
Q: "Allegro " 1/4 = 120 % tempo
K: F
C>C | D2C2F2 | E4 C>C | D2C2G2 | F4 C>C |
w: Hap-py birth-day to you, Hap-py birth-day to you, hap-py
c2A2F2 | (E2D2) _B>B | A2F2G2 | F6 |]
w: birth-day dear fel-low, hap-py birth-day to you!
you, hap py birth day dear fel low, hap py birth day to you!
The text indication in the Q: field (“Allegro” in our example) may be omitted. Besides, Q:
also accepts references to previous tempo indications, as in Q: 3/8 = 1/4.
In Section 4.1 (page 59) we will learn how to change the title fonts.
2.2.5 Lyrics: W: w:
Lyrics can be added at the end of the tune, or aligned with the notes under the staff. In the
first case, at the end of the body we add lines that start with the W: (upper case) field, followed
by the lyrics.
If stanzas are separated by an empty W: line, i.e. not followed by any words, they are
automatically arranged in columns so as to take up less space. Stanzas may also be numbered,
as in the following example:
X: 1
T: W: Lines
K: C
%
W: 1. This is the first column
2.2. MUSIC PROPERTIES 31
W: la la la la la
W: 2. First column again
W: la la la la la
W: % an empty W: line starts a new column
W: 3. This is the second column
W: la la la la la
W: 4. Second column again
W: la la la la la
W: % last stanza is centred
W: 5. Final column, centred
W: la la la la la
% add an empty W: line to left-align
% the last stanza
W: Lines
1. This is the first column 3. This is the second column
la la la la la la la la la la
2. First column again 4. Second column again
la la la la la la la la la la
X: 1
T: W: Lines in One Column
K: C
%
W: This is the first column
W: la la la la la
W: 0̆0A0 % non-breakable space
W: First column again
W: la la la la la
W: 0̆0A0 % non-breakable space
W: Final column
W: la la la la la
W:
Final column
la la la la la
As shown by the sources above, an Abc tune may also consist of W: lines only, even
32 CHAPTER 2. MELODY
without notes to provide the melody! As long as we provide X: and K:, in fact, a tune is
defined.
Note-aligned lyrics are obviously more complex to write. Immediately after a line of mu-
sic, we write one or more lines that start with the w: (lower case) field, followed by the lyrics
split in syllables. Obviously, rests are not matched by lyrics.
Alignment rules between notes and syllables are:
• (underscore) the last syllable is sung for an extra note, and a horizontal line is drawn;
• \- inserts a - character.
If a w: line grows too long, it can be broken and continued on the following line, which
must begin with the + field. These two lines will match the notes on the previous melody line.
Avoid mistakes!
Previous versions of Abc allowed to continue a lyrics line using \ followed by another
w: line. Although abcm2ps still supports this syntax, its use is deprecated: please use +
instead!
X: 1
T: Happy Birthday To You
T: (Good Morning To All)
C: Patty Hill, Mildred J. Hill
M: 3/4
Q: "Allegro " 1/4 = 120
K: F
C>C | D2C2F2 | E4 C>C | D2C2G2 | F4 C>C |
w: Hap-py birth-day to you, Hap-py birth-day to you,
+: hap-py
c2A2F2 | (E2D2) _B>B | A2F2G2 | F6 |]
w: birth-day dear fel-low, hap-py birth-day to you!
%
W: Happy birthday to you, happy birthday to you,
W: Happy birthday dear fellow, happy birthday to you!
2.2. MUSIC PROPERTIES 33
you, hap py birth day dear fel low, hap py birth day to you!
Note that 8th and 16th notes are not beamed; this is common practice when the notes are
sung in different syllables.
Beware of the difference between - (hyphen) and (underscore). Usually, - is used to
skip syllables within a word, while is used at the end of a word. Let’s see a Gregorian chant
example, the Kyrie from Missa de Angelis:
X: 1
L: 1/8
K: D
%
z D FGA A2 BAG A2 dBAG AB A2 AFED GFE E D2|
w: Ky-ri --e, __________ \* e ----- le-i-son.
Ky ri e, * e le i son.
If a w: line begins with digits, these will not be aligned with the notes but moved a bit to
the left; this feature is used to enumerate subsequent w: lines. The digit must be followed by
one or more ~ characters and joined with the following syllable. If we want to align digits
with notes (i.e. for fingerings), all we have to do is insert a ~ character just before the digit.
X: 1
L: 1/4
K: C
CDEF | GABc | c2z2 | z4 |
w: 1.~~~do re mi fa sol la si do doooo
w: ~1 ~2 ~3 ~4 |||
1. do re mi fa sol la si do doooo
1 2 3 4
Take special care to write a number of syllables that matches the number of notes! Mis-
match between notes and syllables is one of the most common causes of error. Besides, please
bear in mind that lyrics may alter the spacing between notes. This effect is especially pro-
nounced when a whole word, or a very long syllable, is forced under a note.
34 CHAPTER 2. MELODY
Typing accented letters using backslash sequences is the best option if you don’t need
other foreign characters. Besides, your Abc source will be encoded in 7–bit pure ASCII, which
is guaranteed to be readable by every digital device on the planet.
However, there are many more foreign characters you might need, not to mention whole
foreign alphabets. In this case, you will need to write your sources using a character encoding
called UTF-8. Simply put, UTF-8 is a computer standard that makes all possible characters
and symbols available to applications.
UTF-8 is fully supported by abcm2ps (with Pango support), abc2svg, and the Abc/Music-
XML translators. If you’re sure that your text editor saves its files in UTF-8 encoding, you
can use accented letters and symbols freely; possibly, by copy & paste.
2. pasting it from a web page. I suggest that you use the virtual keyboards at http://www.
typeit.org/.
3. using the Javascript syntax: replace the leading U+ with \u, followed by the character
code (case insensitive). For example, character U+00A9 can be entered as \u00A9. This
method is limited to the first 65535 (U+FFFF) UTF-8 characters.
4. using the XML character entity reference, or XML syntax for short: replace the leading
U+ with &#x, followed by the character code (case insensitive), then by a semicolon ; .
For example, character U+00A9 can be entered as ©
Copying and pasting UTF-8 characters in the source is the best method; if you can’t, you
should use the XML syntax:
X: 1
T: XML Characters
K: C
%
W: A few strange characters in XML:
W: Ace of hearts: 🂱 (U+1F0B1)
W: G clef: 𝄞 (U+1D11E)
W: Porrectus: 𝇙 (U+1D1D9)
W: Aleph: א (U+05D0)
W: Omega: Ω (U+03A9)
W: Question mark as UTF-8: \u003f (U+003F)
XML Characters
A few strange characters in XML:
Ace of hearts: 🂱 (U+1F0B1)
G clef: 𝄞 (U+1D11E)
Porrectus: 𝇙 (U+1D1D9)
Aleph: ( אU+05D0)
Omega: Ω (U+03A9)
Question mark as UTF-8: ? (U+003F)
If your version of abcm2ps lacks Pango support, in addition to backslash sequences you
can also use octal codes. In fact, abcm2ps recognises a set of octal codes in the form \nnn,
where nnn are three digits. Inserting an octal code in the source we get the corresponding
character; codes are listed below. For the curious: these are a subset of the Basic Latin block
(U+0000–U+007F), with 5 musical symbols thrown in. Octal codes, however, are not recog-
nised by abc2svg and by the Abc/MusicXML translators; more precisely, abc2svg only ac-
cepts codes \201 to \205.
36 CHAPTER 2. MELODY
2.2.8 Parts: P:
Some tunes are made of different parts, possibly repeated in several ways. To specify the
order in which parts are played, we use the P: field. In the header, this field specifies the
order in which parts should be played; in the body, it marks the beginning of each part.
Part names must be uppercase single letters, A . . . Z .
X: 1
T: Song in three parts
L: 1/4
P: AABBC % or: P: A2.B2.C
2.2. MUSIC PROPERTIES 37
K: C
[P: A] C D E F | C D E F | G G G G | G2 z2 ||
[P: B] C E G c | C E G c | c c c c | c2 Cz ||
[P: C] C/E/G/c/ C2 | C/E/G/c/ C2 | C4 |]
C
Note that when the P: field is used in the header, the part name may be followed by a
number indicating the number of repeats. Thus, P:A3 is the same as P:AAA; P:(AB)3C2 is
equivalent to P:ABABABCC. To make the text more readable, dots may be used to separate the
parts.
There you are a more complex example: P:((AB)3.(CD)3)2 is equivalent to P:ABAB-
ABCDCDCDABABABCDCDCD. Try and count carefully!
Avoid mistakes!
P: fields cannot be inserted within repeats (i.e. |:. . . :|), because abc2midi gets con-
fused and produces wrong MIDI output.
X: 1
T: Happy Birthday with chords
M: 3/4
Q: "Allegro" 1/4 = 120 % tempo
K: F
C> C | "F"D2C2F2 | "C"E3 z C> C | "C"D2C2G2 | "F"F3 z C> C |
w: Hap-py birth-day to you, Hap-py birth-day to you, hap-py
"F"c2A2F2 | "Bb"E2D z B> B | "F"A2F2"C"G2 | "F"F6 |]
w: birth-day dear fel-low, hap-py birth-day to you!
38 CHAPTER 2. MELODY
Type Meaning
m or min minor
maj major (also ∆)
dim diminished (◦)
+ or aug augmented (+)
sus suspended
7, 9, . . . seventh, ninth, etc.
F C C
Hap py birth day to you, Hap py birth day to
F F B♭ F C F
you, hap py birth day dear fel low, hap py birth day to you!
Avoid mistakes!
If you need to write accompaniment chords using notes with Italian names, i.e. "Sol7"
instead of "G7", don’t write them this way. Abc requires that only notes in English nota-
tion be used; programs for translating sources into MIDI files conform to this standard.
However, there’s a way to typeset accompaniment chords using Italian notes: please
refer to Section 8.5 (page 127).
Multiple chords per note are possible. They can be notated writing two or more consec-
utive chords before the same note, or using the character ; to separate the chords:
X: 1
L: 1/4
K: C
"C""G"CCCC | "G""G7"GGGG | "C;C7"CCCC |]
C G C
G G7 C7
Text annotations must begin with one of these special characters: ^ <>@ . These char-
acters set the logical difference between an annotation and an accompaniment chord, and
specify the position of the annotation:
When we use @ , it is useful to know that the distance between staff lines is 5 pt.
To include accidentals in text annotations, use \#, \b, and \=; note the leading \ . Multiple
annotations are notated like multiple chords, as seen in Section 2.2.9 (page 37).
Let’s see an example that uses all methods:
X: 1
Q: "Dolcemente" 1/4=60
L: 1/4
K: C
"_below"CEG"^above"c |
"<left"a'">right"A,"^around the note" "<(" ">)"A2 |
[Q: "sostenuto"] "_one" "_two" "_three" CEG"@-15,8.5 anywhere"c|
Dolcemente = 60
left sostenuto
above
)
anywhere
(
right
below one
two
three
Avoid mistakes!
A common mistake is writing text annotations leaving out one of the ^ <>@ charac-
ters. This “annotation” will be misinterpreted as an accompaniment chord, which will
be almost certainly malformed and will wreak havoc in both printed and MIDI output.
Courtesy Accidentals
Courtesy and editorial accidentals are simply a special case of text annotation; the only prob-
lem is how to insert the accidental we need.
Since accidentals and many more musical symbols are defined as UTF-8 characters, we
can insert them in XML syntax (see Section 2.2.7, page 34) if abcm2ps has Pango support. In
this case, we can use all musical characters defined in block U+1D100–U+1D1FF. Accidentals
codes are:
40 CHAPTER 2. MELODY
We can also use a simpler notation that works even without Pango support:
• strings "\b" "\#" "\=" typeset flat, sharp, and natural above the staff. Other characters
in the string are not allowed;
• codes \001 \002 \003 \004 \005 typeset sharp, flat, natural, double sharp, and double
flat;
X: 1
M: none
L: 1/4
K: C
%
"\b"A "\#"A "\="A
"<(\001)"A "<(\002)"A "<(\003)"A "<(\004)"A "<(\005)"A|]
♭ ♯ ♮
X: 1
L: 1/4
K: C
!p!GG!>!!f!GG!segno! | GG!trill!G2!coda!|G4!fine! |
Fine
2.2. MUSIC PROPERTIES 41
As shown above, some symbols are typeset above the staff by default, while others are
typeset under the staff. Manual positioning is possible, as explained in Section 4.1.13 (page
76).
Supported decorations are listed in Figure 2.1. You may notice that some symbols you
need are missing. Don’t worry: new symbols can be easily added, as we will see in Chapter 8
(page 121).
Some symbols have synonims:
While most symbols just typeset something over a note and are self-explanatory, some of
them act on multiple notes or other visual elements:
• symbols that include an open parenthesis ( in their definition start a multi-note dec-
oration, which is ended by the respective symbol with a closed parenthesis ) . For
example, !<(! starts a crescendo hairpin, !<)! ends it. The same holds for !>(!, !>)!,
and their long-name counterparts;
• !beambr1! and !beambr2! act on notes connected by beams, leaving only 1 or 2 beams;
• !beamon! prevents a beam from being broken across measures;
• !rbstop! stops a repeat bracket;
• !invisible! makes the next note or measure bar invisible;
• finally, !xstem! is used in piano music, and it will be explained in Section 4.1.11 (page
73).
The following tune shows a three-times repeat with a hidden start repeat bar:
X: 1
L: 1/4
K: C
GGGG !invisible!|: |1-3 CDEF |G!rbstop!ABc:|
1-3
Piano symbols for “ottava alta” and “ottava bassa” indications automatically transpose the
typeset notes one octave lower or higher:
42 CHAPTER 2. MELODY
Da Coda
!dot! !roll! !fermata! !emphasis! !lowermordent! !coda! !dacoda! !uppermordent!
!slide!
!segno! !trill! !upbow! !downbow! !gmark! !tenuto! !breath!
!longphrase! !mediumphrase! !shortphrase! !invertedturn!
!invertedfermata!
!0! !1! !2! !3! !4! !5! !plus! !+!
D.C. al Coda D.C. al Fine Da Capo
!accent! !>! !marcato! !^! !D.C.! !D.C.alcoda! !D.C.alfine! !dacapo!
D.S. al Coda D.S. al Fine Fine
!D.S.! !D.S.alcoda! !D.S.alfine! !fine!
!f! !ff! !fff! !ffff!
!mordent! !open!
!mf! !mp! !p! !pp! !ppp! !pppp!
!pralltriller!
!ped-up!
!turn! !wedge! !turnx! !snap! !invisible!
!sfz! !ped!
!crescendo(! !crescendo)! !<(! !<)! !diminuendo(! !diminuendo)! !>(! !>)!
8va
!-(! !-)! !~(! !~)! !8va)! 8vb
!8vb(!
!8vb)! !trill(! !trill)!
!8va(!
!trem1! !trem2! !trem3! !trem4! !beambr1! !beambr2!
1-2
!beam-accel! !beam-rall! !beamon!
!rbstop!
X: 1
L: 1/4
M: C
K: C
%
CEGc | !8va(! CEGc !8va)! |
cGEC | !8vb(! cGEC !8vb)! |
8va
8vb
X: 1
L: 1/4
K: C
C/D/ E/F/ G/A/ B/c/ | c/B/ A/G/ F/E/ D/C/ | e2!fermata!c2 | z4 |]
s: !>! !>! * !ff! !p! !mp! * !ff! !>! !>! !>! !ff! * * * !ff! |
Figured Bass
Some symbols of figured bass notation can be written using s: lines, containing text anno-
tations instead of symbols:
X: 1
M: none
L: 1/4
K: C bass
C,4 C,4 C,4 C,4 C,4 C,4 C,4 C,4 C,4]
s: "_6;4" "_\001" "_\0026;\002" "_6+" "_6-" "_-" "_\\6" "_/6" "_6 4"
6 ♯ ♭6 6+ 6- - \6 /6 6 4
4 ♭
As you can see, all annotations have a leading (underscore) to typeset them below the
staff.
44 CHAPTER 2. MELODY
U: T = !trill!
U: H = !fermata!
U: t = !tenuto!
U: T = !nil!
U: H = !nil!
U: t = !nil!
Chapter 3
Harmony
I n previous sections we dealt with simple melodies, i.e. music written for a single voice or
instrument. This is what old version 1.6 of Abc could do, and it is actually a lot; many folk
musicians do not need anything more.
We now turn our attention to Abc 2 and its extensions for polyphonic music, using choral
and piano pieces for our examples.
X: 1
T: Brother John
C: Traditional
L: 1/4
K: F
M: 4/4
V:1
FGAF | FGAF | ABcz | ABcz | c/d/c/B/ AF | c/d/c/B/ AF |
V:2
z4 | z4 | FGAF | FGAF | ABcz | ABcz |
V:1
GCFz |GCFz | z4 | z4 |
V:2
45
46 CHAPTER 3. HARMONY
Brother John
Traditional
This score was written alternating the lines of voices 1 and 2, as in real sheet music. We
could write all of the music of voice 1, then all of voice 2: the resulting score would be typeset
correctly, but the source would be much less readable.
Note
When writing multiple voices:
• slurs and decorations on multiple notes must start and stop in the same voice.
We can add optional voice specifiers to the V: field to set voice properties. The list of
available voice specifiers depends on the application, which is free to implement its own;
further, applications can silently ignore specifiers they don’t implement.
abcm2ps supports auto, down, dyn=, gchord=, gstem=, lyrics=, merge, name=, nm=,
scale=, sname=, snm=, stafflines=, cmdstaffscale=, stem=, and up.
abc2svg supports clef=, clefpitch=, cue=, instrument=, map=, name=, nm=, octave=,
pos=, scale=, score=, shift=, sname=, snm=, sound=, stafflines=, staffnonote=, staff-
scale=, stem=, subname=, and transpose=.
For the moment, let’s examine only a few voice specifiers; more will be explained further
on.
• clef=hclef typei specifies the voice clef; clefs are the same we examined in Sec-
tion 2.2.1 (page 23);
• cue=honi or hoffi sets the current voice as “cue” (i.e. a voice for hints, which are typeset
smaller than other voices) or normal voice;
• merge indicates that this voice belongs to the same staff as the previous voice;
• name=hnamei or nm=hnamei specifies the name that appears at the left of the first staff;
• pos=htypei hpositioni sets the position of music elements (more information in Sec-
tion 4.1.13, page 76);
• scale=hni sets the scale of the voice. Default is 1, maximum value is 2, minimum is
0.5;
• sname=hnamei or snm=hnamei specifies the name that appears at the left of all the
staves after the first one;
• staffnonote=hni: hides the staff associated to the voice (more information in Sec-
tion 4.1.12, page 73);
• staffscale=hni sets the scale of the voice and the associated staff. Default is 1, maxi-
mum value is 3, minimum is 0.5;
X: 1
T: Brother John
C: Traditional
L: 1/4
V: 1 clef=treble name="Soprano" sname="S"
V: 2 clef=treble name="Contralto" sname="C"
K: F
%
[V:1] FGAF | FGAF | ABcz | ABcz | c/d/c/B/ AF | c/d/c/B/ AF |
[V:2] z4 | z4 | FGAF | FGAF | ABcz | ABcz |
%
[V:1] GCFz | GCFz | z4 | z4 |
[V:2] c/d/c/B/ AF| c/d/c/B/ AF | GCFz | GCFz |
48 CHAPTER 3. HARMONY
Brother John
Traditional
Soprano
Contralto
S
C
V: can also define the properties of many voices at once. V:*, written in the tune header
and followed by voice parameters, sets the properties of all voices in the tune; parameters
can be redefined by successive V: fields. To write the same notes to several voices at once,
we can specify the voices in the same V: field, separated by commas:
X: 1
M: 4/4
L: 1/4
V: * clef=bass % applies to all voices
K: C
%
V: 1 clef=alto % overrides previous setting
V: 1,2,3 % specifies 3 identical voices
C, D, E, F, | G, A, B, C ||
Fancy staves can be obtained using staffscale and stafflines. Percussion notes are
notated using sharps for x-shaped note heads, and flats for circle-x-shaped note heads:
X: 1
T: Special Staves
M: 4/4
L: 1/4
V: 1 stafflines=6 staffscale=0.7
V: 2 stafflines=4 scale=1.2
V: 3 stafflines=1 staffscale=1.4 perc
K: C
%
3.1. POLYPHONY IN ABC 2 49
Special Staves
6 staff lines, staffscale=0.7
4
4
4 staff lines, staffscale=1, scale=1.2
4
4
Warning
The above score is typeset with abcm2ps, since percussion notes are not supported in
abc2svg. To be more precise, abc2svg implements percussion notes using an extension
called note mapping that will be explained in Section 8.3 (page 125).
• when voices are not enclosed by any delimiter, they will be simply typeset on separate
staves. The uppermost voice in the system will be the first voice in the list. For example:
%%score SATB
• when two or more voices are enclosed in square brackets, their staves will be joined
by a thick bracket. This arrangement is often used for the choral part of a system. For
example: %%score [SATB]
• when two or more voices are enclosed in curly brackets, their staves will be joined by
a bracket. This is typically used for the piano or organ part of a system. For example:
%%score {MS MD}
• if two or more voices are enclosed between parentheses, they will be typeset on the
same staff. For example: %%score [(SA) (TB)]
• to add measure bars that cross the staves, use the character | between voice names:
%%score [S|A|T|B]
50 CHAPTER 3. HARMONY
When two voices are typeset on the same staff, the stem direction indicates the first voice
(up) or the second (down).
In addition to %%score, voices and staves can also be specified using the alternate directive
%%staves. These two directives use the same parameters, but measure bar indications work
the opposite way. For instance, %%staves [S A T B] is equivalent to %%score [S|A|T|B],
and it means that bar lines are drawn. As you can see, using %%score is more intuitive.
Here is an example of piano music. There are three voices, two of which are played with
the right hand. When one of these voices is silent, normal rests are replaced by invisible rests
we studied in Section 2.1.4 (page 18).
X: 1
T: Prelude
T: Op. 28, No. 7
C: Fryderyk Chopin
L: 1/4
M: 3/4
Q: "Andantino"
%%score (V1 V2) | V3
V: V1 clef=treble
V: V2 clef=treble
V: V3 clef=bass
K: Amaj
%
% 1 - 2
[V:V1] (!p!E | "_dolce"c/>d/ [DGB] [DGB] | [DGB]2) ([df] |
[V:V2] x | x3 | x3 |
[V:V3] z | "_con pedale"E,, [E,E] [E,E] | [E,E]2 z |
% 3 - 4
[V:V1] [^B/^d/]>[c/e/] [ca] [ca] | [ca]2) ([Ec] | % slur not ended!
[V:V2] x3 | x3 |
[V:V3] A, [A,E] [A,E] | [A,E]2 z |
Prelude
Op. 28, No. 7
Fryderyk Chopin
Andantino
dolce
con pedale
Let’s now try a more complex piece. These are the first four measures of Mozart’s famous
“Ave Verum Corpus”, for organ and SATB:
X: 1
T: Ave Verum Corpus
C: W. A. Mozart
M: 4/4
L: 1/4
Q: "Adagio"
3.1. POLYPHONY IN ABC 2 51
Tenore
Basso
A ve, A ve,
Organo
Note that the voices were intentionally written in reverse order, but %%score rearranged
them as expected. Normally, for clarity sake voices should be written in the same order as
specified in %%score.
Sometimes, a piece has a master voice and cue voices; the former is the main voice in the
piece, while cue voices are used, for instance, as hint for variations. %%score and %%staves
accept the symbol + before a voice name, which becomes the master voice. The cue=on
option is then used to set the cue voice(s):
X: 1
M: C
52 CHAPTER 3. HARMONY
L: 1/4
K: C
%%score (1 +2)
V:1 cue=on
cdef | Z2 | g/f/e/d/ c2 |]
V:2
C4 | CEGc | cGEC | C4 |]
As a last example, let’s see a piece written in an unusual manner: the “Kyrie” from Andrea
Gabrieli’s Missa Brevis. This music has no metre, and each voice follows its own tempo: in
this case we use M:none. The length of each measure is different for each voice, consequently
the !longphrase! symbol replaces measure bars. We also want “cut time” tempo indicated.
This is how the piece is written:
X: 1
T: Missa Brevis
C: Andrea Gabrieli (1510? - 1586)
M: C|
L: 1/4
%%score [1 2 3 4]
V: 1 clef=treble
V: 2 clef=treble
V: 3 clef=treble-8
V: 4 clef=bass
U: L = !longphrase!
K: F
%
[P: Kyrie]
[V: 1] [M:none] F4 c2d2c2LG2 A2B2c2A2G2LF2 G2 c4 =B2 Lc4 z2 G2
w: Ky- ri - e e- lei ---son e- lei --son Ky-
[V: 2] [M:none] Lz8 C4 F2G2 FECD E2 F4 E2C2G2A2G2F2E2
w: Ky- ri - e * * e- lei --son e- lei ---
[V: 3] [M:none] z8 Lz8 F4 c2d2c2G2A2d2f2e2d2c2
w: Ky- ri - e e- lei -----
[V: 4] [M:none] z8 z8 Lz8 C,4 F,2G,2F,2LC,2 D,2E,2
w: Ky- ri - e e- lei -
%
[V: 1] c2d2c2LG2 A2B2A3 GAB c2 d4 c3 B/LA/ G4 A16 |]
w: ri - e e- lei -----------son.
[V: 2] A2 F4 E2F2D2 F4 F2 G3 F LF2 E2 F4 E2 F16 |]
w: ---son Ky- ri- e~e- lei -----son.
[V: 3] A3 =B Lc4 z2 G2c2d2c2LG2 A2_B2G2LA2 c4 c16 |]
w: son__ Ky- ri - e e- lei ----son.
[V: 4] LF,4 z2 C,2F,2G,2F,2LD,2 F,2E,2D,2LB,,2 C,8 F,16|]
w: son Ky- ri - e e- lei ----son.
3.1. POLYPHONY IN ABC 2 53
Missa Brevis
Andrea Gabrieli (1510? - 1586)
Kyrie
Ky ri e e lei son e lei son Ky
Ky ri e e lei son e lei
Ky ri e e lei
Ky ri e e lei
ri e e lei son.
son Ky ri ee lei son.
son Ky ri e e lei son.
son Ky ri e e lei son.
3.1.3 Reductions
Just by changing the %%score directive, we can obtain reductions or part extractions from
the same source. In fact, %%score tells the scorewriter to typeset only the voices that are
specified. We are free to omit voices in %%score, even if we wrote the corresponding music
lines.
The next example is an excerpt from Händel’s “Giulio Cesare” that specifies V: fields for
two violins, a solo voice, and bass. We also write three pairs of T: and %%score lines, but keep
two of them commented out. Only the pair that is uncommented will typeset an additional
subtitle and will specify a score layout.
X: 1
T: Giulio Cesare in Egitto
T: Sesto: Svegliatevi nel core, furie d'un alma offesa (excerpt)
C: G.F. Händel
L: 1/8
M: C
T: Full score
%%score [V1 V2 Sesto Bassi]
% T: Vocal part and keyboard reduction
% %%score Sesto {V1 Bassi}
54 CHAPTER 3. HARMONY
T: Full score
%%score [V1 V2 Sesto Bassi]
% T: Full score
% %%score [V1 V2 Sesto Bassi]
% T: Vocal part and keyboard reduction
% %%score Sesto {V1 Bassi}
T: First violin only
%%score V1
then we tell the scorewriter to ignore all voices but V1. The resulting score, predictably, will
contain only one staff:
3.1. POLYPHONY IN ABC 2 55
Similarly, we could have obtained a solo voice and piano reduction leaving these lines
uncommented:
% T: Full score
% %%score [V1 V2 Sesto Bassi]
T: Vocal part and keyboard reduction
%%score Sesto {V1 Bassi}
% T: First violin only
% %%score V1
X:1
M:4/4
L:1/4
K:C
%
cdef & xxCD | gfed & EDCB, | c2G2 & C2x2 | c2 z2 & E2x2 & G2x2 |
X:2
M:4/4
L:1/4
K:C
%%score (1 2 3)
%
[V:1] cdef | gfed | c2G2 | c2 z2 |
[V:2] xxCD | EDCB, | C2x2 | E2 x2 |
[V:3] x4 | x4 | x4 | G2 x2 |
56 CHAPTER 3. HARMONY
• write relatively short music lines (less than 80 characters, 66 would be optimal);
• write the voices in the same order as they would appear on paper;
• insert comments to indicate the measure numbers, and to explain complex passages if
needed;
In general, the layout of the source should resemble that of the printed score as much as
possible. The following source is a model you should follow.
X: 1
T: Son questi i crespi crini
C: Claudio Monteverdi (1567-1643)
M: C
L: 1/4
Q: "Andante mosso" 1/4 = 200
V: 1 clef=treble name="Soprano"sname="A"
V: 2 clef=treble name="Alto" sname="T"
V: 3 clef=bass name="Bass" sname="B"
U: i = !invisible!
K: Eb
%
% 1 - 4
%
[V: 1] i |: z4 | z4 | f2ec | _ddcc |
w: Son que-sti~i cre-spi cri-ni~e
[V: 2] i |: c2BG | AAGc | (F/G/A/B/)c=A| B2AA |
w: Son que-sti~i cre-spi cri-ni~e que ---- sto~il vi-so e
[V: 3] i | :z4 | F,2E,C, | _D,D,C,F, | (B,,/C,/_D,/E,/)F,F,|
w: Son que-sti~i cre-spi cri-ni~e que ---- sto~il
%
% 5 - 9
%
[V: 1] cAB2 | cAAA | c3B | G2HGz :: e4 |
w: que-sto~il vi-so ond' io ri-man-go~uc-ci-so. Deh,
[V: 2] AAG2 | AFFF | A3F | =E2HEz:: c4 |
3.1. POLYPHONY IN ABC 2 57
58 CHAPTER 3. HARMONY
Chapter 4
Formatting
W e have learnt how to write music in Abc, from simple single-voice tunes to complex
polyphonic scores. In theory, we are done: in fact, the old Abc notation only describes
high-level musical elements, and it’s completely output-agnostic.
In practice, Abc 2 allows for the implementation of low-level details such as formatting
parameters, MIDI instruments, and also extensions like tablatures, chord diagrams, and much
more. These features are obtained writing lines that start with %%; these special lines are
known as pseudo-comments or directives. Since they start with % , directives can be treated
as comments by programs that don’t implement them.
We have already dealt with directives; for example, when we learnt %%linebreak or
%%score. There are several types of directives: some specify the page layout, others the fonts,
the spacing, many types of customisation, etc. We will see in Chapter 7 (page 105) that abc-
2midi provides its own directives for MIDI output.
Directives can be written in the source, or in external Abc files known as header files, or
in external files known as format files. abcm2ps and abc2svg support over 160 directives; for
more details, please see Section A.5, page 166.
Unfortunately, at this point Abc applications start to become incompatible with one an-
other. In particular:
• abc2svg and abcm2ps share most directives, but some directives are specific to each
program;
• The Abc/MusicXML translators only support a small subset of the directives supported
by abc2svg, abcm2ps, and abcMIDI;
• other Abc applications may ignore directives altogether, or support their own.
As a result, this chapter is specific to abc2svg and, in some cases, to abcm2ps. Useful
directives that are supported by other programs will be described in the following chapters.
You can skip this chapter if you plan to convert your Abc music to MusicXML, and do
the final formatting with another application.
59
60 CHAPTER 4. FORMATTING
• a unit of length in centimeters (cm), inches (in), PostScript points (pt), or pixels (no
suffix): for instance, 30pt, 1cm, 0.3in, 20. A PostScript point is 1/72 inch or 0.353 mm;
1 pixel is 1/96 inch or 0.265 mm;
• a logical value that can be specified using the words true, yes, 1 if positive; false, no,
0 if negative;
Directives may have a different scope. That is, they may affect the appearance and/or the
behaviour of different elements:
• immediate (the directive will immediately apply to the next music elements);
• generation (the last directive of this scope will apply to the next music elements);
Most directives have a default value. For instance, abcm2ps uses ANSI letter paper size by
default; page width is 8.5 inches, page height is 11 inches. In abc2svg, only the page width
is predefined, and it defaults to 21 cm (A4 paper width). For reference: A4 paper is 210 × 297
mm, 595 × 842 points; letter paper: 8.50 × 11.00 inches, 612 × 792 points.
Both programs have sensible default values, and usually make beautiful scores. In general,
you should refrain from messing about and changing too many directives. Unless you really
know what you are doing, chances are you’ll make the layout worse than the default. I suggest
that you only customise the following directives:
% PAGE LAYOUT
%
4.1. FORMATTING PARAMETERS 61
%%pagewidth 21cm
%%pageheight 29.7cm
%%topmargin 1.5cm
%%botmargin 1.5cm
%%leftmargin 1.5cm
%%rightmargin 1.5cm
%%topspace 0cm
%%footer " $T, p. $P "
%
% FONTS
%
%%titlefont Times-Bold 28
%%subtitlefont Times-Bold 22
%%composerfont Times-Roman 16
%%vocalfont Times-Roman 15
%%annotationfont Times-BoldItalic 14
%%footerfont Times-Roman 12
%
% MISC
%
%%measurebox yes % measure numbers in a box
%%measurenb 0 % measure numbers at start of line
%%pagescale 0.8 % page size
%%maxshrink 1.0 % compact the notes
%%linebreak <none> % automatic line breaks
%%squarebreve yes % typeset breve note as square glyph
As you can see, many directives have a self-explanatory name such as %%pagewidth or
%%leftmargin, while others need explanations. The most important directives will be de-
scribed in the next few sections.
Once the page format and margins are set, you should be able to adjust the number of
pages of your scores just by changing the value of %%pagescale and %%maxshrink.
When directives are written at the top of a file, they apply to all of the tunes that follow. In
this case, they are called global parameters or global definitions. Directives can also be written
within a tune and between tunes.
Most directives can also be used as abc2svg and abcm2ps options in the command line.
For instance, the following command line typesets music with abcm2ps, specifying the %%pa-
gewidth, %%pageheight, %%pagescale, and %%titlefont directives:
Spaces are not allowed in directive parameters that require a unit of length, when they are
specified in the command line. Although quotes are optional, they should always be used to
avoid clashes with the shell. In the command line above, --titlefont "* 18" means: “leave
the title font unchanged, but change the font size to 18 pt”. The asterisk must be enclosed in
quotes, otherwise trouble may occur.
As a final note: if the Abc source contains directives that are also specified as command
line options, the latter override the former. That is: if our source contains the global parameter
%%pagescale 0.85, but we specify, say, --pagescale 0.7 as command line option, the
latter will apply.
62 CHAPTER 4. FORMATTING
% This is example.fmt
pagescale 0.85
topmargin 2 cm
titlefont Times-Bold 24
subtitlefont Times-Bold 20
...
% End of the format file.
This is the corresponding Abc file, which we will call a header file. To make it clear that
is’s a header file and not an ordinary Abc file, it has a .abh extension:
% This is example.abh
%%pagescale 0.85
%%topmargin 2 cm
%%titlefont Times-Bold 24
%%subtitlefont Times-Bold 20
...
% End of the header file.
Let’s suppose we saved example.fmt and example.abh in the same folder as our source
files. To format the file mytune.abc using example.fmt, we insert the line:
%%format example.fmt
at the top of the source, or use abcm2ps’s -F option in the command line:
The .fmt extension can be omitted, both in the command line and in the source. Two or
more format files can be used at the same time.
To use the header file instead of a format file, insert the line:
%%abc-include example.abh
at the top of the source. If you use abc2svg in the browser editor, you will be prompted to
load example.abh alongside the current source.
4.1. FORMATTING PARAMETERS 63
Note
abcm2ps can use both format and header files, while abc2svg only uses header files
(only one per source, in the web editor). Using %%abc-include makes Abc files com-
patible with both abcm2ps and abc2svg, and is therefore highly recommended.
If we keep your format files in a folder, i.e. c:\music\format, we will also have to specify
the -D parameter followed by the folder name:
Binary packages for GNU/Linux and macOS usually store the format files in /usr/share/
abcm2ps. As we already know, the command:
abcm2ps -V
reports the default format file directory. The current version of abcm2ps ships with three
format files: flute.fmt, landscape.fmt, and musicfont.fmt; more could be included in
future releases, along with corresponding header files.
Using format or header files is the best solution when we want to typeset a series of pieces
that share the same style. Moreover, abcm2ps and abc2svg can be extended by defining
additional symbols, as we will see in Chapter 8 (page 121). Format files containing libraries
of symbols can thus be employed when needed.
%%vocalfont Times-Roman 12
I:vocalfont Times-Roman 12
Note
Directives should be preferable over I: fields , because they are ignored by applications
that don’t implement them. On the contrary, the equivalent I:directive field will
probably cause a warning or error message if it’s not recognised.
Let’s use both methods to change the %%vocalfont directive in a tune; this directive
changes the font of lyrics in w: lines. Since it has a “generation” scope, the change is imme-
diate:
%%titlefont Times-Italic 24
X: 1
T: Silent Night
C: F. Gruber
M: 3/4
Q: "Andante tranquillo"
K: C
%
G>A G E3 | G>A G E3 | d2 d B2 B | c2 c G3 |
%%vocalfont Times-Roman 14
w: A- stro del ciel, Par- gol di- vin,
+: mi- te~A- gnel- lo re- den- tor!
I: vocalfont Times-Italic 14
w: Voi- ci No- \"el, \^o dou- ce nuit!
+: L'\'e- toile~est l\`a qui nous con- duit.
%%vocalfont Times-Roman 14
w: Si - lent night! Ho - ly night! All is calm,_ all is bright.
Silent Night
F. Gruber
Andante tranquillo
A stro del ciel, Par gol di vin, mi te A gnel lo re den tor!
Voi ci No ël, ô dou ce nuit! L'é toile est là qui nous con duit.
Si lent night! Ho ly night! All is calm, all is bright.
This method can also be used to change the font in the same line:
X: 1
L: 1/4
K: C
CDEF | !ff!GAB!fermata!c | !mf!cBAG | !p!FED!fermata!C |
%%vocalfont Times-Roman 12
w: la la la la\
I: vocalfont Times-Bold 16
+: la la la la, la la la la\
%%vocalfont Times-Italic 12
+: la la la la.
la la la la la la la la, la la la la la la la la.
4.1. FORMATTING PARAMETERS 65
These are predefined fonts, which we can use anytime with any font directive. To use
other fonts, we have to declare them inserting the %%font directive at the top of the source.
Text and font related directives are:
• %%font declares a font, i.e. it tells the applications that the font will be used. If the font
name contains spaces, then it must be enclosed in double quotes;
• %%textfont sets a font. If the font is not one of the web-safe fonts, it must be declared
beforehand with %%font;
%%text lines are treated differently by abcm2ps and abc2svg. In abcm2ps, a %%text line
stops the music generation, and the text is typeset immediately. In abc2svg, the text is typeset
after the current music line. So, the following source produces different output:
X:1
%%linebreak <none>
%%textfont Times-BoldItalic 14
M:none
K:C
CDEF |
%%text Text within music lines
GABc | cBAG | FEDC |
X:1
%%textfont Times-Bold 14
M:none
K:C
CDEF |
%%vskip 0
%%text Text within music lines
GABc | cBAG | FEDC |
The %%vskip 0 command stops the music generation and lets %%text work as expected.
Here is an example that shows abcm2ps’s capability of alternating text in different fonts
with pieces of music, using one of its additional PostScript fonts (AvantGarde-Book). We can
obtain similar (but not identical!) results using abc2svg and other fonts:
4.1. FORMATTING PARAMETERS 67
%%vskip 0.4cm
%%textfont AvantGarde-Book 16
%%begintext align
Now we'll have a look at something more lively. To start with, let's
switch fonts: from Times-Roman to AvantGarde-Book. Here is the same
Etude with a few small variations to make it more interesting:
%%endtext
X: 2
T: Etude, second version
M: 4/4
L: 1/4
Q: "Adagio"
K: C
%
.C{DCB,}C.G{AGF}G|A>AG2|.F{GFE}F.E{FED}E|D>DC2|
%%sep 0.2cm 0.2cm 7cm
% the following line increases the character size, no font change
%%textfont * 18
%%center End of the example.
%%sep 0.2cm 0.2cm 7cm
68 CHAPTER 4. FORMATTING
Typesetting example
This is an example of text inserted into an ABC file. This abcm2ps feature allows for the writing of
songbooks, music collections or other publications without having to resort to a word processor. Not
bad, is it? Now let’s write a brief musical example.
4
4
p mf
Now we’ll have a look at something more lively. To start with, let’s switch fonts: from
Times-Roman to AvantGarde-Book. Here is the same Etude with a few small variations to
make it more interesting:
To use different fonts in strings, we specify an alternate set of fonts with the %%set-
font-1, %%setfont-2, %%setfont-3, and %%setfont-4 directives, followed by a font name
and a font size in points. These can be referred to in strings as $1 $2 $3 $4, and have the
effect of changing the text font. $0 reverts to the default font.
%%setfont-1 Helvetica 24
%%setfont-2 Times-Italic 22
%%setfont-3 Helvetica-Bold 18
%%setfont-4 Courier 20
X: 1
M: C
L: 1/4
K: C
%%begintext
Hello. This is the default font, $1this is font 1, $2this is font 2,
$3this is font 3, $4this is font 4,$0 and now back to the default font.
%%endtext
CDEF | GABc |
W: It also works in $3W: fields!
W: $0It's useful to $3emphasise $0some parts.
It also works in W: fields!
It's useful to emphasise some parts.
All font directives and their default values are listed in Section A.5.3, page 168.
4.1. FORMATTING PARAMETERS 69
Note
A couple of notes:
• if you use a font that is not recognised, it will be silently replaced by Courier
(abcm2ps) or serif (abc2svg);
• font setting directives have an extended syntax that will be explained later on;
Avoid mistakes!
The ! line-breaking character was widely used in older Abc releases, but its use is now
discouraged.
X: 1
L: 1/4
K: C
%%linebreak * !
CDEF | GABc |* CDEF | GABc | cdef | gabc' |!
%%linebreak
CDEF | GABc | CDEF | GABc | cdef | gabc' |
70 CHAPTER 4. FORMATTING
A staff break is like a line break, but it will not stretch the music between the page margins.
This is done with the %%stretchstaff 0 directive:
%%stretchstaff 0
X: 1
L: 1/4
K: C
CDEF|
CDEF|GABc|
CDEF|GABc|cdef|]
Another way to insert a line break is the %%vskip directive, which is normally used to
insert some vertical space. The above tune could be written as follows:
X: 1
L: 1/4
K: C
CDEF|
% 0-height vertical skip
%%vskip 0
CDEF|GABc|
%%vskip 0
CDEF|GABc|cdef|]
To avoid ugly results, forcing line and staff breaks should be done with special care.
If a tune doesn’t fit in the current page, it is typeset on a new page; this is the default
behaviour in abcm2ps, while abc2svg always splits the tune. To obtain the same behaviour
in abcm2ps, we use the %%splittune directive followed by a logical value, or by the strings
odd or even to split the tune on odd or even pages.
Finally, to force a new page we use the aptly named %%newpage directive.
Most commonly, we will use \ in tunes with repeats; this is one of the cases when we
don’t want abcm2ps or abc2svg to format the music automatically. Typeset the following
tune with and without \ to see the difference:
X:92
T:Breeches Full of Stitches
R:polka
M:2/4
L:1/8
K:Amaj
%
"A" A>B cA | "D" BA ce | "A" A>B cA | "D" BA F2 | \
"A" A>B cA | "D" BA ce | A>B AF | "E" FE E2 :|
"A" e>f ec | "D" BA Bc | "A" e>f ec | "D" BA F2 | \
"A" e>f ec | "D" BA Bc | A>B AF | "E" FE E2 :|
A D A D A D E
To avoid line breaks entirely, even when line breaking characters are written in the source,
we use the %%linebreak <none> command. It is the equivalent of the -c option; it also
works in the command line with abc2svg (please see Section 10.2, page 148.)
To typeset the above tune without line breakes, we will the following command:
Just like the -c option, %%linebreak <none> overrides \ and other line-breaking char-
acters.
• in most cases, it is best to let abcm2ps or abc2svg do the work. Please refer to Sec-
tion 2.1.1, page 15;
• the opposite approach is inserting the exact number of measures in each line, then
running abcm2ps without the -c option or adding I:linebreak <EOL> in the source;
• when we want each staff to contain hni measures, we use the %%barsperstaff hni
directive in the source or the option -B hni in the abcm2ps command line;
• %%alignbars hinti aligns the bars of the next hinti lines of music. It only works on
single-voice tunes, and only with abcm2ps;
72 CHAPTER 4. FORMATTING
• %%equalbars hbooli makes the width of measures proportional to their duration; only
available in abc2svg.
If the last line contains fewer measures that do not extend to the entire width of the page,
we can force the alignment using the %%stretchlast directive.
If you decide to set the number of measures yourself, be careful not to write too many or
too few per line! If you write too few, the score will look ugly; if you write too many, abcm2ps
or abc2svg will rework the lines at their discretion.
X:1
M:4/4
L:1/4
K:C
%%voicescale 1.2 % default=1
cdef & [I:voicescale 0.7] xxCD | gfed & EDCB, |
c2G2 & C2x2 | c2 z2 & E2x2 & G2x2 |
X: 1
M: 4/4
L: 1/4
K: C
%
% let's repeat a single note three times
C [I:repeat 1 3] C C C |
% let's repeat a sequence of four notes twice
C//E//G//E// [I:repeat 4 2] C//E//G//E// C//E//G//E// C |
% let's repeat a whole measure once
4.1. FORMATTING PARAMETERS 73
X:1
M:C
L:1/4
U: m = !xstem!
K:none
%%score {1 2}
V:1
cc//c//c//c//c2 | [CEGc]2[CEGc]2|
V:2 bass
mC,C,//mC,//C,//mC,//mC,2 | m[C,,C,]2[C,,C,]2 |
V:1
c/G/E/C/ [I:staff +1] C/G,/E,/C,/|C,/E,/G,/C/ [I:staff -1]C/E/G/c/|
V:2
z4 | z4 |
Warning
Unfortunately, cross-staff slurs are not yet implemented in abcm2ps and abc2svg.
• if hni = 1, only staves that contain visible noted or visible rests are typeset;
Here is as example. The following rendition of “Orientis partibus” (a medieval song) for
two voices has different stanzas and a refrain. Stanzas are sung by the first voice only; the
refrain is sung by both voices. The %%staffnonote 0 directive instructs the scorewriter to
typeset the active voice only, and hide voices that contain only rests.
X: 1
T: Orientis Partibus
C: Anonymous
M: 2/4
L: 1/8
%%score [1 2]
V:1 name=V1 sname=V1
V:2 name=V2 sname=V2
K: FMix
%%linebreak <EOL>
%%staffnonote 0
%
% 1 - 4: VOICE 1 ONLY
%
[V:1] FG AF | GE F2 | cc dB | cc A2 |
w: O-ri-en-tis par-ti-bus ad-ven-ta-vit a-si-nus,
[V:2] Z4 |
% 5 - 8
[V:1] AG BA | GF A2 | cB AF | GE F2 |
w: pul-cher et for-tis-si-mus, Sar-ci-nis ap-tis-si-mus.
[V:2] Z4|
%
% 9 - 14: BOTH VOICES
%
[V:1] F2 z2 | FG AG | F2 z2 | F2 z2 | FG AG | F2 z2 |
w: Hez, Hez sir as-nes, hez! Hez, hez sir as-nes, hez!
[V:2] A2 z2 |AB cB | A2 z2 | A2 z2 | AB cB | A2 z2 |
%
% 15 - 18: VOICE 1 ONLY
%
[V:1] FG AF | GE F2 | cc dB | cc A2 |
w: Hic in col-li-bus Si-chan iam nu-tri-tus sub Ru-ben
[V:2] Z4 |
% 19 - 22
[V:1] AG BA | GF A2 | cB AF | GE F2 |
w: tran-si-it per Ior-da-nem sa-li-it in Be-thle-hem.
[V:2] Z4|
%
% 23 - 28: BOTH VOICES
%
[V:1] F2 z2 | FG AG | F2 z2 | F2 z2 | FG AG | F2 z2 |
w: Hez, Hez sir as-nes, hez! Hez, hez sir as-nes, hez!
[V:2] A2 z2 | AB cB | A2 z2 | A2 z2 | AB cB | A2 z2 |
4.1. FORMATTING PARAMETERS 75
Orientis Partibus
Anonymous
V1
O ri en tis par ti bus ad ven ta vit a si nus,
V2
V1
pul cher et for tis si mus, Sar ci nis ap tis si mus.
V2
V1
Hez, Hez sir as nes, hez! Hez, hez sir as nes, hez!
V2
V1
Hic in col li bus Si chan iam nu tri tus sub Ru ben
V2
V1
tran si it per Ior da nem sa li it in Be thle hem.
V2
V1
Hez, Hez sir as nes, hez! Hez, hez sir as nes, hez!
V2
X: 1
M: none
L: 1/4
K: C clef=none
%
%%staffnonote 2
%%stretchstaff 1
%%stretchlast 1
%%linebreak *
%%linewarn 0
% 12 blank staves
x4 [] * x4 [] * x4 [] * x4 [] * x4 [] * x4 [] *
x4 [] * x4 [] * x4 [] * x4 [] * x4 [] * x4 [] *
The %%linewarn 0 directive turns off the “Line underfull” warning messages.
• dynamic, to specify the position of decorations concerning dynamics (e.g. !<(!, !>(!,
etc.);
• volume, to specify the position of decorations concerning loudness (e.g. !pp!, !pp!,
etc.).
X: 1
M: C
L: 1/4
K: C
%%pos dynamic up
%%pos volume up
%%pos stem up
%%pos gstem auto
%%pos gchord down
%%pos ornament up
!<(!"C"CDE!<)!!f!F | !>(!"G"GFE!>)!!p!D | "C"CDEF | !fermata!{GA}G2 z2 |
%%pos dynamic down
%%pos volume down
%%pos stem down
%%pos gstem down
%%pos gchord up
%%pos ornament hidden
!<(!"C"CDE!<)!!f!F | !>(!"G"GFE!>)!!p!D | "C"CDED | !fermata!{CD}C2 z2 |]
C G C
C G C
X: 1
M: 4/4
L: 1/8
K: C
%%slurheight 2
%%flatbeams 1
%%straightflags 1
%%stemheight 30 % default: 20
(GABc) (cBAG) | G A B c G A B c |
78 CHAPTER 4. FORMATTING
X: 2
M: 4/4
L: 1/8
K: C
%%slurheight 0.5
%%flatbeams 0
%%straightflags 0
%%stemheight 20
(GABc) (cBAG) | G A B c G A B c |
These parameters are applied once, and cannot change midtune. If we want to change
their value, we will have to start a new tune, or insert a %%vskip command.
%%gchordbox 1
%%gchordfont sans-serifBoldItalic 16
X: 1
L: 1/4
M: C
K: C
%
"C"CDEF | "G"G2 G2 | "G7"GFED | "C"C2 C2 ||
C G G7 C
Another way to highlight accompaniment chords is typeset them in a different colour. The
following tune uses low-level code in PostScript and SVG that will be explained in Section 8.2,
page 123:
<style>
.red {color:red}
</style>
%%endsvg
% use the "red" class in accompaniment chords
%%gchordfont * * class=red
X:1
T: Red accompaniment chords
L:1/4
M:C
K:C
%
"C"CDEF | "G"G2 G2 | "G7"GFED | "C"C2 C2 ||
The %%gchordfont accepts an additional argument that refers to the red class we defined
as SVG code.
In PostScript code, colours can be specified as RGB components (real numbers between
0.0 and 1.0) before the setrgbcolor command. In SVG code, you may use HTML colour
names or the rgb(R, G, B) command; RGB components are numbers between 0 and 255.
• where is a number that indicates where to typeset the tuplet indication. 0 = automatic,
1 = never, 2 = always.
• what is a number that indicates what to draw. 0 = draw a bracket, 1 = draw a slur.
• value indicates the number to typeset. 0 = the value of hni in the tuplet, 1 = no value
at all, 2 = a ratio hni:hti.
X: 1
M: C
L: 1/4
K: none
%
"^Default"(3A/A/A/ "^tuplets 1 0 0"[I:tuplets 1 0 0](3A/A/A/ \
"^tuplets 2 0 0"[I:tuplets 2 0 0](3A/A/A/ \
"^tuplets 0 1 2"[I:tuplets 0 1 2](3A/A/A/ |\
80 CHAPTER 4. FORMATTING
X: 1
M: 2/4
L: 1/4
K: C
%%rbmax 3
%%rbmin 1
|:CD |1 EF | GA | Bc | cG :|2 EF | GG | C2 ||
1 2
X:1
M:C
L:1/4
K:C
%%score (1 2)
V:1
%%text %%voicecombine -1: notes and rests are displayed as written;
%%voicecombine -1
c2cz | c2 c2 | c2 z2 |
V:2
CEGz | z2 _B2 | c2 z2 |
V:1
%%text %%voicecombine 0: rests of equal duration are merged;
%%voicecombine 0
c2cz | c2 c2 | c2 z2 |
V:2
4.1. FORMATTING PARAMETERS 81
CEGz | z2 _B2 | c2 z2 |
V:1
%%begintext
%%voicecombine 1: notes of equal duration are merged as chords,
except in the case of chord inversions, unisons, second intervals;
%%endtext
%%voicecombine 1
c2cz | c2 c2 | c2 z2 |
V:2
CEGz | z2 _B2 | c2 z2 |
V:1
%%text %%voicecombine 2: notes of equal duration are merged as chords;
%%voicecombine 2
c2cz | c2 c2 | c2 z2 |
V:2
CEGz | z2 _B2 | c2 z2 |
V:1
%%text $1voicecombine > 2:$2 unisons are merged.
%%voicecombine 3
c2cz | c2 c2 | c2 z2 |
V:2
CEGz | z2 _B2 | c2 z2 |
%%voicecombine 1: notes of equal duration are merged as chords,
except in the case of chord inversions, unisons, second intervals;
%%voicecombine 2: notes of equal duration are merged as chords;
%%voicecombine > 2: unisons are merged.
82 CHAPTER 4. FORMATTING
4.1.19 Colours
Especially for teaching purposes, it may useful to highlight a voice or a run of notes. This can
be done typesetting the voice at a different scale using the scale= in the corresponding V:
field. A nice option is typesetting the voice (or the notes) using a different colour.
The %%voicecolor #rrggbb directive changes the colour of the following notes. rr gg
bb are exadecimal values (i.e. in the range 00–ff, capital letters allowed) of the red, green,
and blue colour components. Alternatively, the colour can be specified using a valid HTML
4 colour name: aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red,
silver, teal, white, and yellow.
In addition to voice colours, abc2svg also provides the %%bgcolor and %%fgcolor di-
rectives to set the page background and foreground colours.
%%multicol start saves the current page margins and sets the vertical position for the be-
ginning of a column. At this point we can change the margins and typeset the material
in the first column.
%%multicol new moves the vertical position to the beginning of a new column, resetting
the margins. Change the margins again and typeset the material in this new column.
This sequence may be repeated as many times as we wish.
%%multicol end reinitializes the page margins to the values that were used prior to %%multi-
col start, and moves the horizontal position below the columns that were typeset.
It sounds difficult, but it’s actually quite easy as shown in the following example:
4.1. FORMATTING PARAMETERS 83
%%pagewidth 21cm
%%leftmargin 1cm
%%rightmargin 1cm
X: 1
L: 1/4
K: C
CDEF | GABc | cdef | gabc' |
%%multicol start
%%rightmargin 11cm
%%begintext justify
Sator arepo tenet opera rotas. Sator arepo tenet opera rotas.
Sator arepo tenet opera rotas. Sator arepo tenet opera rotas.
%%endtext
"^left"CDEF | GABc |
%%text Left column (margins: 1, 11)
%%text Width: 21 - 1 - 11 = 9 cm
%%multicol new
%%leftmargin 13cm
%%rightmargin 2cm
%%begintext justify
Sator arepo tenet opera rotas. Sator arepo tenet opera rotas.
Sator arepo tenet opera rotas.
%%endtext
"^right"cdef | gabc' |
%%text Right column (margins: 13, 2)
%%text Width: 21 - 13 - 2 = 6 cm
%%multicol end
CDEF | GABc | cdef | gabc' |
Sator arepo tenet opera rotas. Sator arepo tenet Sator arepo tenet opera rotas.
opera rotas. Sator arepo tenet opera rotas. Sator Sator arepo tenet opera rotas.
arepo tenet opera rotas. Sator arepo tenet opera rotas.
left
right
Left column (margins: 1, 11) Right column (margins: 13, 2)
Width: 21 - 1 - 11 = 9 cm Width: 21 - 13 - 2 = 6 cm
and commas. Letters refer to Abc fields, and may be anything in the range A . . . Z ; the cor-
responding field will be typeset. Digits may follow a letter, meaning “0” for centre, “1” for
right align, or “-1” for left align. A comma , forces a newline; unrecognized characters are
ignored.
%%writefields X
%%titleformat R-1 T0 C1, Q-1 T0 O1, T0 H1
X: 123
T: Main Title
T: Second Title
T: Last Title, The
C: Anonymous
H: Written many many years ago...
L: 1/4
M: 4/4
R: march
O: Scotland
Q: 1/4 = 108
K: C
CDEF | GABc | CDEF | GABc |]
First of all: the %%writefields command, followed by X, typesets the tune index number
before the first title.
Let’s examine the %%titleformat line. The first part, R-1 T0 C1, typesets the rhythm
(R:) to the left, the main title at the centre, the composer to the right, and starts a new line.
Q-1 T0 O1, typesets the tempo to the left, the second title at the centre, the origin to the
right, and starts a new line. Finally, T0 H1 typesets the third title at the centre and the history
(H:) to the right.
Note the strange third title. As you can see, it was rearranged to read “The Last Title”.
Whenever abcm2ps or abc2svg find that the last word of a title starts with a capital letter
and it is preceded by a comma and a space, the word is moved to the head of the title. So it is
possible to write titles like “Bay of Fundy, The”, which sorts alphabetically in a more logical
way.
To force the last word to its position (for example, “That’s All, Folks”), write this line
before the tune: %%titletrim 0.
Avoid mistakes!
Do not write the X: number in the tune title; it’s a very bad practice. Sooner or later,
you may need to rearrange the index numbers, and you would have to edit the tune(s)
manually to fix the title(s)!
4.1. FORMATTING PARAMETERS 85
• $d typesets date and time of the last modification of the current input file;
• $P0 and $P1 typesets the page number, but only if it is even or odd;
The three fields must be separated by a tab character (see Section 1.2.3, page 7.)
Here is an example of the %%footer directive used to typeset the even page numbers on
the left, the tune title in the centre, and the odd page numbers on the right. Note that the
three areas are not separated by spaces, but by tabs!
Note
If you need to change headers and/or footers after a new page, insert their new definition
before the %%newpage directive.
X: 1
T: Testing the use of my logo
K: C
CDEF GABc | cBAG FEDC |
cdef gabc' | c'bag fedc |
%%multicol start
86 CHAPTER 4. FORMATTING
%%leftmargin 1cm
%%rightmargin 10cm
%%text
%%text Beautiful music presented by...
%%multicol new
%%leftmargin 7cm
%%rightmargin 1cm
%%EPS logo.eps
%%multicol end
If we omit -c, the resulting EPS file will be black and white.
To include graphics files with abc2svg, please refer to Section 4.1.27 (page 87).
X: 1
L: 1/4
K: C alto4
%%setbarnb 0
%
!stemless![C,G]\
%%staffbreak 0.3cm
K: C treble
CCEE | GGcc | "^al coda"ccee!coda! | fgc2 |\
%%staffbreak 1.5cm
!coda!g2C2 |]
al coda
Since we write a “fake” first measure, we also specify the %%setbarnb 0 directive to
indicate that the first bar should be be numbered 0 instead of 1.
The letter f that follows %%staffbreak means that the staff break is forced even if it
occurs at the beginning or end of a line. If the staff is part of a system, then the staff break
must be applied to all staves in the system.
X: 1
L: 1/4
M: C
K: C
%
%%ambitus 1
CEGc | ecGE | C4 |
X: 1
T: Using web links
L: 1/4
M: C
K: C
%
CDEF | GABc |]
%%beginml
<style>
.center text-align: center; vertical-align: middle;
</style>
<div class="center">
Please <a href="http://abcplus.sourceforge.net/">follow this link</a>
to find ABC software and documentation.
<br>
It's the ABC Plus site:
<img class="center" src="http://abcplus.sourceforge.net/Scherzando.png"
width=300>
</div>
%%endml
Please follow this link to find ABC software and documentation.
Please note that cropping the resulting PDF file with PDFCrop will disable the link, while
pdfcrop.sh will keep it active.
• first of all, the powerful directive %%pagescale hfactori. By default, the score is pro-
duced with a scaling factor of 1. A greater value will enlarge the score, a smaller value
will reduce its size.
• reduce the space between staves with %%staffsep and %%sysstaffsep, and use di-
rectives for setting the vertical spacing of title, subtitle, lyrics, etc.
• if the -c option is used, the %%maxshrink hfactori can be used to reduce the horizontal
spacing between notes. Compression is maximum with hfactori = 1, minimum with
hfactori = 0.
• to flatten slurs and ties, use the %%slurheight and %%tieheight and directive speci-
fying values lesser than 1;
4.2. TRANSPOSITION 89
4.2 Transposition
Transposition is a complex subject, and it can be accomplished in different ways. Unfortu-
nately, applications do not use the same syntax; nevertheless, we can transpose both typeset
and playback output.
X: 1
L: 1/4
M: 4/4
K: C
%
CDEF | GABc | \ % up two half-tones: from C to D
%%transpose 2
CDEF | GABc | \ % from C to E flat
%%transpose C_E
CDEF | GABc | \ % down one octave
%%transpose cC
CDEF | GABc ||
90 CHAPTER 4. FORMATTING
%%transpose is useful to transpose music from concert pitch to another key for a trans-
posing instrument; e.g. for the B[ clarinet. For example, a tune written in the key of C that
includes a %%transpose 2 directive will be typeset as if it were written in the key of D, but
the resulting MIDI will sound in C.
• score=hfromihtoi transposes the typeset output only. hfromi is the original note, htoi
is the transposed note;
These modifiers can also be applied globally when they are written in a V:* field at the
top of a file. Our previous example can be rewritten as:
X: 1
L: 1/4
M: 4/4
K: C shift=CD
%
CDEF | GABc | CDEF | GABc ||
Note
To transpose an Abc file to a new, transposed Abc file, we use abc2abc (Section 10.6,
page 155).
Chapter 5
abc2svg provides several directives that typeset tabulatures and chord grids for the guitar
and other string instruments. abcm2ps does not support these directives, but it can typeset
fingering charts for a few wind instruments.
5.1 Tablatures
The %%strtab directive is used to typeset a voice as tablature for the guitar or other string
instruments. The syntax is:
%%strtab hstring notesi [diafret]
The first parameter is a list of notes that define the instrument tuning; for example, stan-
dard guitar tuning is E,A,DGBe. The optional string parameter diafret indicates that the
fretboard is diatonic, as in the dulcimer.
Sometimes, tablatures consist of two staves; the top staff is in standard notation, the stave
below is the corresponding tablature. We could write two identical voices, but there’s a handy
shortcut. We can specify two voices in the V: field; notes that follow will be typeset on two
staves. Adding %%strtab to the definition of the second voice makes it a tablature:
X: 1
M: 3/4
L: 1/4
%%score 1 T % voice order
V: T % the second voice is the tablature
%%strtab E,A,DGBe % standard guitar tuning
K: C
%
V: 1,T % same notes on both voices
C D E | F G A | B A B | c2 z ||
T
A
B
91
92 CHAPTER 5. TABLATURES AND FINGERING CHARTS
Note
Specifying multiple voices in V: produces no output in abcm2ps and abc2midi, and is
not supported by abc2xml.py.
Let’s now write a tablature for the mandolin in standard tuning GDAE; more precisely,
Gdae’. In this example we typeset only the tablature, and hide note stems using %%pos:
X:1
M:3/4
L:1/4
V:T
%%strtab Gdae' % standard mandolin tuning
%%pos stem hidden
K:G
%
V: T
G A B | c d e | f e f | g2 z ||
T
A
B
X:1
L:1/4
M:4/4
K:Ebmaj
%
%%capo 3
%%grid 1
"Eb"EGBe | "Cm"CEGc | "Ab"AcAE | "Bb"BcBd | "Eb"e4 |
X: 1
T: Happy Birthday with %%grid2
M: 3/4
Q: 1/4=120
K: Gmaj
V: 1
%%grid2 1
D> D| "G"E2D2G2 | "D"F3 z D> D | "D"E2D2A2 | "G"G3 z D> D |
w:Hap-py birth-day to you, Hap-py birth-day to you, hap-py
"G"d2B2G2 | "C"F2E z c> c | "G"B2G2"D"A2 | "G"G6 |]
w:birth-day dear fel-low, hap-py birth-day to you!
G G C G D G
you, hap py birth day dear fel low, hap py birth day to you!
• %%diagram typesets guitar chord diagrams above the notes, in addition to chord names;
%%pagescale 1.3
%%diagram 6 % show diagrams
X: 1
M: none
L: 1/4
K: C
%
"C"C | "D"D | "E"E | "F"F | "G"G | "A"A | "B"B | "C"c ||
94 CHAPTER 5. TABLATURES AND FINGERING CHARTS
C D E F G A B C
342 234
fr1 fr2
x 32 1
x 132 231 23 4 234 x 32 1
To redefine existing diagrams or add diagrams for other keys or shapes, we use the
%%setdiag command as follows:
%%setdiag hnamei hdotsi hlabel[,pos]i hfingeringi [barre=hn1i-hn2i]
where:
• hdotsi is a list of six fret positions: a digit hni plots a dot on the hnith fret, ‘0’ or ‘x’
means “no dot”;
• hfingeringi indicates which finger to use on each fret. ‘x’ means “mute string”, ‘0’ or ‘y’
means “open string”;
• [barre=hn1i-hn2i] draws a barre between strings hn1i and hn2i. Strings are numbered
654321, from E, to e.
The following source defines new chord diagrams for the key of C]:
%%pagescale 1.3
%%diagram 1
X: 1
L: 1/1
M: none
K: none
%%setdiag C# 043020 fr1,1 x43020 barre=3-1
%%setdiag C#m x03320 fr4,1 x03420 barre=5-1
%%setdiag C#7 x03030 fr4,1 002030 barre=5-1
%%setdiag C#m7 x42100 ,0 x42100
%%setdiag C#M7 x43000 fr1,1 x43000 barre=3-1
%%setdiag C#sus2 x03300 fr4 x03400 barre=5-1
%%setdiag C#sus4 000340 fr1,1 000340 barre=6-1
"C#"^C "C#m"^C "C#7"^C "C#m7"^C "C#M7"^C "C#sus2"^C "C#sus4"^C |
5.4. FINGERING CHARTS (ABCM2PS) 95
C♯sus4
C♯ C♯m C♯7 C♯m7 C♯M7 C♯sus2
x 342
fr4
x 43 2
fr1 2 3 x 421 x 43 x 34 34
fr4 fr1 fr4 fr1
Let’s examine how we defined C]. Guitar strings are numbered, right to left, from 1 to 6:
1 is the high e, 6 is the low E,.
• 043020: typesets a dot on string 5 at the 4th fret, on string 4 at the 3rd fret, on string 2
at the 2nd fret. The other strings are not fingered, so 0 means “no dots”;
• x43020 typesets x above the 6th string, 4 above the 5th string, 2 above the 2nd string,
nothing above the other strings;
Just as we defined new tablatures with %%strtab, we can also define chords for other
string instruments with %%setdiag specifying fewer or more strings.
Digit 1 2 3 4 5 6 7 8
Key D C E[ B[ F G A C (galoubet)
Here is an example. The whistle in the key of D is the most commonly used; we’ll specify
the parameters -F flute.fmt -T1. An excerpt from “Atholl Highlanders”:
X: 1
T: The Atholl Highlanders
M: 6/8
L: 1/8
R: jig
K: AMix
|:e2e ecA|ecA Bcd|e2e ecA|Bcd cBA|e2e ecA|ecA Bcd|eae fed|cdB A3:|
6
8
WHISTLE
D
WHISTLE
Chapter 6
Tune Collections
W e learnt in Section 1.2.4 (page 8) that Abc files may contain several tunes. This feature,
along with the ease of use of Abc, spurred the creation of many Abc tune collections
on the Internet.
The ability to create tune collections is one of the strongest points of Abc, and is not
replicated by any other music notation format or application.
X: 2
T: Apples In Winter
M: 6/8
L: 1/8
R: jig
K: Edor
|:G/A/ | BEE dEE | BAG FGE | DA,D FDF | ABc ded |
BEE BAB | def ~g2 e | fdB AGF | GEE E2 ::
%
d | efe edB | e/f/ge fdB | dec dAF | DFA def |
|1 efe edB | def ~g2a | bgb afa | gee e2 :| \
|2 edB def | gba ~g2e | fdB AGF | GEE E2 ||
X: 92
T: Breeches Full of Stitches
97
98 CHAPTER 6. TUNE COLLECTIONS
R: polka
M: 2/4
L: 1/8
K: Amaj
A>B cA | BA ce | A>B cA | BA F2 | \
A>B cA | BA ce | A>B AF | FE E2 :|
e>f ec | BA Bc | e>f ec | BA F2 | \
e>f ec | BA Bc | A>B AF | FE E2 :|
X: 88
T: Wind That Shakes The Barley, The
M: C|
L: 1/8
R: reel
K: Dmaj
A2AB AFED | B2BA BcdB | A2AB AFED | gfed BcdB |
A2AB AFED | B2BA BcdB | A2AB AFED | gfed Bcde |
f2fd g2ge | f2fd Bcde | f2fd g2fg | afed Bcde |
f2fd g2ge | f2fd Bcde | f2ae g2be | afed BcdB |
As you can see, each tune starts with its X: field and ends with one or more blank lines.
Please note the %%writefields line.
A: area. Used to specify an area within the country where the tunes originates. Example:
A:Dublin
G: group. Usually used to specify the instrument on which the tune is played. Example: G:-
whistle, flute
O: origin. Used to specify the country of origin of the tune. Example: O:Ireland
S: source. Used to specify where the Abc tune was found. Example: S:from John Chambers’
site
%%format tunebook
%%abc-include a-f.abc
%%abc-include g-l.abc
%%abc-include m-s.abc
%%abc-include t-z.abc
6.4 Songbooks
The body of a tune may consist of text lines; strange though it may seem, melody lines can
be omitted. This means that we can write songbooks in Abc, as in the following example:
%%textfont Courier 14
%%titlefont Times-Bold 18
%%composerfont Times-Italic 16
%%titleleft 1
%%aligncomposer -1
X: 131
T: Hey Jude
C: The Beatles
K: Fmaj
%%begintext
F C
Hey Jude don't make it bad
C7 F
take a sad song and make it better
Bb F
Remember to let her into your heart
C F
and then you can start to make it better
100 CHAPTER 6. TUNE COLLECTIONS
...
%%endtext
X: 148
T: Rehab
C: Amy Winehouse
K: Cmaj
%%begintext
C
They try to make me go to rehab I say no no no
C
Yes, I've been black but when I come back you'll know, know, know
G F
I ain't got the time and if my daddy thinks I'm fine
C F C
He's tried to make me go to rehab I won't go go go
...
%%endtext
X: 203
T: Imagine
C: John Lennon
K: C
%%begintext
(intro)
C Cmaj7 F
C Cmaj7 F
C Cmaj7 F
Imagine there's no heaven
C Cmaj7 F
It's easy if you try
C Cmaj7 F
No hell below us
C Cmaj7 F
Above us only sky
...
%%endtext
To make sure that chords and lyrics lines are properly aligned, we must set the text font
as Courier (monospace). If we want to make the chords more visible, we can typeset them
using Courier Bold, which preserves the alignment:
%%setfont-1 Courier-Bold 14
%%setfont-2 Courier 14
%%titlefont Times-Bold 18
%%composerfont Times-Italic 16
%%titleleft 1
%%aligncomposer -1
X: 131
T: Hey Jude
C: The Beatles
K: Fmaj
%
6.5. SELECTING TUNES 101
%%begintext
$1 F C
$2Hey Jude don't make it bad
$1 C7 F
$2take a sad song and make it better
$1Bb F
$2Remember to let her into your heart
$1 C F
$2and then you can start to make it better
...
%%endtext
Hey Jude
The Beatles
F C
Hey Jude don't make it bad
C7 F
take a sad song and make it better
Bb F
Remember to let her into your heart
C F
and then you can start to make it better
...
You may wonder why one should write songbooks using Abc instead of plain text or
ad-hoc software; the following section explains why.
%%select 10,12,20-30
The same result can be obtained using the -e command line option of abcm2ps:
In an index range we can omit the last number to specify “to the end”. That is, 20-- means
“from tune #20 to the last tune”.
If we want to select tunes by other fields, we can use a regular expression. This is quite a
complex subject, but it can be simplified: a regular expression is basically a string, containing
special characters, that matches several other strings.
Le’t see a first example. This directive selects tunes that specify “jig” in their R: field:
%%select R:.*jig
More precisely, the above line means: select all tunes that contain an R: field, possibly
followed by one or more spaces (the .* bit), followed by “jig”. The corresponding command
line option is:
%%select K:.*Amin
To select all tunes that have the word “Humours” in the title, we will use:
%%select T:.*Humours
Warning
Global parameters and parameters between tunes will be included in the output of a
%%select directive, probably causing unexpected results!
6.6 Incipits
Another type of tune selection is an incipits file, which is a special tunebook containing only
the first measures of each tune. Incipits files are especially useful for musicians who learn
the music by heart, but need a tune list before or during the performance. “Incipit” is Latin
and it means “(it) begins”.
This feature is provided by a couple of directives working together: %%tune and %%clip.
The first is similar to the %%select directive we examined, and it is followed by a regular
expression to specify the tunes we are interested in. The second is followed by a symbol
selection: in its simplest form, the number of measure bars we want to typeset.
So, if we want to typeset only the first four measures of each tune in a tune collection, at
the top of the file we will write the following lines:
%%tune .*
%%clip 1-5
6.6. INCIPITS 103
In plain English, these mean: select all of the following tunes (the .* bit), and typeset only
the measures included between the first and the fifth measure bars.
To typeset incipits of tunes marked as jigs in their R: field, we will do:
%%tune R:.*jig
%%clip 1-5
104 CHAPTER 6. TUNE COLLECTIONS
Chapter 7
Playing
I n addition to printable output, Abc can also produce playback files; specifically, MIDI
files.
You might be surprised to learn that MIDI files are not audio files, like (say) MP3! In fact,
a midi file is, roughly speaking, an electronic score. It contains instructions that tell MIDI
instruments (or a software MIDI player) what notes to play and how to play them. It is not
as high-level as sheet music; electronic instruments and computers need to be told exactly
what and how to play. In fact, real scores carry a bit of ambiguity. For instance, just how long
a fermata is? MIDI files are not as sophisticated as a human player. Moreover:
Warning
while a score in PDF format will look the same on any computer, this does not hold true
for MIDI files! In fact, the quality of a MIDI file output depends on the sound card of the
computer and the software that is used to listen to it.
Having a MIDI version of our Abc music is convenient, because we get an immediate
feedback of what we wrote. It is especially true for people who can’t easily read music.
To this end, we use the free abc2midi program. Given a tune collection in a file called
file.abc, abc2midi creates a MIDI file for each tune adding the index number of the X:
field to each file name: file1.mid, file2.mid, . . . abc2midi is a command-line program.
abc2midi supports up to 16 voices (“channels”, in MIDI lingo) that can play at the same
time, as defined by the MIDI standard. Each channel can be associated one of the standard
128 MIDI instruments (“programs”), and their loudness (“velocity”) can be controlled inde-
pendently. Don’t ask me about the strange terminology.
abc2midi is just one of the programs of the abcMIDI package:
105
106 CHAPTER 7. PLAYING
/etc/timidity/timidity.cfg
/etc/timidity/freepats.cfg
To replace a missing instrument, edit the second file. Let’s suppose you miss the instru-
ment 41 (Viola) under the bank 0 section. Add this line:
41 Tone_000/040_Violin.pat
which implements the Viola instrument using the same patch used for violin. Not perfect,
but it works.
As a better solution, you may want to install a more complete patch set. Most GNU/Linux
distributions provide two packages called fluid-soundfontgm and fluid-soundfont-gs.
Install the packages and configure TiMidity++ to use them by modifying timidity.cfg:
abc2midi scale1.abc
Warning in line 2 : No M: in header, using default
writing MIDI file scale11.mid
The new file scale11.mid will be written in the same folder as the source. Warning
and/or error messages will be issued when minor and/or serious problems are found.
By default, the MIDI file name is composed using the source file name followed by a
number, corresponding to the number in the K: field of the tune. If you feed abc2midi a tune
collection, a MIDI file will be created for each tune.
To play the MIDI file in the command line:
timidity scale11.mid
X:1
M:2/4
L:1/32
Q:1/4=240
K:Amaj
%%MIDI program 1 80
|:ac'ac'ac'ac'ac'ac'ac'ac'|ac'ac'ac'ac'ac'ac'ac'ac'|[L:1/2]z:|
then I ran abc2midi and obtained Ring1.mid. To convert the MIDI file to MP3, I used the
following commands (boldface):
-------------------------------------------------------------------------------
kbps LR MS % long switch short %
128.0 53.9 46.1 98.5 1.0 0.5
Writing LAME Tag...done
ReplayGain: -2.4dB
˜$ _
Note
In the following sections, I will include some sound samples. In theory, MIDI files cre-
ated by abc2midi should be playable on all computers, but unless you have the same
instrument patches that I use (or compatible ones) there is a chance that you can’t lis-
ten to them. Therefore, all MIDI files were converted to MP3 files with Lame, as shown
above.
!ppp! !pp! !p! !mp! !mf! !f! !ff! !fff! !breath! !arpeggio!
!crescendo(! !crescendo)! !<(! !<)! !diminuendo(! !diminuendo)! !>(! !>)!
X: 1
T: MIDI directives as meta-comments
L: 1/4
K: C
%%MIDI program 1
CDEF|
%%MIDI program 109
GABc|
7.1. MIDI CONVERSION 109
X: 1
T: MIDI directives as inline I: fields
L: 1/4
K: C
[I:MIDI = program 1] CDEF|[I:MIDI = program 109] GABc|
X: 1
T: Ave Verum Corpus
C: W. A. Mozart
M: 4/4
L: 1/4
Q: "Adagio"
%%score [(S A) (T B)] (MD1 MD2) | (MS1 MS2)
%%MIDI program 1 53 % Choir Oohs
%%MIDI program 2 53
110 CHAPTER 7. PLAYING
%%MIDI program 3 53
%%MIDI program 4 53
%%MIDI program 5 19 % Church Organ
%%MIDI program 6 19
%%MIDI program 7 19
%%MIDI program 8 19
V: S clef=treble name="Soprano" sname="S"
V: A clef=treble name="Alto" sname="A"
V: T clef=bass name="Tenor" sname="T"
V: B clef=bass name="Bass" sname="B"
V: MD1 clef=treble name="Organ"
V: MD2 clef=treble
V: MS1 clef=bass
V: MS2 clef=bass
K: D
%
% ... body of transcription ...
The eight voices S A T B MD1 MD2 MS1 MS2 are automatically assigned by abc2midi
the numbers 1 to 8. Then the %%MIDI program directives follow that associate each voice
with an appropriate MIDI instrument, MIDI 54 (“Choir Oohs”) or 20 (“Church Organ”).
Another way to assign an instrument to a voice is the following:
The numbers that identify each instrument are listed in Appendix A.8 (page 183). Note
that the numbers in the list range from 1 to 128, whereas abc2midi numbers them 0 to 127. If
no MIDI program is specified, voices will be assigned by default the General MIDI instrument
1.
The following tune uses shift to let abc2svg transpose its output by two semitones, and
adds %%MIDI transpose 2 to transpose the resulting MIDI file:
X: 1
L: 1/4
M: 4/4
K: C shift=CD
%%MIDI transpose 2
CDEF | GABc | CDEF | GABc ||
X: 1
M: 4/4
L: 1/4
K:C
%%MIDI program 21
|: CDEF | GABc [I:MIDI program 73] :|
Unfortunately, there is no way to change instruments when repeats occur three or more
times.
Additional chords can be defined with %%MIDI chordname, explained in Section 7.1.11
(page 113).
Accompaniment chords are rendered by abc2midi as a sequence of fbcz for each mea-
sure. f stands for the fundamental or root of the chord, b for the fundamental and the
chord played together, c for the chord itself, and z for a rest. A fbcz sequence is designed
to match a time signature: for example, in 4/4 time the accompaniment is fzczfzcz: funda-
mental, rest, chord, rest, fundamental, rest, chord, rest.
abc2midi associates specific fbcz sequences to the more common time signatures: fzczcz
for 3/4 time, fzcfzc for 6/8, fzcfzcfzc for 9/8, and fzcfzcfzcfzc for 12/8.
In practice, the following piece:
X: 1
M: 4/4
L: 1/4
K: C
%
"C"CDEF|"G"GABc|"C"C2"G"E2|"C"Czz2|
112 CHAPTER 7. PLAYING
Beware: the fbcz sequence does not correspond to the beats in a measure, and the length
of the elements does not depend on the value of the L: field. Sequences are adapted to match
one measure; thus, fcz, f2c2z2 and f4c4z4 have equivalent meaning.
If you don’t hear accompaniment chords, your tune might have a time signature for which
a predefined fcz sequence is missing: for example, 3/8, 5/4 or 7/8. The sequence can be easily
added, though. For example, a sequence for 7/8 is fzbczcz.
The fcz sequence can be modified when desired with the %%MIDI gchord directive. Here
is the above tune with a simpler accompaniment:
X: 1
M: 4/4
L: 1/4
K: C
%%MIDI gchord c4c4
%
"C"CDEF|"G"GABc|"C"C2"G"E2|"C"Czz2|
Here we changed the sequence to c4c4 to obtain two chords in every measure.
To modify the instrument associated with the chord, the %%MIDI chordprog directive is
used; for the fundamental, %%MIDI bassprog. To specify the volume, use %%MIDI chordvol
for the chord and %%MIDI bassvol for the fundamental (from 0 to 127). Finally, to disable
temporarily accompaniment chords use %%MIDI gchordoff, and %%MIDI gchordon to turn
chords back on.
Note that chords will continue to be played even when the melody stops. The following
tune has no melody, but only accompaniment chords:
X: 1
T: La Folia
M: 3/4
L: 1/4
Q: 1/4=80
K: Dm
%%MIDI gchord c2c2zc
%%MIDI chordprog 24 % guitar
"Dm"z3|"A"z3|"Dm"z3|"C"z3|"F"z3|"C"z3|"Dm"z3|\
%%MIDI gchord c3
"A"z3|
%%MIDI gchord czc
"Dm"z3|"A"z3|"Dm"z3|"C"z3|"F"z3|"C"z3|"A"z3|\
%%MIDI gchord c3
"Dm"z3|]
Let’s now look at a piece that has 4/4 time but a very different rhythm: “The Girl from
Ipanema”, a famous Brazilian song written by Antônio Carlos Jobim:
X: 1
T: Gar^ota De Ipanema
T: (The Girl From Ipanema)
C: Ant^onio Carlos Jobim
M: 4/4
L: 1/8
K: F
P:A
|:"Fmaj7" !p!G2 GE E2 ED|G2 GE EE DG-|"G7"G2 GE EE DG-|
G2 GE EE DF-|"Gm7"F2 FD DD CE-|"Gb7"E2 EC CC B,C-|
[1"Fmaj7"C8|"Gb7"z8 :|[2"Fmaj7"C8 |z8||
P:B
"Gb7"F8-|(3F2_G2F2 (3:2:3_E2F2E2|"B7"_D3 _E-E4-|_E6 z ^G-|
"F#m7"^G8-|(3^G2A2G2 (3^F2G2F2|"D7"E3 ^F-F4-|^F6 z A-|
"Gm7"A8-|(3A2B2A2 (3:2:3G2A2G2|"Eb7"F3 G-G4-|G4 (3z2A2B2|
"Am7"(3c2C2D2 (3E2F2G2|"D7"^G3 A3 z2|"Gm7" (3B2B,2C2
(3D2E2F2|"C7" ^F3 G3 z2 ||
P:C
"Fmaj7"G3 E EE DG-|G2 GE- EE DG-|"G7"G2 GE EE DG-|G2 GE EE DA-|
"Gm7"A2 AF FF Dc-|"Gb7" c2 cE (3E2E2D2|"Fmaj7" E8-|E2 z6|
P:D
z8|]
When converted to MIDI, it sounds pathetic. . . a bossa nova has a completely different
rhythm. We need to specify another fcz sequence that corresponds to a bossa nova. Let’s
insert these lines after the P:A field:
%%MIDI program 67 % Baritone Sax
%%MIDI gchord fzcffczc % bossa nova (approximate)
%%MIDI chordvol 30
%%MIDI bassvol 30
%%MIDI chordprog 25 % Steel String Guitar
%%MIDI bassprog 25
and this one immediately following the P:D field:
%%MIDI gchord c2
Reconverting to MIDI we now have a bossa nova worth its salt: garota.mp3.
X:1
T:The Swallowtail Jig
R:Jig
M:6/8
L:1/8
Q:180
K:D
%%MIDI program 1 22
E/F/|
% flattish
%%MIDI beat 105 95 80 1
"Em"GEE BEE |GEG BAG |"D"FDD ADD |dcd "Bm"AGF|
"Em"GEE BEE |GEG B2c |"D"dcd "Bm"AGF|"Em"GEE E2 E/F/|
% more swing
%%MIDI beat 105 90 60 3
"Em"GEE BEE |GEG BAG |"D"FDD ADD |dcd "Bm"AGF|
"Em"GEE BEE |GEG B2c |"D"dcd "Bm"AGF|"Em"GEE E2 B|
%%MIDI beat 105 95 80 1
"Em"Bcd e2 f|e2 f edB|Bcd e2 f |edB "D"d2 c|
"Em"Bcd e2 f|e2 f edB|"D"dcd "Bm"AGF|"Em"GEE E2B|
%%MIDI beat 105 90 60 3
"Em"Bcd e2 f|e2 f edB|Bcd e2 f |edB "D"d2 c|
"Em"Bcd e2 f|e2 f edB|"D"dcd "Bm"AGF|"Em"GEE E2z|]
that converts into this MIDI file: swallowtail.mp3. Note how the different parts have less or
more swing.
To remove temporarily the emphasis programmed with %%MIDI beat, use the %%MIDI
nobeataccents directive. To resume it, use %%MIDI beataccents.
7.1.13 Arpeggios
In addition to fcz sequences, we can also specify ghijz sequences that allow us to play the
individual notes comprising the accompaniment chord. This way, we can play broken chords
7.1. MIDI CONVERSION 115
or arpeggios.
The new codes ghijGHIJ reference the individual notes, starting from the lowest note of
the chord. For example, for the C major chord, g refers to C, h refers to E and i refers to
G. Uppercase letters refer to the same notes one octave lower, z to a rest.
The following example plays the C major chord as an arpeggio of CEGE:
Furthermore, we can use fcz and ghij sequences together, like fcbghijGHIJz.
Another way to play chords as arpeggios is the %%MIDI chordattack directive. When
followed by a number hni greater than 0, it delays each note by hni MIDI time units (a quarter
note is 480 MIDI units). Using %%MIDI randomchordattack hni varies the delay of each note
randomly between 0 and hni.
X: 1
T: Broken rhythm
M: 2/4
L: 1/8
K: C
C>D E>F | G>A B>c | c>d e>f | g>a b>c' |
c'>b a>g | f>e d>c | c>B A>G | F>E D>C |
Writing a piece this way can be tedious. There is a shortcut, though: adding the R:hornpipe
field will instruct abc2midi to set the broken rhythm automatically. This effect will only work
if the note length is set to 1/8.
Let’s rewrite the scale:
X: 1
T: Broken rhythm
R: hornpipe
M: 2/4
L: 1/8
K: C
CD EF | GA Bc | cd ef | ga bc' |
c'b ag | fe dc | cB AG | FE DC |
Note
Note that abc2midi plays the notes in a different way than they are notated. For in-
stance, A>B should be played as A3/2 B/2 but is actually played as A4/3 B2/3. That
is, instead of a ratio 3:1 abc2midi employs a ratio 2:1. The rationale (pun unintended)
is that 2:1 is the way hornpipes are approximately played.
This behaviour can be reversed to normal with the %%MIDI ratio 3 1.
116 CHAPTER 7. PLAYING
X: 1
M: 4/4
L: 1/4
K: C
% sequence instrument volume
%%MIDI drum dddd 36 46 36 46 80 100 80 100
% bass drum 1, open hi-hat
%%MIDI drumon
CDEF|GABc| %%MIDI drumoff
cdef| %%MIDI drumon
gabc'|
X: 1
M: 4/4
T: Riff
%%MIDI program 1 25 % Steel String Guitar
Q: 1/4=160
K: C
%%MIDI drum dzddd2dz 35 39 39 35 39 127 80 80 127 80
% Bass Drum 1 + Electric Snare
%%MIDI gchord cccccccc
%%MIDI drumon
"C"CC EE GG AA|_BB AA GG EE|
CC EE GG AA|_BB AA GG EE|
"F"FF AA cc dd|"F7"_ee dd cc AA|
"C"CC EE GG AA|_BB AA GG EE|
%%MIDI gchordoff % no chords
"G"GG BB dd Bd|"F7"FF AA cc Ac|
%%MIDI gchordon % turn chords back on
"C"CC EE GG AA|_BB AA GG EE|
%%MIDI gchord c8
%%MIDI program 1 60 % Brass Section
%%MIDI drumoff
!fermata!"C"[C8E8G8c8]|
7.1. MIDI CONVERSION 117
X: 1
L: 1/4
Q: 1/4 = 120
V: 1 name="Piano" % normal voice
V: 2 clef=perc name="Low Tom" stafflines=1
%%MIDI channel 10
%%MIDI drummap ^A 45
V: 3 clef=perc name="Open Hi Hat" stafflines=1
%%MIDI channel 10
%%MIDI drummap ^A 46
V: 4 clef=perc name="Open Triangle" stafflines=1
%%MIDI channel 10
%%MIDI drummap ^A 81
K: C
%
[V:1] CDEF |GABc | % Piano
[V:2] ^Az^Az |^Az^Az | % Low Tom
[V:3] z^Az^A |z^Az^A | % Open Hi Hat
[V:4] ^A/^A//^A//^A/^A/^A/^A/^A/^A/|\
^A/^A//^A//^A/^A/^A/^A/^A/^A/| % Open Triangle
= 120
Piano
Low Tom
Open Hi Hat
Open Triangle
118 CHAPTER 7. PLAYING
Note that the %%MIDI channel 10 directive must be written after the V: field that starts
a new voice.
7.1.17 Portamento
A glide effect can be added using the %%MIDI portamento [bass] [chord] hni directive,
where hni is a number between 0 (no effect) and 63 (maximum effect).
The following is the riff from Impressioni di Settembre, a great song by Italian progres-
sive rock band PFM. The first repeat has no glide effect, while the second repeat mimics the
original Moog glide (impressioni.mp3):
X: 1
T: Impressioni di Settembre (riff)
C: PFM, 1972
M: 4/4
L: 1/8
Q: 1/4=140
K: Dm octave=-1
%
%%MIDI program 1 81
%%MIDI chordprog 80
%%MIDI gchord b4
%%MIDI chordvol 50
%
%%MIDI portamento 0
|:"Dm"D4-DE F2|G A2 c d2 f e-|"C"e d c2 g4-|gfed- dcg2|
"G"f e2 d2 c =B2-|=B A G3 BG A-|"Dm"A d- d6-|d8
%%MIDI portamento 60
:|
D8-|D8|]
7.1.18 Drone
Bagpipe, medieval and other kinds of music are often accompanied by one or more drone
notes. abc2midi supports drones using these directives:
The parameters of the %%MIDI drone directive are hinstrumenti, that specifies the MIDI
instrument for the drone; hpitch1i and hpitch2i are the MIDI pitches of the drone notes; hvel1i
and hvel2i are the MIDI “velocities”, that is the volume, of the drone notes.
The pitches are not specified as Abc notes, but as standard MIDI pitches. In short, these
are numeric codes (1–127) that correspond to notes, as shown in Table 7.1. To obtain notes
higher or lower than the octave shown in the table, simply add or subtract 12 to the note.
7.1. MIDI CONVERSION 119
The default values of %%MIDI drone are 71 (bassoon), 45 (A,,), 33 (A,,,), 80 and 80.
Let’s put it into practice. This is Amazing Grace, written in G major with bagpipe drone
accompaniment:
X:1
T:Amazing Grace
M:3/4
L:1/8
Q:40
K:G
%%MIDI gracedivider 16
%%MIDI program 109
%%MIDI drone 109 43 31 70 70
%%MIDI droneon
|z3 z2D|/AG2 B/G/ B2 A|/AG2 FE D2 D|
/AG2 /CB/G/ /CB2 A/B/|d3-d2 B|
d2 B/G/ B2 A|G2 E /ED2 D|
/AG2 B/G/ B2 A|/AG3-G2 |]
%%MIDI droneoff
• %%MIDI C
• %%MIDI nobarlines
• %%MIDI barlines
• %%MIDI fermatafixed
• %%MIDI fermataproportional
• %%MIDI ratio
• %%MIDI chordname
• %%MIDI deltaloudness
Obviously, these parameters may be overridden by %%MIDI lines within each tune.
120 CHAPTER 7. PLAYING
• nested tuples;
• “grace chords” (Section 2.1.10, page 22) are not played correctly;
• if a system change occurs in the middle of a piece, abc2midi gets lost and generates
an incorrect MIDI file;
Because of these small incompatibilities, we have the problem of writing music that can
be converted by both abcm2ps and abc2midi. In theory, we should write two source files,
one for abcm2ps and another for abc2midi: this is obviously unacceptable. An alternative is
to use the abcpp preprocessor, which will be explained in Section 10.5 (page 153).
Chapter 8
Advanced Customisation
S ometimes, it could be desirable to use musical features that are not directly supported
in Abc; or to modify the output in specific ways. This is possible, since abcm2ps and
abc2svg provide directives that modify or extend their functionality. For example, users can
redefine note shapes, add colours and decorations, and implement new features. In general,
users can add or modify PostScript and/or SVG routines for output customisation.
abcm2ps has full PostScript customisation, but it also understands some SVG. Simmetri-
cally, abc2svg has full SVG customisation, but it also understands some PostScript. It must
be stressed that these extensions are not part of the Abc notation, and are specific to abcm2ps
and abc2svg only!
• %%*font is one of the several font changing directives like %%titlefont, %%textfont,
etc.;
• hfont namei can also be an URL, which can refer to a locally installed font or to a font
available on the web. For example:
%%textfont url(http://example.org/fonts/coolfont.woff)
%%textfont url(/https/www.scribd.com/usr/share/fonts/coolfont.otf)
• [style/weight] can be one of the strings italic, bold, or normal. These strings can be
separated from the font name by a hyphen or a space. The string normal removes both
style and weight;
• [size] is the font size in pixels, or * that means “keep the previous font size”.
121
122 CHAPTER 8. ADVANCED CUSTOMISATION
– box, which draws a box around the text, or nobox to stop drawing boxes around
text;
– class=hclass namei sets the text using a CSS class defined with %%beginml . . .
%%endml;
– padding=hinti sets the text padding in pixels;
– wadj=hadjustmenti sets the text width adjustment; the parameter can be none,
spacing, or glyph. This parameter only works when using abc2svg in the com-
mand line.
%%titleleft 1
%%titlefont * 32 class=bluetext
X: 1
T: Framed blue title
K: C
%%textfont serif 18
%%text This is simple text
%%textfont serif bold 24 nobox class=redtext
%%text This is unboxed, bold red text
%%textfont * normal 22 box padding=25
%%text Framed and padded text
%%textfont url(/https/www.scribd.com/usr/share/fonts/MuseJazzText.otf) nobox 20
%%text MuseJazz is a nice font
%%ps /dlw
%%ps {0.3 setlinewidth} bind def % default: 0.7
so the score looks better at high values of %%pagescale. This extension, however, will not
work in abc2svg.
When writing several lines of PostScript code, using the sequence %%beginps. . . %%endps
is recommended. In addition to PostScript, commands in SVG can also be specified using
%%beginsvg. . . %%endsvg. Whenever possible, you should write both SVG and PostScript
commands to make the source compatible with both abc2svg and abcm2ps.
• hnamei is the name of the new symbol, without the exclamation marks;
• htypei is an integer number that specifies the symbol type. Values from 0 to 2 indicate
a symbol near the note and within the staff; from 3 to 5, near the note but outside the
staff; 6 and 7, expressions linked to the staff (like dynamic marks); 8, long decorations;
10, colour. To give an idea of symbol positioning, here is a listing:
• hfunctioni is the name of the PostScript/SVG routine that draws the symbol;
Let’s have a look at an example taken from the file deco.abc supplied with abcm2ps. We
will add a few new symbols for dynamics using the predefined pf routine:
New symbols
fp (f) (ff)
%%deco lines implement three new symbols: !fp!, !(f)!, and !(ff)!.
Let’s see another example. The following source adds three new symbols: one note-linked
and two staff-linked, one above the staff and one below. The first symbol !tu! is a triangle-
shaped staccato symbol. !tu! uses the new routine newdot. The other symbols are !rtoe!
and !ltoe! which use the routine toe and add a symbol similar to a ^ above and below the
staff.
%%beginsvg
<defs>
% triangle
<path id="newdot" class="fill"
d="m -2 2 l 2 5 l 2 -5 l -4 0" />
% upside-down V
<path id="toe" class="stroke"
d="m -5 -2 l 5 -5 l 5 5" />
</defs>
%%endsvg
X: 1
K: C
!tu!C!tu!D!tu!E!tu!F GABc|!ltoe!c'!rtoe!bag .f.e.d.c|!ltoe!C4 z4|]
8.3. NOTE MAPPING 125
• hmapped notei is the Abc name of a note, complete with accidentals if needed. The note
name can also be *, meaning “all notes”;
• [heads=]hglyph namesi defines a set of glyph names. Glyphs are defined as PostScript
or SVG paths;
• [print=]hnotei indicates that hmapped notei will be typeset as hnotei (that is, on a dif-
ferent line or space);
It sounds complicated, but some examples will hopefully clarify how %%map works. Let’s
define two maps; one that typeset notes heads C D E in green, and another that typeset all
note heads in red:
X:1
M:C
L:1/4
K:C
% first map: only C D E note heads typeset in green
%%map color_green C color=#00ff00
%%map color_green D color=#00ff00
%%map color_green E color=#00ff00
% second map: all note heads printed in red
%%map color_red * color=#ff0000
%
[V:1][I:voicemap color_green] "^V:1 is mapped to color_green"CDEF | GABc |
[V:2][I:voicemap color_red] "^V:2 is mapped to color_red"CDEF | GABc |
% mapping continues
[V:1] cBAG | FEDC |
[V:2] cBAG | FEDC |
V:1 is mapped to color_green
V:2 is mapped to color_red
126 CHAPTER 8. ADVANCED CUSTOMISATION
In the next example we define a new cross-shaped note head, and we map some notes
to new positions on the staff. This is a simple implementation of percussion notes, that are
notated using peculiar note heads and positions.
%%beginsvg
<defs>
<path id="x_head"
d="m-3 -3l6 6m0 -6l-6 6"
class="stroke" style="stroke-width:1.2"/>
</defs>
%%endsvg
X:1
M:4/4
L:1/4
%%score (1 2)
K:C clef=perc
%
% Note ^A, (hi-hat) will have its head replaced by
% the 'x_head' glyph, and it will be typeset as 'g'
%%map drum ^A, print=g heads=x_head
% Note D, (snare) will be typeset as 'c'
%%map drum D, print=c
% Note C, (bass drum) will be typeset as 'F'
%%map drum C, print=F
%
[V:1] [I:voicemap drum][I:MIDI channel 10]
^A,/^A,/[^A,D,]/^A,/ ^A,/^A,/[^A,D,]/^A,/ |
[V:2] [I:voicemap drum][I:MIDI channel 10]
C,xC,x |
As you can see, notes ^A, D, C, are typeset as g c F; besides, ^A, has a cross-shaped
note head. The new note positions are standard in percussion notation; further, the I:MIDI
inline fields map the notes to percussion instruments (Section 7.1.16, page 117).
Summing up, the example above is displayed correctly and it also plays correctly when it
is converted to MIDI.
We have renamed the symbol definitions that are defined in one of abcm2ps source files
(deco.c).
Warning
If we rename a symbol, abc2midi can’t recognise it any more. Usually this is not a
problem, since many symbols only produce printed output. However, other symbols
like !arpeggio! also produce MIDI output. Hence, in such cases we should use U: to
redefine the symbol.
% itachords.fmt
%
% Displays guitar chords using Italian note names.
% Written by Jean Fran\c cois Moine
% License: GNU GPL 2.
beginps
/gcshow{
dup 0 get
dup dup 65 ge exch 71 le and{
65 sub[(La)(Si)(Do)(Re)(Mi)(Fa)(Sol)]exch get show
dup length 1 sub 1 exch getinterval
} if show}!
/agcshow{
dup 0 get 0 get
dup dup 65 ge exch 71 le and{
65 sub[(La)(Si)(Do)(Re)(Mi)(Fa)(Sol)]exch get show
dup length 1 sub 1 exch getinterval
} if arrayshow}!
endps
If we add -F itachords to the command line, the usual scale will be typeset with ac-
companiment chords in Italian:
X:1
L:1/4
K:Ebmaj
M:4/4
"Eb"EFGA|"Bb"Bcde|"Cm"CDEF|"Gm"GABc|
Mi Si Dom Solm
4
4
%%chordnames Do,Ré,Mi,Fa,Sol,La,Si
Note
A few notes before we begin:
1. the following procedure will not work on the Android platform, which lacks
Ghostscript support;
2. Ghostscript does not use system fonts, i.e. the ones that the operating system
provides to all other applications. You will have to add new fonts following the
procedure outlined in this section;
3. the procedure was tested on GNU/Linux Mint 18.3 (Ghostscript 9.26), Windows
7 and Windows 10 (Ghostscript 9.56.1 installed in C:\gs\gs9.55). You will need
root/administrator privileges.
An excellent site boasting a wide collection of free and high-quality PostScript and True-
Type fonts is http://moorstation.org/typoasis/typoasis1.htm. Under the “Designers” section,
you’ll find several pages devoted to font designers; each page offers many fonts for download.
Select Dieter Steffmann’s page.
Let’s see how to add a new font called Holla Script, downloaded as Holla.zip. Obviously,
the procedure will be very similar with other fonts.
Unzip the archive and copy HollaScript.pfb (the TrueType version, HollaScript.ttf,
will also work) to one of the directories where Ghostscript searches for fonts. Supposing that
8.6. ADDING TEXT FONTS (ABCM2PS) 129
you installed Ghostscript (let’s assume version 9.56.1) and its fonts in default locations, such
directory is:
• Windows: C:\gs\gs9.55\lib
• GNU/Linux: /usr/share/fonts/
gs -h
GPL Ghostscript 9.26 (2018-11-20)
...
Search path:
/usr/share/ghostscript/9.26/Resource/Init :
/usr/share/ghostscript/9.26/lib :
/usr/share/ghostscript/9.26/Resource/Font :
/usr/share/ghostscript/fonts : /var/lib/ghostscript/fonts :
/usr/share/cups/fonts : /usr/share/ghostscript/fonts :
/usr/local/lib/ghostscript/fonts : /usr/share/fonts
...
• Windows: C:\gs\gs9.55\lib\Fontmap
• GNU/Linux: /var/lib/ghostscript/fonts/Fontmap
Note that this file does not have a .txt extension. If the file is missing, create a new one.
Move to the bottom of the file and add this line:
/HollaScript (HollaScript.pfb) ;
which defines a new font called HollaScript. If you wish, you can also define an alias, i.e.
an alternate name for the same font adding a new line:
/Jazz /HollaScript ;
We are now ready to use the HollaScript font in Abc files. First of all, we will have to
declare it using the %%font directive followed by the font name. Look at this:
%%font HollaScript
%%titlefont HollaScript 24
%%textfont HollaScript 18
%%composerfont Jazz 16 % alias
%%vocalfont Jazz 16
%%gchordfont Jazz 18
X: 1
T: Test: HollaScript font (Jazz)
L: 1/4
K: C
130 CHAPTER 8. ADVANCED CUSTOMISATION
%
"C"CDEF|"G"GA"G7"Bc|"C"cBAG|"G"FEDC|"C"C4|]
w: Do Re Mi Fa... |||||
%%text ABCDEFGHIJKLMNOPQRSTUVWXYZ
%%text abcdefghijklmnopqrstuvwxyz 1234567890
C G G7 C G C
4
4
Do Re Mi Fa...
ABCDEFGHIJKLMNOPQRSTUVWXYZ
abcdefghijklmnopqrstuvwxyz 1234567890
Bear in mind that some fonts available on the Internet are not complete (they may only
have capital letters, or miss some characters); not all are free; and not all are of good quality.
• Gadelica, http://www.leabhair.ie/Gadelica.zip
• QT Arabian, https://www.ctan.org/tex-archive/fonts/qualitype/
Install the fonts as usual (GNU/Linux: just copy them to /usr/share/fonts), then de-
clare their names in in %%font lines. Beware: you must specify the real name, as it appears in
the font manager of your operating system, not just the file name. If the font name is made
of more than one word, it must be enclosed in quotes:
%%font Gadelica
%%font QTArabian
%%font "Urbanist Light Italic"
%%textfont Gadelica 24
%%text This is Gadelica
%%textfont QTArabian 24
%%text This is QTArabian
%%textfont Urbanist Light Italic 24
8.8. USING SMUFL FONTS 131
This is Gadelica
This is QTArabian
• Bravura, https://github.com/steinbergmedia/bravura
• Petaluma, https://github.com/steinbergmedia/petaluma; a Jazz style font
• Sebastian, https://github.com/fkretlow/sebastian
• Leland, https://github.com/MuseScoreFonts/Leland
Some of these fonts are available in two versions: one is used to typeset music glyphs in
the score, the other is used to typeset music glyphs in text. For example, we have Bravura
and BravuraText, Sebastian and SebastianText. These fonts are released in OpenType format;
file extension is .otf.
Let’s try Bravura; the procedure is the same for other fonts. Download Bravura.otf
and install it in one of Ghostscript search directories, as explained in Section 8.6; adding the
font in the Fontmap file is not required. The %%musicfont directive instructs abcm2ps and
abc2svg to use the new glyphs provided by Bravura:
%%pagescale 1.2
%%musicfont Bravura
X: 1
T: Using the Bravura music font
M: 4/4
L: 1/4
K: C
132 CHAPTER 8. ADVANCED CUSTOMISATION
44
Some decorations
D.S.
As you can see, note heads and decorations are different than the default glyphs.
Using abcm2ps, not all symbols are replaced by the SMuFL font; for example, dynamics
decorations like !p! are normally implemented as strings. To redefine these missing glyphs,
we can use the smufl.fmt format file, available at the Abc 2 home page. To use smufl.fmt,
we declare a SMuFL-compliant font before loading it:
%%musicfont Bravura
%%format smufl
then all new glyphs will be available using the specified SMuFL font.
Chapter 9
L et’s suppose we want to exchange our music written in Abc with a friend who uses a
commercial music program. Most probably, our friend will be unable to load our Abc
sources into their program. This is a typical problem that plagues people using different pro-
grams running on different operating systems.
Besides, occasionally we may need to use a different music typesetter. Although abcm-
2ps and abc2svg produce excellent scores most of the time, in some cases other programs
produce better-looking results. The same holds for MIDI output.
In these cases, MusicXML is a possible solution. MusicXML is a file format that was de-
signed for the exchange of sheet music files between music applications. Most major pro-
grams support it, including market leaders Sibelius® and Finale® , and popular freeware Finale
NotePad. MuseScore and LilyPond, the most powerful scorewriters in the open source world,
are a precious alternative.
abc2xml.py and xml2abc.py are the gateway between Abc and MusicXML-enabled pro-
grams. The abc2xml.py translator supports nearly all elements of the Abc language, imple-
ments some directives, and provides some useful extensions. Similarly, xml2abc.py imple-
ments the parts of MusicXML that are also included in Abc; the former, in fact, supports
more features than Abc. While you should not expect to obtain a perfect conversion all the
time, the Abc/MusicXML translators work impressively well: manual customisation of the
resulting files is usually trivial.
133
134 CHAPTER 9. ABC AND MUSICXML
You can now save the source using the save button, and use the Options button to exper-
iment with xml2abc-js’ translation options.
• -m hn1i hn2i: given a tune collection (e.g. tunes.abc), skip hn1i tunes and output at
most hn2i tunes to files tunes01.xml. . . tuneshn2i.xml. By default, abc2xml.py reads
the first tune only. Example:
• -p hpage formati: specify the page geometry. hpage formati is a set of 7 decimal numbers
that specify the scale, page height, page width, left margin, right margin, top margin,
and bottom margin in mm The numbers are separated by commas, without spaces.
Default values are 0.75,297,210,18,18,10,10 (European A4 paper size).
• -b: break lines at end of line. Equivalent to the I:linebreak <EOL> field.
Similarly, running xml2abc.py with -h lists its options. The most useful are:
• -n hNCi: set the maximum number of characters per line to hNCi (default: 100).
• -p hpage formati: set the page geometry. hpage formati works as with abc2xml.py.
• %%MIDI program and %%MIDI channel (with some limitations), %%MIDI transpose,
%%MIDI drummap.
These commands suffice to produce full-featured MusicXML files that can successfully
imported in other applications.
136 CHAPTER 9. ABC AND MUSICXML
As you can see, we typeset the score in the command line using MuseScore instead of
abcm2ps. Alternatively, we can run MuseScore interactively and load the MusicXML source
for manual customisation and PDF export.
MuseScore can also convert to other formats: png, svg, wav, flac, ogg, mp3, mid, xml,
and mxl.
A simpler way to convert MusicXML to PDF is the Verovio web converter https://www.
verovio.org/musicxml.html. Load a MusicXML file, press the “Convert to MEI” button, then
save the PDF from the “PDF” button in the left-hand menu.
138 CHAPTER 9. ABC AND MUSICXML
Note
Remember, Abc is just a notation and is not tied to a specific application. We can choose
between five different programs to typeset our music!
9.7.1 Tremolo
Tremolo indications !/-! !//-! !///-! are similar to !trem1! !trem2! !trem3! !trem4!
that are supported by abcm2ps and abc2svg, but are placed differently:
X: 1
L: 1/4
M: none
K: C
%
!/-!CD !//-!EF !///-!GA !/!C !//!D !///!E|
That is, in front of note pairs instead of between notes pairs. Using MuseScore or Verovio
to convert the corresponding MusicXML file, we obtain the following score:
Unfortunately, abc2midi does not support any of the tremolo decorations. MIDI output,
however, can be made by MuseScore.
• [note shape] is a string that specifies the shape of the note head: slash, triangle,
diamond, square, cross, x, circle-x, normal, cluster, inverted triangle, arrow
down, arrow up, slashed, back slashed, do, re, mi, fa, so, la, ti, and none.
Percussion maps can be turned off specifying any clef different than perc, or with the
new option map=off.
The following example, kindly provided by Willem Vree, can be typeset and also played
correctly in MuseScore:
X: 1
L: 1/8
V: 1 clef=treble
V: 2 clef=perc
K: C
% abc2xml.py percussion maps
%%percmap C D 52 triangle
%%percmap A * 60 x
%%percmap c * 47 diamond
%
V:1 % treble clef
cA[CA]A AA[CA]A | cA[CA]A AA[CA]A |
V:2 % percussion
%%MIDI channel 10
cA[CA]A AA[CA]A | cA[CA]A AA[CA]A |
4
4
44
Let’s now examine a more complete example that implements all percussion instruments
described in the “Percussion notation” Wikipedia page. To play the file correctly with abc-
2midi, we also specify the MIDI channel 10 (percussion instruments):
%%percmap D pedal-hi-hat x
%%percmap E bass-drum-1
%%percmap F acou-ba-dr % acoustic bass drum (abbreviation)
%%percmap G low-floor-tom
%%percmap A high-floor-tom
%%percmap B low-tom
%%percmap ^B tambourine triangle
%%percmap c acou-snare % acoustic snare
%%percmap _c elec-snare % electric snare
%%percmap ^c low-wo-blo triangle % low wood block
%%percmap =c side-stick
%%percmap d low-mi-tom % low-mid tom
%%percmap ^d hi-wo-blo triangle % high wood block
%%percmap e hi-mi-tom % high-mid tom
%%percmap ^e cowbell triangle
%%percmap f high-tom
140 CHAPTER 9. ABC AND MUSICXML
%%percmap ^f ride-cymbal-1 x
%%percmap g closed-hi-hat x
%%percmap ^g open-hi-hat diamond
%%percmap a crash-cym-1 x
%%percmap ^a open-tri triangle
X: 1
M: none
T: Sibelius Drum Legend
T: https://en.wikipedia.org/wiki/Percussion_notation
L: 1/4
V: 1 clef=perc
K: C
%
[V:1 clef=perc]
%%MIDI channel 10 % activate abc2midi map
%
D E F G A |
w: pedal bass acoustic lowfloor highfloor
w: hihat drum~1 bass~drum tomtom tomtom
%
B ^B c _c ^c |
w: low tambourine acoustic electric low
w: tomtom * snare snare wood~block
%
=c d ^d e ^e |
w: side lowmid high highmid cowbell
w: stick tomtom wood~block tomtom *
%
f ^f g ^g a ^a |
w: high ride closed open crash open
w: tomtom cymbal~1 hihat hihat cymbal~1 triangle
pedal bass acoustic low-floor high-floor low tambourine acoustic electric low
hi-hat drum 1 bass drum tom-tom tom-tom tom-tom snare snare wood block
3
side low-mid high high-mid cowbell high ride closed open crash open
stick tom-tom wood block tom-tom tom-tom cymbal 1 hi-hat hi-hat cymbal 1 triangle
The above examples can only be typeset by MuseScore. Fortunately, we learnt in Sec-
tion 8.3 (page 125) how to implement percussion notes for abcm2ps and abc2svg using note
mapping. Let’s take our first example and add note mapping, to make it compatible with all
programs:
9.7. ABC2XML.PY EXTENSIONS 141
%%beginsvg
<defs>
% x-shaped head
<path id="x_head"
d="m -3 -3 l 6 6 m 0 -6 l -6 6"
class="stroke" style="stroke-width:1.2"/>
% triangle head
<path id="triangle"
d="m -3.5 3.5 l 3.5 -7 l 3.5 7 l -7 0"
class="fill" />
% diamond head
<path id="diamond"
d="m 0 -3.5 l -3.5 3.5 l 3.5 3.5 l 3.5 -3.5 l -3.5 -3.5"
class="fill" />
</defs>
%%endsvg
X: 1
L: 1/8
V: 1 clef=treble
V: 2 clef=perc
K: C
% abc2xml.py percussion maps
I:percmap C D 52 triangle
I:percmap A * 60 x
I:percmap c * 47 diamond
%
% abcm2ps / abc2svg percussion maps
%
%%map drummap C print=D heads=triangle
%%map drummap A heads=x_head
%%map drummap c heads=diamond
%
V:1 % treble clef
cA[CA]A AA[CA]A | cA[CA]A AA[CA]A |
%
V:2 % perc clef
%%MIDI channel 10 % percussion map for abcMIDI
I:voicemap drummap % percussion map for abcm2ps/abc2svg
cA[CA]A AA[CA]A | cA[CA]A AA[CA]A |
If we want to make the tablature compatible with abc2svg, we just insert a %%strtab
line with no parameters. This directive tells abc2svg to use the abc2xml.py syntax.
As a first example, we rewrite the simple tablature we already used. abc2xml.py does
not support multiple voice definitions in V:, so we will write the same voice twice:
X: 1
M: 3/4
L: 1/4
%%score 1 T
V: T clef=tab octave=-1 % use standard guitar tuning
K: C
%
V: 1
C D E | F G A | B A B | c2 z ||
V: T
C D E | F G A | B A B | c2 z ||
0 2 3
0 2
0
2
0 1
T
A
B
Alternate tunings are notated specifying the right notes in the strings= option. Guitar
DADGAD tuning, for example, is defined as D2,A2,D3,G3,A3,D4; standard Irish bouzouki
as G2,D2,A3,D3; bass guitar as E1,A1,D2,G2.
9.7. ABC2XML.PY EXTENSIONS 143
Guitar music is normally notated using the clef=treble-8 clef specifier. To obtain sen-
sible finger positions, octave=-1 must also be specified in tablature voice definitions.
Optimal string and finger positions are calculated by the scorewriter, but strings can be
forced using decorations !0! . . . !6!; finger positions on the specified strings will be cal-
culated accordingly. In the following example, we typeset a tablature for the C chord using
default strings in the first measure, then specifying alternate string positions:
X: 1
L: 1/4
M: 2/4
K: C
%
V:1 clef=tab octave=-1
% standard positions
[CEG] [CEG] [CEG]2 |
% alternate fingering
[CEG] [!6!C!5!E!4!G] [CE!4!G]2 |
✁ ✁ ✁ ✁ ✄ ✄
✂ ✂ ✂ ✂ ☎ ☎
✆ ✆
Note that adding !4! to G in the second measure suffices to alter the other strings; there
is no other way to get a C chord.
The following example is taken from MuseScore’s documentation, with minor modifica-
tions suggested by Willem Vree. We want to typeset two voices in staff notation and as a
tablature; we then write two almost identical pairs of voices. We add clef=treble-8 to the
K: field, and add tablature options to the V: definition of voices 3 and 4:
X: 1
M: 4/4
L: 1/4
%%score (1 2) (3 4)
K: C clef=treble-8
% standard notation
V:1
g E/G/ G,/e/-e | d E/G/ G,/c/-c | B2 g f- | f D/G/ G,/B/- B |
V:2
C E G, E | C E G, E | G, D G, D | G, D G, D |
% tablature voices
V:3 clef=tab nostems octave=-1
g E/G/ G,/e/-e | d E/G/ G,/c/-c | B2 g f- | f D/G/ G,/B/- B |
V:4 clef=tab nostems octave=-1
C x x E | C x x E | G, D G, D | G, x x D |
144 CHAPTER 9. ABC AND MUSICXML
✂ ✂ ✄ ✄
✄ ✄ ✂ ✂ ✂
✂ ✂ ✂
✁ ✁ ✁ ✁ ✂ ✂ ✂ ✂
As you can see, a few notes were replaced by invisible rests in voice 4 to avoid a minor
issue with MuseScore’s handling of unisons in tablatures. In fact, when MuseScore finds a
unison like E/ and E in voices 1 and 2, it puts the notes on two different strings: this may lead
to unplayable positions. Other programs handle unisons correctly.
The last example, kindly provided by Willem Vree, shows how to implement a tablature
for banjo. We specify 5 notes in strings= and add %%scale, needed by Musescore to make
the tablature fit in one line.
%%linebreak <none>
X:1
T:Blue Moon Of Kentucky (banjo)
C:http://moinejf.free.fr/abcm2ps-doc/banjo.xhtml
M:4/4
L:1/4
V:1 treble-8
V:2 tab strings=G4,D3,G3,B3,D4 octave=-1
K:C
%
[V:1] z[Bg] [cg] [^cg] |: ^c/[dd]/ g/d/ d/g/ d/d/ | \
[V:2] z[B!5!g][c!5!g][^c!5!g] |: ^c/[dd]/ !5!g/!2!d/ d/!5!g/ !2!d/d/ | \
%
[V:1] B/d/ B/d/ A/d/ G/d/ | E/c/ G/d/ g/G/ d/g/ | \
[V:2] B/d/ B/d/ A/d/ G/d/ | E/c/ G/d/ !5!g/G/ d/!5!g/ | \
%
[V:1] G/e/ g/G/ e/G/ E/e/ | D/d/ g/G/ d/g/ B/d/ ||
[V:2] G/e/ !5!g/G/ e/G/ E/e/ | D/d/ !5!g/G/ d/!5!g/ B/d/ ||
0 1 2 0
2 3 3
0
3
0
0
0
0
0
2
0
0
0
1
0
0
0
0
0
2
0
2
0
2 0
0
0
0
0
2 2 0
0 0 0 0 0 0 0 0 0 0
9.8. ABC/MUSICXML CONVERSION: LIMITATIONS 145
146 CHAPTER 9. ABC AND MUSICXML
Chapter 10
Advanced Usage
T his chapter is written for expert users who can work comfortably with the Bash shell;
many useful programs and scripts only work in this environment.
The following information only applies to GNU/Linux and possibly to macOS (not tested).
Regrettably, many commands and scripts that work in Unix-like systems don’t work in Win-
dows, even in POSIX-like environments like MSYS2. Therefore, Windows power users will
have to install Windows Subsystem for Linux, or a virtual machine running GNU/Linux.
#!/bin/sh
# pdfcrop.sh
# Guido Gonzato, PhD. GPL 2 or later.
MYSELF=$(basename $0)
if [ $# -eq 0 ] ; then
printf "Usage: ${MYSELF} <file.pdf>\n"
printf "This script uses ghostscript to crop a one-page pdf file.\n"
exit 1
fi
GS=gs
INPUT=$1
PDF=$(basename $1 .pdf)
OUTPUT=$PDF-cropped.pdf
GSOPTS="-q -sDEVICE=bbox -dBATCH -dNOPAUSE"
147
148 CHAPTER 10. ADVANCED USAGE
/bin/rm -f $PDF.bbox
/bin/mv -f $OUTPUT $INPUT
This is the procedure that I used in this manual to include the music examples.
To crop a multi-page PDF file, the recommended program is PDFCrop, http://pdfcrop.
sourceforge.net:
$ pdfcrop tunes.pdf
PDFCROP 1.38, 2012/11/02 - Copyright (c) 2002-2012 by Heiko Oberdiek.
==> 49 pages written on `tunes-crop.pdf'.
$ _
which installs the abc2svg, abc2odt, and abctopdf scripts. abcqjs is equivalent to abc2svg,
but it’s much faster.
abcqjs translates an Abc source to an html file:
file.html can then be loaded into any web browser; we can just display it or print it to
PDF. As stated earlier, Chromium is the recommended browser.
Other actions are possible. abcqjs can load other scripts that convert the Abc sources in
several ways:
• tomei.js converts the input (single tune only) to the MEI music notation format (https:
//music-encoding.org/about);
For example, this is how to use abcqjs to select Abc files by K: field:
If we omit the -o file.pdf option, the output file will be named abc.pdf.
The following script (abc2pdf.sh) is a simplified version of abctopdf that turns an Abc
file to a single-page, cropped PDF file:
150 CHAPTER 10. ADVANCED USAGE
#!/bin/bash
# abc2pdf.sh
# Guido Gonzato, PhD. GPL 2 or later.
MYSELF=$(basename $0)
if [ $# -eq 0 ] ; then
printf "Usage: ${MYSELF} <file.abc>\n"
printf "abc -> cropped pdf conversion.\n"
exit 1
fi
\documentclass[a4paper,12pt]{article}
\usepackage{graphicx}
\begin{document}
This is some ABC music:
\medskip
10.3. USING ABC.STY 151
\includegraphics[width=\linewidth]{music.pdf}
\end{document}
You can also insert whole pages of music using the pdfpages package. The simplest way
is this LATEX source:
\documentclass[oneside]{article}
\usepackage{pdfpages}
\usepackage[a4paper,margin=1.5cm]{geometry}
\begin{document}
\end{document}
More explanations are included in the package documentation. This is a sample LATEX
document that employs abc.sty:
\documentclass[a4paper,12pt]{article}
\usepackage[generate,ps2eps]{abc}
\usepackage{mathptmx}
\begin{document}
\medskip
\begin{abc}
X:4
152 CHAPTER 10. ADVANCED USAGE
T:Cronin's Hornpipe
R:hornpipe
S:Keenan and Glackin
E:7
M:C|
L:1/8
K:G
BA|GABc dBde|gage dega|bage dBGB|cABG A2BA|
GABc dBde|gage dega|bage dBAB|G2G2 G2:|
fg|afd^c d2ga|bged e2ga|(3bag (3agf gedB|(3cBA AG AcBA|
GABc dBde|~g3e dega|bage dBAB|G2G2 G2:|
\end{abc}
\medskip
\medskip
\abcinput{tune}
\end{document}
By default, the resulting Abc file will contain only one measure per line.
Much better MIDI conversion can often be obtained using MuseScore, which can open
MIDI files and export them in MusicXML format. We then use xml2abc.py to convert the
MusicXML files to Abc.
Note
The quality of input MIDI files heavily affects the quality of the converted Abc files.
Results may vary from near perfection to unreadable junk.
10.5. THE ABCPP PREPROCESSOR 153
X: 1
T: Test with abcpp
#ifdef ABCMIDI
T: (version for abc2midi)
Q: 1/4 = 120
#else
T: (version for abcm2ps)
Q: "Allegro" 1/4 = 120
#endif
K: C
#ifndef ABCMIDI
|::cdef gabc'::|
#else
|:|1-3 cdef gabc':|
#endif
c'bag fedc|
Note the lines that start in # : these are directives (commands) to the preprocessor.
The first directive means: “if the symbol ABCMIDI is defined, then. . . ” If the condition is
true, the source continues with the next two lines; otherwise, with the lines that follow the
#else directive. The #endif directive terminates the condition. Similarly, the fourth directive
means: “if the symbol ABCMIDI is not defined, then. . . ”. The following two measures are
written for abcm2ps; after the #else directive, two measures are written in an abc2midi-
compatible way.
To convert the source to make it acceptable to abc2midi, we’ll run abcpp with this com-
mand line:
This way we define the ABCMIDI symbol, and a new Abc file will be created:
154 CHAPTER 10. ADVANCED USAGE
X: 1
T: Test with abcpp
T: (version for abc2midi)
Q: 1/4 = 120
K: C
|:|1-3 cdef gabc':|
c'bag fedc|
If we run abcpp without defining any symbols, we’ll get the right source for abcm2ps:
X: 1
T: Test with abcpp
T: (version for abcm2ps)
Q: "Allegro" 1/4 = 120
K: C
|::cdef gabc'::|
c'bag fedc|
Let’s consider another example. Some Abc applications don’t support invisible rests. To
make it possible to use them portably, we have to insert these lines in the source:
#ifdef OLD
#define !x! z
#else
#define !x! x
#endif
In plain English: “if the OLD symbol is defined, then turn the !x! decoration into z ;
otherwise, !x! will become x ”. As we write the tune, we will use !x! to denote invisible
rests. When we convert the source for abcm2ps or other programs, the !x! symbol will be
turned into x or z in accordance with the presence of the symbol OLD.
then write the tune using the “new” symbols !fmt!, !lmd!, and so on. Before converting the
source, we preprocess it with the command:
-t hni transposes the music by hni semitones. hni may be a negative number.
-X hni for a file with several pieces, renumbers the X: field starting with hni.
X: 1
L: 1/4
K: C
CDEF|GABc|cdef|gabc'|c'cCz|
$ abc2abc cde.abc -n 2 -t 2
$ _
This command reformats the source to get two measures per line and transpose the music
up two half-tones. This is what we obtain:
X:1
L:1/4
K:Eb
156 CHAPTER 10. ADVANCED USAGE
%
EFGA|Bcde|
efga|bc'd'e'|
e'eEz|
The transposing feature will be extremely useful to players of clarinet and other trans-
posing instruments.
Chapter 11
The End
157
158 CHAPTER 11. THE END
No rhetoric, Annarosa was unique. She profoundly loved and enjoyed art and music. She
shared her love with me when I was just a kid, giving me records of opera arias as presents.
She took me by train to visit Venice for the first time in my life, and she introduced me to the
beauty of the mountains.
She confronted her fatal illness with courage and dignity. Till the end she listened to her
favourite music, till the end she gave me beautiful records of operas as present. This guide is
dedicated to her memory: a tiny leaf born from the seed she threw when she had a six-year-
old kid listen to Rigoletto, so many years ago. Ciao, Annarosa.
Appendix A
• Hudson Lacerda’s Abc page, including advanced customisation and many new Post-
Script routines:
http://hudsonlacerda.webs.com/
159
160 APPENDIX A. BITS & PIECES
Tune structure
X:1 % first header field, mandatory
K:C % last header field, mandatory Rests
% defaults: free meter, note = 1/8,
% bars can be inserted anywhere X:1
A A A A A A A A | \ % line continues K:C
A A | % new line z8 z4 z2 y20 z z/ z// z/// z//// Z3
A A A A | A A 3
Beaming
X:1
K:C
A A AA A/A/ A/A/ A/A/A/A/
Pitch, absolute
X:1
K:C clef=treble % force clef
C, E, G, C E G c e g c' e' g' Measure bars
X:1
K:C
A2 | A2 || A2 [| A2 [] A2 |] A2 .| A2
[|: A2 :|]|: A2 :|]: A2 :]|[: A2 \
|:: A2 ::| A2 |]
Pitch, relative
X:1
K:C
[K:octave=-3] A [K:octave=-2] A \
[K:octave=-1] A [K:octave=0] A \
[K:octave=1] A [K:octave=2] A Accidentals
X:1
K:C
^A2 ^^A2 _A2 __A2 =A2 \
"\#"A2 "\b"A2 "\="A2
X:1
K:C Dotted notes
A8 A4 A2 A0 A A/ A// A/// A//// X:1
L:1/4
K:C
A3/2 A7/4 A15/8 | A>A A>>A A<<A A<A
Largo = 40
4 7
4 8
Tuplets
Repeats and endings
X:1
K:C X:1
(3CDE (5CDEFG (3:2:4G2A2Bc K:C
3 |: C2D2E2F2 |1 G2E2G2z4 :|2 E2D2C2z2 :|
3 5
1 2
Chords
X:1 Accompaniment chords
K:C
[CEGc]2 [CEGc]4 [CEGc]>[CEGc] \ X:1
[CEGc]-[CEGc] ([CEGc][CEGc]) K:C
"A"A2 "Am"A2 "A7"A2 "Amaj7"A2 "A+"A2
A Am A7 Amaj7 A+
Grace notes
Text annotations
X:1
K:C X:1
{B}A2 {B}A2 {/B}A2 {AB}A2 {/[Ace]}A2 K:C
"^up"A2 "_down"A2 "<left"a2 ">right"a2\
"<aro" ">und"A,2 "@-20,25@x,y"A2
up @x,y
left right
Keys
X:1 down aro und
K:C
[K:Gmaj] G2 [K:F#m] F2 \ Title and composer
[K:F] F2 [K:Gm] G2
X:1
T:Title
T:Subtitle
C:Composer
K: C
Clefs C2 D2 E2 F2 | G2 A2 B2 c2 |
X:1 Title
K:C
[K:clef=none] A8 [K:clef=perc] A8 \ Subtitle
[K:clef=F] A,,8 [K:clef=C] A,8 \ Composer
[K:clef=G] A8
Other decorations
Singing, singing, singing!
X:1
Dynamics K:C
!//!A2 A2!trem2!A2 !8va(!A2 !ped!A2 \
X:1 !8va)!!ped-up!A//A//!beambr1!A//A//|
K:C
!pp!!<(!A2 B2 !<)!c2 !f!d2 | \ 8va
!ff!!>(!d2 c2 B2 !mf!!>)!A2 |
*
Ped
pp f ff mf Voices
Articulations X:1
%%score (1 2)
X:1 K:C
K:C [V:1] c2 d2 e2 f2 |
.A2 !>!A2 !tenuto!A2 HA2 | [V:2] C2 G2 E2 G2 |
Position markings
Staves
X:1
K:C X:1
[P:A] !segno!A2 !coda!A2 \ %%score [1 2]
!D.C.!A2 !D.S.!A2 [P:B] !fine!A2 | V:1 name="Tenor"
V:2 name="Bass" octave=-1
A B K:C
D.C. D.S. FINE [V:1] c2 d2 e2 f2 |
[V:2] C2 G2 E2 G2 |
Tenor
Fingerings
X:1
K:C Bass
!+!A2 !5!A2 !upbow!A2 !open!A2 |
164 APPENDIX A. BITS & PIECES
$ file *abc
england.abc: ISO-8859 text, with CRLF line terminators
ireland.abc: data
klezmer.abc: Non-ISO extended-ASCII text, with very long lines
O_Neills_1001.abc: data
O_Neills_1850.abc: ASCII text
oneills.abc: ASCII text
scotland.abc: ASCII text
session.abc: UTF-8 Unicode text
tunes.abc: ASCII text
In the above list, the only correct files are those described as “ASCII text” or “UTF-8 Uni-
code text”. To fix an ISO-8859 encoded file, run this command:
Q: Syntax
The Q: field used to accept a simplified syntax, like Q:108. This is deprecated; please specify
the tempo indicating the note length, like Q:1/4=108.
By the way: please do use the Q: field to let other people know how fast a tune should be
played!
! as End of Line
As we learnt in Section 4.1.6 (page 69), there are several ways to force line breaks. If your
sources use ! as an end of line marker, the easiest way to fix them is including the %%I:line-
break ! command.
\ in w: Lines
Using \ to split a w: line into two w: lines is now deprecated: please use + instead.
middle= Specifier
The K: or V: middle=hnotei specifier was once used to specify the note that corresponds to
the third line in the score. This syntax is now deprecated.
166 APPENDIX A. BITS & PIECES
Parameter Type
length unit length indicated in cm, in or pt
text generic text
char character
logical logical value, true or false, yes or no, 1 or 0
int integer number
float number with decimals
str character string
char single character
These directives are also listed and explained at the abcm2ps parameters page.
Directives only available in abcm2ps:
%%abc2pscompat
%%alignbars
%%autoclef
%%botmargin
%%clip
%%dateformat
%%decoration
%%EPS
%%footerfont
%%footer
%%format
%%glyph
%%gutter
%%header
%%headerfont
%%landscape
%%leftmargin
%%micronewps
%%oneperpage
%%pageheight
%%pagewidth
%%pango
%%pdfmark
%%rightmargin
%%setdefl
%%splittune
%%staffwidth
%%tablature
%%topmargin
%%beginml
%%chordnames
%%grid
%%grid2
%%ottava
%%fullsvg
%%printmargin
%%singleline
%%sth
%%botmargin hlengthi sets the page bottom margin to hlengthi. Default: 1 cm; scope: page;
not available in abc2svg.
%%footer htexti: sets the text to be typeset as footer on each page. Default: none; scope:
page; not available in abc2svg.
%%header htexti: sets the text to be typeset as header on each page. Default: none; scope:
page; not available in abc2svg.
%%indent hlengthi: sets the indentation for the first line or system to hlengthi. Default: 0;
scope: tune.
%%landscape hlogicali: if 1, sets the page layout as landscape. Default: 0; scope: page; not
available in abc2svg.
%%leftmargin hlengthi: sets the page left margin to hlengthi. Default: 1.8 cm; scope: page,
restart.
%%multicol hcommandi: defines columns. hcommandi may be start, new, and end. De-
fault: none; scope: immediate, restart.
%%pageheight hlengthi: sets the page height to hlengthi. Default: 11 inches; scope: page;
not available in abc2svg. For European A4 paper, the right value is 29.7cm.
%%pagewidth hlengthi: sets the page width to hlengthi. Default: 8.5 inches; scope: page; not
available in abc2svg. For European A4 paper, the right value is 21cm.
%%rightmargin hlengthi: sets the page right margin to hlengthi. Default: 1.8 cm; scope:
page, restart.
%%topmargin hlengthi: sets the page top margin to hlengthi. Default: 1 cm; scope: page; not
available in abc2svg.
168 APPENDIX A. BITS & PIECES
A.5.2 Text
These directives are used to write text lines within a tune and between tunes. Fonts and
spacing are set with other directives that we will examine later on.
%%begintext
Spanish folk song, usually
accompanied by guitar and cymbals.
The %%begintext directive can be given a parameter to change the text alignment:
%%textoption hinti: sets the default text option to be used between %%begintext and
%%endtext, or in %%EPS files. The parameter can be a digit or a corresponding string:
0 or obeylines), 1 (justify), 2 (fill), 3 (center), 4 (skip), 5 (right). If the option
is 4 (skip), no text or EPS is output. Default: 0; scope: generation.
A.5.3 Fonts
These directives specify the character fonts used in various parts of a score. Please note that
the common True Type fonts used by the operating system are not the same fonts used by
abcm2ps. In fact, abcm2ps uses the PostScript fonts, provided for and managed by Ghostscript.
Standard PostScript fonts are shown in Appendix A.6 (page 179). I remind you that indications
for adding new fonts are given in Section 8.6 (page 128).
%%capofont hstringi: font of %%capo indications. Default: sans-serif 12; scope: immediate.
%%footerfont hstringi: font of %%footer lines. Default: serif 16; scope: page.
%%gchordfont hstringi [box]: accompaniment chords font. If the parameter box is present,
a box is drawn around the accompaniment chord. Default: sans-serif 12; scope: imme-
diate.
%%gridfont hstringi: font of chord grids. lines. Default: serif 16; scope: tune.
%%headerfont hstringi: font of %%header lines. Default: serif 16; scope: page.
%%measurefont hstringi [box]: text font of measure numbers. If the parameter box is pre-
sent, a box is drawn around the measure number. Default: serifItalic 10; scope: gener-
ation.
%%musicfont hstringi: defines a music font that replaces PostScript and/or SVG glyphs.
%%repeatfont hstringi: font of repeat numbers or text. Default: serif 13; scope: generation.
%%setfont-hinti hstringi hinti: sets an alternate font for strings. In most strings, the cur-
rent font may be changed by $n (n = 1, 2, 3, 4). $0 resets the font to the default value.
Default size 12; scope: generation.
%%subtitlefont hstringi: font of the second T: field. Default: serif 16; scope: generation.
%%titlecaps hlogicali: if 1, writes the title in capital letters. Default: 0; scope: tune.
%%titlefont hstringi: font of the first T: field. Default: serif 20; scope: tune.
%%titleformat hstringi: defines the format of the tune title. This format overrides %%ti-
tleleft, %%infoline, and %%composerspace. Scope: tune.
%%titleleft hlogicali: if 1, writes the title left-aligned instead of centered. Default: 0; scope:
tune.
%%tupletfont hstringi: font of tuplet indications. Default: serifItalic 12; scope: tune.
%%vocalfont hstringi: font of the text in w: lines. Default: serifBold 13; scope: generation.
%%voicefont hstringi: font of voice names. Default: serifBold 13; scope: tune.
%%wordsfont hstringi: font of the text in W: lines. Default: serif 16; scope: tune.
170 APPENDIX A. BITS & PIECES
A.5.4 Spacing
These directives specify spacing between score elements.
%%barsperstaff hinti: attempts to typeset the score with hinti bars on each line. Default:
0; scope: generation.
%%breaklimit hfloati: used together with %%maxshrink, it lets the user control where line
breaks may occur. The parameter can range between 0.5 (line break occurs when the
line is 50% full) and 1.0. Default: 0.7; scope: generation.
%%break hinti: inserts a break after hint - 1i symbols. Default: none; scope: generation.
%%breakoneoln hlogicali: if 1, treats an end of line as if it were a space (i.e. it breaks note
beams). Default: 1; scope: generation.
%%composerspace hlengthi: sets the vertical space above the C: field to hlengthi. Default:
0.2 cm; scope: tune.
%%gracespace hfloati hfloati hfloati: defines the space before, within and after grace no-
tes. Default: 6.5, 8.0, 12.0; scope: generation.
%%gutter hlengthi: specifies the amount of gutter, i.e. the space between facing pages. De-
fault: 0; scope: page.
%%infospace hlengthi: sets the vertical space above the I: field to hlengthi. Default: 0;
scope: tune.
%%linebreak hstringi: defines or undefines the line break separators. The string may be
empty or contain the values <EOL>, $, !, and <none>. Default: <EOL>; scope: imme-
diate.
%%lineskipfac hfloati: sets the factor for spacing between lines of text to hfloati. Default:
1.1; scope: generation.
%%maxshrink hfloati: sets how much to compress horizontally when staff breaks are chosen
automatically. hfloati must be between 0 (don’t shrink) and 1.0 (full shrink). Default:
0.65; scope: generation.
%%maxstaffsep hlengthi: sets the maximum vertical space between systems. Default: 2000
pt; scope: generation.
%%maxsysstaffsep hlengthi: sets the maximum vertical space between staves in a system.
Default: 2000 pt; scope: generation.
%%musicspace hlengthi: sets the vertical space before the first staff to hlengthi. Default: 0.2
cm; scope: tune.
%%pagescale hfloati: sets the music scale factor to hfloati. Default: 1.0; scope: generation,
restart.
%%parskipfac hfloati: sets the factor for spacing between text paragraphs to hfloati. De-
fault: 0.4; scope: generation.
%%partsspace hlengthi: sets the vertical space above the P: field in the header to hlengthi.
Default: 0.3 cm; scope: generation.
%%scale hfloati: sets the music scale factor to hfloati, assuming a 72 PPI resolution; you
should use %%pagescale instead. Default: 0.75; scope: generation, restart.
%%sep hlength1i hlength2i hlength3i: typesets a centered line long hlength3i, with hlen-
gth1i space above and hlength2i space below. Default; none; scope: immediate, restart.
%%slurheight hfloati: sets the slur height factor; lesser than 1 flattens the slur, greater than
1 expands it. Default; 1.0; scope: generation.
%%staffbreak hlengthi [“f”]: sets a hlengthi-long break (gap) in the current staff. If the
letter f is present, the staff break is forced even if it occurs at the beginning or end of
a line. Default: none; scope: immediate, voice.
%%staffsep hlengthi: sets the vertical space between different systems to hlengthi. Default:
46 pt; scope: generation.
%%stretchlast hfloati: stretches the last staff of a tune when underfull by more than hfloati.
Default; 0.25; scope: generation.
%%stretchstaff hlogicali: if 1, stretches underfull staves across the page. Default: 1; scope:
generation.
%%subtitlespace hlengthi: sets the vertical space above the second T: field to hlengthi.
Default: 0.1 cm; scope: tune.
%%sysstaffsep hlengthi: sets the vertical space between staves in the same system to hlen-
gthi. Default: 36 pt; scope: generation.
%%textspace hlengthi: sets the vertical space above H: fields at the end of a tune to hlengthi.
Default: 0.5 cm; scope: generation.
%%tieheight hfloati: sets the tie height factor; lesser than 1 flattens the tie, greater than 1
expands it. Default; 1.0; scope: generation.
%%titlespace hlengthi: sets the vertical space above the first T: field to hlengthi. Default:
0.2 cm; scope: tune.
%%topspace hlengthi: sets the vertical space above a tune to hlengthi. Note that a tune may
begin with %%text directives before the title. Default: 0.8 cm; scope: tune.
%%vocalspace hlengthi: sets the vertical space above w: lines to hlengthi. Default: 23 pt;
scope: generation.
172 APPENDIX A. BITS & PIECES
%%voicescale hlengthi: sets the scale of a voice, or of all voices if the comand is included
in the header. Default: 1 (0.5–1.5); scope: generation, voice.
%%vskip hhi: adds hhi vertical space. hhi may be a negative value. Default: none; scope:
immediate, restart.
%%wordsspace hlengthi: sets the vertical space above W: lines at end of the tune to hlengthi.
Default: 0 pt, 5 pt; scope: tune.
%%abc hstringi: defines some Abc code. Along with %%abcm2ps, this directive is used for
conditional output generation. Default: none; scope: immediate.
%%abc2pscompat hlogicali : if 1, reverts to the old metod of dealing with notes in bass and
other clefs. Default: 0; scope: generation.
%%abc-include hstringi: includes the Abc file named hstringi. Default: none; scope: imme-
diate.
%%alignbars hinti: aligns the bars of the next hinti lines of music. It only works on single-
voice tunes. Default: 0; scope: immediate, restart; not available in abc2svg.
%%aligncomposer hinti: specifies where to print the C: field. A negative value means “on
the left”, 0 means “centre”, and a positive value means “on the right”. Default: 1; scope:
tune.
%%ambitus h1i: typesets an ambitus before the clef. Scope: generation. Not available in abcm-
2ps.
%%autoclef hlogicali: if 1, the clef set by the K: is initialised to “auto”; if 0, the clef is set as
“treble”. Default: 1; scope: generation.
%%bgcolor hstringi: defines the background colour of HTML output. The parameter can be
a colour name, like ‘green’, or an RGB colour value, like #00ff00. Default: none; scope:
page.
%%bstemdown hlogicali: if 1, the stem of the note on the third staff line points downwards.
Otherwise, it points upwards or downwards in accordance with the previous note. De-
fault: 0; scope: immediate, voice.
A.5. FORMATTING DIRECTIVES 173
%%cancelkey hlogicali: if 1, accidentals are cancelled using natural signs when the key sig-
nature changes. Default: 1; scope: generation.
%%capo hinti: for accompaniment chords, specifies that a capo should be used on fret hni.
Scope: generation.
%%clef hclefi [line] [octave]: inserts a clef change, in a manner similar to K:. hclefi may
be treble (or G2), alto (C3), tenor (Cf), bass (F4), perc (P2), G, C, G, C, F, P, or none.
The latter typesets no clef on the staff. The name of a user-provided PostScript glyph
may also be used. [line] specifies the staff line on which the clef sits. [octave] can be +8
or -8, to print “8” above or below the clef; ^8 or 8, to print “8” above or below the clef
and perform octave transposition. Default: none; scope: immediate, voice.
%%clip hstringi: defines a subset of tune(s) to be printed. Default: none; scope: generation.
%%contbarnb hlogicali: if 1, the bar number of the second repeat(s) is reset to the number
of the first repeat. If 0, bars are sequentially numbered. Default: 0; scope: generation.
%%custos hlogicali: if 1, a custos is added at the end of each music line. A custos is a symbol
that indicates the pitch for the first note of the next line. This directive works with single
voice tunes only. Default: 0; scope: generation.
%%dateformat hstringi: defines the format of date and time. Default is %b %e, %Y %H:%M.
The fields specify, respectively: abbreviated month name (Jan–Dec), day of month (1–
31), year, hour (0–23), minute (0–59). Default: %b %e, %Y %H:%M; scope: page.
%%dblrepbar hstringi: defines how double repeat bars are drawn; e.g. :][: (default), or ::,
or :|:. Scope: generation.
%%deco hstring1i hint1i hstring2i hint2i hint3i hint4i hstring3i: adds a new decoration.
Default: none; scope: immediate.
%%diagram hinti: if 1, typesets guitar chords diagram above the notes. Scope: generation.
Not available in abcm2ps.
%%dynalign hlogicali: if 1, horizontally aligns the dynamics marks. Default: 1; scope: gen-
eration.
%%EPS hstringi: includes an external EPS file in the score. Default: none; scope: immediate,
restart; not available in abc2svg.
%%equalbars hbooli: makes the width of measures proportional to their duration. Default:
none; scope: generation; not available in abcm2ps.
174 APPENDIX A. BITS & PIECES
%%fgcolor hstringi: defines the foreground colour of HTML output. The parameter can be
a colour name, like ‘green’, or an RGB colour value, like #00ff00. Default: none; scope:
page.
%%flatbeams hlogicali: if 1, forces flat (horizontal) note beams. Default: 0; scope: genera-
tion.
%%format hstringi: reads the format file specified as parameter. Default: none; scope: im-
mediate.
%%glyph hstring1i hstring1i: sets the name of a Unicode glyph. The first parameter is a
hexadecimal value, the second is the name of the associated glyph in the font files.
Default: none; scope: generation.
%%graceword hlogicali: if 1, aligns lyrics words under grace notes when they are present.
Default: 0; scope: generation.
%%grid hinti: typesets a chord grid above (hni = 1) or below (hni = -1) the tune. Default: 0;
scope: generation; not available in abcm2ps.
%%grid2 [int]: replaces a voice with a chord grid. When [int] is missing, the grid is disabled.
Default: 0; scope: voice; not available in abcm2ps.
%%hyphencont hlogicali: if 1, and if lyrics under the staff end with a hyphen, puts a hyphen
in the next line. Default: 1; scope: generation.
%%infoline hlogicali: if 1, displays R: and A: fields on the same line above the first music
line. Default: 0; scope: tune.
%%infoname hstringi hstringi: defines the name of information fields that are printed when
%%writefields is also set to 1. Defaults: fieldR:, ”Rhythm: ”; B:, ”Book: ”; S:, ”Source:
”; D:, ”Discography: ”; N:, ”Notes: ”; Z:, ”Transcription: ”; H:, ”History: ”; scope: tune.
%%keywarn hlogicali: if 1, a cautionary key signature is printed when a key signature change
occurs at the beginning of a music line. Default: 1; scope: generation.
%%linewarn hlogicali: if 1, outputs a warning message if there are too many or too few
elements in a music line. Default: 1; scope: generation.
%%measurenb hinti: if hinti is greater than 0, typesets measure numbers every hinti bars; if
it is 0, typesets the measure number at the beginning of the staff. Default: -1; scope:
generation.
%%measurebox hlogicali: if 1, draws a box around measure numbers. Default: 0; scope: gen-
eration.
A.5. FORMATTING DIRECTIVES 175
%%micronewps hlogicali: if 1 uses the new PostScript functions to draw microtonal acciden-
tals. Default: 0; scope: page; not available in abc2svg.
%%microscale hinti: defines the denominator for microtone accidentals. Default: none; scope:
immediate, voice.
%%oneperpage hlogicali: if 1, outputs one tune per page. Default: 0; scope: page.
%%pango hlogicali: if abcm2ps was compiled with Pango support, this directive enables or
disables PostScript output with Pango. Default: 1; scope: generation.
%%partsbox hlogicali: if 1, draws a box around part names (P: fields.) Default: 0; scope:
generation.
%%pdfmark hinti: if the parameter is 1, inserts marks in the PostScript output for titles. Post-
Script to PDF translators can use the marks to create a PDF tune index. If the parameter
is greater than 1, marks are inserted for titles and subtitles. Default: 0; scope: page.
%%pos htypei hpositioni: defines the direction and/or the position of some music elements.
htypei can be dynamic, gchord, gstem, ornament, stem, vocal, and volume. hpositioni
can be auto, above or up, below or down, hidden, and opposite. Default: auto; scope:
immediate, voice.
%%postscript hstringi: lets the user add a new PostScript routine, or change an existing
one. Default: none; scope: immediate; not available in abc2svg.
%%ps hstringi: same as %%postscript.
%%rbdstop hlogicali: if 1, repeat brackets stop on a double bar. Default: 1; scope: generation.
%%rbmax hinti: sets the maximum number of bars over which a repeat bracket is drawn.
Default: 4; scope: generation.
%%rbmin hinti: sets the minimum number of bars over which a repeat bracket is drawn.
Default: 2; scope: generation.
%%repbra hlogicali: if 0, prevents displaying repeat brackets for the current voice. Default:
1; scope: generation, voice.
%%repeat hint1i hint2i: repeats a sequence of notes or bars. Default: none; scope: immedi-
ate.
%%score hstringi: defines how staves are to be printed in multivoice tunes. Default: none;
scope: immediate.
%%select hstringi: select a subset of tunes to be printed. Default: none; scope: generation.
%%setbarnb hinti: sets the number of the next measure, excluding the first. To set the num-
ber of the first measure, the directive must be written in the tune header. Default: none;
scope: immediate.
%%setdefl hlogicali: if 1, outputs some indications about the note/chord and/or decora-
tions for customization purposes. These indications are stored in the PostScript variable
defl. Default: 0; scope: generation; not available in abc2svg.
176 APPENDIX A. BITS & PIECES
%%shiftunison hlogicali: if 1, shifts note heads that belong to different voices that are in
unison. It applies to dotted notes and notes that are shorter than a half note. Default:
0; scope: generation.
%%splittune hlogicali: if 1, splits tunes that do not fit in a single page. Default: 0; scope:
generation.
%%squarebreve hlogicali: if 1, displays “brevis” notes in square format. Ending brevis notes
are always squared. Default: 0; scope: generation.
%%staff hinti: typesets the next symbols of the current voice on the hinti-th staff. Default:
none; scope: immediate, voice.
%%stafflines hinti: sets the number of staff lines of the current voice. Default: 5; scope:
generation, voice.
%%staffnonote hinti: avoids printing a staff, depending on the parameter. If it is 0, the staff
is not printed if it contains only invisible rests and notes; if it is 1, the staff is not printed
if it contains only rests and invisible notes; if it is 2, the staff is printed. Default: 1; scope:
generation.
%%staffscale hfloati: sets the scale of the staff of the current voice. This directive corre-
sponds to the staffscale V: parameter. Default: 1; scope: generation, voice.
%%staves hstringi: defines how staves are to be printed. This directive is deprecated; please
use %%score instead. Default: none; scope: immediate.
%%stemheight hfloati: sets the stem height to hfloati. Default: 20.0; scope: generation.
%%titletrim hlogicali: if 1, move the last word of a title to the head if it starts with a capital
letter and it is preceded by a space and a comma. Default: 1; scope: tune.
%%transpose hinti [char]: transposes the music by hinti semitones. The optional param-
eter may be # or b , meaning that the new key signature will have sharps or flats.
Default: 0; scope: immediate.
%%tune hstringi: select the tune(s) to which the following options will be applied. Default:
none; scope: generation.
%%tuplets hint1i hint2i hint3i hint4i: defines how tuplets are to be drawn. Default: 0, 0,
0, 0; scope: immediate.
A.5. FORMATTING DIRECTIVES 177
%%user hstringi: this directive is the equivalent of the U: field, and can be used to redefine
default decorations in format files. Default: none; scope: generation.
%%voice hstringi: select the voice(s) to which the following options will be applied. Default:
none; scope: generation.
%%voicecolor hstringi: defines the colour of the symbols in the current voice. The param-
eter is an RGB colour, like #aaff80. Default: none, #000000; scope: immediate, voice.
%%voicecombine hinti: defines how to combine notes and rests of several voices on the
same staff. Default: 0; scope: immediate, voice.
%%voicemap hstringi: defines the note mapping of a voice. Default: none; scope: immediate,
voice.
AvantGarde-Book Helvetica-Narrow
AvantGarde-BookOblique Helvetica-Narrow-Bold
AvantGarde-Demi Helvetica-Narrow-Oblique
AvantGarde-DemiOblique Helvetica-Narrow-BoldOblique
Bookman-Light NewCenturySchlbk-Roman
Bookman-LightItalic NewCenturySchlbk-Bold
Bookman-Demi NewCenturySchlbk-Italic
Bookman-DemiItalic NewCenturySchlbk-BoldItalic
Courier Palatino-Roman
Courier-Bold Palatino-Bold
Courier-Oblique Palatino-Italic
Courier-BoldOblique Palatino-BoldItalic
Helvetica Times-Roman
Helvetica-Bold Times-Bold
Helvetica-Oblique Times-Italic
Helvetica-BoldOblique Times-BoldItalic
Σψµβολ (Symbol)
ZapfChancery-MediumItalic
✺❁❐❆✤❉■❇❂❁▼▲ (ZapfDingbats)
%%MIDI bassprog hinti: sets the MIDI instrument for the bass notes in accompaniment
chords to hinti (0–127).
%%MIDI bassvol hinti: sets the velocity (i.e., volume) of the bass notes in accompaniment
chords to hinti (0–127).
%%MIDI beat hint1i hint2i hint3i hint4i: controls the volumes of the notes in a measure.
The first note in a bar has volume hint1i; other “strong” notes have volume hint2i and
all the rest have volume hint3i. These values must be in the range 0–127. The parameter
hint4i determines which notes are “strong”. If the time signature is x/y, then each note
is given a position number k = 0, 1, 2. . . x-1 within each bar. If k is a multiple of hint4i,
then the note is “strong”.
%%MIDI beataccents: reverts to normally emphasised notes. See also %%MIDI nobeatac-
cents.
180 APPENDIX A. BITS & PIECES
%%MIDI beatstring hstringi: similar to %%MIDI beat, but indicated with an fmp string.
%%MIDI bendstring hinti [int]. . . : specifies pitch trajectory for bent notes.
%%MIDI bendvelocity hint1i hint2i: specifies the change in pitch and rate of change of
bent notes.
%%MIDI c hinti: specifies the MIDI pitch which corresponds to C . The default is 60. This
number should normally be a multiple of 12.
%%MIDI chordattack hinti: delays the start of chord notes by hinti MIDI units.
%%MIDI chordname hstring int1 int2 int3 int4 int5 int6i: defines new chords or redefi-
nes existing ones as was seen in Section 7.1.11 (page 113).
%%MIDI chordprog hinti: sets the MIDI instrument for accompaniment chords to hinti (0–
127).
%%MIDI chordvol hinti: sets the volume (velocity) of chord notes to hinti (0–127).
%%MIDI control hbass/chordi hint1 int2i: generates a MIDI control event. If %%control
is followed by hbassi or hchordi, the event apply to the bass or chord channel, otherwise
it will be applied to the melody channel. hint1i is the MIDI control number (0–127) and
hint2i the value (0–127).
%%MIDI controlcombo: indicates that the next %%MIDI controlcombo directive does not
replace previous ones.
%%MIDI controlstring hint1 int2 . . . i: used for note shaping; this directive is still in de-
velopment.
%%MIDI deltaloudness hinti: by default, !crescendo! and !dimuendo! modify the beat
variables hvol1i hvol2i hvol3i 15 volume units. This directive allows the user to change
this default.
%%MIDI drone hint1 int2 int3 int4 int5i: specifies a two-note drone accompaniment. hint1i
is the drone MIDI instrument, hint2i the MIDI pitch 1, hint3i the MIDI pitch 2, hint4i
the MIDI volume 1, hint5i the MIDI volume 2. Default values are 70 45 33 80 80.
%%MIDI drumbars hinti: specifies the number of bars over which a drum pattern string is
spread. Default is 1.
%%MIDI drum hstri hint1 int2 int3 int4 int5 int6 int7 int8i: generates a drum accompa-
niment pattern, as described in Section 7.1.15 (page 116).
A.7. ABCMIDI DIRECTIVES 181
%%MIDI drummap hstri hinti: associates the note hstri (in Abc notation) to the a percussion
instrument, as listed in Section A.8.2 (page 184).
%%MIDI expand: expand notes to make them overlap the following notes.
%%MIDI fermatafixed: expands a !fermata! by one unit length; that is, HC3 becomes C4.
%%MIDI gchordbars hstri: spreads the chord hstri over hni consecutive bars of equal length.
The length of hstri should be evenly divisible by hni, otherwise the chords will not play
properly.
%%MIDI gchord hstri: sets up how accompaniment chords are generated; please see Sec-
tion 7.1.10 (page 111).
%%MIDI grace hfloati: sets the fraction of the next note that grace notes will take up. hfloati
must be a fraction such as 1/6.
%%MIDI gracedivider hinti: sets the grace note length as 1/hintith of the following note.
%%MIDI makechordchannels hinti: this is a very complex directive used in chords contain-
ing microtones. Please consult the abcMIDI documentation.
%%MIDI nobarlines: normally, an accidental applied to a note also applies to other equal
notes until the next bar. By using this directive, the accidental will apply to the follow-
ing note only.
%%MIDI nobeataccents: forces the hint2i volume (see %%MIDI beat) for each note in a bar,
regardless of their position.
%%MIDI noportamento: turns off the portamento controller on the current channel.
%%MIDI pitchbend hbass/chordi hint1 int2i: generates a pitchbend event on the current
channel, or on the bass or chord channel as specified. The value given by the following
two bytes indicates the pitch change.
%%MIDI portamento [bass] [chord] hinti: turns on the portamento controller (glide ef-
fect) on the current channel (or to bass/chord channel) and set it to hinti. 0 turns off
the effect.
%%MIDI program [int1] hint2i: selects the program (instrument) hint2i (0–127) for channel
hint1i. If this is not specified, the instrument will apply to the current channel.
%%MIDI ptstress hstringi: uses the stress pattern in the file name given as hstringi.
182 APPENDIX A. BITS & PIECES
%%MIDI randomchordattack: delays the start of chord notes by a random number of MIDI
units.
%%MIDI ratio hint1 int2i: sets the ratio of note lengths in broken rhythm. Normally, c>c
will make the first note three times as long as the second; this ratio can be changed
with %%ratio 2 1.
%%MIDI snt hinti hfloati: alters the standard MIDI pitch of a note h0–127i; e.g. %%MIDI snt
60 60.5 alters the pitch of C.
%%MIDI temperamentequal hint1i [int2] [int3] [int4]: uses a tempered scale defined by
hint1i equal divisions of [int2] cents (default: 1200). The parameters [int3] and [int4]
give the size of the fifth interval and of accidentals.
%%MIDI temperamentlinear hfloat1 float2i: changes the temperament of the scale. hfl-
oat1i specifies the size of an octave in cents of a semitone, or 1/1200 of an octave.
hfloat2i specifies in the size of a fifth (normally 700 cents).
%%MIDI transpose hinti: transposes the output by hinti semitones. hinti may be positive
or negative.
%%MIDI trim hint1i hint2i: controls the articulation of notes and chords by placing silent
gaps between the notes. The length of these gaps is determined by hint1i/hint2i and the
unit length is specified by the L: field. These gaps are produced by shortening the notes
by the same amount. If the note is already shorter than the specified gap, then the gap
is set to half the length of the note. It is recommended that hint1i/hint2i be a fraction
close to zero. Trimming is disabled inside slurs as indicated by parentheses. Trimming
is disabled by setting hint1i to 0.
%%MIDI tuningsystem hstringi: when hstringi is comma53, the Holdrian scale (53 micro-
tones) will be used instead of the standard 12-note tempered scale.
%%MIDI vol hinti: increases the loudness of the next note by hinti.
35. B,,, Acoustic Bass 36. C,, Bass Drum 1 37. ^C,, Side Stick
Drum
38. D,, Acoustic Snare 39. ^D,, Hand Clap 40. E,, Electric Snare
41. F,, Low Floor Tom 42. ^F,, Closed Hi Hat 43. G,, High Floor Tom
44. ^G,, Pedal Hi-Hat 45. A,, Low Tom 46. ^A,, Open Hi-Hat
47. B,, Low-Mid Tom 48. C, Hi Mid Tom 49. ^C, Crash Cymbal 1
50. D, High Tom 51. ^D, Ride Cymbal 1 52. E, Chinese Cymbal
53. F, Ride Bell 54. ^F, Tambourine 55. G, Splash Cymbal
56. ^G, Cowbell 57. A, Crash Cymbal 2 58. ^A, Vibraslap
59. B, Ride Cymbal 2 60. C Hi Bongo 61. ^C Low Bongo
62. D Mute Hi Conga 63. ^D Open Hi Conga 64. E Low Conga
65. F High Timbale 66. ^F Low Timbale 67. G High Agogo
68. ^G Low Agogo 69. A Cabasa 70. ^A Maracas
71. B Short Whistle 72. c Long Whistle 73. ^c Short Guiro
74. d Long Guiro 75. ^d Claves 76. e Hi Wood Block
77. f Low Wood Block 78. ^f Mute Cuica 79. g Open Cuica
80. ^g Mute Triangle 81. a Open Triangle
T his manual explains how to make beautiful sheet
music and MIDI files using a computer, some free
and open source software, and the Abc 2 music no-
tation. It is aimed at musicians with some computer
expertise who don’t want to spend a lot of money
on commercial music software. Music teachers, stu-
dents, amateur and professional musicians may ben-
efit greatly from this guide and from the software it
describes.