Skip to main content

A rhythm feature extractor and classifier for MIDI files

Project description

groover 0.0.3

Installation

groover is a beat-by-beat rhythm feature clustering and token generation tool for .mid files. You can download groover using pip:

pip install groover

To check if groover is successfully installed, type python in the terminal, and do the following:

>>> from groover import RhythmKMeans
>>> type(RhythmKMeans())
<class 'groover.classifier.RhythmKMeans'>

Documentation

data

get_heat_maps(midi_obj, beat_resolution=480, rid_melody=False, min_pitch=0, max_pitch=127)

Returns a numpy array of shape (n, 24), where n is the number of beats in midi_obj. Each row is the rhythmic heat map of a beat, taking into consideration the notes' velocity and pitch.

Parameters
  • midi_obj: miditoolkit.midi.parser.MidiFile
    • the midi object to get heat maps from
  • beat_resolution: int
    • the number of ticks per beat
  • rid_melody: bool
    • whether to ignore melody notes when calculating rhythmic intensity
  • min_pitch: int
    • the minimum pitch of the note to be considered when calculating rhythmic intensity
  • max_pitch: int
    • the maximum pitch of the note to be considered when calculating rhythmic intensity

get_dataset(midi_objs, beat_resolution=480, rid_melody=False, min_pitch=0, max_pitch=127)

Returns a numpy array of shape (n, 24), where n is the total number of beats of midi objects in midi_objs. Each row is the rhythmic heat map of a beat, taking into consideration the notes' velocity and pitch.

Parameters
  • midi_obj: list
    • the list containing midi objects to get heat maps from
  • beat_resolution: int
    • the number of ticks per beat
  • rid_melody: bool
    • whether to ignore melody notes when calculating rhythmic intensity
  • min_pitch: int
    • the minimum pitch of the note to be considered when calculating rhythmic intensity
  • max_pitch: int
    • the maximum pitch of the note to be considered when calculating rhythmic intensity

RhythmKMeans

RhythmKMeans classifies rhythmic heat maps and use them to predict and evaluate rhythmic tokens.

RhythmKMeans.__init__(self, cluster_centers=None)

Parameters
  • cluster_centers: numpy.ndarray
    • the cluster centers in the shape of (k, 24), where k is the number of clusters and each row is a cluster.

RhythmKMeans.load_cluster_centers(self, cluster_centers)

Loads cluster_centers as the classifier's cluster centers.

Parameters
  • cluster_centers: numpy.ndarray
    • the cluster centers in the shape of (k, 24), where k is the number of clusters and each row is a cluster.

RhythmKMeans.fit(self, dataset, k, max_iter=1000, epsilon=1e-6)

Makes the classifier's cluster centers align with the dataset.

Parameters
  • dataset: numpy.ndarray
    • a numpy array of shape (n, 24), where n is the total number of beats in the dataset, with each row being the rhythmic heat map of a beat
  • k: int
    • the number of clusters to be generated
  • max_iter: int
    • the maximum number of iterations to perform
  • epsilon: float
    • if the average distance of the cluster centers between iterations is lower than epsilon, clustering ends early

RhythmKMeans.k(self)

Returns the number of clusters of the classifier.

RhythmKMeans.is_empty(self)

Returns True if the classifier is not fitted to any data yet, False otherwise.

RhythmKMeans.add_beat_clusters(self, midi_obj, beat_resolution=480, preprocessing='default', min_pitch=0, max_pitch=127)

Adds markers with rhythm types to midi_obj.

Parameters
  • midi_obj: miditoolkit.midi.parser.MidiFile
    • the midi object to add beat-by-beat rhythm markers to
  • beat_resolution: int
    • the number of ticks per beat
  • preprocessing: str
    • can be either 'default', 'binary', or 'quantized', which will then change the rhythmic heat maps' values accordingly
  • min_pitch: int
    • the minimum pitch of the note to be considered when calculating rhythmic intensity
  • max_pitch: int
    • the maximum pitch of the note to be considered when calculating rhythmic intensity

RhythmKMeans.get_rhythm_scores(self, midi_obj, beat_resolution=480, min_pitch=0, max_pitch=127)

Returns a tuple of numpy arrays. The first is the rhythm types in shape (n,) that is specified by the markers in the midi object, and the second array is the alignment score between the notes and the rhythm type in shape (n,). n is the number of beats in the midi object.

Parameters
  • midi_obj: miditoolkit.midi.parser.MidiFile
    • the midi object to be evaluated
  • beat_resolution: int
    • the number of ticks per beat
  • preprocessing: str
    • can be either 'default', 'binary', or 'quantized', which will then change the rhythmic heat maps' values accordingly
  • min_pitch: int
    • the minimum pitch of the note to be considered when calculating rhythmic intensity
  • max_pitch: int
    • the maximum pitch of the note to be considered when calculating rhythmic intensity

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

groover-0.0.3.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

groover-0.0.3-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file groover-0.0.3.tar.gz.

File metadata

  • Download URL: groover-0.0.3.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.10

File hashes

Hashes for groover-0.0.3.tar.gz
Algorithm Hash digest
SHA256 86b47e3fdc8df359028607e5fe1029d298c5d2eaa0d9b4cbae70b4b5fba8fa43
MD5 a6b23c13366bbf25e73478da55046496
BLAKE2b-256 65af0932e77f82e15ef7e2df03b53e2fd1e43eaf38558e2a2774f1c3c1b643b9

See more details on using hashes here.

File details

Details for the file groover-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: groover-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.10

File hashes

Hashes for groover-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4c1b46fdaa8b9ef20a234294069761cde00d1ceef35b59949233af7261ceb76e
MD5 18447b764f9c0ecffa4b9d0bacee6172
BLAKE2b-256 dada2b0c0cc94b7dea01cec49efe5e2fabc4844ce222e88c6c6f66118374bd9c

See more details on using hashes here.

Supported by

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