-
Notifications
You must be signed in to change notification settings - Fork 0
/
analysis.py
executable file
·40 lines (24 loc) · 890 Bytes
/
analysis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import music21
import os
MAINDIR = '/home/marcos/Dropbox/ongoing/string-quartets-analysis'
beethoven_dir = MAINDIR + '/beethoven-quartets/'
quartets = sorted(os.listdir(beethoven_dir))
def testa_parts(filename, directory=beethoven_dir):
"""Testa arquivos"""
if len(music21.converter.parse(directory + filename).parts) != 4:
return filename
def flatten(seq):
"""Flatten Sequences.
>>> flatten([[0, 1], [2, 3]])
[0, 1, 2, 3]
"""
return [item for sublist in seq for item in sublist]
q = music21.converter.parse(beethoven_dir + quartets[0])
v1 = q.parts[0]
n = v1.flat.notes
nr = v1.flat.notesAndRests
notas_simples = v1.flat.notes.getElementsNotOfClass(music21.chord.Chord)
acordes = v1.flat.notes.getElementsByClass(music21.chord.Chord)
todas_notas = flatten([notas_simples, flatten(acordes)])