There are a number of functions that assist with music programming around note and pitch validation, comparison, equivalence checking, and various manipulations and transformations. In a previous section, you saw `is_note`

and `is_chord`

. Other identity functions include:

`note_is_natural`

`note_is_accidental`

`note_is_flat`

`note_is_sharp`

`is_diatonic`

```
#> [1] TRUE FALSE TRUE FALSE
```

```
#> [1] FALSE TRUE FALSE TRUE
```

```
#> [1] FALSE TRUE FALSE TRUE
```

```
#> [1] FALSE FALSE FALSE FALSE
```

These `note_is_*`

functions strictly accept notes. There is also `is_diatonic`

, which less strictly requires any noteworthy string. It can be applied to notes and chords alike. Given the name, it is slightly less basic than the prior functions. It takes a `key`

signature for context.

```
#> [1] TRUE FALSE TRUE FALSE FALSE
```

```
#> [1] TRUE TRUE TRUE TRUE FALSE
```

There are a number of functions that summarize the data in noteworthy strings. Here are several examples.

`n_steps`

`n_notes`

`n_chords`

`n_octaves`

`tally_notes`

`tally_pitches`

`tally_octaves`

`distinct_notes`

`distinct_pitches`

`distinct_octaves`

`pitch_range`

`semitone_range`

`semitone_span`

`octave_range`

`octave_span`

`octave_type`

`accidental_type`

`time_format`

`is_space_time`

`is_vector_time`

See `?note-metadata`

for details. A few examples are shown here:

```
#> # A tibble: 6 x 2
#> note n
#> <chr> <int>
#> 1 c# 2
#> 2 e_ 1
#> 3 f# 2
#> 4 a_ 1
#> 5 a# 2
#> 6 b_ 1
```

```
#> # A tibble: 9 x 2
#> pitch n
#> <chr> <int>
#> 1 e_2 1
#> 2 a_, 1
#> 3 b_, 1
#> 4 c# 1
#> 5 f# 1
#> 6 a# 1
#> 7 c#' 1
#> 8 f#' 1
#> 9 a#'' 1
```

```
#> <Noteworthy string>
#> Format: space-delimited time
#> Values: c# e_ f# a_ a# b_
```

```
#> <Noteworthy string>
#> Format: space-delimited time
#> Values: e_2 a_, b_, c# f# a# c#' f#' a#''
```

```
#> [1] "e_2" "a#''"
```

```
#> [1] 39 82
```

Note that it is common for functions to treat notes as different if they sound the same but one is transcribed as a flat and the other as a sharp. `tabr`

makes the distinction for notation purposes; same pitch, different notes. This also supports transcription. Functions like `transpose`

of course handle pitch as pitch and therefore the style of representation does not affect computation.

There are functions for enforcing a singular representation for accidentals in noteworthy strings since it is unusual to mix flats and sharps.

```
#> <Noteworthy string>
#> Format: space-delimited time
#> Values: e_, a_, b_, <d_g_b_> <d_'g_'b_''>
```

```
#> <Noteworthy string>
#> Format: space-delimited time
#> Values: d#, g#, a#, <c#f#a#> <c#'f#'a#''>
```

Do not be confused about the names of these functions. They are for enforcing a single type of accidental. To actually lower sharps by a half step or semitone as well as raise flats similarly, use `naturalize`

.

```
#> <Noteworthy string>
#> Format: space-delimited time
#> Values: e2 a, b, <cfa> <c'f'a''>
```

These are helpful building blocks for music programming. A useful wrapper around `flatten_sharp`

and `sharpen_flat`

is `note_set_key`

. Like `is_diatonic`

, this function takes a `key`

argument. Providing a key signature is often used in `tabr`

functions for the purpose of enforcing the correct representation of accidentals intended by the user, which `tabr`

cannot know until informed.

Be aware that the default for functions that take a `key`

argument is `c`

, but `c`

and `am`

