diff --git a/Armonia.py b/Armonia.py new file mode 100644 index 0000000..6f795cf --- /dev/null +++ b/Armonia.py @@ -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) + + diff --git a/Prova_main.py b/Prova_main.py new file mode 100755 index 0000000..410faab --- /dev/null +++ b/Prova_main.py @@ -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() diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..5c77900 --- /dev/null +++ b/README.txt @@ -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. diff --git a/kostacivos/armonia.py b/kostacivos/armonia.py new file mode 100644 index 0000000..56e99f6 --- /dev/null +++ b/kostacivos/armonia.py @@ -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) + + diff --git a/kostacivos/durata.py b/kostacivos/durata.py new file mode 100644 index 0000000..c9a335b --- /dev/null +++ b/kostacivos/durata.py @@ -0,0 +1,4 @@ +#!/usr/bin/env python3 + +class Durata(): + # TODO combiare la durata in fuzione di quello che si fa diff --git a/kostacivos/evaluate.py b/kostacivos/evaluate.py new file mode 100644 index 0000000..9c63632 --- /dev/null +++ b/kostacivos/evaluate.py @@ -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 diff --git a/kostacivos/function_node.py b/kostacivos/function_node.py new file mode 100644 index 0000000..e20571e --- /dev/null +++ b/kostacivos/function_node.py @@ -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()'), + } + diff --git a/kostacivos/kostacivos b/kostacivos/kostacivos new file mode 100644 index 0000000..811d995 --- /dev/null +++ b/kostacivos/kostacivos @@ -0,0 +1,459 @@ + + + + + umbrello uml modeller http://umbrello.kde.org + 1.6.10 + UnicodeUTF8 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/kostacivos/kostacivos.xmi b/kostacivos/kostacivos.xmi new file mode 100644 index 0000000..22052ae --- /dev/null +++ b/kostacivos/kostacivos.xmi @@ -0,0 +1,459 @@ + + + + + umbrello uml modeller http://umbrello.kde.org + 1.6.10 + UnicodeUTF8 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/kostacivos/linker.py b/kostacivos/linker.py new file mode 100644 index 0000000..c9726eb --- /dev/null +++ b/kostacivos/linker.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python3 + +def linker(nodo): + # TODO uesto linker dovrebbe cercare i riferimenti e mandare + return nuovo_sorgente diff --git a/kostacivos/main.py b/kostacivos/main.py new file mode 100644 index 0000000..82462ba --- /dev/null +++ b/kostacivos/main.py @@ -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 + + diff --git a/kostacivos/note.csv b/kostacivos/note.csv new file mode 100644 index 0000000..212cc63 --- /dev/null +++ b/kostacivos/note.csv @@ -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 diff --git a/kostacivos/parser.py b/kostacivos/parser.py new file mode 100644 index 0000000..5fae5c9 --- /dev/null +++ b/kostacivos/parser.py @@ -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()) diff --git a/kostacivos/player.py b/kostacivos/player.py new file mode 100644 index 0000000..87abd8b --- /dev/null +++ b/kostacivos/player.py @@ -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() + diff --git a/kostacivos/scale.py b/kostacivos/scale.py new file mode 100644 index 0000000..52ad843 --- /dev/null +++ b/kostacivos/scale.py @@ -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] + + diff --git a/kostacivos/schemaKostacivosUML.png b/kostacivos/schemaKostacivosUML.png new file mode 100644 index 0000000..25a8eff Binary files /dev/null and b/kostacivos/schemaKostacivosUML.png differ diff --git a/kostacivos/struttura.py b/kostacivos/struttura.py new file mode 100644 index 0000000..91dd989 --- /dev/null +++ b/kostacivos/struttura.py @@ -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 diff --git a/kostacivos/tempo.py b/kostacivos/tempo.py new file mode 100644 index 0000000..f236449 --- /dev/null +++ b/kostacivos/tempo.py @@ -0,0 +1,4 @@ +#!/usr/bin/env python3 + +class Tempo(): + # TODO combiare il tempo in fuzione di quello che si fa diff --git a/kostacivos/visit_superpotente.py b/kostacivos/visit_superpotente.py new file mode 100644 index 0000000..fc28cde --- /dev/null +++ b/kostacivos/visit_superpotente.py @@ -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) + diff --git a/kostacivos/volume.py b/kostacivos/volume.py new file mode 100644 index 0000000..8771ebc --- /dev/null +++ b/kostacivos/volume.py @@ -0,0 +1,4 @@ +#!/usr/bin/env python3 + +class Volume(): + # TODO combiare il volume in fuzione di quello che si fa diff --git a/kostacivos/waveform.py b/kostacivos/waveform.py new file mode 100644 index 0000000..7f7b034 --- /dev/null +++ b/kostacivos/waveform.py @@ -0,0 +1,4 @@ +#!/usr/bin/env python3 + +class Waveform(): + # TODO combiare le onde in fuzione di quello che si fa diff --git a/note.csv b/note.csv new file mode 100644 index 0000000..212cc63 --- /dev/null +++ b/note.csv @@ -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 diff --git a/parser/syntax.py b/parser/syntax.py new file mode 100644 index 0000000..3446c87 --- /dev/null +++ b/parser/syntax.py @@ -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 diff --git a/test.py b/test.py new file mode 100755 index 0000000..72569de --- /dev/null +++ b/test.py @@ -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() + diff --git a/visit_superpotente.py b/visit_superpotente.py new file mode 100644 index 0000000..8f9457c --- /dev/null +++ b/visit_superpotente.py @@ -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], + + +}