Skip to main content

An extremely easy way to create notes, intervals, chords, and scales! Save yourself the trouble of music theory!

Project description

MusicLibrary

A simple and intuitive music library to create notes, chords and all the different inversions associated with them, scales, intervals, and so much more.

Created by Zeyn Schweyk. Contact zschweyk@gmail.com for any questions.

Install:

pip install ZMusicLibrary

Note

Create a note object:

n = Note("C4")

Add an interval: returns a Note object

All the fundamental intervals. Includes intervals in greater octaves as well.

  • "P1", "A1", "m2", "M2", "A2", "m3", "M3", "P4", "A4", "D5", "P5", "A5", "m6", "M6", "A6", "D7", "m7", "M7"
n1 = Note("F#3") + "M2" # add a major 2nd (G#3)
n2 = Note("A6") - "P4" # subtract a perfect 4th (E5)
n3 = Note("Eb5") + "-M3" # add a negative major 3rd (Cb5)
n4 = Note("Eb5") - "-M6" # subtract a negative major 3rd (C6)
# Can perform arithmetic on intervals greater than a perfect 8th
# like a "M9" (major 9th), as long as it fits within the piano keyboard

Compare 2 notes: returns a str

n1 = Note("C4")
n2 = Note("Eb5")
print(n1.compare_with(n2)) # will print a "m10", minor 10th

Perform logical tests:

n1 = Note("F5")
n2 = Note("G5")
print(n1 == n2) # False
print(n1 < n2) # True
print(n1 <= n2) # True
print(n1 > n2) # False
print(n1 >= n2) # False
print(n1 != n2) # True

Simplify a note's notation: returns a new Note object

n = Note("C##4")
print(n.simplify_notation()) # prints Note(D4)

Chord

Create a pre-defined chord object:

Here are the following chord types, and the intervals that they consist of:

  • "Maj": ["P1", "M3", "P5"]
  • "Maj7": ["P1", "M3", "P5", "M7"]
  • "Dom": ["P1", "M3", "P5", "m7"]
  • "Min": ["P1", "m3", "P5"]
  • "Min7": ["P1", "m3", "P5", "m7"]
  • "MinNat7": ["P1", "m3", "P5", "M7"]
  • "Dim": ["P1", "m3", "D5"]
  • "Dim7": ["P1", "m3", "D5", "D7"]
  • "HDim7": ["P1", "m3", "D5", "m7"]
c = Chord(chord_type="Min", bass_note="E4") # bass_note can be a str or Note object
print(c) # prints Chord([Note(F4), Note(Ab4), Note(C5)])

Create a custom chord object:

c1 = Chord(list_of_notes=["F#4", "G#4", "A5", "C#4"])
print(c1) # prints Chord([Note(F#4), Note(G#4), Note(A5), Note(C#4), Note(F#5)])

# OR

c2 = Chord(list_of_notes=[Note("F#4"), Note("G#4"), Note("A5"), Note("C#4")])
print(c2) # prints Chord([Note(F#4), Note(G#4), Note(A5), Note(C#4), Note(F#5)])

print("Equal:", c1 == c2) # prints True

Loop through the notes of a chord:

c1 = Chord(chord_type="Dim7", bass_note="E4")
for note in c1:
    print(note)

Make a chord have n notes (works with predefined and custom chords): returns a new chord

c1 = Chord(chord_type="Maj", bass_note="B3")
c1 = c1.to_n_number_notes(5)
print(c1) # prints Chord([Note(B3), Note(D#3), Note(F#3), Note(B4), Note(D#4)])

Change the inversion of a chord (works with predefined and custom chords): returns a new chord

There is no limit on the number of inversions, although the chord will shift an octave higher at len(chord) inversions.

c1 = Chord(chord_type="Maj", bass_note="B3")
c1 = c1.inversion(2)
print(c1) # prints Chord([Note(F#3), Note(B4), Note(D#4)])

Combine to_n_number_notes and inversion:

c1 = Chord(chord_type="Maj", bass_note="B3")
c1 = c1.to_n_number_notes(4)
print(c1.inversion(1)) # prints Chord([Note(D#3), Note(F#3), Note(B4), Note(D#4)])