have no accidentals in their key signatures, so `note_set_key`

will have no effect if you pass these values to `key`

. It is also important to recognize that it does not matter for this function what key you choose specifically; it only matters that you choose a key that has the type of accidentals in its signature that you wish to force your noteworthy string to use. If you want flats, it makes no difference if you set `key = "f"`

or `key = "b_"`

. For this function, you can also literally enter `key = "flat"`

or `key = "sharp"`

, options that stress the extent to which `key`

actually matters to `note_set_key`

.

```
#> <Noteworthy string>
#> Format: space-delimited time
#> Values: e_2 a_, b_, <c#f#a#> <c#'f#'a#''>
```

```
#> <Noteworthy string>
#> Format: space-delimited time
#> Values: e_, a_, b_, <d_g_b_> <d_'g_'b_''>
```

```
#> <Noteworthy string>
#> Format: space-delimited time
#> Values: d#, g#, a#, <c#f#a#> <c#'f#'a#''>
```

The intent is not to force notes which may not be diatonic to the key signature to fit that signature. All pitches remain exactly what they are. It does not matter if they are not in the key. But they are forced to conform to a key’s representation of accidentals.

For other functions in `tabr`

, `key`

arguments utilize the specific key signature in a more complete manner, and the options `flat`

and `sharp`

are not relevant or allowed.

Octave numbering can be ambiguous, including both tick and integer numbering format. You can coerce a noteworthy string strictly to one of the other:

```
#> <Noteworthy string>
#> Format: space-delimited time
#> Values: c2 c c4 c2 c c4
```

```
#> <Noteworthy string>
#> Format: space-delimited time
#> Values: c, c c' c, c c'
```

Similarly, you can coerce the time format of a noteworthy string between space-delimited time and vectorized time:

```
#> <Noteworthy string>
#> Format: space-delimited time
#> Values: c e g <ceg>
```

```
#> <Noteworthy string>
#> Format: vectorized time
#> Values: c e g <ceg>
```

```
#> [1] "c e g ceg"
```

```
#> [1] "c" "e" "g" "ceg"
```

The `note_is_*`

functions mentioned earlier are vectorized, but the operations they perform are self checks. Other functions are available for comparative checks of identity or equivalence between two notes. These functions are also vectorized. Each note input can be an entire noteworthy string.

There are different dimensions along which the strictness of equality varies and are worth taking a moment to break these and other properties down clearly:

- These functions come in
`*_is_equal`

and`*is_identical`

pairs. Equality is more relaxed than identity. - The
`note_is_*`

pairs below also offer the argument`ignore_octave`

. This further weakens the requirements for passing both equality and identity comparisons of two notes. - These functions perform a noteworthy check, but do not require anything stricter. This means these comparisons work on all notes, even those belonging to chords.
- The general distinction between notes being equal and notes being identical is sound vs. transcription/written notation. If two notes sound the same, e.g.
`e_`

and`d#`

, they are equal, but not identical. - There are additional nuances with octave comparisons using the
`octave_is_*`

pairs.

First look at note and pitch comparisons. The main difference is that pitch is more complete than note in that the former implicitly carries the octave position. Setting `ignore_octave = FALSE`

for note comparisons makes them equivalent to their pitch comparison counterparts.

```
#> [1] TRUE TRUE
```

```
#> [1] TRUE FALSE
```

```
#> [1] FALSE TRUE
```

```
#> [1] FALSE FALSE
```

There are minimal requirements for equivalence that precede the forms and degrees of equivalence described and shown above. At a bare minimum, two noteworthy strings must have the same number of time steps available for pairwise comparison. Otherwise a simple `NA`

is returned. In the following example, the strings `x`

and `y`

have the same number of notes, in the same order, but the first has three times steps and the second has two.

```
#> [1] NA
```

In the next example, `x`

and `y`

have the same number of of the same notes, again in the same order, and even have an equal number of timesteps. Having the same number of timesteps makes pairwise comparisons possible. They return `FALSE`

