A package containing representation tools for musical purposes


Keywords
music, music-theory, plotting
License
MIT
Install
pip install pitchplots==1.4.2

Documentation

pitchplots

header

A python library for plotting note distributions in different tonal spaces.

Getting Started

The library contains the following files

  • functions.py,
  • reader.py,
  • modified_music_xml.py,
  • parser.py
  • static.py

Prerequisites

In order to use pitchplots you need a running Python 3 environment and the following libraries:

  • matplotlib
  • pandas
  • numpy

to install these libraries, you can do the following command in the prompt:

python3 -m pip install matplotlib>=3.0.1 pandas>=0.23.4 numpy>=1.15.3

or if you're using the Anaconda prompt

pip install matplotlib>=3.0.1 pandas>=0.23.4 numpy>=1.15.3

Or you can use the requirements.txt file in the github. Dont' forget to set the path to the one of the requirements file.

python3 -m pip install -r requirements.txt

Installation

You can install the pitchplots package on pypi with pip using the following command in the prompt:

python3 -m pip install pitchplots

or if you're using the Anaconda prompt

pip install pitchplots

Functions

1 2 2 4 5 6

Pitchplots has currently three plotting functions

  • tonnetz uses a .csv file or a pandas DataFrame of a piece of music to do a hexagonal 2D representation ("Tonnetz").
  • circle uses a csv file or a pandas DataFrame of a piece of music to represent the notes by fifth or chromatic.
  • line uses a csv file or a pandas DataFrame of a piece of music to represent the notes by fifth or chromatic on a line, the unrolled equivalent to the circle function.

Two animation functions

  • tonnetz_animation plot the same graphs as the tonnetz function but is animated.
  • circle_animation plot the same graphs as the circle function but is animated.

and one function to parse (compressed) MusicXML files and uncompressed xml files

  • xml_to_csv uses a .mxl or .xml file and parses it into a .csv file using the TensorFlow Magenta musicxml_parser.py.

Working with files

Parsing

Pitchplots plots note distributions from MusicXML files (.xml or .mxl). You can either specify your own file or use the test file data_example.mxl. contained in the package.

The first step is to parse the file into a note list representation that is stored in a pandas DataFrame where each line corresponds to a note or a rest.

import pitchplots.parser as ppp

# If no filepath is specified, will automatically charge data_example.mxl
df_data_example = ppp.xml_to_csv(save_csv=True)

To use your own file, add filepath= with the location of your file in the parameters of the function xml_to_csv.

Plotting

In order to plot the notes of a piece, import the pitchplots.static module and use one of its plotting functions. They take as input the output of the parser, i.e. either a DataFrame object:

import pitchplots.static as pps

pps.tonnetz(df_data_example)

or a CSV file:

import pitchplots.static as pps

pps.tonnetz('csv/data_example.csv')

In both cases the output should look like the following image (of course, the note distribution depends on the piece you are plotting):

tonnetz_example

Or if you want to plot a line:

import pitchplots.static as pps

pps.line(df_data_example)

or a CSV file:

import pitchplots.static as pps

pps.line('csv/data_example.csv')

In both cases the output should look like the following image (of course, the note distribution depends on the piece you are plotting):

line_example

Or if you want to plot a circle:

import pitchplots.static as pps

pps.circle(df_data_example)

or a CSV file:

import pitchplots.static as pps

pps.circle('csv/data_example.csv')

In both cases the output should look like the following image (of course, the note distribution depends on the piece you are plotting):

circle_example

detailed functionality

see the following files for more informations about the functions parser, line, circle, tonnetz, circle_animation and tonnetz_animation.

parser documentation line documentation circle documentation tonnetz documentation

Further Information

Authors

Usage of Magenta's code

The modified_musicxml_parser.py file is taken from the TensorFlow Magenta project and has been modified. See the modifications and the Magenta License.

License

Pitchplots is licensed under the MIT License - see the LICENSE file for details