Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion just_intonation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 9 additions & 4 deletions midi_play.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]:
Expand All @@ -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
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -158,6 +161,7 @@ def play_seq(pitch, intervals, rest=rest):
play_freq(root + x)
time.sleep(rest)


pitch = Pitch(110)

# Lydian mode
Expand All @@ -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)
Expand Down
16 changes: 7 additions & 9 deletions test_just_intonation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -453,5 +452,4 @@ def test_chord():
# TODO: this is screwing up IPython's _

# Test assertions
import pytest
pytest.main(['--tb=short', __file__])
Loading