These functions assist with summarizing temporal data for music objects.

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.

Value

depends on function

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().

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
#> [1] 5.375
n_measures(x)
#> [1] 5.375

n_beats(x)
#> [1] 21.5
n_beats(x, 1)
#> [1] 5.375
n_beats(x, "t16")
#> [1] 129

bpm(x)
#> [1] 120
bpm(x, "t8")
#> [1] 360

seconds(x)
#> [1] 10.75
seconds(info, "4 = 120")
#> [1] 10.75
seconds(info, "2 = 60")
#> [1] 10.75
seconds(x, "4 = 100")
#> [1] 12.9

steps_per_measure(x)
#> # A tibble: 5 × 2
#>   measure steps
#>     <int> <int>
#> 1       1     8
#> 2       2     2
#> 3       3     4
#> 4       4     4
#> 5       5     1
seconds_per_measure(x)
#> [1] 2
seconds_per_step(x)
#>  [1] 0.1666667 0.1666667 0.1666667 0.1250000 0.8750000 0.1250000 0.1250000
#>  [8] 1.0000000 1.0000000 0.7500000 0.2500000 0.5000000 0.5000000 0.2500000
#> [15] 0.2500000 0.2500000 0.2500000 2.0000000 2.0000000
steps_start_time(x)
#>  [1] 0.0000000 0.1666667 0.3333333 0.5000000 0.6250000 1.5000000 1.6250000
#>  [8] 1.7500000 2.7500000 3.7500000 4.5000000 4.7500000 5.2500000 5.7500000
#> [15] 6.0000000 6.2500000 6.5000000 6.7500000 8.7500000