def split_value(self, voice: Voice, value):
        if self.is_bar_full:
            yield 0, 0, False

        event_beats = self.voice_value_to_beats(voice, value)

        leftovers = self.beats_per_bar - self.beats_count

        if event_beats <= leftovers:
            yield value, voice.get_duration_absolute(value), True

            self.beats_count += event_beats
        else:
            while event_beats > leftovers:
                sub_value = self.beats_to_voice_value(leftovers, voice)

                sub_duration = voice.get_duration_absolute(sub_value)

                yield sub_value, sub_duration, False

                self.beats_count += leftovers

                event_beats -= leftovers

                leftovers = self.beats_per_bar - self.beats_count

            sub_value = self.beats_to_voice_value(event_beats, voice)

            sub_duration = voice.get_duration_absolute(sub_value)

            yield sub_value, sub_duration, True

            self.beats_count += event_beats
Exemple #2
0
 def apply(self, voice: Voice):
     if self.upper != None or self.lower != None:
         voice.time_signature = (self.upper, self.lower)
     elif self.upper != None:
         voice.time_signature = (self.upper, voice.time_signature[1])
     elif self.lower != None:
         voice.time_signature = (voice.time_signature[0], self.lower)
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
Exemple #4
0
 def __init__(self,
              transformer: 'VoiceIdentifierTransformer',
              parent: Voice,
              index: int,
              staff: int = None):
     self.transformer: VoiceIdentifierTransformer = transformer
     self.parent_name: str = parent.name
     self.parent_staff: Optional[int] = staff
     self.voice: Voice = parent.clone(parent.name + '/' + str(index))
     self.index = index
     self.average_pitch: SlidingAverage = SlidingAverage()
     self.auto_create_rests: bool = True
     self.auto_create_end_rests: bool = True
     self.last_event: Optional[MusicEvent] = None
        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
Exemple #6
0
 def apply ( self, voice : Voice ):
     voice.tempo = self.tempo
Exemple #7
0
 def apply(self, voice: Voice):
     voice.value = self.length
Exemple #8
0
 def apply(self, voice: Voice):
     voice.octave = self.octave
 def apply ( self, voice : Voice ):
     voice.velocity = self.velocity
 def apply(self, voice: Voice):
     voice.instrument = Instrument.from_program(self.instrument)