Closed EricDuminil closed 11 months ago
Here's a way to show two scales at once.
It displays the first scale in blue (with root notes in red), and add the extra notes from the second scale, in smaller, green circles:
from fretboardgtr import ScaleGtr, ScaleFromName
"""Draw a guitar fretboard with a base scale,
and fill notes from another scale, in another color and size.
Current example is to show a major pentatonic scale with large circles,
and show the other notes from the major scale with smaller circles.
"""
# Parameters
ROOT = 'C'
FIRST_MODE = 'Majorpentatonic'
SECOND_MODE = 'Ionian' # Should contain more notes than the first one
FILENAME = f'{ROOT}_{FIRST_MODE}_and_{SECOND_MODE}.svg'
ROOT_COLOR = 'rgb(231, 0, 0)'
FIRST_SCALE_COLOR = 'rgb(0, 73, 151)'
SECOND_SCALE_COLOR = 'rgb(0, 108, 0)'
SMALLER_RADIUS = 10
# Define the first scale
first_scale = ScaleFromName(root=ROOT, mode=FIRST_MODE)
F = ScaleGtr(first_scale)
F.pathname(FILENAME)
F.theme(show_note_name=True, last_fret=18, open_color_scale=True)
# Set colors for first scale
OTHER_NOTES = ['minorsecond', 'majorsecond', 'minorthird', 'majorthird',
'perfectfourth', 'diminishedfifth', 'perfectfifth',
'minorsixth', 'majorsixth', 'minorseventh', 'majorseventh']
F.set_color(root=ROOT_COLOR)
for note in OTHER_NOTES:
F.set_color(**{note: FIRST_SCALE_COLOR})
# Draw the first scale
F.draw()
# Which notes should be added?
second_scale = ScaleFromName(root=ROOT, mode=SECOND_MODE)
first_notes = first_scale.results['scale']
second_notes = second_scale.results['scale']
F.scale = [note for note in second_notes if note not in first_notes]
# Show second scale in different colors
for note in OTHER_NOTES:
F.set_color(**{note: SECOND_SCALE_COLOR})
F.theme(R=SMALLER_RADIUS)
F.fill_with_scale()
F.save(extension='png')
Here's the corresponding result:
You can directly do this now be setting up the config dynamically :
from fretboardgtr.fretboard import FretBoard, FretBoardConfig
from fretboardgtr.notes_creators import ScaleFromName
FIRST_MODE = "Majorpentatonic"
SECOND_MODE = "Ionian" # Should contain more notes than the first one
ROOT = "C"
ROOT_COLOR = "rgb(231, 0, 0)"
FIRST_SCALE_COLOR = "rgb(0, 73, 151)"
SECOND_SCALE_COLOR = "rgb(0, 108, 0)"
SMALLER_RADIUS = 10
FIRST_SCALE_CONFIG = {
"general": {
"fretted_colors": {
"root": "rgb(255,255,255)",
"minor_second": FIRST_SCALE_COLOR,
"major_second": FIRST_SCALE_COLOR,
"minor_third": FIRST_SCALE_COLOR,
"major_third": FIRST_SCALE_COLOR,
"perfect_fourth": FIRST_SCALE_COLOR,
"diminished_fifth": FIRST_SCALE_COLOR,
"perfect_fifth": FIRST_SCALE_COLOR,
"minor_sixth": FIRST_SCALE_COLOR,
"major_sixth": FIRST_SCALE_COLOR,
"minor_seventh": FIRST_SCALE_COLOR,
"major_seventh": FIRST_SCALE_COLOR,
},
},
}
SECOND_SCALE_CONFIG = {
"general": {
"fretted_colors": {
"root": SECOND_SCALE_COLOR,
"minor_second": SECOND_SCALE_COLOR,
"major_second": SECOND_SCALE_COLOR,
"minor_third": SECOND_SCALE_COLOR,
"major_third": SECOND_SCALE_COLOR,
"perfect_fourth": SECOND_SCALE_COLOR,
"diminished_fifth": SECOND_SCALE_COLOR,
"perfect_fifth": SECOND_SCALE_COLOR,
"minor_sixth": SECOND_SCALE_COLOR,
"major_sixth": SECOND_SCALE_COLOR,
"minor_seventh": SECOND_SCALE_COLOR,
"major_seventh": SECOND_SCALE_COLOR,
},
},
"fretted_notes": {"radius": SMALLER_RADIUS},
}
# Declaring configuration
first_fretboard_config = FretBoardConfig.from_dict(FIRST_SCALE_CONFIG)
second_fretboard_config = FretBoardConfig.from_dict(SECOND_SCALE_CONFIG)
# Get scales notes
major_pentatonic = ScaleFromName(root=ROOT, mode=FIRST_MODE).get()
ionian = ScaleFromName(root=ROOT, mode=SECOND_MODE).get()
# Display first fretboard (In your example the second scale should be below the first one)
fretboard = FretBoard(config=second_fretboard_config)
fretboard.add_notes(scale=ionian)
# Display second fretboard (In your example the second scale should be below the first one)
fretboard.set_config(config=first_fretboard_config)
fretboard.add_notes(scale=major_pentatonic)
fretboard.export("my_fretboard.svg", format="svg")
Is it possible to show 2 scales at once, for example to show which notes are added between major pentatonic and ionian, or between phrygian and flamenco?