Midipy
A Python package for MIDI data processing, analysis, and parsing.
Overview
Midipy provides tools to read, analyze, and process MIDI files. This package decodes MIDI data, extracts musical features, and enables parsing of multiple MIDI files within a directory. It’s ideal for music data analysis, educational projects, and MIDI-related applications in Python.
Features
- Read MIDI files: Parse and load MIDI files for analysis.
- Analyze MIDI data: Extract information such as note counts, velocities, and asynchrony.
- Batch processing: Process multiple MIDI files from a specified directory.
- Segment-wise Analysis: Perform analyses on specific segments within each MIDI file.
Installation
To install the package, use:
pip install midipy
Usage
Importing and Using the parser Function
The main function to use in this package is the parser function, which parses all MIDI files in a specified directory and extracts relevant metrics. Below are the details on how to use this function.
Parameters for parser
source: (Required) The directory path containing MIDI files. Ensure that this directory contains only.midfiles.metrics: (Optional) Specify['all']to include all available metrics or provide a list of specific metrics you want to display.output_format: (Optional) Choose'excel'or'csv'as the format for saving the output file.save_path: (Optional) Define the path and filename (without extension) for the output file. The default is"Output".ue_keys: (Optional) List of MIDI note values to treat as upper extremity. Defaults to[38, 40, 43, 51, 53, 59].lf_key: (Optional) Single MIDI note value for left foot. Defaults to44.rf_key: (Optional) Single MIDI note value for right foot. Defaults to36.
Segment-wise Analysis Using parser_segments
You can perform segment-wise analysis by using the parser_segments function. It divides each MIDI file into a specified number of segments and calculates metrics for each segment.
source: (Required) Directory path containing MIDI files.metrics: (Optional) See above.output_format: (Optional)'excel'or'csv.save_path: (Optional) Base name for output file. Defaults to'SegmentOutput'.num_segments: (Optional) Number of segments to divide each MIDI file into for analysis. Defaults to10.mean_segments: (Optional) IfTrue, averages each segment index across all files. Defaults toFalse.ue_keys,lf_key,rf_key: Same as inparser—override default extremity note values.
Available Metrics
When specifying metrics in the metrics parameter, use the following keywords to select specific data columns:
'Total_Counts': The total number of notes in each MIDI file.'UE_Counts': Count of upper extremity (UE) notes, such as certain drum hits.'LF_Counts': Count of left foot (LF) notes.'RF_Counts': Count of right foot (RF) notes.'Avg_Velocity': Average velocity of all notes, including a measure of the standard deviation (e.g.,45.37 (14.25)).'UE_Velocity': Average velocity of UE notes, with standard deviation.'LF_Velocity': Average velocity of LF notes, with standard deviation.'RF_Velocity': Average velocity of RF notes, with standard deviation.'Avg_Async': Average asynchrony for all notes, showing the mean and standard deviation.'UE_Async': Average asynchrony for UE notes, with standard deviation.'LF_Async': Average asynchrony for LF notes, with standard deviation.'RF_Async': Average asynchrony for RF notes, with standard deviation.
Note: When selecting a subset of metrics, include
'Name'in yourmetricslist if you want the session identifiers (e.g., "Patient 1 session 2") to appear in the DataFrame output.
Example
The following example demonstrates how to parse MIDI files in a specified directory, select specific metrics, and save the output to an Excel file.
import midipy
from midipy.midi_parser import parser
# Default usage with optional overrides:
df_default = parser(
source="./P1",
metrics=['Total_Counts', 'Avg_Velocity'],
output_format='excel',
save_path='MyMIDIOutput'
)
# Customizing extremity keys:
df_custom = parser(
source="./P1",
ue_keys=[36, 38, 40],
lf_key=37,
rf_key=39,
metrics=['UE_Counts', 'RF_Async'],
output_format='csv'
)
print(df_default)
print(df_custom)
Segment-wise Analysis Example
import midipy
from midipy.midi_parser import parser_segments
# Default segment-wise analysis:
df_segments = parser_segments(
source="./P1",
num_segments=10
)
# Segment analysis with custom keys and averaging:
df_mean_segments = parser_segments(
source="./P1",
num_segments=5,
mean_segments=True,
ue_keys=[36, 38, 40],
lf_key=37,
rf_key=39
)
print(df_segments)
print(df_mean_segments)
In these examples:
- Directory: The directory
./P1contains the MIDI files to be parsed. - Metrics and Overrides: Demonstrates both default and custom extremity-key settings.
Output Files
parseroutput: Contains selected metrics for each session (entire MIDI file).parser_segmentsoutput: Contains metrics for each segment within each session, offering finer-grained analysis.
Metadata
Release files for midipy 0.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| midipy-0.1.6.tar.gz | 14.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| midipy-0.1.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 28.2 kB
Release files / midipy-0.1.6.tar.gz
| Download URL | midipy-0.1.6.tar.gz |
|---|---|
| Size | 14.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b1ec9ab4d57b97f41a8959758df6759f441992340bc628e0da31f84003c74ec2
|
|
BLAKE2b-256 checksum How to use checksums |
588425933928e885a43d1af9a40654d1e595262bc2b628766058da8d47287cc3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.17
|
Release files / midipy-0.1.6-py3-none-any.whl
| Download URL | midipy-0.1.6-py3-none-any.whl |
|---|---|
| Size | 13.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
74ee8431d906343436bf8ea78e2ec4ceeda934b60616d9fa2229b7be6f014752
|
|
BLAKE2b-256 checksum How to use checksums |
f55eecc15d4f764afd0d2961d36d8eea7f38735e46b54f7574100b58818fb38c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.17
|
Security for midipy 0.1.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.