Move ProtoValue to noisicaa.value_types

model-merge
Ben Niemann 4 years ago
parent ddf5d05591
commit 581e078435
  1. 2
      noisicaa/model_base/__init__.py
  2. 16
      noisicaa/model_base/model_base.py
  3. 3
      noisicaa/model_base/model_base_test.py
  4. 1
      noisicaa/value_types/CMakeLists.txt
  5. 1
      noisicaa/value_types/__init__.py
  6. 4
      noisicaa/value_types/clef.py
  7. 4
      noisicaa/value_types/color.py
  8. 4
      noisicaa/value_types/control_value.py
  9. 4
      noisicaa/value_types/key_signature.py
  10. 4
      noisicaa/value_types/node_port_properties.py
  11. 4
      noisicaa/value_types/pitch.py
  12. 4
      noisicaa/value_types/pos2f.py
  13. 34
      noisicaa/value_types/proto_value.py
  14. 4
      noisicaa/value_types/sizef.py
  15. 4
      noisicaa/value_types/time_signature.py

@ -38,8 +38,6 @@ from .model_base import (
PropertyListInsert, PropertyListDelete, PropertyListSet,
AbstractPool, Pool,
ProtoValue,
)
from .model_base_pb2 import (
ObjectTree,

@ -32,10 +32,11 @@ from typing import (
from google.protobuf import message as protobuf
from google.protobuf.internal import containers as protobuf_containers
from noisicaa import value_types
from . import model_base_pb2
if typing.TYPE_CHECKING:
from google.protobuf import descriptor as protobuf_descriptor
from google.protobuf import descriptor as protobuf_descriptor # pylint: disable=ungrouped-imports
def _checktype(o: Any, t: Type) -> None:
@ -45,7 +46,7 @@ def _checktype(o: Any, t: Type) -> None:
VALUE = TypeVar('VALUE')
PROTO = TypeVar('PROTO', bound=protobuf.Message)
PROTOVAL = TypeVar('PROTOVAL', bound='ProtoValue')
PROTOVAL = TypeVar('PROTOVAL', bound=value_types.ProtoValue)
OBJECT = TypeVar('OBJECT', bound='ObjectBase')
POOLOBJECTBASE = TypeVar('POOLOBJECTBASE', bound='ObjectBase')
@ -164,17 +165,6 @@ class PropertyListSet(Generic[VALUE], PropertyListChange[VALUE]):
return self._fmt(index=self.index, old=self.old_value, new=self.new_value)
# TODO: use a protocol instead of a base class
# Then I can use MusicalTime without hassle
class ProtoValue(object):
def to_proto(self) -> protobuf.Message:
raise NotImplementedError # pragma: no coverage
@classmethod
def from_proto(cls, pb: protobuf.Message) -> 'ProtoValue':
raise NotImplementedError # pragma: no coverage
class BaseList(Generic[VALUE], MutableSequence[VALUE]):
def __init__(
self, instance: 'ObjectBase', prop_name: str, pb: protobuf_containers.BaseContainer

@ -25,6 +25,7 @@ from typing import cast, Any, Optional, Type, Iterator, List, Tuple
from noisidev import unittest
from noisicaa import core
from noisicaa import value_types
from . import model_base
from . import model_base_pb2
from . import model_base_test_pb2
@ -41,7 +42,7 @@ class Pool(collections.UserDict, model_base.AbstractPool[model_base.ObjectBase])
raise NotImplementedError
class Proto(model_base.ProtoValue):
class Proto(value_types.ProtoValue):
def __init__(self, a, b):
self.a = a
self.b = b

@ -28,6 +28,7 @@ add_python_package(
pitch.py
pitch_test.py
pos2f.py
proto_value.py
sizef.py
time_signature.py
time_signature_test.py

@ -18,6 +18,7 @@
#
# @end:license
from .proto_value import ProtoValue
from .key_signature import KeySignature
from .time_signature import TimeSignature
from .clef import Clef

@ -24,13 +24,13 @@ import enum
from google.protobuf import message as protobuf
from noisicaa import model_base
from . import proto_value
from . import value_types_pb2
from . import pitch
@enum.unique
class Clef(model_base.ProtoValue, enum.Enum):
class Clef(proto_value.ProtoValue, enum.Enum):
FrenchViolin = 'french-violin'
Treble = 'treble'
Soprano = 'soprano'

@ -23,11 +23,11 @@
import decimal
from google.protobuf import message as protobuf
from noisicaa import model_base
from . import proto_value
from . import value_types_pb2
class Color(model_base.ProtoValue):
class Color(proto_value.ProtoValue):
def __init__(self, r: float, g: float, b: float, a: float = 1.0) -> None:
self.__context = decimal.Context(prec=4)
self.__r = self.__context.create_decimal_from_float(r)

@ -23,10 +23,10 @@
from google.protobuf import message as protobuf
from noisicaa import audioproc
from noisicaa import model_base
from . import proto_value
class ControlValue(model_base.ProtoValue):
class ControlValue(proto_value.ProtoValue):
def __init__(self, name: str, value: float, generation: int) -> None:
self.__name = name
self.__value = value

@ -24,11 +24,11 @@ from typing import Dict, List
from google.protobuf import message as protobuf
from noisicaa import model_base
from . import proto_value
from . import value_types_pb2
class KeySignature(model_base.ProtoValue):
class KeySignature(proto_value.ProtoValue):
_signatures = {
'C major': [],
'A minor': [],

@ -23,10 +23,10 @@
from google.protobuf import message as protobuf
from noisicaa import audioproc
from noisicaa import model_base
from . import proto_value
class NodePortProperties(model_base.ProtoValue):
class NodePortProperties(proto_value.ProtoValue):
def __init__(self, name: str, *, exposed: bool = False) -> None:
self.__name = name
self.__exposed = exposed

@ -25,7 +25,7 @@ from typing import Optional, Union, Dict, List, Set, Tuple
from google.protobuf import message as protobuf
from noisicaa import model_base
from . import proto_value
from . import value_types_pb2
from . import key_signature as key_signature_lib
@ -60,7 +60,7 @@ def _fill_midi_maps(note_to_midi: Dict[str, int], midi_to_note: Dict[int, str])
_fill_midi_maps(NOTE_TO_MIDI, MIDI_TO_NOTE)
class Pitch(model_base.ProtoValue):
class Pitch(proto_value.ProtoValue):
_values = ['C', 'C#', 'Db', 'D', 'D#', 'Eb', 'E', 'F', 'F#', 'Gb', 'G',
'G#', 'Ab', 'A', 'A#', 'Bb', 'B']

@ -22,11 +22,11 @@
from google.protobuf import message as protobuf
from noisicaa import model_base
from . import proto_value
from . import value_types_pb2
class Pos2F(model_base.ProtoValue):
class Pos2F(proto_value.ProtoValue):
def __init__(self, x: float, y: float) -> None:
self.__x = float(x)
self.__y = float(y)

@ -0,0 +1,34 @@
#!/usr/bin/python3
# @begin:license
#
# Copyright (c) 2015-2019, Benjamin Niemann <pink@odahoda.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# @end:license
from google.protobuf import message as protobuf
# TODO: use a protocol instead of a base class
# Then I can use MusicalTime without hassle
class ProtoValue(object):
def to_proto(self) -> protobuf.Message:
raise NotImplementedError # pragma: no coverage
@classmethod
def from_proto(cls, pb: protobuf.Message) -> 'ProtoValue':
raise NotImplementedError # pragma: no coverage

@ -22,11 +22,11 @@
from google.protobuf import message as protobuf
from noisicaa import model_base
from . import proto_value
from . import value_types_pb2
class SizeF(model_base.ProtoValue):
class SizeF(proto_value.ProtoValue):
def __init__(self, width: float, height: float) -> None:
self.__width = float(width)
self.__height = float(height)

@ -24,11 +24,11 @@ from typing import Tuple
from google.protobuf import message as protobuf
from noisicaa import model_base
from . import proto_value
from . import value_types_pb2
class TimeSignature(model_base.ProtoValue):
class TimeSignature(proto_value.ProtoValue):
def __init__(self, upper: int = 4, lower: int = 4) -> None:
if upper < 1 or upper > 99:
raise ValueError("Bad time signature %r/%r" % (upper, lower))

Loading…
Cancel
Save