User:Xenwolf/Python: Difference between revisions

Xenwolf (talk | contribs)
Created page with "... just snippets ... <syntaxhighlight lang="python"> import math # formatted output integrated, default (5) is for step size def interval_size(steps, division, equave, digi..."
 
Xenwolf (talk | contribs)
m expanded
Line 1: Line 1:
... just snippets ...
... just snippets ...
== Calculate ED step size ==


<syntaxhighlight lang="python">
<syntaxhighlight lang="python">
import math
import math


# formatted output integrated, default (5) is for step size
# formatted size string
def interval_size(steps, division, equave, digits=5):
def ed_interval_size(steps, division=12, equiv=2, digits=0):
     return f'{math.log(equave, 2)/division*steps * 1200:.{digits}f}'
     return f'{math.log(equiv, 2)/division*steps * 1200:.{digits}f}'
 
# some examples
print('1\\271 EDT --- ', ed_interval_size(1, 271, 3, 5))
print('1\\100 EDF --- ', ed_interval_size(1, 100, 3/2, 5))
print('1\\171 EDO --- ', ed_interval_size(1, 171, 2, 5))
</syntaxhighlight>
</syntaxhighlight>
The equivalence intervals are:
* [[EDO]]: <code>equiv = 2</code> (octave)
* [[EDF]]: <code>equiv = 3/2</code> (fifth)
* [[EDT]]: <code>equiv = 3</code> (tritave)
Output of above script:
<pre>
1\271 EDT ---  7.01828
1\100 EDF ---  7.01955
1\171 EDO ---  7.01754
</pre>