Module project.music_gen.data_types

Expand source code
import enum as e

import project.esn.utils as ut


class AutoName(e.Enum):
    def _generate_next_value_(name, start, count, last_values):
        count += 2
        return 2**count


class IndexName(e.Enum):
    def _generate_next_value_(name, start, count, last_values):
        return count


@e.unique
class Tempo(AutoName):
    """Tempo enum,define all the possible tempo

    """
    QUARTER = e.auto()
    EIGHTH = e.auto()
    SIXTEENTH = e.auto()
    THIRTY_SECOND = e.auto()


def max_tempos(t0: Tempo, t1: Tempo):
    return t0 if t0.value > t1.value else t1


@e.unique
class Quarters(e.Enum):
    """ Quarters enum, define all the possible quarter
    """
    ONE = e.auto()
    TWO = e.auto()
    THREE = e.auto()
    FOUR = e.auto()


@e.unique
class Abs_note(IndexName):
    """Abs_note enum, define all the possible note

    """
    HI_HAT_CLOSE = e.auto()
    HI_HAT_OPEN = e.auto()
    BASS_DRUM = e.auto()
    CRASH = e.auto()
    SNARE = e.auto()
    HIG_TOM = e.auto()
    MID_TOM = e.auto()
    FLOOR_TOM = e.auto()
    RIDE = e.auto()


@ut.mydataclass(init=True, repr=True)
class Note():
    """Note class, a note is represented as follows : It has a Tempo, a
    Quarters (in which the note is played), a value which is the
    intensity of the note, finally the abstract note

    """
    tempo: Tempo
    note: Abs_note
    quarter: Quarters
    val: float = 1.0


def check_instance(obj, typ, fun, string):
    if isinstance(obj, typ):
        return fun(obj)
    raise ValueError(string)

Functions

def check_instance(obj, typ, fun, string)
Expand source code
def check_instance(obj, typ, fun, string):
    if isinstance(obj, typ):
        return fun(obj)
    raise ValueError(string)
def max_tempos(t0: Tempo, t1: Tempo)
Expand source code
def max_tempos(t0: Tempo, t1: Tempo):
    return t0 if t0.value > t1.value else t1

Classes

class Abs_note (value, names=None, *, module=None, qualname=None, type=None, start=1)

Abs_note enum, define all the possible note

Expand source code
class Abs_note(IndexName):
    """Abs_note enum, define all the possible note

    """
    HI_HAT_CLOSE = e.auto()
    HI_HAT_OPEN = e.auto()
    BASS_DRUM = e.auto()
    CRASH = e.auto()
    SNARE = e.auto()
    HIG_TOM = e.auto()
    MID_TOM = e.auto()
    FLOOR_TOM = e.auto()
    RIDE = e.auto()

Ancestors

Class variables

var BASS_DRUM
var CRASH
var FLOOR_TOM
var HIG_TOM
var HI_HAT_CLOSE
var HI_HAT_OPEN
var MID_TOM
var RIDE
var SNARE
class AutoName (value, names=None, *, module=None, qualname=None, type=None, start=1)

An enumeration.

Expand source code
class AutoName(e.Enum):
    def _generate_next_value_(name, start, count, last_values):
        count += 2
        return 2**count

Ancestors

  • enum.Enum

Subclasses

class IndexName (value, names=None, *, module=None, qualname=None, type=None, start=1)

An enumeration.

Expand source code
class IndexName(e.Enum):
    def _generate_next_value_(name, start, count, last_values):
        return count

Ancestors

  • enum.Enum

Subclasses

class Note (tempo: Tempo, note: Abs_note, quarter: Quarters, val: float = 1.0)

Note class, a note is represented as follows : It has a Tempo, a Quarters (in which the note is played), a value which is the intensity of the note, finally the abstract note

Expand source code
class Note():
    """Note class, a note is represented as follows : It has a Tempo, a
    Quarters (in which the note is played), a value which is the
    intensity of the note, finally the abstract note

    """
    tempo: Tempo
    note: Abs_note
    quarter: Quarters
    val: float = 1.0

Class variables

var val : float
class Quarters (value, names=None, *, module=None, qualname=None, type=None, start=1)

Quarters enum, define all the possible quarter

Expand source code
class Quarters(e.Enum):
    """ Quarters enum, define all the possible quarter
    """
    ONE = e.auto()
    TWO = e.auto()
    THREE = e.auto()
    FOUR = e.auto()

Ancestors

  • enum.Enum

Class variables

var FOUR
var ONE
var THREE
var TWO
class Tempo (value, names=None, *, module=None, qualname=None, type=None, start=1)

Tempo enum,define all the possible tempo

Expand source code
class Tempo(AutoName):
    """Tempo enum,define all the possible tempo

    """
    QUARTER = e.auto()
    EIGHTH = e.auto()
    SIXTEENTH = e.auto()
    THIRTY_SECOND = e.auto()

Ancestors

Class variables

var EIGHTH
var QUARTER
var SIXTEENTH
var THIRTY_SECOND