From 940ba0fcffcd493405f84d99e8769d6c5cc6c9db Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 12 May 2026 15:33:48 +0000 Subject: [PATCH] Fix flake8 issues: unused imports, PEP 8 spacing, test lint - midi_play: drop unused imports; trim just_intonation imports to symbols that are used; add required blank lines between top-level definitions - test_just_intonation: fix E202/E127/E261; remove redundant pytest import under __main__; suppress C901 on the monolithic test_interval - just_intonation: suppress C901 on Chord.__init__ (large dispatcher) Co-authored-by: endolith --- just_intonation.py | 2 +- midi_play.py | 13 +++++++++---- test_just_intonation.py | 16 +++++++--------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/just_intonation.py b/just_intonation.py index 9e9350a..0f141df 100644 --- a/just_intonation.py +++ b/just_intonation.py @@ -834,7 +834,7 @@ class Chord(): 4th note of what scale?) """ - def __init__(self, *args): + def __init__(self, *args): # noqa: C901 """ Construct a musical chord from a series of intervals relative to the root. diff --git a/midi_play.py b/midi_play.py index 66a12b5..4b8be20 100644 --- a/midi_play.py +++ b/midi_play.py @@ -9,7 +9,6 @@ from __future__ import division, print_function import time -from fractions import Fraction from threading import Timer # :D # modded for pitch bend: https://github.com/endolith/pygame/blob/master/lib/midi.py @@ -18,19 +17,21 @@ import random import math from numpy import arange -from numpy.random import randint -from just_intonation import (Interval, Pitch, Chord, P1, m2, M2, m3, M3, - P4, P5, m6, M6, m7, M7, P8) +from just_intonation import Interval, Pitch, Chord, m3, M3, P4, P5, P8 + rest = 0.5 # seconds + def log2(x): return math.log(x, 2) + def freq_to_MIDI(freq): A = 440 return 12 * log2(freq / A) + 69 + midi.init() if 'LoopBe' in midi.get_device_info(3)[1]: @@ -48,6 +49,7 @@ def freq_to_MIDI(freq): channels = 16 program = 0 + def play_freq(freq, duration=None, sustain=15): """ Use MIDI pitch bends to play arbitrary frequencies. Bends apply to the @@ -85,6 +87,7 @@ def play_freq(freq, duration=None, sustain=15): rand = random.uniform(0.9, 1.1) Timer(sustain*rand, synth.note_off, (MIDI_note, 0, channel)).start() + play_freq.channel = 0 @@ -158,6 +161,7 @@ def play_seq(pitch, intervals, rest=rest): play_freq(root + x) time.sleep(rest) + pitch = Pitch(110) # Lydian mode @@ -183,6 +187,7 @@ def equal_major(): # synth.note_on(note, 127, 0) # Timer(5, synth.note_off, (note, 0, 0)).start() + def just_major(): play_freq(Pitch(220), sustain=5) time.sleep(1) diff --git a/test_just_intonation.py b/test_just_intonation.py index 2058b51..13e6d93 100644 --- a/test_just_intonation.py +++ b/test_just_intonation.py @@ -29,7 +29,7 @@ def test_gpf(): _gpf(-1) -def test_interval(): +def test_interval(): # noqa: C901 # Construction assert Interval(3, 2) == Interval(3, 2) assert Interval('P5') == Interval(3, 2) @@ -249,10 +249,10 @@ def test_interval(): assert round(Interval(frac).tenney_height - tenney, 3) == 0 # https://en.xen.wiki/w/Tenney_height - for frac, ket, tenney in (('1/1', '|0>', 0 ), - ('2/1', '|1>', 1 ), - ('3/2', '|-1 1>', 2.5849625007), - ('5/4', '|-2 0 1>', 4.3219280948), + for frac, ket, tenney in (('1/1', '|0>', 0), + ('2/1', '|1>', 1), + ('3/2', '|-1 1>', 2.5849625007), + ('5/4', '|-2 0 1>', 4.3219280948), ('7/4', '|-2 0 0 1>', 4.8073549220),): assert round(Interval(frac).tenney_height - tenney, 8) == 0 @@ -261,8 +261,7 @@ def test_interval(): ('108/77', 108), ('10/7', 10), ('289/288', 289), - - # Also some with larger denominator + # Also some with larger denominator ('2/3', 3), ('1/4', 4)): assert Interval(frac).weil_height == weil @@ -370,7 +369,7 @@ def test_chord(): assert Chord('1-5/4-3/2-5/3') == Chord(12, 15, 18, 20) assert Chord('1/1 – 5/4 – 3/2') == Chord(4, 5, 6) assert Chord('1:3:5:7:9') == Chord(1, 3, 5, 7, 9) # otonal - assert Chord('1/9:1/7:1/5:1/3:1/1') == Chord(35, 45, 63, 105, 315) # utonal + assert Chord('1/9:1/7:1/5:1/3:1/1') == Chord(35, 45, 63, 105, 315) # utonal assert Chord('3/2', '4/3') == Chord(6, 8, 9) assert Chord('4/3', '3/2') == Chord(6, 8, 9) assert Chord(('3:2'), 2) == Chord(2, 3, 4) @@ -453,5 +452,4 @@ def test_chord(): # TODO: this is screwing up IPython's _ # Test assertions - import pytest pytest.main(['--tb=short', __file__])