Skip to content

Commit

Permalink
Delete ComparedNoteSets (#162)
Browse files Browse the repository at this point in the history
* delete ComparedNoteSets

* start new dev cycle
  • Loading branch information
tandav authored Feb 8, 2024
1 parent 85d9224 commit 889166c
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 95 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "musiclib"
version = "2.3.0"
version = "2.4.0dev0"
authors = [
{name = "Alexander Rodionov", email = "[email protected]"},
]
Expand Down Expand Up @@ -51,7 +51,7 @@ build-backend = "setuptools.build_meta"
# ==============================================================================

[tool.bumpver]
current_version = "v2.3.0"
current_version = "v2.4.0-dev"
version_pattern = "vMAJOR.MINOR.PATCH[-TAG]"
commit_message = "bump version {old_version} -> {new_version}"
commit = true
Expand Down
2 changes: 1 addition & 1 deletion src/musiclib/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.3.0'
__version__ = '2.4.0dev0'
59 changes: 0 additions & 59 deletions src/musiclib/noteset.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,62 +300,3 @@ def subsets(noteset: NoteSet, min_notes: int = 1) -> frozenset[NoteSet]:
for notes in itertools.combinations(noteset, n_subset):
out.add(NoteSet(frozenset(notes)))
return frozenset(out)


class ComparedNoteSets(Cached, ReprSVGMixin):
"""
this is compared scale
local terminology: left scale is compared to right
left is kinda parent, right is kinda child
"""

def __init__(self, left: NoteSet, right: NoteSet) -> None:
if not (isinstance(left, NoteSet) and isinstance(right, NoteSet)):
raise TypeError(f'expected NoteSet, got {type(left)} and {type(right)}')
self.left = left
self.right = right
self.key = left, right
self.shared_notes = frozenset(left.notes) & frozenset(right.notes)
self.new_notes = frozenset(right.notes) - frozenset(left.notes)
self.del_notes = frozenset(left.notes) - frozenset(right.notes)

def __eq__(self, other: object) -> bool:
if not isinstance(other, ComparedNoteSets):
raise TypeError
return self.key == other.key

def __hash__(self) -> int:
return hash(self.key)

def __str__(self) -> str:
return f'{self.left} | {self.right}'

def __repr__(self) -> str:
return f'ComparedNoteSets({self})'

def svg_piano(self, **kwargs: Any) -> svg.SVG:
from musiclib.svg.card import Piano
kwargs = pickle.loads(pickle.dumps(kwargs)) # faster than copy.deepcopy
setdefault_path(
kwargs,
'regular_piano_kwargs.note_colors',
dict.fromkeys(self.del_notes, config.RED) |
dict.fromkeys(self.new_notes, config.GREEN) |
dict.fromkeys(self.shared_notes, config.BLUE),
)
setdefault_path(kwargs, 'header_kwargs.title', str(self))
return Piano(**kwargs).svg

def svg_plane_piano(self, **kwargs: Any) -> svg.SVG:
from musiclib.svg.card import PlanePiano
kwargs = pickle.loads(pickle.dumps(kwargs)) # faster than copy.deepcopy
n0 = Note(config.chromatic_notes[0])
setdefault_path(kwargs, 'header_kwargs.title', str(self))
kwargs.setdefault(
'interval_colors',
dict.fromkeys([n - n0 for n in self.del_notes], config.RED) |
dict.fromkeys([n - n0 for n in self.new_notes], config.GREEN) |
dict.fromkeys([n - n0 for n in self.shared_notes], config.BLUE),
)
kwargs.setdefault('interval_text', FromIntervalDict({n - n0: str(n) for n in CHROMATIC_NOTESET}, abstract=True))
return PlanePiano(**kwargs).svg
12 changes: 0 additions & 12 deletions tests/noteset_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from musiclib.interval import AbstractInterval
from musiclib.note import Note
from musiclib.note import SpecificNote
from musiclib.noteset import ComparedNoteSets
from musiclib.noteset import NoteSet
from musiclib.scale import Scale

Expand Down Expand Up @@ -237,14 +236,3 @@ def test_subtract_types():
noteset.subtract('C', SpecificNote('D', 1)) # type: ignore[arg-type]
with pytest.raises(TypeError):
noteset.subtract('D1', Note('C')) # type: ignore[arg-type]


def test_compared():
left = Scale.from_name('C', 'major').noteset
right = Scale.from_name('A', 'minor').noteset
assert ComparedNoteSets(left, right).shared_notes == frozenset(left.notes)

right = Scale.from_name('C', 'mixolydian').noteset
c = ComparedNoteSets(left, right)
assert c.new_notes == frozenset({Note('b')})
assert c.del_notes == frozenset({Note('B')})
21 changes: 0 additions & 21 deletions tests/svg/repr_svg_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import pytest
from colortool import Color
from musiclib import config
from musiclib.noteset import ComparedNoteSets
from musiclib.noteset import NoteSet
from musiclib.noteset import SpecificNoteSet
from musiclib.scale import Scale
Expand Down Expand Up @@ -95,26 +94,6 @@ def test_svg_scale(kind, svg_method, title, subtitle, title_href, background_col
svg_helper(svg, class_, title, subtitle, title_href, background_color)


@pytest.mark.parametrize(
('scale0', 'scale1'), [
(Scale.from_name('C', 'major'), Scale.from_name('f', 'phrygian')),
(Scale.from_name('A', 'major'), Scale.from_name('f', 'phrygian')),
],
)
@pytest.mark.parametrize('svg_method', ['svg_piano', 'svg_plane_piano'])
@pytest.mark.parametrize('title', [None, TITLE])
@pytest.mark.parametrize('subtitle', [None, SUBTITLE])
@pytest.mark.parametrize('title_href', [None, TITLE_HREF])
@pytest.mark.parametrize('background_color', [BACKGROUND_COLOR])
def test_svg_compared_notesets(scale0, scale1, svg_method, title, subtitle, title_href, background_color):
if title is None and title_href is not None:
pytest.skip('title_href requires title')
class_ = ('cls1', 'cls2')
kw = kw_helper(class_, title, subtitle, title_href, background_color, svg_method)
svg = str(getattr(ComparedNoteSets(scale0.noteset, scale1.noteset), svg_method)(**kw))
svg_helper(svg, class_, title, subtitle, title_href, background_color)


@pytest.mark.parametrize(
'sns', [
SpecificNoteSet.from_str('C1_E1_f1'),
Expand Down

0 comments on commit 889166c

Please sign in to comment.