%matplotlib inline
from pylab import *
On code les notes de la manière suivante : un chiffre entre 0 (C) et 11 (B).
def note2int(note):
""" returns int associated with a given note"""
notes = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
ints = range(12)
return dict(zip(notes, ints))[note]
note2int('D')
2
def int2note(integer):
""" returns note associated to a given int"""
notes = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
ints = range(12)
return dict(zip(ints, notes))[integer]
int2note(4)
'E'
On peut construire les cordes de la guitare en empilant des lignes qui correspondent à chaque corde, alors que les colonnes de la matrice correspondent aux cases.
guitar = vstack((((arange(12) + 4) % 12), # mi aigu
((arange(12) + 11) % 12),
((arange(12) + 7) % 12),
((arange(12) + 2) % 12),
((arange(12) + 9) % 12),
((arange(12) + 4) % 12)))
[int2note(guitar[i, 0]) for i in range(6)]
['E', 'B', 'G', 'D', 'A', 'E']
Par comparaison booléenne, on peut n'afficher que certains notes.
figure(figsize=(15, 6))
imshow(guitar == note2int('C'), interpolation = 'nearest', aspect=.5)
<matplotlib.image.AxesImage at 0x106829668>
On peut étendre ce principe à plusieurs notes.
def guitar_with_notes(notes):
guitar_with_notes = zeros(guitar.shape, dtype=bool8)
for note in notes:
guitar_with_notes += (guitar == note2int(note))
return guitar_with_notes
figure(figsize=(15, 6))
imshow(guitar_with_notes(['C', 'D']), interpolation = 'nearest', aspect=.5)
<matplotlib.image.AxesImage at 0x106b52ef0>
Finalement, on peut afficher un accord de A mineur 7 b5, les notes étant : [A, C, Eb==D#, G]
figure(figsize=(15, 6))
imshow(guitar_with_notes(['A', 'C', 'D#', 'G']), interpolation = 'nearest', aspect=.5)
<matplotlib.image.AxesImage at 0x106d32d68>
Voir même avec des couleurs.
figure(figsize=(15, 6))
imshow(guitar_with_notes(['A', 'C', 'D#', 'G']) * (guitar + 1), interpolation = 'nearest', aspect=.5, cmap=cm.Accent)
cbar = colorbar(shrink=0.4)
Enfin, nous pouvons également expérimenter avec le dessin des cordes individuelles.
figure(figsize=(15, 6))
def plot_neck():
scale = 0.15
delta = 0.05
# lignes horizontales
for i in range(7):
plot([0, 1], array([i, i]) / 6. * scale, 'black')
# lignes verticales
for i in range(13):
plot(array([1, 1]) * i/12., [scale, 0], 'black')
xlim(-delta, 1 + delta)
ylim(-delta, scale + delta)
plot_neck()
def plot_notes(notes):
guitar_neck = guitar_with_notes(notes)
for i in range(6):
for j in range(12):
if guitar_neck[i, j] == True:
plot([(j + 0.5) / 12.], [i], 'bo')
plot_notes(['C'])
class guitar_plotter(object):
def __init__(self, scale=0.3, delta=0.1):
self.scale = scale
self.delta = delta
def plot_neck(self):
for i in range(6):
plot([0, 1], array([i, i]) / 5. * self.scale, 'black')
for i in range(13):
line = plot(array([1, 1]) * i/12., [self.scale, 0], 'black')
if i == 0 or i == 12:
setp(line, linewidth=4.0)
xlim(-self.delta, 1 + self.delta)
ylim(-self.delta, self.scale + self.delta)
def plot_notes(self, notes, labels=[]):
guitar_neck = guitar_with_notes(notes)
for i in range(6):
for j in range(12):
if guitar_neck[i, j] == True:
plot([(j - 0.5) / 12.], [(5 - i) / 5. * self.scale], 'bo')
if labels != []:
text = dict(zip(notes, labels))[int2note(guitar[i, j])]
else:
text = int2note(guitar[i, j])
annotate(text, ((j - 0.5) / 12., (5 - i + 0.15) / 5. * self.scale))
def plot_neck_and_notes(self, notes, labels=[]):
self.plot_neck()
self.plot_notes(notes, labels)
gca().set_axis_off()
figure(figsize=(15, 4))
gp = guitar_plotter()
gp.plot_neck_and_notes(['C', 'E', 'G'], ['1', '3', '5'])
figure(figsize=(15, 4))
gp = guitar_plotter()
gp.plot_neck_and_notes(['C', 'E', 'G', 'B'], ['1', '3', '5', '7'])
figure(figsize=(15, 4))
gp = guitar_plotter()
gp.plot_neck_and_notes(['D', 'F', 'A', 'C'], ['1', 'b3', '5', 'b7'])
figure(figsize=(15, 4))
gp = guitar_plotter()
gp.plot_neck_and_notes(['G', 'B', 'D', 'F'], ['1', '3', '5', 'b7'])
figure(figsize=(15, 4))
gp = guitar_plotter()
gp.plot_neck_and_notes(['B', 'D', 'F', 'A'], ['1', 'b3', 'b5', 'b7'])
figure(figsize=(15, 4))
gp = guitar_plotter()
gp.plot_neck_and_notes(['A', 'B', 'C', 'E'], ['1', '2', 'b3', '5'])
Au vu du diagramme ci-dessus, il me semble que la meilleure position pour jouer l'accord mineur vers suspendu soit celle avec la tonique sur la corde de La, en barré.
from IPython.html.widgets import interact
:0: FutureWarning: IPython widgets are experimental and may change in the future.
def show_notes(notes):
notes = notes.split(',')
gp = guitar_plotter()
gp.plot_neck_and_notes(notes, notes)
interact(show_notes,
notes="")
"A,".split(',')