Skip to main content

Apply chromatic and diatonic transformations to music notes

Project description

Music Melodic-Device

Apply chromatic and diatonic transformations to music notes

DESCRIPTION

This class provides methods to do chromatic and diatonic transformations to music notes.

The three major categories are transpositions, inversions, and five types of ornamentation.

SYNOPSIS

from music_melodicdevice import Device

# default scale: chromatic
device = Device(notes=['C4', 'E4', 'D4', 'G4', 'C5'])
notes = device.transpose(2) # ['D4', 'F#4', 'E4', 'A4', 'D5']
notes = device.invert('C4') # ['C4', 'G#3', 'A#3', 'F3', 'C3']

# diatonic transformation:
device = Device(scale_name='major', verbose=True)
device.notes = ['C4', 'E4', 'D4', 'G4', 'C5']
notes = device.transpose(2) # ['E4', 'G4', 'F4', 'B4', 'E5']
notes = device.invert('C4') # ['C4', 'A3', 'B3', 'F3', 'C3']

# unknown note:
device = Device()
device.build_scale('major')
notes = device.transpose(2, ['C4', 'E4', 'D#4', 'G4', 'C5'])
# ['E4', 'G4', None, 'B4', 'E5']
notes = device.invert('C4', ['C4', 'E4', 'D#4', 'G4', 'C5'])
# ['C4', 'A3', None, 'F3', 'C3']

# Ornamentation:

# chromatic
device = Device()

notes = device.grace_note(1, 'D5') # [[1/16, 'D5'], [1 - 1/16, 'D5']])
notes = device.grace_note(1, 'D5', offset=1) # [[1/16, 'D#5'], [1 - 1/16, 'D5']])
notes = device.grace_note(1, 'D5', offset=-1) # [[1/16, 'C#5'], [1 - 1/16, 'D5']])

notes = device.turn(1, 'D5') # [[1/4,'D#5'], [1/4,'D5'], [1/4,'C#5'], [1/4,'D5']])
notes = device.turn(1, 'D5', offset=-1) # [[1/4,'C#5'], [1/4,'D5'], [1/4,'D#5'], [1/4,'D5']])

notes = device.trill(1, 'D5', number=2, offset=1)
# [[1/4,'D5'], [1/4,'D#5'], [1/4,'D5'], [1/4,'D#5']])
notes = device.trill(1, 'D5', number=2, offset=-1)
# [[1/4,'D5'], [1/4,'C#5'], [1/4,'D5'], [1/4,'C#5']])

notes = device.mordent(1, 'D5', offset=1) # [[1/4,'D5'], [1/4,'D#5'], [1/2,'D5']])
notes = device.mordent(1, 'D5', offset=-1) # [[1/4,'D5'], [1/4,'C#5'], [1/2,'D5']])

notes = device.slide(1, 'D5', 'F5') # [[1/4,'D5'], [1/4,'D#5'], [1/4,'E5'], [1/4,'F5']])
notes = device.slide(1, 'D5', 'B4') # [[1/4,'D5'], [1/4,'C#5'], [1/4,'C5'], [1/4,'B4']])

# diatonic
device = Device(scale_name='major')

notes = device.grace_note(1, 'D5') # [[1/16, 'D5'], [1 - 1/16, 'D5']])
notes = device.grace_note(1, 'D5', offset=1) # [[1/16, 'E5'], [1 - 1/16, 'D5']])
notes = device.grace_note(1, 'D5', offset=-1) # [[1/16, 'C5'], [1 - 1/16, 'D5']])

notes = device.turn(1, 'D5', offset=1) # [[1/4,'E5'], [1/4,'D5'], [1/4,'C5'], [1/4,'D5']])
notes = device.turn(1, 'D5', offset=-1) # [[1/4,'C5'], [1/4,'D5'], [1/4,'E5'], [1/4,'D5']])

