Skip to content

Instantly share code, notes, and snippets.

@gab-gash
gab-gash / dissonanza_interattiva_v26.1.py
Created October 6, 2025 13:52
Generatore Interattivo Avanzato di Curve di Dissonanza Tonale (Roughness). Questo script Python (basato su NumPy, SciPy e Matplotlib) implementa un generatore interattivo di curve di dissonanza tonale (o roughness) secondo il modello psicoacustico di Plomp-Levelt/Sethares. Lo strumento permette di analizzare la sonorità di intervalli musicali (m…
# -*- coding: utf:8 -*-
"""
Generatore interattivo Avanzato di curve di dissonanza tonale.
Versione 26.1
Requisiti:
pip install numpy scipy matplotlib pandas
"""
import numpy as np
@gab-gash
gab-gash / I_x-EDy_eng.py
Last active October 1, 2025 21:29
This Python script, given a set of musical intervals, calculates the closest steps of xEDa (x-Equal Divisions of the "a"-ve) temperaments for them, allowing x and a to vary within specified parameters. It also computes the relative approximation error, expressed both in cents and in hundredths of a single x-EDa step.
import math
from fractions import Fraction
# --- UTILITY FUNCTIONS FOR MONZO AND FACTORIZATION ---
PRIMES = [
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997
]
@gab-gash
gab-gash / I_x-EDy_esp.py
Last active July 9, 2025 17:26
Este script en Python, dado un conjunto de intervalos musicales, calcula los pasos más cercanos de los temperamentos xEDa (x-Divisiones Iguales de la "a"-va) para ellos, permitiendo que x y a varíen dentro de parámetros elegidos. También calcula el error de aproximación relativo, expresado tanto en cents como en centésimas de un paso de x-EDa.
import math
from fractions import Fraction
# --- FUNCIONES DE UTILIDAD PARA MONZO Y FACTORIZACIÓN ---
PRIMES = [
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997
]
@gab-gash
gab-gash / I_x-EDy_it.py
Last active July 9, 2025 21:11
Questo script in python, dati degli intervalli, trova gli step degli xEDy a loro più vicini al variare di x e y entro certi parametri scelti e l'errore relativo espresso in cent e in centesimi del singolo step di x-EDy. Permette anche l'inserimento degli intervalli sotto forma di Monzo razionale o con semplici formule.
import math
from fractions import Fraction
# --- FUNZIONI DI UTILITÀ PER MONZO E FATTORIZZAZIONE ---
PRIMES = [
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997
]
@gab-gash
gab-gash / x-EDa_p-limit_JI_eng.py
Created July 7, 2025 03:54
Calculate the error in cents between b-EDa tunings ('b' varies within the chosen range and 'a' is fixed) and the specified p-limit JI intervals with defined exponent ranges
import math
from fractions import Fraction
from itertools import product
# --- HELPER FUNCTIONS ---
def get_primes_up_to(n):
"""
Returns an ordered list of prime numbers up to n.
Uses the Sieve of Eratosthenes for efficiency.
@gab-gash
gab-gash / x-EDa_p-limit_JI_esp.py
Created July 7, 2025 03:53
Calcula el error en cents entre las afinaciones b-EDa ('b' varía en el intervalo elegido y 'a' está fijo) y los intervalos JI de límite p especificados con rangos de exponentes definidos
import math
from fractions import Fraction
from itertools import product
# --- FUNCIONES AUXILIARES ---
def get_primes_up_to(n):
"""
Devuelve una lista ordenada de números primos hasta n.
Utiliza la Criba de Eratóstenes para mayor eficiencia.
@gab-gash
gab-gash / x-EDa_p-limit_JI_it.py
Created July 7, 2025 03:52
Calcola l'errore in cent tra le accordature b-EDa ('b' varia nell'intervallo scelto e 'a' fissato) e gli intervalli del p-limit JI specificato con range di esponenti definiti
import math
from fractions import Fraction
from itertools import product
# --- FUNZIONI AUSILIARIE ---
def get_primes_up_to(n):
"""
Restituisce una lista ordinata di numeri primi fino a n.
Utilizza il Crivello di Eratostene per efficienza.
@gab-gash
gab-gash / k-comma_b-EDa_eng.py
Last active July 6, 2025 08:06
Find mesotonic temperaments that are best approximated by b-EDas (b-Equal Division of the interval 'a') with 'b' varying within a given integer range
import sympy as sp
import math
from sympy.ntheory.continued_fraction import continued_fraction, continued_fraction_convergents
from sympy.functions import sign
def calculate_and_analyze_k_for_b_ED_a(a_interval, b_divisions, m_max_partial):
"""
Calculates the value of k (as a continued fraction) for a mesotonic temperament
approximated by a given b-EDa.
@gab-gash
gab-gash / k-comma_b-EDa_esp.py
Last active July 6, 2025 08:07
Encuentra los temperamentos mesotónicos que mejor se aproximan mediante b-EDas (división equitativa de 'a' en 'b' partes) con 'b' variando en un cierto intervalo de enteros
import sympy as sp
import math
from sympy.ntheory.continued_fraction import continued_fraction, continued_fraction_convergents
from sympy.functions import sign
def calcula_y_analiza_k_para_b_ED_a(a_intervalo, b_divisiones, m_max_parcial):
"""
Calcula el valor de k (como fracción continua) para un temperamento mesotónico
aproximado por un b-EDa dado.
@gab-gash
gab-gash / k-comma_b-EDa_it.py
Last active July 6, 2025 08:08
trova i temperamenti mesotonici che approssimano meglio dei b-EDa (divisione di a:1 in b parti) con b che varia in certo intervallo di interi
import sympy as sp
import math
from sympy.ntheory.continued_fraction import continued_fraction, continued_fraction_convergents
from sympy.functions import sign
def calcola_e_analizza_k_per_b_ED_a(a_intervallo, b_divisioni, m_max_parziale):
"""
Calcola il valore di k (come frazione continua) per un temperamento mesotonico
approssimato da un dato b-EDa.