R/2-add-lyric.R

Defines functions add.Lyric

Documented in add.Lyric

#' @keywords internal
#' @export
add.Lyric <- function(object, music) {
  to <- object$to
  i <- object$i
  lines <- music$lines
  lyrics <- music$lyrics

  # Validation
  check_add_to(to, lines, object)
  line <- normalize_to(to, lines)
  check_i(i, line, music$notes)

  # Normalization
  names(object)[names(object) == "to"] <- "line"
  object$line <- line
  if (is.null(object$verse)) object$verse <- 1L

  # Construction
  to_remove <-
    lyrics$line == line &
    lyrics$verse == object$verse &
    lyrics$i == i

  music$lyrics <- rbind(lyrics[!(to_remove), ], to_case(object))
  music
}

Try the gm package in your browser

Any scripts or data that you put into this service are public.

gm documentation built on Sept. 11, 2024, 6:11 p.m.