File size: 27,656 Bytes
d3d89b3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 | # README
# Phillip Long
# October 7, 2023
# Music object classes better suited for storing expressive features from musescore
# taken from https://github.com/salu133445/muspy/blob/b2d4265c6279e730903d8abe9dddda8484511903/muspy/classes.py
# python /home/pnlong/model_musescore/reading/classes.py
# IMPORTS / CONSTANTS
##################################################
import muspy
from collections import OrderedDict
from typing import Any, List
DEFAULT_VELOCITY = 64
DEFAULT_QPM = 120
##################################################
# MUSIC OBJECTS INHERITING FROM MUSPY
##################################################
# METADATA
class Metadata(muspy.classes.Metadata):
"""A container for metadata.
Attributes
----------
schema_version : str, default: `muspy.schemas.DEFAULT_SCHEMA_VERSION`
Schema version.
title : str, optional
Song title.
subtitle : str, optional
Song subtitle.
creators : list of str, optional
Creator(s) of the song.
copyright : str, optional
Copyright notice.
collection : str, optional
Name of the collection.
source_filename : str, optional
Name of the source file.
source_format : str, optional
Format of the source file.
"""
_attributes = OrderedDict([("schema_version", str), ("title", str), ("subtitle", str), ("creators", str), ("copyright", str), ("collection", str), ("source_filename", str), ("source_format", str)])
_optional_attributes = ["title", "subtitle", "creators", "copyright", "collection", "source_filename", "source_format"]
_list_attributes = ["creators"]
def __init__(self, schema_version: str = muspy.schemas.DEFAULT_SCHEMA_VERSION, title: str = None, subtitle: str = None, creators: List[str] = None, copyright: str = None, collection: str = None, source_filename: str = None, source_format: str = None):
super().__init__(schema_version = schema_version, title = title, creators = creators, copyright = copyright, collection = collection, source_filename = source_filename, source_format = source_format)
self.subtitle = subtitle
# TEMPO
class Tempo(muspy.classes.Tempo):
"""A container for key signatures.
Attributes
----------
time : int
Start time of the tempo, in time steps.
qpm : float, optional, default: DEFAULT_QPM = 120
Tempo in qpm (quarters per minute).
text : str, optional, default: ""
Text associated with the tempo (if applicable)
measure : int, optional, default: None
Measure number where this element is found.
"""
_attributes = OrderedDict([("time", int), ("qpm", (float, int)), ("text", str), ("measure", int)])
_optional_attributes = ["qpm", "text", "measure"]
def __init__(self, time: int, qpm: float = DEFAULT_QPM, text: str = "", measure: int = None):
super().__init__(time = time, qpm = qpm)
self.measure = measure
self.text = "" if text is None else text
# KEY SIG
class KeySignature(muspy.classes.KeySignature):
"""A container for key signatures.
Attributes
----------
time : int
Start time of the key signature, in time steps.
measure : int, optional, default: None
Measure number where this element is found.
root : int, optional
Root (tonic) of the key signature.
mode : str, optional
Mode of the key signature.
fifths : int, optional
Number of sharps or flats. Positive numbers for sharps and
negative numbers for flats.
root_str : str, optional
Root of the key signature as a string.
Note
----
A key signature can be specified either by its root (`root`) or the
number of sharps or flats (`fifths`) along with its mode.
"""
_attributes = OrderedDict([("time", int), ("measure", int), ("root", int), ("mode", str), ("fifths", int), ("root_str", str)])
_optional_attributes = ["root", "mode", "fifths", "root_str", "measure"]
def __init__(self, time: int, root: int = 0, mode: str = "major", fifths: int = 0, root_str: str = "C", measure: int = None):
super().__init__(time = time, root = root, mode = mode, fifths = fifths, root_str = root_str)
self.measure = measure
# TIME SIG
class TimeSignature(muspy.classes.TimeSignature):
"""A container for time signatures.
Attributes
----------
time : int
Start time of the time signature, in time steps.
measure : int, optional, default: None
Measure number where this element is found.
numerator : int
Numerator of the time signature.
denominator : int
Denominator of the time signature.
"""
_attributes = OrderedDict([("time", int), ("measure", int), ("numerator", int), ("denominator", int)])
_optional_attributes = ["measure"]
def __init__(self, time: int, numerator: int = 4, denominator: int = 4, measure: int = None):
super().__init__(time = time, numerator = numerator, denominator = denominator)
self.measure = measure
# BEATS
class Beat(muspy.classes.Beat):
"""A container for beats.
Attributes
----------
time : int
Time of the beat, in time steps.
measure : int, optional, default: None
Measure number where this element is found.
is_downbeat : bool, optional, default: False
Is this beat a downbeat?
"""
_attributes = OrderedDict([("time", int), ("measure", int), ("is_downbeat", bool)])
_optional_attributes = ["is_downbeat", "measure"]
def __init__(self, time: int, is_downbeat: bool = False, measure: int = None):
super().__init__(time = time)
self.measure = measure
self.is_downbeat = is_downbeat
# BARLINES
class Barline(muspy.classes.Barline):
"""A container for barlines.
Attributes
----------
time : int
Time of the barline, in time steps.
measure : int, optional, default: None
Measure number where this element is found.
subtype : str, optional, default: 'single'
Type of barline (double, dashed, etc.)
"""
_attributes = OrderedDict([("time", int), ("measure", int), ("subtype", str)])
_optional_attributes = ["measure"]
def __init__(self, time: int, subtype: str = "single", measure: int = None):
super().__init__(time = time)
self.measure = measure
self.subtype = subtype if (subtype is not None) else "single"
# LYRICS
class Lyric(muspy.classes.Lyric):
"""A container for lyrics.
Attributes
----------
time : int
Start time of the lyric, in time steps.
measure : int, optional, default: None
Measure number where this element is found.
lyric : str
Lyric (sentence, word, syllable, etc.).
"""
_attributes = OrderedDict([("time", int), ("measure", int), ("lyric", str)])
_optional_attributes = ["measure"]
def __init__(self, time: int, lyric: str, measure: int = None):
super().__init__(time = time, lyric = lyric)
self.measure = measure
# ANNOTATIONS
class Annotation(muspy.classes.Annotation):
"""A container for annotations.
Attributes
----------
time : int
Start time of the annotation, in time steps.
measure : int, optional, default: None
Measure number where this element is found.
annotation : any
Annotation of any type.
group : Any, optional
Group name (for better organizing the annotations).
"""
_attributes = OrderedDict([("time", int), ("measure", int), ("annotation", object), ("group", Any)])
_optional_attributes = ["measure", "group"]
def __init__(self, time: int, annotation: Any, measure: int = None, group: Any = None):
super().__init__(time = time, annotation = annotation, group = group)
self.measure = measure
# NOTES
class Note(muspy.classes.Note):
"""A container for notes.
Attributes
----------
time : int
Start time of the note, in time steps.
measure : int, optional, default: None
Measure number where this element is found.
pitch : int
Note pitch, as a MIDI note number. Valid values are 0 to 127.
duration : int
Duration of the note, in time steps.
velocity : int, default: `muspy.DEFAULT_VELOCITY` (64)
Note velocity. Valid values are 0 to 127.
pitch_str : str, optional
Note pitch as a string, useful for distinguishing, e.g., C# and Db.
is_grace : bool, optional, default: False
Is this note a grace note?
"""
_attributes = OrderedDict([("time", int), ("measure", int), ("pitch", int), ("duration", int), ("velocity", int), ("pitch_str", str), ("is_grace", bool)])
_optional_attributes = ["velocity", "pitch_str", "is_grace", "measure"]
def __init__(self, time: int, pitch: int, duration: int, velocity: int = DEFAULT_VELOCITY, pitch_str: str = None, is_grace: bool = False, measure: int = None):
super().__init__(time = time, pitch = pitch, duration = duration, velocity = velocity, pitch_str = pitch_str)
self.measure = measure
self.is_grace = is_grace
# CHORDS
class Chord(muspy.classes.Chord):
"""A container for chords.
Attributes
----------
time : int
Start time of the chord, in time steps.
measure : int, optional, default: None
Measure number where this element is found.
pitches : list of int
Note pitches, as MIDI note numbers. Valid values are 0 to 127.
duration : int
Duration of the chord, in time steps.
velocity : int, default: `muspy.DEFAULT_VELOCITY` (64)
Chord velocity. Valid values are 0 to 127.
pitches_str : list of str, optional
Note pitches as strings, useful for distinguishing, e.g., C# and
Db.
is_grace : bool, optional, default: False
Is this note a grace note?
"""
_attributes = OrderedDict([("time", int), ("measure", int), ("pitches", int), ("duration", int), ("velocity", int), ("pitches_str", str), ("is_grace", bool)])
_optional_attributes = ["velocity", "pitches_str", "measure", "is_grace"]
def __init__(self, time: int, pitches: List[int], duration: int, velocity: int = None, pitches_str: List[str] = None, measure: int = None, is_grace: bool = False):
super().__init__(time = time, pitches = pitches, duration = duration, velocity = velocity, pitches_str = pitches_str)
self.measure = measure
self.is_grace = is_grace
# TRACKS
class Track(muspy.classes.Track):
"""A container for music track.
Attributes
----------
program : int, default: 0 (Acoustic Grand Piano)
Program number, according to General MIDI specification [1]_.
Valid values are 0 to 127.
is_drum : bool, default: False
Whether it is a percussion track.
name : str, optional
Track name.
notes : list of :class:`muspy.Note`, default: []
Musical notes.
chords : list of :class:`muspy.Chord`, default: []
Chords.
annotations : list of :class:`muspy.Annotation`, default: []
Annotations.
lyrics : list of :class:`muspy.Lyric`, default: []
Lyrics.
Note
----
Indexing a Track object returns the note at a certain index. That
is, ``track[idx]`` returns ``track.notes[idx]``. Length of a Track
object is the number of notes. That is, ``len(track)`` returns
``len(track.notes)``.
References
----------
.. [1] https://www.midi.org/specifications/item/gm-level-1-sound-set
"""
_attributes = OrderedDict([("program", int), ("is_drum", bool), ("name", str), ("notes", Note), ("chords", Chord), ("lyrics", Lyric), ("annotations", Annotation)])
_optional_attributes = ["name", "notes", "chords", "lyrics", "annotations"]
_list_attributes = ["notes", "chords", "lyrics", "annotations"]
def __init__(self, program: int = 0, is_drum: bool = False, name: str = None, notes: List[Note] = None, chords: List[Chord] = None, lyrics: List[Lyric] = None, annotations: List[Annotation] = None):
self.program = program if program is not None else 0
self.is_drum = is_drum if program is not None else False
self.name = name
self.notes = notes if notes is not None else []
self.chords = chords if chords is not None else []
self.lyrics = lyrics if lyrics is not None else []
self.annotations = annotations if annotations is not None else []
##################################################
# PARENT OBJECTS
##################################################
# TEXT
class Text(muspy.base.Base):
"""A container for text. Meant to be stored as an annotation, so the Text class itself has no timestamp (the timestamp is stored in the annotation object).
Attributes
----------
text : str
The text contained in the text element.
is_system : bool, optional, default: False
Is this text system-wide (True) or just for a specific staff (False)?
style : str, optional, default: None
The style of the text element.
"""
_attributes = OrderedDict([("text", str), ("is_system", bool), ("style", str)])
_optional_attributes = ["is_system", "style"]
def __init__(self, text: str, is_system: bool = False, style: str = None):
self.text = "" if text is None else text
self.is_system = bool(is_system)
self.style = style
# SUBTYPE
class Subtype(muspy.base.Base):
"""A container for objects with the 'subtype' attribute.
Attributes
----------
subtype : Any
The subtype attribute.
"""
_attributes = OrderedDict([("subtype", object)])
SUBTYPES = []
def __init__(self, subtype):
self.subtype = subtype
def get_subtype_index(self):
try:
index = self.SUBTYPES.index(self.subtype)
except ValueError:
index = -1
return index
##################################################
# ANNOTATIONS
##################################################
# REHEARSAL MARK
class RehearsalMark(Text):
"""A container for RehearsalMark elements.
Attributes
----------
text : str
The text contained in the text element.
"""
_attributes = OrderedDict([("text", str)])
def __init__(self, text: str):
super().__init__(text = text, is_system = True)
# CHORD SYMBOL
class ChordSymbol(Text):
"""A container for ChordSymbol elements.
Attributes
----------
root_str : str
Root pitch as a string, useful for distinguishing, e.g., C# and Db.
name : str, optional
The text contained in the ChordSymbol element.
"""
_attributes = OrderedDict([("root_str", str), ("name", str)])
_optional_attributes = ["name"]
def __init__(self, root_str: str, name: str = "Maj"):
super().__init__(text = root_str + (name if name else ""), is_system = False)
self.root_str = root_str
self.name = name
# TECH ANNOTATION
class TechAnnotation(Text):
"""A container for PlayTechAnnotation elements.
Attributes
----------
text : str
The text contained in the text element.
tech_type : str, optional, default: None
The type of technical annotation to play.
is_system : bool, optional, default: False
Is this text system-wide (True) or just for a specific staff (False)?
"""
_attributes = OrderedDict([("text", str), ("tech_type", str), ("is_system", bool)])
_optional_attributes = ["tech_type", "is_system"]
def __init__(self, text: str, tech_type: str = None, is_system: bool = False):
super().__init__(text = text, is_system = is_system)
self.tech_type = tech_type
# DYNAMIC MARKINGS
class Dynamic(Subtype):
"""A container for Dynamic Marking elements.
Attributes
----------
subtype : str
The type of the Dynamic element.
velocity : int, optional, default: `muspy.DEFAULT_VELOCITY`
The velocity associated with the dynamic marking.
"""
_attributes = OrderedDict([("subtype", str), ("velocity", int)])
_optional_attributes = ["velocity"]
def __init__(self, subtype: str, velocity: int = DEFAULT_VELOCITY):
super().__init__(subtype = subtype)
self.velocity = velocity
# FERMATA
class Fermata(Subtype):
"""A container for Fermatas. Meant to be stored as an annotation, so the Fermata class itself has no timestamp (the timestamp is stored in the annotation object).
Attributes
----------
is_fermata_above : bool, optional, default: True
The subtype of fermata contained in the text element.
"""
_attributes = OrderedDict([("is_fermata_above", bool)])
_optional_attributes = ["is_fermata_above"]
def __init__(self, is_fermata_above: bool = True):
self.is_fermata_above = bool(is_fermata_above)
super().__init__(subtype = "fermata above" if self.is_fermata_above else "fermata below")
# ARPEGGIO
class Arpeggio(Subtype):
"""A container for Arpeggios.
Attributes
----------
subtype : int, optional, default: 0
Arpeggio subtype.
"""
_attributes = OrderedDict([("subtype", int)])
_optional_attributes = ["subtype"]
SUBTYPES = ["default", "up", "down", "bracket", "up straight", "down straight"]
def __init__(self, subtype: int = 0):
super().__init__(subtype = self.SUBTYPES[subtype if subtype in range(len(self.SUBTYPES)) else 0])
# TREMOLO
class Tremolo(Subtype):
"""A container for Tremolos.
Attributes
----------
subtype : str, optional, default: 'r8'
Tremolo subtype.
"""
_attributes = OrderedDict([("subtype", str)])
_optional_attributes = ["subtype"]
def __init__(self, subtype: str = "r8"):
super().__init__(subtype = subtype)
# CHORDLINE
class ChordLine(Subtype):
"""A container for ChordLines.
Attributes
----------
subtype : str, default: 'fall'
Subtype of the ChordLine.
is_straight : bool, default: False
Is the ChordLine straight?
"""
_attributes = OrderedDict([("subtype", str), ("is_straight", bool)])
_optional_attributes = ["subtype", "is_straight"]
def __init__(self, subtype: str = "fall", is_straight: bool = False):
super().__init__(subtype = subtype)
self.is_straight = bool(is_straight)
# ORNAMENT
class Ornament(Subtype):
"""A container for Ornaments.
Attributes
----------
subtype : str
Ornament subtype.
"""
_attributes = OrderedDict([("subtype", str)])
def __init__(self, subtype: str):
super().__init__(subtype = subtype)
# ARTICULATION
class Articulation(Subtype):
"""A container for Articulations.
Attributes
----------
subtype : str
Articulation subtype.
"""
_attributes = OrderedDict([("subtype", str)])
def __init__(self, subtype: str):
super().__init__(subtype = subtype)
# NOTEHEAD
class Notehead(Subtype):
"""A container for Noteheads.
Attributes
----------
subtype : str
Notehead subtype.
"""
_attributes = OrderedDict([("subtype", str)])
def __init__(self, subtype: str):
super().__init__(subtype = subtype)
# SYMBOL
class Symbol(Subtype):
"""A container for Symbols.
Attributes
----------
subtype : str
Symbol subtype.
"""
_attributes = OrderedDict([("subtype", str)])
def __init__(self, subtype: str):
super().__init__(subtype = subtype)
##################################################
# POINT-RELATED
##################################################
# POINT
class Point(muspy.base.Base):
"""A container for point objects.
Attributes
----------
time : int
The time of the point (in time steps)
pitch : int
The pitch of the point
vibrato : int, optional, default: 0
The vibrato
"""
_attributes = OrderedDict([("time", int), ("pitch", int), ("vibrato", int)])
_optional_attributes = ["vibrato"]
def __init__(self, time: int, pitch: int, vibrato: int = 0):
self.time = int(time)
self.pitch = int(pitch)
self.vibrato = int(vibrato)
# BEND
class Bend(muspy.base.ComplexBase):
"""A container for bends.
Attributes
----------
points : List[Point]
List of points that make up bend
"""
_attributes = OrderedDict([("points", List[Point])])
_list_attributes = ["points"]
def __init__(self, points: List[Point]):
self.points = points
# TREMOLO BAR
class TremoloBar(Bend):
"""A container for tremolo bars.
Attributes
----------
points : List[Point]
List of points that make up tremolo bar
"""
_attributes = OrderedDict([("points", List[Point])])
_list_attributes = ["points"]
def __init__(self, points: List[Point]):
super().__init__(points = points)
##################################################
# SPANNERS
##################################################
# SPANNER PARENT CLASS
class Spanner(muspy.base.Base):
"""A parent-class container for MuseScore Spanners. Meant to be stored as an annotation, so the Spanner class itself has no timestamp (the timestamp is stored in the annotation object).
Attributes
----------
duration : int
Duration of spanner, in time steps
"""
_attributes = OrderedDict([("duration", int)])
def __init__(self, duration: int):
self.duration = duration
# SUBTYPE SPANNER
class SubtypeSpanner(Subtype, Spanner):
"""A container for spanners whose only attribute is subtype.
Attributes
----------
duration : int
Duration of spanner, in time steps
subtype : Any
Subtype.
"""
_attributes = OrderedDict([("duration", int), ("subtype", object)])
def __init__(self, duration: int, subtype: object):
Subtype.__init__(self = self, subtype = subtype)
Spanner.__init__(self = self, duration = duration)
# TEMPO CHANGE SPANNERS
class TempoSpanner(SubtypeSpanner):
"""A container for GradualTempoChange spanners.
Attributes
----------
duration : int
Duration of spanner, in time steps
subtype : str
type of tempo change
"""
_attributes = OrderedDict([("duration", int), ("subtype", str)])
def __init__(self, duration: int, subtype: str):
super().__init__(duration = duration, subtype = subtype)
# TEXT SPANNER
class TextSpanner(Text, Spanner):
"""A container for Text spanners.
Attributes
----------
duration : int
Duration of spanner, in time steps
text : str
The text contained in the text element.
is_system : bool, optional, default: False
Is this text system-wide (True) or just for a specific staff (False)?
"""
_attributes = OrderedDict([("duration", int), ("text", str), ("is_system", bool)])
_optional_attributes = ["is_system"]
def __init__(self, duration: int, text: str, is_system: bool = False):
Text.__init__(self = self, text = text, is_system = is_system)
Spanner.__init__(self = self, duration = duration)
# HAIRPIN SPANNER
class HairPinSpanner(SubtypeSpanner):
"""A container for HairPin spanners.
Attributes
----------
duration : int
Duration of spanner, in time steps
subtype : str, optional, default: None
The text associated with the HairPin spanner.
hairpin_type : int, optional, default: -1
The type of hairpin found within the MuseScore xml element.
"""
_attributes = OrderedDict([("duration", int), ("subtype", str), ("hairpin_type", int)])
_optional_attributes = ["subtype", "hairpin_type"]
def __init__(self, duration: int, subtype: str = None, hairpin_type: int = -1):
super().__init__(duration = duration, subtype = subtype)
self.hairpin_type = hairpin_type
# SLUR/TIE SPANNER
class SlurSpanner(SubtypeSpanner):
"""A container for Slur spanners.
Attributes
----------
duration : int
Duration of spanner, in time steps
is_slur : bool, optional, default: True
Is this object a slur (True), meaning it connects different pitches, or a tie (False), meaning it connects the same pitch?
subtype : str, optional, default: 'slur'
Derived from is_slur.
"""
_attributes = OrderedDict([("duration", int), ("is_slur", bool)])
_optional_attributes = ["is_slur"]
def __init__(self, duration: int, is_slur: bool = True):
self.is_slur = bool(is_slur)
super().__init__(duration = duration, subtype = "slur" if self.is_slur else "tie")
# PEDAL SPANNER
class PedalSpanner(Spanner):
"""A container for Pedal spanners.
Attributes
----------
duration : int
Duration of spanner, in time steps
"""
_attributes = OrderedDict([("duration", int)])
def __init__(self, duration: int):
super().__init__(duration = duration)
# TRILL SPANNER
class TrillSpanner(SubtypeSpanner):
"""A container for Trill spanners.
Attributes
----------
duration : int
Duration of spanner, in time steps
subtype : str, optional, default: 'trill'
Subtype of trill
ornament : str, optional, default: None
Subtype of ornament associated with the trill
"""
_attributes = OrderedDict([("duration", int), ("subtype", str), ("ornament", str)])
_optional_attributes = ["subtype", "ornament"]
def __init__(self, duration: int, subtype: str = "trill", ornament: str = None):
super().__init__(duration = duration, subtype = subtype)
self.ornament = ornament
# VIBRATO SPANNER
class VibratoSpanner(SubtypeSpanner):
"""A container for Vibrato spanners.
Attributes
----------
duration : int
Duration of spanner, in time steps
subtype : str, optional, default: 'vibratoSawtooth'
Subtype of vibrato
"""
_attributes = OrderedDict([("duration", int), ("subtype", str)])
_optional_attributes = ["subtype"]
def __init__(self, duration: int, subtype: str = "vibratoSawtooth"):
super().__init__(duration = duration, subtype = subtype)
# GLISSANDO SPANNER
class GlissandoSpanner(SubtypeSpanner):
"""A container for Glissando spanners.
Attributes
----------
duration : int
Duration of spanner, in time steps
is_wavy : bool, optional, default: False
Is this Glissano wavy (True) or straight (False)?
subtype : str, optional, default: 'straight'
Derived from is_wavy.
"""
_attributes = OrderedDict([("duration", int), ("is_wavy", bool)])
_optional_attributes = ["is_wavy"]
def __init__(self, duration: int, is_wavy: bool = False):
self.is_wavy = bool(is_wavy)
super().__init__(duration = duration, subtype = "wavy" if self.is_wavy else "straight")
# OTTAVA SPANNER
class OttavaSpanner(SubtypeSpanner):
"""A container for Ottava spanners.
Attributes
----------
duration : int
Duration of spanner, in time steps
subtype : str, optional, default: '8va'
Subtype of ottava
"""
_attributes = OrderedDict([("duration", int), ("subtype", str)])
_optional_attributes = ["subtype"]
def __init__(self, duration: int, subtype: str = "8va"):
super().__init__(duration = duration, subtype = subtype)
##################################################
|