Sustain
Functions responsible for applying the sustain pedal effect to a MIDI file.
apply_sustain(df, sustain, sustain_threshold=64)
Apply sustain pedal effects to the notes in a DataFrame.
This function uses a second DataFrame containing sustain pedal events to extend the duration of notes in the original DataFrame. It modifies the end times of notes that are held during the time when the sustain pedal is pressed down.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The DataFrame containing musical note data. Expected to have columns 'start', 'end', and 'pitch', where 'start' and 'end' represent the start and end times of the notes. |
required |
sustain
|
DataFrame
|
The DataFrame containing sustain pedal events. Expected to have columns 'time' and 'value', where 'time' is the timestamp of the pedal event and 'value' is the intensity of the pedal press. |
required |
sustain_threshold
|
int
|
The threshold value above which the sustain pedal is considered to be pressed down. Defaults to 64. |
64
|
Returns:
| Name | Type | Description |
|---|---|---|
df |
DataFrame
|
The modified DataFrame with updated end times for notes affected by the sustain pedal. |
Notes
- The sustain effect is applied by extending the end time of notes to either the start of the next note with the same pitch or the time when the sustain pedal is released, whichever comes first.
Source code in fortepyan/midi/tools.py
note_number_to_name(note_number)
Convert a MIDI note number to its name, in the format
'(note)(accidental)(octave number)' (e.g. 'C#4').
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
note_number
|
int
|
MIDI note number. If not an int, it will be rounded. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
note_name |
str
|
Name of the supplied MIDI note number. |
Source code in fortepyan/midi/tools.py
sustain_notes(df, pedal_down, pedal_up)
Extend the end times of notes affected by a sustain pedal down event.
This helper function is called by apply_sustain to process each group of sustain
pedal down events. It extends the end times of notes that are playing during the
sustain pedal down event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The DataFrame containing musical note data. Expected to have columns 'start', 'end', and 'pitch'. |
required |
pedal_down
|
float
|
The start time of the sustain pedal down event. |
required |
pedal_up
|
float
|
The end time of the sustain pedal down event, indicating when the pedal is released. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
df |
DataFrame
|
The DataFrame with updated end times for the notes affected by the sustain pedal. |