Create a musical phrase from character strings that define notes, note metadata, and optionally explicit strings fretted. The latter can be used to ensure proper tablature layout.
phrase(notes, info = NULL, string = NULL, bar = NULL)
p(notes, info = NULL, string = NULL, bar = NULL)
noteworthy and note info strings. When info = NULL
,
it is assumed that notes
refers to a music object or string formatted
as such.
space-delimited character string or vector (or integer vector
if simple string numbers). This is an optional argument that specifies which
instrument strings to play for each specific timestep. Otherwise NULL
.
character or NULL
(default). Terminates the phrase with a
bar or bar check. See details. Also see the LilyPond help documentation
on bar notation for all the valid options.
a phrase.
A phrase object combines a valid string of notes with a corresponding valid
string of note info. The only required note info is time, but other
information can be included as well. You do not need to input an existing
noteworthy
class object and noteinfo
class object, but both
inputs must be valid and thus coercible to these classes. This is similar to
how the music
class works. The difference with phrase objects is that
they are used to create LilyPond syntax analogous to what a music object
contains.
Note that if you convert a music object to a phrase object, you are changing
contexts. The phrase object is the simplest LilyPond-format music structure.
Coercion with phrase()
strips all attributes of a music object and
retains only notes, note info and string numbers.
See the help documentation on noteworthy
, noteinfo
, and
music
classes for an understanding of the input data structures.
The function p()
is a convenient shorthand wrapper for phrase()
.
If a string is provided to bar
, it is interpreted as LilyPond bar
notation. E.g., bar = "|"
adds the LilyPond syntax \bar "|"
to the end of a phrase. If only a bar check is desired, use
bar = TRUE
. FALSE
is treated as NULL
for completeness.
phrase("c ec'g' ec'g'", "4- 4 2") # no string arg (not recommended for tabs)
#> <Musical phrase>
#> <c>4\glissando <e c' g'>4 <e c' g'>2
phrase("c ec4g4 ec4g4", "4 4 2") # same as above
#> <Musical phrase>
#> <c>4 <e c' g'>4 <e c' g'>2
phrase("c b, c", "4. 8( 8)", "5 5 5") # direction implies hammer on
#> <Musical phrase>
#> <c\5>4. <b,\5>8( <c\5>8)
phrase("b2 c d", "4( 4)- 2", "5 5 5") # hammer and slide
#> <Musical phrase>
#> <b,\5>4( <c\5>4)\glissando <d\5>2
phrase("c ec'g' ec'g'", "1 1 1", "5 432 432")
#> <Musical phrase>
#> <c\5>1 <e\4 c'\3 g'\2>1 <e\4 c'\3 g'\2>1
p("c ec'g' ec'g'", 1, "5 4 4") # same as above
#> <Musical phrase>
#> <c\5>1 <e\4 c'\3 g'\2>1 <e\4 c'\3 g'\2>1
n <- "a, b, c d e f g e f g a~ a"
i <- "8- 8 8 8-. t8( t8)( t8) t16( t16)( t16) 8 1"
m <- as_music(n, i)
x <- p(n, i)
x
#> <Musical phrase>
#> <a,>8\glissando <b,>8 <c>8 <d>8-. \tuplet 3/2 4 { <e>8( <f>8)( <g>8) } \tuplet 3/2 8 { <e>16( <f>16)( <g>16) } <a~>8 <a>1
identical(x, p(m))
#> [1] TRUE
x <- "a,4;5*5 b,4- c4 cgc'e'~4 cgc'e'1 e'4;2 c';3 g;4 c;5 ce'1;51"
p(x)
#> <Musical phrase>
#> <a,\5>4 <a,\5>4 <a,\5>4 <a,\5>4 <a,\5>4 <b,\5>4\glissando <c\5>4 <c~\5 g~\4 c'~\3 e'~\2>4 <c\5 g\4 c'\3 e'\2>1 <e'\2>4 <c'\3>4 <g\4>4 <c\5>4 <c\5 e'\1>1
identical(p(x), p(as_music(x)))
#> [1] TRUE
x <- p("a b", 2, bar = "|.")
x2 <- pc(p("a b", 2), '\\bar "|."')
identical(x, x2)
#> [1] TRUE