Skip to main content

A MIDI and music data manipulation library

Project description

S-Coda

GitHub Release GitHub Actions Workflow Status Python Version

DOI DOI

Overview

S-Coda is a Python library for handling MIDI files. It is written with the purpose of machine learning tasks in mind. S-Coda supports a plethora of different MIDI manipulation operations, such as:

  • quantisation of notes
  • quantisation of note lengths
  • splitting sequences into bars
  • transposing of sequences
  • creating piano-roll visualisations of pieces
  • tokenisation of sequences

S-Coda was used in our project PAUL-2 to process MIDI files. For information about how to use S-Coda we refer to chapter 5 of the thesis in which S-Coda was introduced. Note that this thesis refers to version 1.0 of S-Coda, which has since received major overhauls.

Installation

We recommend installing S-Coda from PyPI using pip:

pip install scoda

Changelog

See CHANGELOG.md for a detailed changelog.

Usage

Example

We refer to the aforementioned thesis for a more in-depth guide on how to use S-Coda. We provide a short listing on how to use basic S-Coda functions, which is up-to-date as of version 2.4.0.:

    # Load sequence, choose correct track (often first track contains only meta messages)
sequence = Sequence.sequences_load(file_path=RESOURCE_BEETHOVEN)[1]

# Quantise the sequence to sixteenths and sixteenth triplets (standard values)
sequence.quantise_and_normalise()

# Split the sequence into bars based on the occurring time signatures
bars = Sequence.sequences_split_bars([sequence], meta_track_index=0)[0]

# Prepare tokeniser and output tokens
tokeniser = MultiTrackLargeVocabularyNotelikeTokeniser(num_tracks=1)
tokens = []

# Tokenise all bars in the sequence
for bar in bars:
    tokens.extend(tokeniser.tokenise([bar.sequence]))

# Convert to a numeric representation
encoded_tokens = tokeniser.encode(tokens)

# (Conduct ML operations on tokens)
encoded_tokens = encoded_tokens

# Convert back to token representation
decoded_tokens = tokeniser.decode(encoded_tokens)

# Create sequence from tokens
detokenised_sequences = tokeniser.detokenise(decoded_tokens)

# Save sequence
detokenised_sequences[0].save("../out/generated_sequence.mid")

Implementational Details

S-Coda is built around the Sequence class, which represents a musical sequence. The Sequence object is a wrapper for two internal classes, AbsoluteSequence and RelativeSequence, which represent music in two different ways. For the absolute sequences, the elements of the sequences are annotated with their absolute points in time within the sequence, while for the relative sequence elements specify the time between events. These two representations are used internally for different operations. The Sequence object abstracts away the differences between these two representations and provides the user with a unified experience.

The atomic element of S-Coda is the Message, which is comparable to a MIDI event. Messages have a MessageType, denoting the type of the message, and several other fields depending on which type of message it is. For example, a message of type NOTE_ON will have a note field, which denotes the pitch number of the note that it represents.

Note that directly editing single messages or the messages of a sequence is possible, but not recommended, as it can lead to inconsistencies in the Sequence object. If you still need to do so, make sure to invalidate either the absolute or relative internal representation (using Sequence.invalidate_abs() and Sequence.invalidate_rel()) after directly editing messages. This is not required when modifying the sequence using the functions provided by Sequence, as staleness of the internal representations is kept track of this way.

Citing

If you use S-Coda in your research, please cite the following paper:

@inproceedings{Schoen.2023,
  author       = {Felix Sch{\"{o}}n and
                  Hans Tompits},
  title        = {{PAUL-2:} An Upgraded Transformer-Based Redesign of the Algorithmic Composer {PAUL}},
  booktitle    = {22nd International Conference of the Italian Association for Artificial Intelligence ({AIxIA 2023})},
  series       = {Lecture Notes in Computer Science},
  volume       = {14318},
  pages        = {278--291},
  publisher    = {Springer},
  year         = {2023},
  doi          = {10.1007/978-3-031-47546-7\_19}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scoda-2.5.tar.gz (40.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

scoda-2.5-py3-none-any.whl (46.4 kB view details)

Uploaded Python 3

File details

Details for the file scoda-2.5.tar.gz.

File metadata

  • Download URL: scoda-2.5.tar.gz
  • Upload date:
  • Size: 40.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for scoda-2.5.tar.gz
Algorithm Hash digest
SHA256 8104bd5a3a8dd601bfab54387ca22622a7eae27c8a3ef1badd57a57cb297e032
MD5 0ae6380eaa07d5ddb071f53135417431
BLAKE2b-256 139a25d8b1e498094f5ba1d7525b2721f063bd3c07ae3ac5e9e5a7d503312664

See more details on using hashes here.

File details

Details for the file scoda-2.5-py3-none-any.whl.

File metadata

  • Download URL: scoda-2.5-py3-none-any.whl
  • Upload date:
  • Size: 46.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for scoda-2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 f3cd65bbe05fa1799291469ab632021a80d85a35933c6b9df183db44b3f987a6
MD5 2eb93a5fd1320d384269296198050a3f
BLAKE2b-256 c385cb6fb805e8f5a84dd892772289d863a77f8550d8c3db8ca7a889066b23dd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page