示例#1
0
 def __init__(
     self, pos: PointDef, accidental_type: AccidentalType, parent: GraphicObject
 ):
     self._accidental_type = accidental_type
     canonical_name = self._canonical_names[self.accidental_type]
     MusicText.__init__(self, pos, [canonical_name], parent)
     StaffObject.__init__(self, parent)
示例#2
0
文件: notehead.py 项目: ajyoon/brown
 def __init__(
     self, pos_x: Unit, pitch: PitchDef, duration: BeatDef, parent: GraphicObject
 ):
     """
     Args:
         pos_x (Unit): The x-axis position relative to `parent`.
             The y-axis position is calculated automatically based
             on `pitch` and contextual information in `self.staff`.
         pitch (Pitch or str): May be a `str` pitch representation.
             See `Pitch` for valid signatures.
         duration (Beat or init tuple): The logical duration of
             the notehead. This is used to determine the glyph style.
         parent (GraphicObject): Must either be a `Staff` or an object
             with an ancestor `Staff`.
     """
     self._pitch = Pitch.from_def(pitch)
     self._duration = Beat.from_def(duration)
     # Use a temporary y-axis position before calculating it for real
     MusicText.__init__(
         self,
         (pos_x, ZERO),
         [self._glyphnames[self.duration.base_division]],
         parent,
     )
     StaffObject.__init__(self, parent)
     self.y = self.staff.unit(
         self.staff_pos - map_between(self.staff, self.parent).y
     )
示例#3
0
    def __init__(
        self,
        start: PointDef,
        start_parent: GraphicObject,
        end: PointDef,
        end_parent: Optional[GraphicObject] = None,
    ):
        """
        Args:
            start: The position of the start-pedal mark relative to `start_parent`.
            start_parent: Anchor for the start-pedal mark, which must be in a staff
                or a staff itself.
            end: The position of the release-pedal mark relative to `end_parent`.
            end_parent: An optional anchor for the release-pedal mark. If provided,
                this must be in the same staff as `start_parent`. Otherwise, this
                defaults to `self`.
        """
        ObjectGroup.__init__(self, start, start_parent)
        Spanner2D.__init__(
            self,
            end if isinstance(end, Point) else Point(*end),
            cast(Positioned, end_parent) if end_parent else self,
        )
        StaffObject.__init__(self, self.parent)

        # Add opening pedal mark
        # (GraphicObject init handles registration with ObjectGroup)
        self.depress_mark = MusicText((GraphicUnit(0), GraphicUnit(0)),
                                      "keyboardPedalPed",
                                      parent=self)
        self.lift_mark = MusicText(self.end_pos,
                                   "keyboardPedalUp",
                                   parent=self.end_parent)
示例#4
0
 def __init__(self, pos: PointDef, text: str, parent: GraphicObject):
     """
     Args:
         pos: The object position
         text: A valid dynamic indicator string consisting
             of the letters: 'p, m, f, r, s, z, n'
         parent: The object parent.
     """
     parsed_text = self._parse_dynamic_string(text)
     MusicText.__init__(self, pos, parsed_text, parent)
     StaffObject.__init__(self, parent)
示例#5
0
文件: rest.py 项目: ajyoon/brown
 def __init__(
     self,
     pos: PointDef,
     parent: Union[StaffObject, Staff],
     duration: BeatDef,
 ):
     pos = Point.from_def(pos)
     self._duration = Beat.from_def(duration)
     MusicText.__init__(self, pos,
                        [self._glyphnames[self.duration.base_division]],
                        parent)
     StaffObject.__init__(self, parent)
示例#6
0
 def test_init(self):
     mock_parent = InvisibleObject((Unit(10), Unit(11)), parent=self.staff)
     test_object = MusicText((Unit(5), Unit(6)), "accidentalFlat",
                             mock_parent, self.font)
     assert test_object.x == GraphicUnit(5)
     assert test_object.y == GraphicUnit(6)
     assert test_object.text == "\ue260"
     assert test_object.font == self.font
     assert test_object.parent == mock_parent
示例#7
0
 def __init__(
     self, pos: PointDef, parent: GraphicObject, length: Unit, indication: str
 ):
     """
     Args:
         pos:
         parent:
         length:
         indication: A valid octave indication.
             Should be a valid entry in `OctaveLine.glyphs`.
     """
     MusicText.__init__(self, pos, OctaveLine.glyphs[indication], parent)
     StaffObject.__init__(self, parent)
     open_paren_char = MusicChar(self.font, OctaveLine.glyphs["("])
     close_paren_char = MusicChar(self.font, OctaveLine.glyphs[")"])
     self.parenthesized_text = (
         open_paren_char.codepoint + self.text + close_paren_char.codepoint
     )
     self._length = length
示例#8
0
 def setUp(self):
     neoscore.setup()
     self.flowable = Flowable((Mm(0), Mm(0)), Mm(10000), Mm(30), Mm(5))
     self.staff = Staff((Mm(0), Mm(0)), Mm(5000), self.flowable)
     self.left_parent = MockStaffObject((Mm(0), Mm(0)), self.staff)
     self.right_parent = MockStaffObject((Mm(10), Mm(2)), self.staff)
     self.char = "gClef"
     self.single_repetition_width = MusicText((Mm(0), Mm(0)),
                                              self.char,
                                              self.staff,
                                              scale=2).bounding_rect.width
