Welcome to Musicpy's documentation!

Musicpy is a music programming language in Python designed to write music in very handy syntax through music theory and algorithms.

It is easy to learn and write, easy to read, and incorporates a fully computerized music theory system.

Musicpy can do way more than just writing music. This package can also be used to analyze music through music theory logic, and you can design algorithms to explore the endless possibilities of music, all with musicpy.

With musicpy, you can express notes, chords, melodies, rhythms, volumes and other information of a piece of music with a very concise syntax. It can generate music through music theory logic and perform advanced music theory operations.

You can easily output musicpy codes into MIDI file format, and you can also easily read any MIDI files and convert to musicpy's data structures to do a lot of advanced music theory operations. The syntax of musicpy is very concise and flexible, and it makes the codes written in musicpy very human-readable.

a J-rock intro in musicpy

guitar = (
(C('Cmaj7') @ 1) @ [1,2,3,4,1,2,3,2] |
(C('Fmaj7',3) ^ 2) @ [1,2,3,4,1,2,3,2] |
(C('G7sus',3) ^ 2) @ [1,2,3,4,1,2,3,2] |
C('Am11',3) @ [1,2,4,6,1,4,6,4] |
(C('Cmaj7') @ 1) @ [1,2,3,4,1,2,3,2] |
C('Fadd9',3).up(2,1) @ [1,2,3,4,1,2,3,2] |
(C('G7sus',3) ^ 2) @ [1,2,3,4,1,2,3,2] |
C('Am11',3) @ [1,2,4,6,1,4,6,4]) % (1/2,1/8)
bass1 = chord('D2[.8;.], E2[.8;.], D2[.8;.], E2[1;.], F2[1;.], G2[1;.], A1[.2;.], A2[.8;.], G2[.8;.], E2[.8;.], D2[.8;.]')
bass2 = (chord('E2')*8 + chord('F1')*8 + chord('G1')*8 + chord('A1,A1,E2,A1,A2,A1,G2,D2')) % (1/8,1/8) * 4
bass = bass1 | bass2
string1 = chord('B5[1;.],C6[1;.],D6[.2;.],E6[.2;.],\
F6[.2;.],E6[.2;.],C6[1;.],B5[.2;.],C6[.2;.],G5[1;.],\
F5[.2;.],E5[.2;.],C5[1;.],D5[.4;.],E5[.4;.],F5[.4;.],\
E5[.4;.],D5[.2;.],G5[.2;.],E5[1;.]')
result = piece(tracks=[guitar * 3, bass, string1],
               instruments=[28, 34, 49],
               bpm=135,
               start_times=[0, 4-3/8, 12])
play(result)

Click here to hear what this sounds like (Microsoft GS Wavetable Synth)

If you think this is too simple, musicpy could also produce music like this within 30 lines of code (could be even shorter if you don't care about readability). Anyway, this is just an example of a very short piece of electronic dance music, and not for complexity.

Contents

Introduction

Quickstart and Cheat Sheet

Data structures

Basic syntax

Useful functionality

Musicpy composition code examples

Musicpy daw module

Algorithms

Frequently Asked Questions