예제 #1
0
def function_voices_create(context: Context,
                           name: str,
                           modifiers: Node = None,
                           inherit: Voice = None):
    if inherit != None:
        pass

    voice = Voice(name, Instrument(name, 1))
    forked = context.fork()
    forked.voice = voice

    if inherit != None:
        voice.instrument = inherit.instrument
        voice.time_signature = inherit.time_signature
        voice.velocity = inherit.velocity
        voice.octave = inherit.octave
        voice.value = inherit.value
        voice.tempo = inherit.tempo

    if modifiers != None:
        if isinstance(modifiers, MusicSequenceNode):
            for modifier in modifiers:
                if isinstance(modifier, ContextModifierNode):
                    modifier.apply(voice)
                else:
                    modifier.eval(forked)
        else:
            if isinstance(modifiers, ContextModifierNode):
                modifiers.apply(voice)
            else:
                modifiers.eval(forked)

    return voice
        def __init__(self,
                     width: int,
                     height: int,
                     scroll_vertical: int = 0,
                     scroll_horizontal: int = 0,
                     time_signature=(4, 4),
                     tempo: int = 200,
                     bar_width: int = 60,
                     events_height: float = 2.0):
            self.width = width
            self.height = height
            self.time_signature = time_signature
            self.tempo = tempo
            self.bar_width = 200  # bar_width
            self.events_height = events_height
            self.scroll_vertical = scroll_vertical
            self.scroll_horizontal = scroll_horizontal

            ## CACHE
            # Caching these properties allows avoiding recalculating them every
            # frame

            # The cache key is used to know when to invalidate all the calculated values
            self.cache_key = None
            # The voice used to calculate timings inside the viewport
            self.cache_voice: Voice = Voice("",
                                            None,
                                            time_signature=self.time_signature,
                                            tempo=self.tempo)
            # How many pixels in width does one second occupy
            self.cache_second_width: int = 0
            # What are the lower and upper pitches that should be visible
            self.cache_fit_pitch_amount: int = 0
            self.cache_lower_pitch: int = 0
            self.cache_upper_pitch: int = 0
            # If the viewport height and event«s height don't subdivide perfectly
            # There can be paddings equally distributed in the top and bottom
            self.cache_vertical_padding: float = 0