Functions for creating and checking lyrics objects.

lyrical(x)

as_lyrics(x, format = NULL)

is_lyrics(x)

lyrics_template(x, format = NULL)

Arguments

x

character or lyrics object. For lyrics_template(), an integer or one of the classes noteworthy, noteinfo or music to derive the number of timesteps from.

format

NULL or character, the timestep delimiter format, "space" or "vector".

Value

depends on the function

Details

The lyrics class is a simple class for arranging lyrics text by timestep. Its structure and behavior aligns with that of the classes noteworthy, noteinfo and music.

lyrical() is a trivial function that returns a scalar logical result essentially for any object that inherits from character, though this check may become more specific in the future.

as_lyrics() can be used to coerce to the lyrics class. Coercion will fail if the string is not lyrical. The lyrics class has its own print() and summary() methods.

When format = NULL, the timestep delimiter format is inferred from the lyrical string input.

Examples

# space-delimited lyrics; use periods for timesteps with no lyric
x <- "These are the ly- rics . . . to this song"
is_lyrics(x)
#> [1] FALSE
lyrical(x)
#> [1] TRUE
as_lyrics(x)
#> <Lyrics string>
#>   Format: space-delimited time
#>   Values: These are the ly- rics . . . to this song

# character vector; empty, period or NA for no lyric
x <- c("These", "are", "the", "ly-", "rics",
       "", ".", NA, "to", "this", "song") #
as_lyrics(x)
#> <Lyrics string>
#>   Format: vectorized time
#>   Values: These are the ly- rics . . . to this song

# generate empty lyrics object from noteworthy, noteinfo or music object
notes <- as_noteworthy("c d e d c r*3 e g c'")
x <- lyrics_template(notes)
x
#> <Lyrics string>
#>   Format: space-delimited time
#>   Values: . . . . . . . . . . .

x[1:5] <- strsplit("These are the ly- rics", " ")[[1]]
x[9:11] <- c("to", "this", "song")
x
#> <Lyrics string>
#>   Format: space-delimited time
#>   Values: These are the ly- rics . . . to this song

summary(x)
#> <Lyrics string>
#>   Timesteps: 11 (8 lyrics, 3 pauses)
#>   Format: space-delimited time
#>   Values: These are the ly- rics . . . to this song

attributes(x)
#> $steps
#> [1] 11
#> 
#> $n_lyric
#> [1] 8
#> 
#> $n_pause
#> [1] 3
#> 
#> $format
#> [1] "space-delimited time"
#> 
#> $class
#> [1] "lyrics"    "character"
#>