initial commit

master
Matteo 2017-11-20 18:08:55 +00:00
parent 8b5ce065e0
commit 2158849c5c
25 changed files with 1750 additions and 0 deletions

25
Armonia.py 100644
View File

@ -0,0 +1,25 @@
#!/usr/bin/env python3
#contiene una classe che contiene i metodi per trovare tutte
#le armoniche data una frequenza
# E` necessaria una classe? Non ha neanche attributi...
def armonica(f, typeOf):
types = {"8_inf" : 1/2,
"2_maj" : 9/8,
"2_min" : 16/15,
"3_maj" : 5/4,
"3_min" : 6/5,
"4" : 4/3,
"4_rai" : 3/2,
"4_dec" : 64/45,
"5" : 3/2,
"6_maj" : 5/3,
"6_min" : 8/5,
"7_maj" : 15/8,
"7_min" : 9/5,
"8" : 2,
}
return f*types.get(typeOf)

62
Prova_main.py 100755
View File

@ -0,0 +1,62 @@
#!/usr/bin/env python3
#prova di utilizzo di una classe per per produrre le note armoniche
#e per mappare il CSV che indica per ogni nota la sua frequenza naturale
import numpy as np
import pyaudio
import csv
from Armonia import armonica
import csv
reader = csv.reader(open('note.csv', 'r'))
nota = {}
for rows in reader:
k, v = rows
nota[k] = float(v)
fr = 0
while nota.get(fr) == None:
fr = input("inserisci in MAIUSC il nome della nota di cui fare le armoniche,\ninserire anche l'ottava a cui appariene (2-7):")
f = float(nota.get(fr))
print(f)
duration = 0.6
fs = 44100
volume = 1.0
i = 0
# inizializzo questo oggetto pyaudio, parte sonora
p = pyaudio.PyAudio()
#ciclo in cui si fanno tutti gli accordi della frequenza data
while f<4200:
accordo_maggiore=[f, armonica(f, "3_maj"), armonica(f, "5")]
prima = (np.sin(2*np.pi*np.arange(fs*duration)*accordo_maggiore[0]/fs)).astype(np.float32)
terza = (np.sin(2*np.pi*np.arange(fs*duration)*accordo_maggiore[1]/fs)).astype(np.float32)
quinta = (np.sin(2*np.pi*np.arange(fs*duration)*accordo_maggiore[2]/fs)).astype(np.float32)
print('ACCORDO MAGGIORE', (accordo_maggiore[0], accordo_maggiore[1], accordo_maggiore[2]))
stream = p.open(format=pyaudio.paFloat32, channels=1, rate=fs, output=True)
stream.write(volume*prima)
stream.write(volume*terza)
stream.write(volume*quinta)
stream.stop_stream()
#ottava maggiore
f = f*2+0.15
while f>66:
f = f/2
accordo_maggiore=[f, armonica(f, "3_maj"), armonica(f, "5")]
quinta = (np.sin(2*np.pi*np.arange(fs*duration)*accordo_maggiore[2]/fs)).astype(np.float32)
terza = (np.sin(2*np.pi*np.arange(fs*duration)*accordo_maggiore[1]/fs)).astype(np.float32)
prima = (np.sin(2*np.pi*np.arange(fs*duration)*accordo_maggiore[0]/fs)).astype(np.float32)
print('ACCORDO MAGGIORE', (accordo_maggiore[2], accordo_maggiore[1], accordo_maggiore[0]))
stream = p.open(format=pyaudio.paFloat32, channels=1, rate=fs, output=True)
stream.write(volume*quinta)
stream.write(volume*terza)
stream.write(volume*prima)
stream.stop_stream()
stream.close()
p.terminate()

44
README.txt 100644
View File

