n_measures: Summarize rhythm and time of music objects

View source: R/time.R

n_measuresR Documentation

Summarize rhythm and time of music objects

Description

These functions assist with summarizing temporal data for music objects.

Usage

n_measures(x)

n_beats(x, unit = 4)

steps_per_measure(x)

bpm(x, unit = 4, tempo = NULL)

seconds(x, tempo = NULL)

seconds_per_measure(x, tempo = NULL)

seconds_per_step(x, tempo = NULL)

steps_start_time(x, tempo = NULL)

Arguments

x

note info or music object.

unit

character, or an equivalent integer. A beat unit. See details.

tempo

character, LilyPond format tempo, e.g., "4 = 120" is 120 quarter note beats per minute.

Details

These functions also work with the simpler noteinfo class, though some functions require you to provide additional arguments.

Functions that deal with real time require a known tempo, which music objects have. The simpler note info object does not contain this information. You can provide a value to the tempo argument of such functions. This overrides the tempo of x if a music object. But the reason to use tempo is to provide one when x is a note info object. By default tempo = NULL, in which case it will derive the value from the music object or return an error for note info objects.

n_measures() gives the total number of measures covered by all timesteps. Functions providing the number of beats and beats per minute both take a unit, defaulting to 4 for quarter note beats. The unit can be any even beat, triplet beat, dotted, or double dotted beat, from "t32" up to 1.

The number of timesteps starting in each measure is obtained with steps_per_measure().

Value

depends on function

Examples

a <- notate("t8x", "Start here")
notes <- "a, b, c d e f g# a r ac'e' a c' e' c' r*3 ac'e'~ ac'e'"
info <- paste(a, "t8x t8-. 16 4.. 16- 16 2^ 2 4. 8( 4)( 4) 8*4 1 1")
info <- as_noteinfo(info)
x <- as_music(notes, info)

n_measures(info) # fraction indicates incomplete final measure
n_measures(x)

n_beats(x)
n_beats(x, 1)
n_beats(x, "t16")

bpm(x)
bpm(x, "t8")

seconds(x)
seconds(info, "4 = 120")
seconds(info, "2 = 60")
seconds(x, "4 = 100")

steps_per_measure(x)
seconds_per_measure(x)
seconds_per_step(x)
steps_start_time(x)

tabr documentation built on Sept. 12, 2024, 6:18 a.m.