where unequal.

```
#> [1] TRUE FALSE FALSE
```

Finally, there are octave comparisons, which must be defined and behave somewhat differently. `octave_is_equal`

and `octave_is_identical`

allow much weaker forms of equivalence in that they ignore notes completely. These functions are only concerned with comparing the octave numbers spanned by any pitches present at each timestep.

When checking for equality, `octave_is_equal`

only looks at the octave number associated with the first note at each step, e.g., only the root note of a chord. `octave_is_identical`

compares all octaves spanned at a given timestep by considering all notes when a chord is present.

This still leaves open the definitions of equivalence. To clarify:

- It does not matter when comparing two chords that they may be comprised of a different numbers of notes.
- If the set of unique octaves spanned by one chord is identical to the set spanned by the other, they are considered to have identical octave coverage.

Consider an example: `a1b2c3`

is identical to `d1e1f2g3`

. The notes are irrelevant. The number of notes is irrelevant. The fact that octave number one occurs a different number of times in each chord is irrelevant. What matters is that they both have the same set of unique octave positions `{1, 2, 3}`

. To be equal, even less is required. In this case it only matters that the two chords begin with `x1`

, where `x`

is any note.

One alternative, for `octave_is_identical`

only, is to set `single_octave = TRUE`

. This increases the requirement for identity to require that all notes from both chords being compared at a given timestep share a single octave.

```
#> [1] FALSE TRUE TRUE TRUE TRUE
```

```
#> [1] FALSE TRUE TRUE FALSE TRUE
```

```
#> [1] FALSE TRUE FALSE FALSE TRUE
```

A noteworthy string can be subset by index. This can with specific integers or with a logical vector with the same length as the number of time steps.

```
#> <Noteworthy string>
#> Format: space-delimited time
#> Values: b <ceg>
```

```
#> <Noteworthy string>
#> Format: space-delimited time
#> Values: b <ceg>
```

Vectorized time is more trivial but is of course handled the same way and still applies the noteworthiness check and class assignment.

```
#> <Noteworthy string>
#> Format: vectorized time
#> Values: b <ceg>
```

```
#> <Noteworthy string>
#> Format: vectorized time
#> Values: b <ceg>
```

Rotating or cycling a sequence of notes and chords in a noteworthy string is done with `note_rotate`

. This is a simple function. It only rotates the sequence left or right. It does not do any transposition. It does not break chords, but rather rotates them intact.

```
#> <Noteworthy string>
#> Format: vectorized time
#> Values: b <ceg> a
```

```
#> <Noteworthy string>
#> Format: vectorized time
#> Values: <ceg> a b
```

`note_shft`

only operates on notes, not chords, but is a more complex function. It also rotates notes, but it maintains a consistent direction of increasing or decreasing pitch. The direction is determined by `n`

being negative or positive.

This function is intended for use on strings of notes that are already ordered by increasing pitch. However, if applied to a sequence of unordered notes, the sequence will eventually become ordered if `n`

is large enough, because each shift transposes the current lowest note by however many full octaves necessary to be above the current highest note and as close to it as possible.

```
#> <Noteworthy string>
#> Format: space-delimited time
#> Values: e g c4
```

```
#> <Noteworthy string>
#> Format: space-delimited time
#> Values: g1 c2 e2
```

`note_arpeggiate`

is like `note_shift`

but it extends the original note sequence rather than shifting it and maintaining its fixed size. `n`

refers to the number of additional notes to append to the sequence. The length of the final sequence is the length of the original sequence plus `n`

.

```
#> <Noteworthy string>
#> Format: space-delimited time
#> Values: c e g c4 e4 g4 c5 e5
```

```
#> <Noteworthy string>
#> Format: space-delimited time
#> Values: e1 g1 c2 e2 g2 c e g
```

The next section on music programming covers various helper functions related to chords.