@ -0,0 +1,44 @@
Analisi dinamica del codice
- Isomorfismi sinestetici
Partendo dalla domanda "come si identifica un suono?"
si identificano quattro componenti. Ci si pone l'obiettivo
di scegliere come queste componenti possano essere
rappresentate dal codice. Una breve proposta di seguito/
+--------------------------------+
| SUONI CODICE |
| |
| timbro tipo di dato |
| altezza valore |
| velocita` ??? costante??? |
| durata elementi contenuti |
| |
| chiave classe |
| tempo metodo/funzione |
| pausa ??? |
+--------------------------------+
Problemi da risolvere:
- altezza: range troppo alti. In python ad esempio il valore int massimo
e` 9223372036854775807. Quindi non ha senso associare una nota
ad ogni possibile valore. Una soluzione puo` essere quella di
analizzare nel codice valori massimi e minimi che ogni variabile
puo` assumere con un dato input e creare un range usando quelle
come estremi.
Con i float il discorso si complica leggermente, ma per risolverlo
e` possibile stabilire quali siano
- maggior valore
- minor valore
- minimo scarto tra valori
e aggiustare la scala di conseguenza.
Con questo metodo si ottiene qualcosa di udibile sempre ma e` possibile
ottenere spesso qualcosa di non fedele (ad esempio, una variabile
intera che assume i valori 9223372036854775807 e 9223372036854775007
che rumore fa rispetto ad una che assume i valori 2 e 30?).
Durata: elementi contenuti
Dipende. Riempire un array di 100000 elementi a suonare impiega lo
stesso tempo di riempirne uno di 2?
NO! Ma uno da 100000 deve risultare secondo me ben piu` acelerato di
uno da due (direi massimo 10 volte di piu`).
Per calcolare l'acelerazione si fa tipo log2(n). Onesto.

View File