notes = device.trill(1, 'D5', number=2, offset=1) # [[1/4,'D5'], [1/4,'E5'], [1/4,'D5'], [1/4,'E5']])
notes = device.trill(1, 'D5', number=2, offset=-1) # [[1/4,'D5'], [1/4,'C5'], [1/4,'D5'], [1/4,'C5']])

notes = device.mordent(1, 'D5', offset=1) # [[1/4,'D5'], [1/4,'E5'], [1/2,'D5']])
notes = device.mordent(1, 'D5', offset=-1) # [[1/4,'D5'], [1/4,'C5'], [1/2,'D5']])

METHODS

transpose

notes = device.transpose(amount)

Transpose a note by an integer amount.

invert

notes = device.invert(axis_note, note_list)

Invert the note_list of named notes, around the named axis_note.

grace_note

notes = device.grace_note(duration, pitch, offset=offset)

Return a list with a 64th-note grace-note and the original named pitch with octave. The grace-note is offset semi-tone steps from the given pitch. The duration is the total, original length of the pitch.

turn

notes = device.turn(duration, pitch, offset=offset)

Return a list of four notes, having an up-down pattern, in place of the given pitch and duration.

trill

notes = device.trill(duration, pitch, number=number, offset=offset)

Return a list of pairs of notes, given the number, in place of the given pitch and duration.

The first of the pair is part of the original note, and the second is the note plus the given offset.

mordent

notes = device.mordent(duration, pitch, offset=offset)

Return a list of three notes in place of the given pitch and duration.

slide

notes = device.slide(duration, from_pitch, to_pitch)

Return a list of chromatic notes inclusively between the from_pitch and to_pitch, in place of the given duration.

MUSICAL EXAMPLES

from music21 import duration, note, stream
from music_melodicdevice import Device

device = Device(notes=['C4', 'E4', 'D4', 'G4'])
notes = device.invert('C5')

s = stream.Stream()
p = stream.Part()

for i in device.notes + notes:
    n = note.Note(i)
    n.duration = duration.Duration(1)
    p.append(n)

s.append(p)
s.show()
notes = ['C4', 'E4', 'D4', 'G4']

device = Device(scale_name='major')
device.notes = notes
device.notes = device.invert('C5')
device.notes = device.transpose(-5)

s = stream.Stream()
p = stream.Part()

length = len(notes) + len(device.notes)

for i,j in enumerate(notes + device.notes):
    if (i + 1) % 4 == 0:
        turn = device.turn(1, j)
        for t in turn:
            m = note.Note(t[1])
            m.duration = duration.Duration(t[0])
            p.append(m)
    else:
        n = note.Note(j)
        n.duration = duration.Duration(1)
        p.append(n)

s.append(p)
s.show()

SEE ALSO

https://en.wikipedia.org/wiki/Inversion_(music)#Melodies

https://en.wikipedia.org/wiki/Ornament_(music)

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

music_melodicdevice-0.1.1.tar.gz (45.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

music_melodicdevice-0.1.1-py3-none-any.whl (31.9 kB view details)

Uploaded Python 3

File details

Details for the file music_melodicdevice-0.1.1.tar.gz.

File metadata

  • Download URL: music_melodicdevice-0.1.1.tar.gz
  • Upload date:
  • Size: 45.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for music_melodicdevice-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ae4b65585a9e6b303d0a73206ae42317b21935c3ffb66ff1284eac4d1f092ffe
MD5 fb023489a98a75f9792b9e620b4f003e
BLAKE2b-256 4519b28f1ddd5e38584c54ff64330b31c110b06d351fd8c2ec924304f2a96537

See more details on using hashes here.

File details

Details for the file music_melodicdevice-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for music_melodicdevice-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7fe26b1909ccf09d89abc7a29cea7ad89fe9cea6046c6828c518096dd5c1d86a
MD5 eb549da3e7f109c12615d206ec00d9fd
BLAKE2b-256 db69730d0347c80adfe3a4b7bcfc92f70d6ed9a86e653a2080f0c5ff7a0ada8e

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