sjkabc¶
sjkabc.sjkabc¶
This module provides functionality for parsing ABC music notation.
copyright: |
|
---|---|
license: | BSD, see LICENSE for more details. |
-
sjkabc.
HEADER_KEYS
¶ Supported ABC notation header keys. This dict is used to populate the attributes of
Tune
.
-
sjkabc.
DECORATIONS
= ['!trill!', '!trill(!', '!trill)!', '!lowermordent!', '!uppermordent!', '!mordent!', '!pralltriller!', '!roll!', '!turn!', '!turnx!', '!invertedturn!', '!invertedturnx!', '!arpeggio!', '!>!', '!accent!', '!emphasis!', '!fermata!', '!invertedfermata!', '!tenuto!', '!0!', '!1!', '!2!', '!3!', '!4!', '!5!', '!+!', '!plus!', '!snap!', '!slide!', '!wedge!', '!upbow!', '!downbow!', '!open!', '!thumb!', '!breath!', '!pppp!', '!ppp!', '!pp!', '!p!', '!mp!', '!mf!', '!f!', '!ff!', '!fff!', '!ffff!', '!sfz!', '!crescendo(!', '!<(!', '!crescendo)!', '!<)!', '!diminuendo(!', '!>(!', '!diminuendo)!', '!>)!', '!segno!', '!coda!', '!D.S.!', '!D.C.!', '!dacoda!', '!dacapo!', '!fine!', '!shortphrase!', '!mediumphrase!', '!longphrase!', '.', '~', 'H', 'L', 'M', 'O', 'P', 'S', 'T', 'u', 'v']¶ List of decoration symbols according to the ABC notation standard v2.1.
-
class
sjkabc.
Parser
(abc=None)[source]¶ This class provides iterable parsing capabilities.
Parser must be initialised with a string containing ABC music notation. This class is iterable and will return a Tune object for every tune found in the provided ABC notation.
Example:
>>> for tune in Parser(abc): ... print('Parsed ', tune.title)
See also
-
class
sjkabc.
Tune
(**kwargs)[source]¶ This class represents a parsed tune.
Its attributes are generated from
HEADER_KEYS
, with the addition ofabc
andexpanded_abc()
.Example:
>>> t = Tune() >>> t.title = 'Example tune' >>> t.abc = '|:abc abc:|' >>> t.expanded_abc 'abcabcabcabc'
See also
-
abc
= None¶ Tune body.
-
expanded_abc
¶ Expanded ABC suitable for searching
Returns: expanded abc Return type: str
-
-
sjkabc.
expand_abc
(abc)[source]¶ Create searchable abc string
This runs all the stripping and expanding functions on the input string, and also makes it lowercase.
Parameters: abc (str) – string of abc to expand Returns: string of expanded abc Return type: str
-
sjkabc.
expand_notes
(abc)[source]¶ Expand notes, so that E2 becomes EE et.c.
Parameters: abc (str) – abc to expand Returns: expanded abc Return type: str
-
sjkabc.
expand_parts
(abc)[source]¶ Expand repeats with support for (two) alternate endings.
Example:
>>> print(expand_parts('aaa|bbb|1ccc:|2ddd|]')) aaa|bbb|ccc|aaa|bbb|ddd|
Parameters: abc (str) – abc to expand Returns: expanded abc Return type: str
-
sjkabc.
get_field_from_id
(id)[source]¶ Get long field name from id char.
Parameters: id (str) – id char, for example ‘T’ Returns: long field name, like ‘title’ Return type: str
-
sjkabc.
get_id_from_field
(field)[source]¶ Get id char from field name
Parameters: field (str) – ‘long’ name of field, for example ‘title’ Returns: id character, for example ‘T’ Return type: str
-
sjkabc.
parse_dir
(dir)[source]¶ Run
Parser
on every file with .abc extension in dirParameters: dir – Directory of abc files Returns: Tune
object for every found fileReturn type: Tune
See also
-
sjkabc.
parse_file
(filename)[source]¶ Run Parser on file contents
This function is iterable.
Example: >>> for tune in parse_file('test.abc'): ... print(tune.title)
Parameters: filename – Name of file to parse
Returns: Tune
object for every found tune.Return type: See also
-
sjkabc.
strip_accidentals
(abc)[source]¶ Remove accidentals from string.
Example:
>>> from sjkabc import strip_accidentals >>> stripped = strip_whitespace('abc ^c=de|_e^fg _g=fe') >>> stripped 'abc cde|efg gfe'
Parameters: abc (str) – abc to filter Returns: abc with accidentals removed Return type: str
-
sjkabc.
strip_bar_dividers
(abc)[source]¶ Strip bar dividers from string
This function can safely be run before expand_parts, as it won’t remove repeats.
Example:
>>> from sjkabc import strip_bar_dividers >>> stripped = strip_bar_dividers('abcd bcde|bcde abcd|defg abcd|bebe baba') >>> stripped 'abcd bcdebcde abcddefg abcdbebe baba'
Parameters: abc (str) – abc to filter Returns: abc without bar dividers Return type: str
-
sjkabc.
strip_chords
(abc)[source]¶ Strip chords and ‘guitar chords’ from string.
Example:
>>> from sjkabc import strip_chords >>> stripped = strip_chords('"G" abc|"Em" bcd|[GBd] cde') >>> stripped ' abc| bcd | cde'
Parameters: abc (str) – abc to filter Returns: abc with chords stripped Return type: str
-
sjkabc.
strip_decorations
(abc)[source]¶ Remove decorations
Removes decorations defined in the v2.1 ABC notation standard.
Parameters: abc (str) – ABC notation to process Returns: stripped ABC Return type: str See also
New in version 1.2.0.
-
sjkabc.
strip_extra_chars
(abc)[source]¶ Strip misc extra chars (/<>)
Parameters: abc (str) – abc to filter Returns: filtered abc Return type: str
-
sjkabc.
strip_gracenotes
(abc)[source]¶ Remove gracenotes
Example:
>>> stripped = strip_gracenotes('abc bcd|c3 def|{/def}efg abc|') >>> stripped 'abc bcd|c3 def|efg abc|'
Parameters: abc (str) – abc to strip Returns: abc stripped from gracenotes Return type: str
-
sjkabc.
strip_octave
(abc)[source]¶ Remove octave specifiers from string.
Example:
>>> from sjkabc import strip_octave >>> stripped = strip_octave("A,B,C,d'e'f'") >>> stripped 'ABCdef'
Parameters: abc (str) – abc to filter Returns: abc with octave specifiers removed Return type: str
-
sjkabc.
strip_ornaments
(abc)[source]¶ Remove gracenotes, tildes, trills, turns and fermatas from string.
Example:
>>> from sjkabc import strip_ornaments >>> stripped = strip_ornaments('abc bcd|~c3 def|{/def}efg !trill(!abc|') >>> stripped 'abc bcd|c3 def|efg abc|'
Parameters: abc (str) – abc to filter Returns: filtered abc Return type: str Deprecated since version 1.2.0: Use
strip_gracenotes()
andstrip_decorations()
instead.
-
sjkabc.
strip_slurs
(abc)[source]¶ Remove slurs from string.
Example:
>>> strip_slurs('|:ab(cd) (a(bc)d):|') |:abcd abcd:|
Warning
Don’t use this before
strip_decorations()
as it may change certain decorations so that they wont be recognized. One example would be !trill(!.Parameters: abc (str) – abc to manipulate Returns: abc stripped from slurs Return type: str
-
sjkabc.
strip_triplets
(abc)[source]¶ Remove duplets, triplets, quadruplets, etc from string.
Please note that this simply removes the (n and leaves the following notes.
Example:
>>> from sjkabc import strip_triplets >>> stripped = strip_triplets('AB(3cBA Bcde|fd(3ddd (4efed (4BdBF') >>> stripped 'ABcBA Bcde|fdddd efed BdBF'
Parameters: abc (str) – abc to filter Returns: abc without triplets Return type: str