import math from numpy import concatenate from midiutil.MidiFile import MIDIFile from itertools import product, combinations from copy import deepcopy from re import sub, split import random from itertools import combinations def freq2note(f): return 12*math.log(f/440.0, 2) + 69 def note2freq(n): return math.pow(2, (n-69)/12)*440 def midi2note(m): notes = ["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"] if '.5' in str(m): return notes[int(m%12)] + str(int((m//12)-2)) + "+" else: return notes[int(m%12)] + str(int((m//12)-2)) def notes2midis(s): spl = split("[, ]+", s) notes = ["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"] midis = [] for s in spl: if '+' in s: s2 = s.replace("+", '') midis.append( (int(sub("[^\d-]+", "", s2))+2) * 12 + notes.index( sub("-?[\d]+", "", s2)) + 0.5 ) else: midis.append( (int(sub("[^\d-]+", "", s))+2) * 12 + notes.index( sub("-?[\d]+", "", s)) ) return midis def notes2midisQ(s): return [x+0.5 for x in notes2midis(s)] def filterInRange(arr, filterNotes): newArr = [] for _x in arr: if _x >= filterNotes[0] and _x <= filterNotes[1]: newArr.append(_x) return newArr noPartials = 31 n0 = 60-12*2 f0 = note2freq(n0) partials = [] for i in range(noPartials+1): partials.append(freq2note( f0 * (i+1) )) diff = [] comb = combinations(partials, 2) for c in comb: d = round(c[1] - c[0], 2) if d not in diff: diff.append(d) diff2 = sorted(diff) print(diff2)