A package for representing music data based on music theory
Project description
Music Embedding
By Pooya Hekmati 2021-24
Music Embedding is an open source python package for representing music data based on music theory. It provides tools to convert melodic and harmonic sequences to and from pianorolls.
Features
- Representation of music intervals
- Create a sequence of (harmonic or melodic) intervals from pianoroll presentation
- Create pianoroll from a sequence of (harmonic or melodic) intervals
- Break the sequence of intervals into smaller pieces e.g. bars
- Compress the sequence of intervals using Run Length Encoding (RLE)
Why Music Embedding
Embedding is an underexplored area in the intersection of AI and music. While many works try to apply NLP-based embedding and automatic embedding (such as convolution), representing music data based on music theory is important. Music Embedding package aims to make employment of music theory easy to enhance the computationals music projects' results. Some potential use cases are:
- Statistical and probabilistic analysis of music pieces,
- Developing generative models to have AI-synthesized music,
- Genre classification,
- Mood recognition,
- Melody extraction,
- Audio-to-Score alignment,
- Score structure analysis.
Installation
Music Embedding's only prerequisite is the Numpy package. Music Embedding is developed and tested in interaction with Pypianoroll; yet, any other code which can handle pianorolls should work just fine.
To install Music Embedding, please run pip install music_embedding
. To build Music Embedding from source, please download the source and run python setup.py install
.
Semantic Versioning Policy
Music Embedding uses the x.y.z format to indicate the version where x is the major version number, y is the minor version number, and z is the patch number.
Documentation
Documentation is available here and as docstrings with the code.
Citing
Please cite this paper if you use Music Embedding in a published work.
Usage
Please visit the Getting Started page.
The following code snippet demonstrates how to convert a midi file into a sequence of harmonic intervals.
import music_embedding
import pypianoroll
if __name__ == '__main__':
#opening midi file using pypianoroll
midi_path = r'c:\Moonlight Sonata.mid'
multi_track = pypianoroll.read(midi_path)
#mergeing midi tracks into a single pianoroll so harmonic intervals can be extracted
merged_piano_roll = multi_track.blend('max')
#getting pianoroll of the first track
pianoroll = multi_track.tracks[0].pianoroll
#creating embedder object from music embedding package
embedder = music_embedding.embedder.embedder()
#extracting harmonic intervals
harmonic_intervals = embedder.get_harmonic_intervals_from_pianoroll(pianoroll=pianoroll, ref_pianoroll=merged_piano_roll)
#creating interval object from music embedding package
interval = music_embedding.interval.interval()
#printing the first 20 intervals
for i in range(20):
interval.set_specs_list(harmonic_intervals[i])
print(interval)
Issues
If you find a problem, please file a bug.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file music_embedding-1.1.2.tar.gz
.
File metadata
- Download URL: music_embedding-1.1.2.tar.gz
- Upload date:
- Size: 18.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1b39c72a9bec6fcc5f1e5edfd4e7bc91435150a0e488ce15b34be8ff45214a5 |
|
MD5 | 9410aeee32d10bed5f51fe65a7be3959 |
|
BLAKE2b-256 | 713346adcfc8c8e2e23d53937453149a0cf41305ee1d0eb30f0c871db9de1458 |
File details
Details for the file music_embedding-1.1.2-py3-none-any.whl
.
File metadata
- Download URL: music_embedding-1.1.2-py3-none-any.whl
- Upload date:
- Size: 15.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 565a2bbdf73b41ba711d4280e144f5909637dcc4ad3d945dc585b05592c9ec6f |
|
MD5 | 7d2399d2d485cd0bd02ef35694608c05 |
|
BLAKE2b-256 | 899bee23a73d3f39b5b5866b1bc07e25d1641014cb054ccd14a909cb4c1f31f0 |