concertina_helper.layouts.base_classes

 1from __future__ import annotations
 2from abc import ABC, abstractmethod
 3from collections.abc import Callable
 4from typing import TypeVar, Generic
 5
 6from ..type_defs import Shape, Pitch, PitchToStr
 7
 8
 9T = TypeVar('T')
10
11
12class Fingering(ABC):
13    @abstractmethod
14    def format(self, button_down_f: PitchToStr,
15               button_up_f: PitchToStr,
16               direction_f: Callable) -> str:
17        '''
18        Returns a formatted, human-readable string
19        '''
20
21    @abstractmethod
22    def get_pitches(self) -> set[Pitch]:
23        '''
24        Returns the pitches that would be produced by this fingering
25        '''
26
27
28class Layout(ABC, Generic[T]):
29    @property
30    @abstractmethod
31    def shape(self) -> Shape:
32        '''
33        Returns tuple representing the number of buttons in each row, left and right.
34        '''
35
36    @abstractmethod
37    def get_fingerings(self, pitch: Pitch) -> set[T]:
38        '''
39        Returns a set of possible fingerings on the layout for a given pitch
40        '''
41
42    @abstractmethod
43    def transpose(self, semitones: int) -> Layout:
44        '''
45        Given a number of semitones, return a new layout,
46        transposed up or down.
47        '''
class Fingering(abc.ABC):
13class Fingering(ABC):
14    @abstractmethod
15    def format(self, button_down_f: PitchToStr,
16               button_up_f: PitchToStr,
17               direction_f: Callable) -> str:
18        '''
19        Returns a formatted, human-readable string
20        '''
21
22    @abstractmethod
23    def get_pitches(self) -> set[Pitch]:
24        '''
25        Returns the pitches that would be produced by this fingering
26        '''

Helper class that provides a standard way to create an ABC using inheritance.

@abstractmethod
def format( self, button_down_f: collections.abc.Callable[[concertina_helper.type_defs.Pitch], str], button_up_f: collections.abc.Callable[[concertina_helper.type_defs.Pitch], str], direction_f: collections.abc.Callable) -> str:
14    @abstractmethod
15    def format(self, button_down_f: PitchToStr,
16               button_up_f: PitchToStr,
17               direction_f: Callable) -> str:
18        '''
19        Returns a formatted, human-readable string
20        '''

Returns a formatted, human-readable string

@abstractmethod
def get_pitches(self) -> set[concertina_helper.type_defs.Pitch]:
22    @abstractmethod
23    def get_pitches(self) -> set[Pitch]:
24        '''
25        Returns the pitches that would be produced by this fingering
26        '''

Returns the pitches that would be produced by this fingering

class Layout(abc.ABC, typing.Generic[~T]):
29class Layout(ABC, Generic[T]):
30    @property
31    @abstractmethod
32    def shape(self) -> Shape:
33        '''
34        Returns tuple representing the number of buttons in each row, left and right.
35        '''
36
37    @abstractmethod
38    def get_fingerings(self, pitch: Pitch) -> set[T]:
39        '''
40        Returns a set of possible fingerings on the layout for a given pitch
41        '''
42
43    @abstractmethod
44    def transpose(self, semitones: int) -> Layout:
45        '''
46        Given a number of semitones, return a new layout,
47        transposed up or down.
48        '''

Helper class that provides a standard way to create an ABC using inheritance.

shape: tuple[typing.Iterable[int], typing.Iterable[int]]

Returns tuple representing the number of buttons in each row, left and right.

@abstractmethod
def get_fingerings(self, pitch: concertina_helper.type_defs.Pitch) -> set[~T]:
37    @abstractmethod
38    def get_fingerings(self, pitch: Pitch) -> set[T]:
39        '''
40        Returns a set of possible fingerings on the layout for a given pitch
41        '''

Returns a set of possible fingerings on the layout for a given pitch

@abstractmethod
def transpose(self, semitones: int) -> concertina_helper.layouts.base_classes.Layout:
43    @abstractmethod
44    def transpose(self, semitones: int) -> Layout:
45        '''
46        Given a number of semitones, return a new layout,
47        transposed up or down.
48        '''

Given a number of semitones, return a new layout, transposed up or down.