c2 = Chord(chord_type="Maj", bass_note="B3")
c2 = c2.inversion(1)
print(c2.to_n_number_notes(4)) # prints Chord([Note(D#3), Note(F#3), Note(B4), Note(D#4)])

Perform logical tests:

Compares the last note of each chord, except for == and !=, which compare the every note in each chord.

c1 = Chord(chord_type="Maj", bass_note="B3")
c1 = c1.to_n_number_notes(4)
c1 = c1.inversion(1)

c2 = Chord(chord_type="Maj", bass_note="B3")
c2 = c2.to_n_number_notes(4)
c2 = c2.inversion(2)

print(c1 < c2) # True
print(c1 <= c2) # True
print(c1 > c2) # False
print(c1 >= c2) # False
print(c1 == c2) # False
print(c1 != c2) # True

Scale

Create a pre-defined scale object:

Here are the following scale types, and the intervals that they consist of:

  • "Maj": ["P1", "M2", "M3", "P4", "P5", "M6", "M7"]
  • "Min": ["P1", "M2", "m3", "P4", "P5", "m6", "m7"]
  • "Chromatic": ["P1", "A1", "M2", "A2", "M3", "P4", "A4", "P5", "A5", "M6", "A6", "M7"],
  • "HMin": ["P1", "M2", "m3", "P4", "P5", "m6", "M7"]
  • "MMin": ["P1", "M2", "m3", "P4", "P5", "M6", "M7"]
  • "MinBlues": ["P1", "m3", "P4", "D5", "P5", "m7"]
  • "MajBlues": ["P1", "M2", "m3", "M3", "P5", "M6"]
  • "MajPent": ['P1', 'M2', 'M3', 'P5', 'M6']
  • "MinPent": ['P1', 'm3', 'P4', 'P5', 'm7']
  • 'Ionian': ['P1', 'M2', 'M3', 'P4', 'P5', 'M6', 'M7']
  • 'Dorian': ['P1', 'M2', 'm3', 'P4', 'P5', 'M6', 'm7']
  • 'Phrygian': ['P1', 'm2', 'm3', 'P4', 'P5', 'm6', 'm7']
  • 'Lydian': ['P1', 'M2', 'M3', 'A4', 'P5', 'M6', 'M7']
  • 'Mixolydian': ['P1', 'M2', 'M3', 'P4', 'P5', 'M6', 'm7']
  • 'Aeolian': ['P1', 'M2', 'm3', 'P4', 'P5', 'm6', 'm7']
  • 'Locrian': ['P1', 'm2', 'm3', 'P4', 'd5', 'm6', 'm7']
s1 = Scale(scale_type="HMin", start_note="D4")
print(s1) # prints Scale([Note(D4), Note(E4), Note(F4), Note(G4), Note(A5), Note(Bb5), Note(C#5)])

Create a custom Scale object:

s2 = Scale(list_of_notes=["D4", "Eb4", "F4", "G4", "A5", "Bb5", "C#5"])
print(s2) # prints Scale([Note(D4), Note(Eb4), Note(F4), Note(G4), Note(A5), Note(Bb5), Note(C#5)])

Loop through the notes of a scale:

s1 = Scale(scale_type="MinBlues", start_note="C4")
for note in s1:
    print(note)

Perform logical tests:

Compares the last note of each scale, except for == and !=, which compare the every note in each scale.

s1 = Scale(scale_type="MinBlues", start_note="C4")
s2 = Scale(scale_type="Lydian", start_note="D4")

print(s1 < s2) # True
print(s1 <= s2) # True
print(s1 > s2) # False
print(s1 >= s2) # False
print(s1 == s2) # False
print(s1 != s2) # True

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

ZMusicLibrary-1.0.6.tar.gz (10.3 kB view details)

Uploaded Source

File details

Details for the file ZMusicLibrary-1.0.6.tar.gz.

File metadata

  • Download URL: ZMusicLibrary-1.0.6.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.6

File hashes

Hashes for ZMusicLibrary-1.0.6.tar.gz
Algorithm Hash digest
SHA256 9cfe0645c59736a051a0cfce3ed16bc14f485fd63d78e6356ecb649644578a8e
MD5 f7bfdaa294fd009a1e895898b149ce65
BLAKE2b-256 6dcf9e2132adf50635f309d74632fb3726cc91fa02bfb7463ffa54169844b3bf

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