Helper functions for concatenating musical phrases and other strings together as well as repetition. The functions pc and pn are based on base functions paste andrep, respectively, but are tailored for efficiency in creating musical phrases.

pc(...)

pn(x, n = 1)

Arguments

...

character, phrase or non-phrase string.

x

character, phrase or non-phrase string.

n

integer, number of repetitions.

Value

phrase on non-phrase character string, noteworthy string if applicable.

Details

These functions respect and retain the phrase class when applied to phrases. They are aggressive for phrases and secondarily for noteworthy strings. Combining a phrase with a non-phrase string will assume compatibility and result in a new phrase object. If no phrase objects are present, the presence of any noteworthy string will in turn attempt to force conversion of all strings to noteworthy strings. The aggressiveness provides convenience, but is counter to expected coercion rules. It is up to the user to ensure all inputs can be forced into the more specific child class.

This is especially useful for repeated instances. This function applies to general slur notation as well. Multiple input formats are allowed. Total number of note durations must be even because all slurs require start and stop points.

Examples

pc(8, "16-", "8^")
#> [1] "8 16- 8^"
pn(1, 2)
#> [1] "1 1"
x <- phrase("c ec'g' ec'g'", "4 4 2", "5 432 432") y <- phrase("a", 1, 5) pc(x, y)
#> <Musical phrase> #> <c\5>4 <e\4 c'\3 g'\2>4 <e\4 c'\3 g'\2>2 <a\5>1
pc(x, pn(y, 2))
#> <Musical phrase> #> <c\5>4 <e\4 c'\3 g'\2>4 <e\4 c'\3 g'\2>2 <a\5>1 <a\5>1
pc(x, "r1") # add a simple rest instance
#> <Musical phrase> #> <c\5>4 <e\4 c'\3 g'\2>4 <e\4 c'\3 g'\2>2 r1
class(pc(x, y))
#> [1] "phrase" "character"
class(pn(y, 2))
#> [1] "phrase" "character"
class(pc(x, "r1"))
#> [1] "phrase" "character"
class(pn("r1", 2))
#> [1] "character"
class(pc("r1", "r4"))
#> [1] "character"