@ -0,0 +1,38 @@
#!/usr/bin/env python3
#contiene una classe che contiene i metodi per trovare tutte
#le armoniche data una frequenza
# E` necessaria una classe? Non ha neanche attributi...
class Armonia:
_types = {"8_inf" : 1/2,
"2_maj" : 9/8,
"2_min" : 16/15,
"3_maj" : 5/4,
"3_min" : 6/5,
"4" : 4/3,
"4_rai" : 3/2,
"4_dec" : 64/45,
"5" : 3/2,
"6_maj" : 5/3,
"6_min" : 8/5,
"7_maj" : 15/8,
"7_min" : 9/5,
"8" : 2,
}
#la funzione prende in input una nota e l'accordo che si vuole raggiungere e genera una nuova "nota"
def nota_armonica(f, typeOf):
return f*types.get(typeOf)
#definisce le note possibili che vengono usate dentro quella classe.
def armonia(self, nota):
accordo = []
pas = list(types.keys())
infima = nota
#questo ciclo cerca l'ottava piu' piccola udibile della nota passata
while infima > 66: infima = nota_armonica(infima, pas[0])
#vengono salvati in una lista tutte le armoniche di quella nota
while infima < 4200:
for i in pas[1:]:
accordo.append(nota_armonica(infima, i)

View File

@ -0,0 +1,4 @@
#!/usr/bin/env python3
class Durata():
# TODO combiare la durata in fuzione di quello che si fa

View File

@ -0,0 +1,5 @@
#!/usr/bin/env python3
class Evaluate():
# TODO deve avere delle funzioni che prendano in input pezzi del codice che devono essere eseguiti
# analisi dinamica del codice

View File

@ -0,0 +1,72 @@
#!/usr/bin/env python3
# dictionary che raccoglie tutti i tipi che vengono parserati da ast e ne restituisce le funzioni che quel tipo deve eseguire
# tuple, contengono funzioni: cercare in prondita' o caricando valori foglia dell'albero, chiare le funzioni di traduttore musicale
class function_node():
typeOfNode = {
'ast.Num' : ('node.n',),
'ast.Str' : ('node.s',),
'ast.FormattedValues' : ('node.value',),
'ast.JoinedStr' : ('node.values',),
'ast.Bytes' : ('node.s',),
'ast.List' : ('node.elts',),
'ast.Tuple' : ('node.elts',),
'ast.Set' : ('node.elts',),
'ast.Dict' : ('node.keys',),
'ast.NameConstant' : ('node.value',),
'ast.Name' : ('node.id',),
'ast.Starred' : ('node.value',),
'ast.Expr' : ('node.value',),
'ast.UnaryOP' : ('node.operand',),
'ast.BinOp' : ('[node.left, node.right]',),
'ast.BoolOP' : ('[node.op, node.values]',),
'ast.Compare' : ('[node.left, node.ops, node.comparators]',),
'ast.Call' : ('[node.func, node.args, node.keywords]',),
'ast.keyword' : ('[node.arg, node.value]',),
'ast.ifExp' : ('[node.test, node.body, node.orelse]',),
'ast.Attribute' : ('[node.attr, node.value]',),
'ast.Subscript' : ('[node.slice, node.value]',),
'ast.Index' : ('node.value',),
'ast.Slice' : ('[node.lower, node.upper, node.step]',),
'ast.ExtSlice' : ('node.dims',),
'ast.ListCompe' : ('[node.generators, node.elt]',),
'ast.SetCompe' : ('[node.generators, node.elt]',),
'ast.GeneratorExp' : ('[node.generators, node.elt]',),
'ast.DictComp' : ('[node.key, node.value, node.generator]',),
'ast.comprehension' : ('[node.target, node.iter, node.ifs]',),
'ast.Assign' : ('[node.targets, node.value]',),
'ast.AnnAssign' : ('[node.targets, node.target, node.value, node.simple]',),
'ast.AugAssign' : ('[node.targets, node.op, node.value]',),
'ast.Print' : ('[node.dest, node.values]',),
'ast.Raise' : ('[node.exc, node.cause]',),
'ast.Assert' : ('[node.test, node.msg]',),
'ast.Delete' : ('node.targets',),
'ast.Import' : ('node.names',),
'ast.ImportFrom' : ('[node.module, node.names, node.level]',),
'ast.Alias' : ('node.name',),
'ast.If' : ('[node.test, node.body, node.orelse]',),
'ast.For' : ('[node.target, node.iter, node.body, node.orelse]',),
'ast.While' : ('[node.test, node.body, node.orelse]',),
'ast.Try' : ('[node.handlers, node.body, node.orelse, node.finalbody]',),
'ast.TryFinally' : ('[node.body, node.finalbody]',),
'ast.TryExcept' : ('[node.handlers, node.body, node.orelse]',),
'ast.ExceptHandler' : ('[node.type, node.name, node.body]',),
'ast.With' : ('[node.items, node.body]',),
'ast.withitem' : ('[node.context_expr]',),
'ast.FunctionDef' : ('[node.name, node.args, node.body, node.decorator_list]',),
'ast.Lambda' : ('[node.args, node.body]',),
'ast.arguments' : ('[node.args, node.default]',),
'ast.arg' : ('[node.arg, node.annotation]',),
'ast.Return' : ('node.value',),
'ast.Yield' : ('node.value',),
'ast.YieldFrom' : ('node.value',),
'ast.Global' : ('node.names',),
'ast.Nonlocal' : ('node.names',),
'ast.ClassDef' : ('[node.name, node.bases, node.keywords, node.starargs, node.body, , node.kwargs, node.decorator_list]','armonia(store.get_nota())'),
'ast.Await' : ('node.value',),
'ast.AsyncFunctionDef' : ('[node.name, node.args, node.body, node.decorator_list, node.returns]',),
'ast.AsyncFor' : ('[node.target, node.iter, node.body, node.orelse]',),
'ast.AsyncWith' : ('[node.items, node.body]',),
'ast.Module' : ('node.body', 'nota()'),
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,5 @@
#!/usr/bin/env python3
def linker(nodo):
# TODO uesto linker dovrebbe cercare i riferimenti e mandare
return nuovo_sorgente

20
kostacivos/main.py 100644
View File

@ -0,0 +1,20 @@
#!/usr/bin/env python3
import parser
import z
import player
import struttura
from sys import argv
# Questo codice non funziona!
#def main():
f = open(argv[1], "r")
source = "".join(x for x in f.readlines())
nodo = parser.parser(source)
visitor = z()
visitor.visit(nodo)
# TODO mancano delle verifiche
return

View File

@ -0,0 +1,73 @@
DO2, 66
DO#2, 70
RE2, 74
RE#2, 78
MI2, 83
FA2, 88
FA#2, 93
SOL2, 98
SOL#2, 104
LA2, 110
LA#2, 117
SI2, 124
DO3, 131
DO#3, 139
RE3, 147
RE#3, 156
MI3, 165
FA3, 175
FA#3, 185
SOL3, 196
SOL#3, 208
LA3, 220
LA#3, 233
SI3, 247
DO4, 262
DO#4, 277
RE4, 294
RE#4, 311
MI4, 330
FA4, 349
FA#4, 370
SOL4, 392
SOL#4, 415
LA4, 440
LA#4, 466
SI4, 494
DO5, 523
DO#5, 554
RE5, 587
RE#5, 622
MI5, 659
FA5, 698
FA#5, 740
SOL5, 784
SOL#5, 831
LA5, 880
LA#5, 932
SI5, 988
DO6, 1046
DO#6, 1109
RE6, 1175
RE#6, 1245
MI6, 1319
FA6, 1397
FA#6, 1480
SOL6, 1568
SOL#6, 1661
LA6, 1760
LA#6, 1865
SI6, 1976
DO7, 2093
DO#7, 2217
RE7, 2349
RE#7, 2489
MI7, 2637
FA7, 2794
FA#7, 2960
SOL7, 3136
SOL#7, 3322
LA7, 3520
LA#7, 3729
SI7, 3951
DO8, 4186
1 DO2 66
2 DO#2 70
3 RE2 74
4 RE#2 78
5 MI2 83
6 FA2 88
7 FA#2 93
8 SOL2 98
9 SOL#2 104
10 LA2 110
11 LA#2 117
12 SI2 124
13 DO3 131
14 DO#3 139
15 RE3 147
16 RE#3 156
17 MI3 165
18 FA3 175
19 FA#3 185
20 SOL3 196
21 SOL#3 208
22 LA3 220
23 LA#3 233
24 SI3 247
25 DO4 262
26 DO#4 277
27 RE4 294
28 RE#4 311
29 MI4 330
30 FA4 349
31 FA#4 370
32 SOL4 392
33 SOL#4 415
34 LA4 440
35 LA#4 466
36 SI4 494
37 DO5 523
38 DO#5 554
39 RE5 587
40 RE#5 622
41 MI5 659
42 FA5 698
43 FA#5 740
44 SOL5 784
45 SOL#5 831
46 LA5 880
47 LA#5 932
48 SI5 988
49 DO6 1046
50 DO#6 1109
51 RE6 1175
52 RE#6 1245
53 MI6 1319
54 FA6 1397
55 FA#6 1480
56 SOL6 1568
57 SOL#6 1661
58 LA6 1760
59 LA#6 1865
60 SI6 1976
61 DO7 2093
62 DO#7 2217
63 RE7 2349
64 RE#7 2489
65 MI7 2637
66 FA7 2794
67 FA#7 2960
68 SOL7 3136
69 SOL#7 3322
70 LA7 3520
71 LA#7 3729
72 SI7 3951
73 DO8 4186

View File

@ -0,0 +1,12 @@
#!/usr/bin/env python3
import parser
import ast
def parser(self, source):
tree = ast.parse(source)
return tree
def linker(self, node):
# e' da leggere il codice
#linker(source, glob())

View File

@ -0,0 +1,14 @@
#!/usr/bin/env python3
import pyaudio
import struttura
def player(songa):
volume = songa.volume
onda = songa.waveform
p = pyaudio.PyAudio()
stream = p.open(format=pyaudio.paFloat32, channels=1, rate=fs, output=True)
stream.write(volume*onda)
stream.stop_stream()

View File

@ -0,0 +1,44 @@
#!/usr/bin/env python3
# per il momento questa parte di codice e' di dubbia utilita'
# TODO
ACOUSTIC_SCALE = [0, 2, 4, 6, 7, 9, 10]
ADONAI_MALAKH = [0, 2, 4, 5, 7, 8, 10]
AEOLIAN_MODE = [0, 2, 3, 5, 7, 8, 10]
ALGERIAN_SCALE = [0, 2, 3, 6, 7, 8, 11]
ALTERED_SCALE = [0, 1, 3, 4, 6, 8, 10]
AUGMENTED_SCALE = [0, 3, 4, 7, 8, 11]
BEBOP_DOMINANT = [0, 2, 4, 5, 7, 9, 10, 11]
BLUES_SCALE = [0, 3, 5, 6, 7, 10]
DORIAN_MODE = [0, 2, 3, 5, 7, 9, 10]
DOUBLE_HARMONIC_SCALE = [0, 1, 4, 5, 7, 8, 11]
ENIGMATIC_SCALE = [0, 1, 4, 6, 8, 10, 11]
FLAMENCO_MODE = [0, 1, 4, 5, 7, 8, 11]
GYPSY_SCALE = [0, 2, 3, 6, 7, 8, 10]
HALF_DIMINISHED_SCALE = [0, 2, 3, 5, 6, 8, 10]
HARMONIC_MAJOR_SCALE = [0, 2, 4, 5, 7, 8, 11]
HARMONIC_MINOR_SCALE = [0, 2, 3, 5, 7, 8, 11]
HIRAJOSHI_SCALE = [0, 4, 6, 7, 11]
HUNGARIAN_GYPSY_SCALE = [0, 2, 3, 6, 7, 8, 11]
INSEN_SCALE = [0, 1, 5, 7, 10]
IONIAN_MODE = [0, 2, 4, 5, 7, 9, 11]
IWATO_SCALE = [0, 1, 5, 6, 11]
LOCRIAN_MODE = [0, 1, 3, 5, 6, 8, 10]
LYDIAN_AUGMENTED_SCALE = [0, 2, 4, 6, 8, 9, 11]
LYDIAN_MODE = [0, 2, 4, 6, 7, 9, 11]
MAJOR_LOCRIAN = [0, 2, 4, 5, 6, 8, 10]
MELODIC_MINOR_SCALE = [0, 2, 3, 5, 7, 9, 11]
MIXOLYDIAN_MODE = [0, 2, 4, 5, 7, 9, 10]
NEAPOLITAN_MAJOR_SCALE = [0, 1, 3, 5, 7, 9, 11]
NEAPOLITAN_MINOR_SCALE = [0, 1, 3, 5, 7, 8, 11]
PERSIAN_SCALE = [0, 1, 4, 5, 6, 8, 11]
PHRYGIAN_MODE = [0, 1, 3, 5, 7, 8, 10]
PROMETHEUS_SCALE = [0, 2, 4, 6, 9, 10]
TRITONE_SCALE = [0, 1, 4, 6, 7, 10]
UKRAINIAN_DORIAN_SCALE = [0, 2, 3, 6, 7, 9, 10]
WHOLE_TONE_SCALE = [0, 2, 4, 6, 8, 10]
MAJOR = [0, 2, 4, 5, 7, 9, 11]
MINOR = [0, 2, 3, 5, 7, 8, 10]

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

View File

@ -0,0 +1,38 @@
#!/usr/bin/env python3
# getter e setter delle variabili sonore
class stuttura():
nota = 0
accordo = []
waveform = []
tempo = 0
volume = 0
scala = []
def get_nota():
return nota
def get_accordo():
return accordo
def get_tempo():
return tempo
def get_waveform():
return waveform
def get_volume():
return volume
def get_scala():
return scala
def set_nota(self, nota):
return nota
def set_accordo(self, accordo):
return accordo
def set_tempo(self, tempo):
self.tempo = tempo
def set_waveform(self, waveform):
self.waveform = waveform
def set_volume(self, volume):
self.volume = volume
def set_scala( scala):
self.scala = scala

View File

@ -0,0 +1,4 @@
#!/usr/bin/env python3
class Tempo():
# TODO combiare il tempo in fuzione di quello che si fa

View File

@ -0,0 +1,121 @@
import ast
import re
from Note import nota
from Armonia import armonia
import struttura
store = struttura()
# dictionary che raccoglie tutti i tipi che vengono parserati da ast e ne restituisce le funzioni che quel tipo deve eseguire
# tuple, contengono funzioni: cercare in prondita' o caricando valori foglia dell'albero, chiare le funzioni di traduttore musicale
typeOfNode = {
'ast.Num' : ('node.n',),
'ast.Str' : ('node.s',),
'ast.FormattedValues' : ('node.value',),
'ast.JoinedStr' : ('node.values',),
'ast.Bytes' : ('node.s',),
'ast.List' : ('node.elts',),
'ast.Tuple' : ('node.elts',),
'ast.Set' : ('node.elts',),
'ast.Dict' : ('node.keys',),
'ast.NameConstant' : ('node.value',),
'ast.Name' : ('node.id',),
'ast.Starred' : ('node.value',),
'ast.Expr' : ('node.value',),
'ast.UnaryOP' : ('node.operand',),
'ast.BinOp' : ('[node.left, node.right]',),
'ast.BoolOP' : ('[node.op, node.values]',),
'ast.Compare' : ('[node.left, node.ops, node.comparators]',),
'ast.Call' : ('[node.func, node.args, node.keywords]',),
'ast.keyword' : ('[node.arg, node.value]',),
'ast.ifExp' : ('[node.test, node.body, node.orelse]',),
'ast.Attribute' : ('[node.attr, node.value]',),
'ast.Subscript' : ('[node.slice, node.value]',),
'ast.Index' : ('node.value',),
'ast.Slice' : ('[node.lower, node.upper, node.step]',),
'ast.ExtSlice' : ('node.dims',),
'ast.ListCompe' : ('[node.generators, node.elt]',),
'ast.SetCompe' : ('[node.generators, node.elt]',),
'ast.GeneratorExp' : ('[node.generators, node.elt]',),
'ast.DictComp' : ('[node.key, node.value, node.generator]',),
'ast.comprehension' : ('[node.target, node.iter, node.ifs]',),
'ast.Assign' : ('[node.targets, node.value]',),
'ast.AnnAssign' : ('[node.targets, node.target, node.value, node.simple]',),
'ast.AugAssign' : ('[node.targets, node.op, node.value]',),
'ast.Print' : ('[node.dest, node.values]',),
'ast.Raise' : ('[node.exc, node.cause]',),
'ast.Assert' : ('[node.test, node.msg]',),
'ast.Delete' : ('node.targets',),
'ast.Import' : ('node.names',),
'ast.ImportFrom' : ('[node.module, node.names, node.level]',),
'ast.Alias' : ('node.name',),
'ast.If' : ('[node.test, node.body, node.orelse]',),
'ast.For' : ('[node.target, node.iter, node.body, node.orelse]',),
'ast.While' : ('[node.test, node.body, node.orelse]',),
'ast.Try' : ('[node.handlers, node.body, node.orelse, node.finalbody]',),
'ast.TryFinally' : ('[node.body, node.finalbody]',),
'ast.TryExcept' : ('[node.handlers, node.body, node.orelse]',),
'ast.ExceptHandler' : ('[node.type, node.name, node.body]',),
'ast.With' : ('[node.items, node.body]',),
'ast.withitem' : ('[node.context_expr]',),
'ast.FunctionDef' : ('[node.name, node.args, node.body, node.decorator_list]',),
'ast.Lambda' : ('[node.args, node.body]',),
'ast.arguments' : ('[node.args, node.default]',),
'ast.arg' : ('[node.arg, node.annotation]',),
'ast.Return' : ('node.value',),
'ast.Yield' : ('node.value',),
'ast.YieldFrom' : ('node.value',),
'ast.Global' : ('node.names',),
'ast.Nonlocal' : ('node.names',),
'ast.ClassDef' : ('[node.name, node.bases, node.keywords, node.starargs, node.body, , node.kwargs, node.decorator_list]','armonia(store.get_nota())'),
'ast.Await' : ('node.value',),
'ast.AsyncFunctionDef' : ('[node.name, node.args, node.body, node.decorator_list, node.returns]',),
'ast.AsyncFor' : ('[node.target, node.iter, node.body, node.orelse]',),
'ast.AsyncWith' : ('[node.items, node.body]',),
'ast.Module' : ('node.body', 'nota()'),
}
# visitatore padre che cerca funzioni di tipo nodo
class v(ast.NodeVisitor):
def generic_visit(self, node):
print (type(node).__name__)
ast.NodeVisitor.generic_visit(self, node)
# visitatore figlio, dato un nodo percorre tutto l'albero
# esegue anche le funzioni di traduzione assegnate ad ogni nodo
class z(v):
import ast
def visit(self, node):
a = 0
funzione = 0
for i in typeOfNode:
if re.match(i, str(type(node))[9:]):
print (type(node), typeOfNode.get(i))
locals()
a = eval(typeOfNode.get(i)[0], locals())
try:
funzione = eval(typeOfNode.get(i)[1], locals(), globals())
print (funzione)
except: pass
l = z()
print (typeOfNode.get(i)[0]+'\n')
try:
print (type(a))
for i in a:
if type(i) == list:
for j in i:
l.visit(j)
else :
l.visit(i)
except:
try:
if re.match('ast', str(type(a))[9:]):
l.visit(a)
else:
print(a)
except: print ('---------------------> Pass'),
return a
a = z()
g = a.visit(tree01)

View File

@ -0,0 +1,4 @@
#!/usr/bin/env python3
class Volume():
# TODO combiare il volume in fuzione di quello che si fa

View File

@ -0,0 +1,4 @@
#!/usr/bin/env python3
class Waveform():
# TODO combiare le onde in fuzione di quello che si fa

73
note.csv 100644
View File

@ -0,0 +1,73 @@
DO2, 66
DO#2, 70
RE2, 74
RE#2, 78
MI2, 83
FA2, 88
FA#2, 93
SOL2, 98
SOL#2, 104
LA2, 110
LA#2, 117
SI2, 124
DO3, 131
DO#3, 139
RE3, 147
RE#3, 156
MI3, 165
FA3, 175
FA#3, 185
SOL3, 196
SOL#3, 208
LA3, 220
LA#3, 233
SI3, 247
DO4, 262
DO#4, 277
RE4, 294
RE#4, 311
MI4, 330
FA4, 349
FA#4, 370
SOL4, 392
SOL#4, 415
LA4, 440
LA#4, 466
SI4, 494
DO5, 523
DO#5, 554
RE5, 587
RE#5, 622
MI5, 659
FA5, 698
FA#5, 740
SOL5, 784
SOL#5, 831
LA5, 880
LA#5, 932
SI5, 988
DO6, 1046
DO#6, 1109
RE6, 1175
RE#6, 1245
MI6, 1319
FA6, 1397
FA#6, 1480
SOL6, 1568
SOL#6, 1661
LA6, 1760
LA#6, 1865
SI6, 1976
DO7, 2093
DO#7, 2217
RE7, 2349
RE#7, 2489
MI7, 2637
FA7, 2794
FA#7, 2960
SOL7, 3136
SOL#7, 3322
LA7, 3520
LA#7, 3729
SI7, 3951
DO8, 4186
1 DO2 66
2 DO#2 70
3 RE2 74
4 RE#2 78
5 MI2 83
6 FA2 88
7 FA#2 93
8 SOL2 98
9 SOL#2 104
10 LA2 110
11 LA#2 117
12 SI2 124
13 DO3 131
14 DO#3 139
15 RE3 147
16 RE#3 156
17 MI3 165
18 FA3 175
19 FA#3 185
20 SOL3 196
21 SOL#3 208
22 LA3 220
23 LA#3 233
24 SI3 247
25 DO4 262
26 DO#4 277
27 RE4 294
28 RE#4 311
29 MI4 330
30 FA4 349
31 FA#4 370
32 SOL4 392
33 SOL#4 415
34 LA4 440
35 LA#4 466
36 SI4 494
37 DO5 523
38 DO#5 554
39 RE5 587
40 RE#5 622
41 MI5 659
42 FA5 698
43 FA#5 740
44 SOL5 784
45 SOL#5 831
46 LA5 880
47 LA#5 932
48 SI5 988
49 DO6 1046
50 DO#6 1109
51 RE6 1175
52 RE#6 1245
53 MI6 1319
54 FA6 1397
55 FA#6 1480
56 SOL6 1568
57 SOL#6 1661
58 LA6 1760
59 LA#6 1865
60 SI6 1976
61 DO7 2093
62 DO#7 2217
63 RE7 2349
64 RE#7 2489
65 MI7 2637
66 FA7 2794
67 FA#7 2960
68 SOL7 3136
69 SOL#7 3322
70 LA7 3520
71 LA#7 3729
72 SI7 3951
73 DO8 4186

46
parser/syntax.py 100644
View File

@ -0,0 +1,46 @@
import json
import parser
import ast
from sys import argv
#f = open(argv[1], "r")
f = open("../test.py", "r")
source = "".join(x for x in f.readlines())
#print(parser.suite(source).tolist())
tree = ast.parse(source)
#print(ast.dump(tree))
#class Tree(ast.NodeTransformer):
# def __init__(self, source):
# r = ast.parse(source)
# self.visit(r)
# def vist_Str(self, node):
# print(ast.Str(node.body))
a = ast.parse(source)
#Tree().vist_Str(a)
def nodes(parsed_source):
r = []
for i in ast.walk(parsed_source):
r.append(i)
return r
#print(nodes(a))
f = open("../test.py", "r")
linee = f.readlines()
# da completare sta puttanata dello strip
#for i in linee:
# i = i.rstrip()
for i in ast.walk(a):
try:
print(str(i.lineno-1) + " " + linee[i.lineno-1])
except:
print("SALTATA" + " " + str(i))
# Divagazioni notturne importanti
# Ecco come funziona Visitor
my_visit = ast.NodeVisitor()
print(my_visit.visit(a))
# peccato non stampi nulla

53
test.py 100755
View File

@ -0,0 +1,53 @@
#!/usr/bin/env python3
# Semplice file per far vedere come possono essere
# regolate altezza,intensita`, durata, e timbro
# di un suono tramite pyaudio
import numpy as np
import pyaudio
from Armonia import armonica
# dati per l'inizializzazione dell'onda
duration = 2.0
fs = 44100
volume = 1.0
# frequenza la 66 Hz il DO piu' basso udibile
f = 66.0
i=0
nota = armonica(f, "5")
while i<7:
# inizializzo questo oggetto pyaudio
p = pyaudio.PyAudio()
# onda sinusoidale, non so bene perche` e` da fare cosi`
prima = (np.sin(2*np.pi*np.arange(fs*duration)*f/fs)).astype(np.float32)
print(prima)
stream = p.open(format=pyaudio.paFloat32, channels=1, rate=fs, output=True)
# riproduce lo stream al volume impostato
stream.write(volume*prima)
stream.stop_stream()
# genera la quinta nota armonica naturale della nota di partenza
h = armonica(f, "3_maj")
p = pyaudio.PyAudio()
terza = (np.sin(2*np.pi*np.arange(fs*duration)*h/fs)).astype(np.float32)
print(terza)
stream = p.open(format=pyaudio.paFloat32, channels=1, rate=fs, output=True)
stream.write(volume*terza)
stream.stop_stream()
# genera la terza nota armonica naturale della nota di partenza
g = armonica(f, "5")
p = pyaudio.PyAudio()
quinta = (np.sin(2*np.pi*np.arange(fs*duration)*g/fs)).astype(np.float32)
print(quinta)
stream = p.open(format=pyaudio.paFloat32, channels=1, rate=fs, output=True)
stream.write(volume*quinta)
stream.stop_stream()
# passa alla prossima ottava
f=f*2-1+i
i=i+1
stream.close()
p.terminate()

View File

@ -0,0 +1,71 @@
import ast
arm = open("Armonia.py")
source02 = "".join(x for x in arm.readlines())
tree02 = ast.parse(source02)
t = open("test.py")
source = "".join(x for x in t.readlines())
tree = ast.parse(source)
p = open("Prova_main.py")
source01 = "".join(x for x in p.readlines())
tree01 = ast.parse(source01)
ast.dump(tree01, annotate_fields = False)
def visitor_pers(self, node):
typeOfNode = { ast.Num : node.n,
ast.Str : node.s,
ast.FormattedValues : node.value,
ast.JoinedStr : node.values,
ast.Bytes : node.s,
ast.List : node.elts,
ast.Tuple : node.elts,
ast.Set : node.elts,
ast.Dict : node.keys,
ast.NameConstant : node.value,
ast.Name : node.id,
ast.Starred : node.value,
ast.Expr : node.value,
ast.UnaryOP : node.operand,
ast.BinOp : [node.left, node.right],
ast.BoolOP : node.values,
ast.Compare : [node.left, node.comparators],
ast.Call : node.args,
ast.keyword : [node.arg, node.value],
ast.ifExp : node.body,
ast.Attribute : [node.attr, node.value],
ast.Subscript : node.value,
ast.Index : node.value,
ast.Slice : [node.lower, node.upper],
ast.ExtSlice : node.dimis,
ast.ListCompe : [node.generators, node.elt],
ast.SetCompe : [node.generators, node.elt],
ast.GeneratorExp : [node.generators, node.elt],
ast.DictComp : [node.key, node.value, node.elt],
ast.comprehension : [node.target, node.iter],
ast.Assign : [node.targets, node.value],
ast.AnnAssign : [node.targets, node.value, node.simple],
ast.AugAssign : [node.targets, node.value],
ast.Print : [node.dest, node.values],
ast.Raise : [node.exce, node.cause],
ast.Assert : [node.test, node.msg],
ast.Delete : node.targets,
ast.Import : node.names,
ast.ImportFrom : [node.module, node.names],
ast.Alias : node.name,
ast.Assign : [node.targets, node.value],
ast.If : [node.test, node.body, node.orelse],
ast.For : [node.target, node.iter, node.body, node.orelse],
ast.While : [node.test, node.body, node.orelse],
ast.Try : [node.handlers, node.body, node.orelse, node.finalbody],
ast.TryFinally : [node.body, node.finalbody],
ast.TryExcept : [node.handlers, node.body, node.orelse],
ast.ExceptHandler : [node.type, node.name, node.body}
ast.With : [node.items, node.body],
ast.withitem : [node.context_expr],
ast.FunctionDef : [node.name, node.args, node.body],
ast.Lambda : [node.args, node.body],
ast.arguments : [node.args, node.default],
ast.arg : [node.items, node.body],
}