def test_span_limit(self): one = music.Chord(['F3', 'A#5']) self.assertEqual(one.shapes, [[1, None, None, None, None, 6]]) two = music.Chord(['F3', 'F5']) self.assertEqual( two.shapes, [[1, None, None, None, 6, None], [1, None, None, None, None, 1]])
def progress_with_connection(): # arr = [ # 'Cm7', 'Cm7', 'Cm7', 'Cm7', 'Cm7', 'Cm7', 'Cm7', 'Cm7', # 'Fm7', 'Fm7', 'Fm7', 'Fm7', 'Fm7', 'Fm7', 'Fm7', 'Fm7', # 'Dm7-5', 'Dm7-5', 'Dm7-5', 'Dm7-5', 'G7#5', 'G7#5', 'G7#5', 'G7#5', # 'Cm7', 'Cm7', 'Cm7', 'Cm7', 'Cm7', 'Cm7', 'Cm7', 'Cm7', # # 'Ebm7', 'Ebm7', 'Ebm7', 'Ebm7', 'Ab9', 'Ab9', 'Ab9', 'Ab9', # 'DbM7', 'DbM7', 'DbM7', 'DbM7', 'DbM7', 'DbM7', 'DbM7', 'DbM7', # 'Dm7-5', 'Dm7-5', 'Dm7-5', 'Dm7-5', 'G7#5', 'G7#5', 'G7#5', 'G7#5', # 'Cm7', 'Cm7', 'Cm7', 'Cm7', 'Cm7', 'Cm7', 'G7b9', 'G7b9', # ] arr = "Bmaj7,D7,Gmaj7,Bb7,Ebmaj7,Ebmaj7,Am7,D7," \ "Gmaj7,Bb7,Ebmaj7,Gb7,Bmaj7,Bmaj7,Fm7,Bb7," \ "Ebmaj7,Ebmaj7,Am7,D7," \ "Gmaj7,Gmaj7,Dbm7,Gb7," \ "Bmaj7,Bmaj7,Fm7,Bb7," \ "Ebmaj7,Ebmaj7,D7,D7".split(',') arr *= 5 lastchord = music.Chord('Cmaj7') for name in arr: c = music.Chord(name) c.connect_to(lastchord) c.show_info() lastchord = c ps.play(c, interval=0, duration=0.6)
def main(): lastchord = music.Chord('Cmaj7') lastchord.expand() while 1: try: chord = input('> ') chord = music.Chord(chord) chord.connect_to(lastchord) lastchord = chord ps.play(chord, interval=0.1, duration=0.2) except Exception as e: print(e)
def __init__(self, parent, n, lines, box): self.parent = parent self.n = n self.lines = lines self.box = box self.origin = (min(box[0], box[2]), min(box[1], box[3])) # (x, y) self.image = self.subarray(self.parent.image, box) self.gray = self.subarray(self.parent.gray, box) self.note_size = int(self.parent.staff_size / 4) q = cv2.imread('template/Q.png', cv2.IMREAD_GRAYSCALE) scale = self.note_size / q.shape[0] self.q = cv2.resize( q, None, fx=scale, fy=scale, ) # Find and group notes note_blobs = self.find_notes() self.notes = self.filter_local_maxima(note_blobs, self.note_size) self.chord_groups = self.group_chords(self.notes) # Assign names to found notes key = (min(i[1] for i in self.lines) - self.origin[1], max(i[1] for i in self.lines) - self.origin[1]) named_groups = [self.name_notes(i, key) for i in self.chord_groups] try: self.chords = [music.Chord([*chord]) for chord in named_groups] except ValueError: self.chords = []
def test_song_add(self): songs = [music.Song() for i in range(3)] songs[0].add(music.Note('E3')) songs[1].add(music.Chord(['E3'])) songs[2].add('E3') for song in songs: self.assertIn('E3', str(song.notes)) # This is sloppy
def randomlyplaywithconnection(): arr = [ 'Ebmaj7', 'Fm7', 'Fo7', 'G7', 'Abmaj7', 'Ab7', 'Gm', 'Bb7', 'Cm7', 'Do7', 'Dbmaj7' ] lastchord = music.Chord('Ebmaj7') l = [] for ch in arr: l.append(music.Chord(ch)) for i in range(200): ch = random.choice(l) ch.connect_to(lastchord) ch.show_info() for i in range(1): ps.play(ch, interval=0.04, duration=1) lastchord = ch
def __init__(self, m, n): PanelPattern.__init__(self, m, n) self.call_name = 'arTheoryDemo' self.frameCount = 0 self.frame_sleep_time = 0.0 self.pix_np = np.zeros([3, self.m, self.n]) self.stream = micStream.Stream() self.volume = music.ExpFilter(0.0, alpha_rise=0.8, alpha_decay=0.3) self.keyObj = music.Key(self.stream.notes) self.noteSumsObj = music.NoteSums(self.stream.notes) self.chordObj = music.Chord(self.stream.notes)
def setUp(self): self.e = music.Chord([-8, -1, 4, 8, 11, 16]) self.a = music.Chord([-8, -3, 4, 9, 13, 16]) self.d = music.Chord([-3, 2, 9, 14, 18]) self.g = music.Chord([-5, -1, 2, 7, 11, 19]) self.c = music.Chord([-8, 0, 4, 7, 12, 16]) self.b = music.Chord([-6, -1, 6, 11, 15, 18]) self.f = music.Chord([-7, 0, 5, 9, 12, 17]) self.chords = [self.e, self.a, self.d, self.g, self.c, self.b, self.f] self.shapes = [ open_e, open_a, open_d, open_g, open_c, barre_b, barre_f ]
def test_mixed_notes(self): song = music.Song() bb_chords = [(['G3', 'B4'], 1 / 6), (['G4'], 1 / 6), (['A3', 'C5'], 1 / 6), (['G4'], 1 / 6), (['B3', 'D5'], 1 / 6), (['G4'], 1 / 6), (['G4', 'B5'], 1 / 4), (['G4'], 1 / 8), (['B5'], 1 / 8), (['G4'], 1 / 8), (['B5'], 1 / 8), (['G4'], 1 / 4)] for chord in bb_chords: song.add(music.Chord(*chord)) g = player.Guitarist(song) try: self.assertEqual(g.arr, blackbird) except AssertionError as AE: print(f'Blackbird, two bars, auto:\n{g.arr}') raise AE
def test_chords(self): song = music.Song() sotw_chords = [(['E3', 'B3', 'E4'], 1 / 4), (['G3', 'D4', 'G4'], 1 / 4), (['A3', 'E4', 'A4'], 3 / 8), (['E3', 'B3', 'E4'], 1 / 4), (['G3', 'D4', 'G4'], 1 / 4), (['B3', 'F#4', 'B4'], 1 / 8), (['A3', 'E4', 'A4'], 1 / 2)] for chord in sotw_chords: song.add(music.Chord(*chord)) g = player.Guitarist(song) try: self.assertEqual(g.arr, smoke_on_the_water) except AssertionError as AE: print(f'Smoke on the Water, two bars, auto:\n{g.arr}') raise AE
def test_4_note_chord_shapes(self): C7 = music.Chord(['C4', 'E4', 'A#4', 'C5']) C7_shape = [(1, 3), (2, 2), (3, 3), (4, 1)] Bdim = music.Chord(['B3', 'F4', 'G#4', 'D5']) Bdim_shape = [(1, 2), (2, 3), (3, 1), (4, 3)] Dmaj7 = music.Chord(['D4', 'A4', 'C#5', 'F#5']) Dmaj7_shape = [(2, 0), (3, 2), (4, 2), (5, 2)] # cV_Dmaj7_shape = [(1,5), (2,7), (3,6), (4,7)] E7 = music.Chord(['B4', 'E5', 'G#5', 'D6']) E7_shape = [(2, 9), (3, 9), (4, 9), (5, 10)] cVII_A = music.Chord(['A4', 'E5', 'A5', 'C#6']) cVII_A_shape = [(2, 7), (3, 9), (4, 10), (5, 9)] cVII_G = music.Chord(['G4', 'B4', 'D5', 'G5']) cVII_G_shape = [(1, 10), (2, 9), (3, 7), (4, 8)] for chord, shape in zip((C7, Bdim, Dmaj7, E7, cVII_A, cVII_G), (C7_shape, Bdim_shape, Dmaj7_shape, E7_shape, cVII_A_shape, cVII_G_shape)): with self.subTest(i=chord): self.assertEqual(chord.shape, shape)