Generate musical basslines
Project description
Music Bassline-Generator
Generate musical basslines
DESCRIPTION
This class generates randomized basslines based on named chords.
The "formula" implemented by this module is basically: "Play any notes of the chord, modal chord scale, or chord-root scale (and drop any notes replaced by extended jazz chords)."
The chords recognized by this module, are those known to music21.
The logic and music theory implemented here, can generate some possibly sour notes. This is an approximate composition tool, and not a drop-in bass player! Import rendered MIDI into a DAW and alter notes until they sound suitable.
Named chords and the keycenter use # and b for accidentals.
To constrain the notes to a chosen set of scale degrees, use the positions attribute illustrated below.
The one and only public method in this class is generate(). Which generates n MIDI pitch numbers given a named chord. If format is set to ISO, the method returns named notes. If next_chord is True, we perform an intersection of the two scales, and replace the final note of the generated phrase with a note of the intersection, if there are notes in common. If the modal attribute is set, then the chosen notes will be within the mode given the keycenter setting. If it is not set (the default), notes will be chosen as if the key has changed to the current chord.
SYNOPSIS
from music_bassline_generator import Bassline
bass = Bassline(
keycenter='C', # tonic for modal accompaniment
modal=False, # only choose notes within the mode
chord_notes=True, # use chord notes outside the scale
intervals=[-3, -2, -1, 1, 2, 3], # allowed voicegen intervals
octave=1, # lowest MIDI octave
tonic=False, # play the first scale note to start the generated phrase
positions=None, # allowed notes for major and minor scales
guitar=False, # transpose notes below E1 (midi #28) up an octave
wrap=None, # transpose notes above this ISO named note, down an octave
verbose=False, # show progress
)
scale = bass.scale_fn('C7b5') # 'major'
scale = bass.scale_fn('Dm7b5') # 'minor'
scale = bass.scale_fn('D#/A#') # 'major'
notes = bass.generate('C7b5', 4)
notes = bass.generate('D/A', 4)
notes = bass.generate('D', 4, 'C/G')
notes = bass.generate('D', 1)
bass = Bassline(modal=True)
mode = bass.scale_fn('C7b5') # 'ionian'
mode = bass.scale_fn('Dm7b5') # 'dorian'
notes = bass.generate('Dm7')
notes = bass.generate('Dm7b5')
bass = Bassline(
octave=3,
wrap='C3',
modal=True,
)
notes = bass.generate('C', 4)
bass = Bassline(
chord_notes=False,
positions={'major': [x for x in range(6)], 'minor': [x for x in range(6)]} # no 7ths!
)
notes = bass.generate('C', 4)
MUSICAL EXAMPLES
from music21 import note, stream
from music_bassline_generator import Bassline
def add_notes(p, notes):
print(notes)
for n in notes:
n = note.Note(n, type='quarter')
p.append(n)
s = stream.Stream()
bass_part = stream.Part()
bass = Bassline(octave=2)
num = 4
# Autumn Leaves verse
for chord in ['Am7','D7','GM7','CM7','F#m7b5','B7','Em','Em']:
notes = bass.generate(chord, num)
add_notes(bass_part, notes)
s.insert(0, bass_part)
s.show()
from music21 import chord, note, stream
from music_bassline_generator import Bassline
from pychord import Chord as pyChord
def add_notes(p, notes):
for n in notes:
n = note.Note(n, type='quarter')
p.append(n)
s = stream.Stream()
bass_part = stream.Part()
chord_part = stream.Part()
bass = Bassline(modal=True, octave=2)
num = 4
# Autumn Leaves verse
for my_chord in ['Am7','D7','GM7','CM7','F#m7b5','B7','Em','Em']:
c = pyChord(my_chord)
c = chord.Chord(c.components(), type="whole")
chord_part.append(c)
notes = bass.generate(my_chord, num)
add_notes(bass_part, notes)
s.insert(0, chord_part)
s.insert(0, bass_part)
s.show()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file music_bassline_generator-0.1.13.tar.gz.
File metadata
- Download URL: music_bassline_generator-0.1.13.tar.gz
- Upload date:
- Size: 44.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e4fe78ada0f7f04facff7c46d8fe011b4691057c3f73b442b334f762b4628a5
|
|
| MD5 |
2f1109258265ce36e655f2419c0b422e
|
|
| BLAKE2b-256 |
5571b6697e001daf39d593d677d420009bae0cfc42befc96631bdc5f218d49ac
|
File details
Details for the file music_bassline_generator-0.1.13-py3-none-any.whl.
File metadata
- Download URL: music_bassline_generator-0.1.13-py3-none-any.whl
- Upload date:
- Size: 30.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a94ff9be1674a2a0bfd8c0e63f89ddc51ddeac38465b5b884c1228e8c242b1c4
|
|
| MD5 |
13ffddc90c97738791d3881bd797d35e
|
|
| BLAKE2b-256 |
7e291ad70ce13af45d3fb5d11954b4ae32bf87b77ce5978135b1974a7d344a6c
|