| Title: | Seamless Data Sonification with 'ggplot2' |
|---|---|
| Description: | Provides a simple framework for data sonification in R, mapping 'ggplot2'-style aesthetics to MIDI events. Designed for creative exploration rather than strict auditory data analysis. |
| Authors: | Akiru Kato [aut, cre], Craig Stuart Sapp [cph] |
| Maintainer: | Akiru Kato <[email protected]> |
| License: | BSD_2_clause + file LICENSE |
| Version: | 0.0.2 |
| Built: | 2026-05-02 07:48:57 UTC |
| Source: | https://github.com/paithiov909/pipopaplot |
as_notes() converts an arbitrary data frame or a ggplot object into
a tibble containing the required columns for MIDI sonification:
x, y, channel, group, duration, and velocity.
as_notes(d, ...) ## Default S3 method: as_notes(d, ...) ## S3 method for class 'ggplot' as_notes(d, ..., .id = 1)as_notes(d, ...) ## Default S3 method: as_notes(d, ...) ## S3 method for class 'ggplot' as_notes(d, ..., .id = 1)
d |
A data frame or a |
... |
Optional name mappings.
Provide named arguments to override the default column names
(e.g., |
.id |
Layer index to extract from a ggplot object. Defaults to |
The returned tibble serves as the standard 'notes' format accepted by sonify().
Numeric or logical columns are converted to numeric and missing values are replaced with 1.
A tibble with columns:
x, y – coordinate-like values to be mapped to time and pitch
channel – grouping for MIDI channels
group – sub-group within each channel
duration, velocity – numeric modifiers for note length and intensity
rollup() provides a simple mechanism to summarize or reshape
note-level data prior to sonification.
By default, it performs numeric aggregation within each
(channel, group, by) combination.
rollup(d, by, .fun = base::mean)rollup(d, by, .fun = base::mean)
d |
A data frame returned by |
by |
A variable or expression used for grouping within each
|
.fun |
A summary function applied to numeric columns.
Defaults to |
Although rollup() uses summarization by default,
any transformation that returns a data frame with the expected
columns will work in a sonification pipeline.
Users can define their own custom rollup functions,
including those that duplicate rows to generate chords or
parallel voices.
A data frame containing the same key columns
(x, y, channel, group, duration, velocity)
and suitable for use in sonify().
sonify() transforms a notes tibble into a structured data frame of
note-on and note-off events that can be written to a Standard MIDI file
via write_midi().
sonify( notes, phrase_len = 4, tpq = 480, pitch_range = c(27, 102), vel_range = c(60, 100), duration_range = c(16, 4), offset = 0.1 )sonify( notes, phrase_len = 4, tpq = 480, pitch_range = c(27, 102), vel_range = c(60, 100), duration_range = c(16, 4), offset = 0.1 )
notes |
A tibble containing columns
|
phrase_len |
Length of the phrase in beats. |
tpq |
Ticks per quarter note. |
pitch_range |
Range of MIDI note numbers to map |
vel_range |
Range of MIDI velocities to map |
duration_range |
Range of note durations (in ticks) mapped from |
offset |
Padding fraction for mapping |
Value scaling is handled by scales::rescale(), so the input value ranges
are arbitrary but must be finite.
Note that because of this rescaling behavior, a velocity value of 0
will not be mapped to complete silence by default (i.e., the minimum input
value will still be mapped to the lower bound of vel_range rather than 0).
Within each channel, duplicated timing values (x) are deduplicated
using dplyr::distinct().
To produce simultaneous notes (like chords), you must assign different
channel values in advance.
A data frame with factor and integer columns:
channel, group, tick_on, tick_off, pitch, and velocity.
Suitable as input to write_midi().
Write a data frame of notes to a Standard MIDI file
write_midi(notes, filename = "test.mid", opt = list())write_midi(notes, filename = "test.mid", opt = list())
notes |
A data frame containing columns
|
filename |
Name of the output file. |
opt |
A list of options. |
The path to the output file is invisibly returned.