mirror of
https://github.com/flancian/garden.git
synced 2026-08-07 23:16:21 +00:00
autopushed
This commit is contained in:
@@ -6,9 +6,6 @@ import click
|
|||||||
import math
|
import math
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
# I'm not proud (I am a little bit?).
|
|
||||||
PROOF = [] # :)
|
|
||||||
|
|
||||||
class AgoraCmd(click.Command):
|
class AgoraCmd(click.Command):
|
||||||
def format_help(self, ctx, formatter):
|
def format_help(self, ctx, formatter):
|
||||||
click.echo("""Usage:
|
click.echo("""Usage:
|
||||||
@@ -31,7 +28,7 @@ class AgoraCmd(click.Command):
|
|||||||
sys.exit(exc.exit_code)
|
sys.exit(exc.exit_code)
|
||||||
|
|
||||||
@click.command(cls=AgoraCmd)
|
@click.command(cls=AgoraCmd)
|
||||||
@click.argument('freq', type=click.INT)
|
@click.argument('freq', type=click.FLOAT)
|
||||||
def hz(freq):
|
def hz(freq):
|
||||||
"""Calculates the closest note to input hz :)"""
|
"""Calculates the closest note to input hz :)"""
|
||||||
|
|
||||||
@@ -39,15 +36,19 @@ def hz(freq):
|
|||||||
|
|
||||||
# Number of half steps away.
|
# Number of half steps away.
|
||||||
n = 12 * math.log2(freq / A4)
|
n = 12 * math.log2(freq / A4)
|
||||||
octave = 4 + (n // 12)
|
n = round(n)
|
||||||
n_rounded = round(n)
|
note_index = n % 12
|
||||||
note_index = n_rounded % 12
|
|
||||||
|
|
||||||
notes = ["A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"]
|
notes = ["A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"]
|
||||||
note = notes[note_index]
|
note = notes[note_index]
|
||||||
|
|
||||||
# click.echo(f"hz({freq}) is {note}{str(octave)}.")
|
octave = 4 + (n // 12)
|
||||||
click.echo(f"hz({freq}) is {note}.")
|
if note in ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"]:
|
||||||
|
# compensate for the fact that octaves are counted from C
|
||||||
|
octave += 1
|
||||||
|
|
||||||
|
click.echo(f"hz({freq}) is {note}{str(octave)}.")
|
||||||
|
# click.echo(f"hz({freq}) is {note}.")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user