示例#9
0
文件: clef.py 项目: ajyoon/brown
    def __init__(self, staff: Staff, pos_x: Unit, clef_type: Union[ClefType,
                                                                   str]):
        """
        Args:
            staff (Staff):
            pos_x (Unit):
            clef_type (ClefType or str): The type of clef.
                For convenience, any `str` of a `ClefType`
                enum name may be passed.

        Raises:
            KeyError: If the given `clef_type` is not a valid
                `ClefType` or `ClefType` enum name.
        """
        if isinstance(clef_type, ClefType):
            self._clef_type = clef_type
        else:
            self._clef_type = ClefType[clef_type.upper()]
        MusicText.__init__(self, (pos_x, staff.unit(0)),
                           self._canonical_names[self._clef_type], staff)
        StaffObject.__init__(self, staff)
        self.y = self.staff_position
示例#10
0
 def __init__(
     self,
     pos,
     pitch_letter,
     accidental_type,
     key_signature,
     music_font,
     scale,
     length,
 ):
     MusicText.__init__(
         self,
         pos,
         Accidental._canonical_names[accidental_type],
         key_signature,
         music_font,
         scale,
     )
     StaffObject.__init__(self, key_signature)
     self._length = length
     self.pitch_letter = pitch_letter
     self.accidental_type = accidental_type
示例#11
0
 def __init__(
     self,
     start: PointDef,
     parent: GraphicObject,
     end_x: Unit,
     text,
     end_parent: Optional[GraphicObject] = None,
     font: Optional[MusicFont] = None,
     scale: float = 1,
 ):
     """
     Args:
         start (Point or init tuple): The starting point.
         parent (GraphicObject): The parent of the starting point.
         end_x (Unit): The end x position.
         text (str, tuple, MusicChar, or list of these):
             The text to be repeated over the spanner,
             represented as a str (glyph name), tuple
             (glyph name, alternate number), MusicChar, or a list of them.
         end_parent (GraphicObject): An optional parent of the end point.
             If omitted, the end position is relative to the main object.
         font (MusicFont): The music font to be used. If not specified,
             the font is taken from the ancestor staff.
         scale (float): A hard scaling factor to be applied
             in addition to the size of the music font.
     """
     start = start if isinstance(start, Point) else Point(*start)
     # init the MusicText to ask it how wide a single
     # repetition of `text` is in order to calculate how many
     # repetitions are needed to cover the spanner.
     MusicText.__init__(self, start, text, parent, font, scale)
     StaffObject.__init__(self, parent)
     Spanner.__init__(self, end_x, end_parent or self)
     self.repeating_music_chars = self.music_chars
     self.repeating_text = self.text
     repetitions = self._repetitions_needed
     self.music_chars = self.music_chars * repetitions
     self._text = self.text * repetitions
示例#12
0
文件: brace.py 项目: ajyoon/brown
 def __init__(self, pos_x: Unit, staves: set[Staff]):
     """
     Args:
         pos_x (Unit): Where this brace goes into effect
         staves (set(Staff)): The staves this brace spans
     """
     MultiStaffObject.__init__(self, staves)
     StaffObject.__init__(self, self.highest_staff)
     # Calculate the height of the brace in highest_staff staff units
     scale = self.vertical_span / self.highest_staff.unit(4)
     if self.vertical_span > self.highest_staff.unit(50):
         text = ("brace", 4)
     elif self.vertical_span > self.highest_staff.unit(30):
         text = ("brace", 3)
     elif self.vertical_span > self.highest_staff.unit(15):
         text = ("brace", 2)
     elif self.vertical_span > self.highest_staff.unit(4):
         text = "brace"
     else:
         text = ("brace", 1)
     try:
         # Attempt to use size-specific optional glyph
         MusicText.__init__(
             self,
             (pos_x, self.vertical_span),
             text,
             self.highest_staff,
             scale=scale,
         )
     except MusicFontGlyphNotFoundError:
         # Default to non-optional glyph
         MusicText.__init__(
             self,
             (pos_x, self.vertical_span),
             "brace",
             self.highest_staff,
             scale=scale,
         )
示例#13
0
 def __init__(self,
              pos: PointDef,
              parent: GraphicObject,
              font: Optional[MusicFont] = None):
     MusicText.__init__(self, pos, [self._glyph_name], parent, font)
     StaffObject.__init__(self, parent)
示例#14
0
 def test_init_with_multiple_chars_in_list(self):
     test_object = MusicText((Unit(5), Unit(6)),
                             ["accidentalFlat", ("brace", 1)], self.staff)
     assert test_object.text == "\ue260\uF400"
示例#15
0
 def test_init_with_one_tuple(self):
     test_object = MusicText((Unit(5), Unit(6)), ("brace", 1), self.staff)
     assert test_object.text == "\uF400"
示例#16
0
 def test_init_with_one_music_char(self):
     test_object = MusicText((Unit(5), Unit(6)),
                             MusicChar(self.staff.music_font, "brace", 1),
                             self.staff)
     assert test_object.text == "\uF400"
示例#17
0
 def __init__(self, pos, parent, length, text, font):
     Event.__init__(self, pos, parent, length)
     self.text = MusicText(pos, text, self, font)
     MusicTextEvent._center_music_text(self.text)