Skip to content

Latest commit

 

History

History
127 lines (104 loc) · 3.69 KB

getting_started.rst

File metadata and controls

127 lines (104 loc) · 3.69 KB

Getting Started

Welcome to MusPy! We will go through some basic concepts in this tutorial.

Hint

Be sure you have MusPy installed. To install MusPy, please run pip install muspy.

In the following example, we will use this JSON file as an example.

First of all, let's import the MusPy library. :

import muspy

Now, let's load the example JSON file into a Music object. :

music = muspy.load("example.json")
print(music)

Here's what we got. :

Music(metadata=Metadata(schema_version='0.0', title='Für Elise', creators=['Ludwig van Beethoven'], collection='Example dataset', source_filename='example.json'), resolution=4, tempos=[Tempo(time=0, qpm=72.0)], key_signatures=[KeySignature(time=0, root=9, mode='minor')], time_signatures=[TimeSignature(time=0, numerator=3, denominator=8)], downbeats=[4, 16], lyrics=[Lyric(time=0, lyric='Nothing but a lyric')], annotations=[Annotation(time=0, annotation='Nothing but an annotation')], tracks=[Track(program=0, is_drum=False, name='Melody', notes=[Note(time=0, duration=2, pitch=76, velocity=64), Note(time=2, duration=2, pitch=75, velocity=64), Note(time=4, duration=2, pitch=76, velocity=64), ...], lyrics=[Lyric(time=0, lyric='Nothing but a lyric')], annotations=[Annotation(time=0, annotation='Nothing but an annotation')])])

Hard to read, isn't it? Let's print it beautifully. :

music.print()

Now here's what we got.

You can use dot notation to assess the data. For example, music.metadata.title returns the song title, and music.tempos[0].qpm returns the first tempo in qpm (quarter notes per minute). If you want a list of all the pitches, you can do :

print([note.pitch for note in music.tracks[0].notes])

Then you will get [76, 75, 76, 75, 76, 71, 74, 72, 69].

Hint

music[i] is a shorthand for music.tracks[i], and len(music) for len(music.tracks).

There's more MusPy offers. Here is an example of data preparation pipeline using MusPy.

image

And here is another example of result writing pipeline using MusPy.

image