time: Clock-time representations of duration

timeR Documentation

Clock-time representations of duration

Description

These functions convert duration values to clock-time representations. seconds() and ms() output numeric values. dur() outputs a character string encoding the humdrum **dur representation of time.

If seconds() is applied to a humdrumR data class you may use the data's fields as arguments. If no field names are specified, the first selectedField is used as x.

If ms() is applied to a humdrumR data class you may use the data's fields as arguments. If no field names are specified, the first selectedField is used as x.

If dur() is applied to a humdrumR data class you may use the data's fields as arguments. If no field names are specified, the first selectedField is used as x.

Usage

## Default S3 method:
seconds(
  x,
  ...,
  BPM = "*M60",
  parseArgs = list(),
  scale = 1,
  unit = 1,
  inPlace = FALSE
)

humData |> select(Token) |> seconds() 
humData |> seconds(Token)

seconds(
  x,
  ...,
  BPM = "*M60",
  parseArgs = list(),
  scale = 1,
  unit = 1,
  inPlace = FALSE
)

## Default S3 method:
ms(
  x,
  ...,
  BPM = "*M60",
  parseArgs = list(),
  scale = 1,
  unit = 1,
  inPlace = FALSE
)

humData |> select(Token) |> ms() 
humData |> ms(Token)

ms(
  x,
  ...,
  BPM = "*M60",
  parseArgs = list(),
  scale = 1,
  unit = 1,
  inPlace = FALSE
)

## Default S3 method:
dur(
  x,
  ...,
  BPM = "*M60",
  minutes = FALSE,
  hours = FALSE,
  days = FALSE,
  months = FALSE,
  years = FALSE,
  parseArgs = list(),
  scale = 1,
  unit = 1,
  inPlace = FALSE
)

humData |> select(Token) |> dur() 
humData |> dur(Token)

dur(
  x,
  ...,
  BPM = "*M60",
  minutes = FALSE,
  hours = FALSE,
  days = FALSE,
  months = FALSE,
  years = FALSE,
  parseArgs = list(),
  scale = 1,
  unit = 1,
  inPlace = FALSE
)

Arguments

x

An input vector.

The x argument can be any (atomic) vector, or a rational (rhythmInterval), or NULL.

Must be parsable as rhythm infromation.

...

Arguments passed to the rhythm parser.

There are also two hidden (advanced) arguments you can specify: memoize and deparse (see the details below).

scale

A numeric or rational value which is used as the output unit of measurement.

Defaults to rational(1, 1).

Must be numeric or rational.

inPlace

Should non-rhythm information be retained in the output string?

Defaults to FALSE.

Must be a singleton logical value: an on/off switch.

Defaults to FALSE.

A singleton logical value, or NA.

See "Grace notes" section below.

minutes

(logical, T/F) Should the dur output include minutes?

hours

(logical, T/F) Should the dur output include hours?

days

(logical, T/F) Should the dur output include days?

months

(logical, T/F) Should the dur output include months?

years

(logical, T/F) Should the dur output include years?

Details

These functions require a BPM (beats-per-minute) argument to be specified. By default, the value is 60 bpm.

dur

The **dur output can be modified to include different clock-time units: The minutes, hours, days, months, and years arguments are all true/false logical arguments, indicating whether to use that unit in the output (all default to FALSE). For example, if minutes = FALSE, an input of 90 seconds will return ":90" (90 seconds!), but if minutes = TRUE, the output will be ⁠:1:30⁠ (one minute and thirty seconds).

See Also

To better understand how this function works, read about the family of rhythm functions, or how rhythms are parsed and deparsed.

Other time functions: bpm2sec()

Examples


tokens <- c('4.GG', '8G', '16E', '16F#', '16G', '16D', 'q8D#', '4E')

seconds(tokens)
seconds(tokens, BPM = '90')
ms(tokens, BPM = '90')
dur(tokens)

wholenotes <- c(10, 30, 90, 310, 5000)
dur(wholenotes)
dur(wholenotes, minutes = TRUE)
dur(wholenotes, minutes = TRUE, hours = TRUE)

quarternotes <- c(10, 30, 90, 310, 5000)
dur(quarternotes, minutes = TRUE, BPM = '120', parse(unit = '4'))

## Not run: 
B075 <- readHumdrum(humdrumRroot, "HumdrumData/BeethovenVariations/B075_00_05_a.krn")

with(B075[[,3:4]], seconds(Token))

## End(Not run)



Computational-Cognitive-Musicology-Lab/humdrumR documentation built on Oct. 22, 2024, 9:28 a.m.