Ejemplo n.º 1
0
    def update(self, values, dur=None):
        """ Updates the TimeVar with new values """

        if dur is not None:
            self.dur = asStream(dur)

        if InfinityObj in self.dur:
            if self.dur[-1] != InfinityObj:
                raise
            else:
                self.has_inf = True

        self.data = []
        a, b = 0, -1

        for i, val in enumerate(asStream(values)):

            if isinstance(modi(self.dur, i), _infinity):

                # Replace infinity with a reasonable amount of time

                this_dur = GeomFill(Stretch(self.dur, i))[-1]

            else:

                # Get the duration for this value

                this_dur = modi(self.dur, i)

            a = b + 1
            b = a + (self.metro.steps * this_dur) - 1

            self.data.append(val)
            self.time.append((a, b))

        return self
Ejemplo n.º 2
0
    def update(self, values, dur=None):
        """ Updates the TimeVar with new values """

        if dur is not None:
            self.dur=asStream(dur)

        if InfinityObj in self.dur:
            if self.dur[-1] != InfinityObj:
                raise
            else:
                self.has_inf = True

        self.data = []
        a, b = 0, -1

        for i, val in enumerate(asStream(values)):

            if isinstance(modi(self.dur,i), _infinity):

                # Replace infinity with a reasonable amount of time
                
                this_dur = GeomFill(Stretch(self.dur, i))[-1]
                
            else:

                # Get the duration for this value
                
                this_dur = modi(self.dur, i)

            a = b + 1
            b = a + (self.metro.steps * this_dur) - 1
    
            self.data.append( val )
            self.time.append((a,b))

        return self
Ejemplo n.º 3
0
    def now(self):
        """ Returns the value from self.data for time t in self.metro """

        if self.inf:
            return self.inf_value

        t = self.metro.now() % self.length()

        for i in range(len(self.data)):

            if self.time[i][0] <= t <= self.time[i][1]:

                val = self.data[i]

                if modi(self.dur, i) == InfinityObj:
                    self.inf = True
                    self.inf_value = val

                return val * self.multiplier + float(self.modifier)
Ejemplo n.º 4
0
    def now(self):
        """ Returns the value from self.data for time t in self.metro """

        if self.inf:
            return self.inf_value

        t = self.metro.now() % self.length()

        for i in range(len(self.data)):
            
            if self.time[i][0] <= t <= self.time[i][1]:

                val = self.data[i]

                if modi(self.dur, i) == InfinityObj:
                    self.inf = True
                    self.inf_value = val

                return val * self.multiplier + float(self.modifier)
Ejemplo n.º 5
0
Archivo: Parse.py Proyecto: lvm/FoxDot
    def parse(self, string, dur=1):
        # Iterate over the string
        string = PlayString(string)
        items = []
        contains_nest = False
        i = 0
        #counter = 0
        while i < len(string):
            char = string[i]

            # Look for a '()'
            if char == "(":

                # Parse the contents of the brackets if found
                j = string.index(")", start=i + 2)

                s = string[i + 1:j]
                i = j

                chars, _ = self.parse(s, dur)

                items.append(chars)

                contains_nest = True

            # Look for a '{}'
            elif char == "{":

                # Parse the contents of the brackets if found
                j = string.index("}", start=i + 2)
                s = string[i + 1:j]
                i = j

                chars, _ = self.parse(s, dur)

                items.append(RandomPlayGroup(chars))

            # Look for a '[]'
            elif char == "[":

                j = string.index("]", start=i + 2)
                s = string[i + 1:j]
                i = j

                chars, contains_nest = self.parse(s, dur)

                # Un-nest
                if contains_nest:

                    # May contain sub-nests, so re-parse with calculated duration

                    chars, _ = self.parse(s, dur / float(len(chars)))

                    new_chars = []

                    for num in range(max([len(ch) for ch in chars])):

                        new_chars.append(
                            PlayGroup([modi(ch, num) for ch in chars]))

                    items.append(new_chars)

                else:

                    new_chars = []

                    for char in chars:

                        char.divide(len(chars))

                        if isinstance(char, PCHAR):

                            new_chars.append(char)

                        else:

                            new_chars.extend(char)

                    items.append(PlayGroup(new_chars))

            # Add single character to list

            elif char not in ")]":

                items.append(PCHAR(char, dur))

            # Increase iterator
            i += 1

        return items, contains_nest
Ejemplo n.º 6
0
 def parse(self, string, dur=1):
     # Iterate over the string
     string = PlayString(string)
     items = PlayString([])
     index = []
     i = 0
     counter = 0
     while i < len(string):
         char = string[i]
         # Look for a '()'
         if char == "(":
             # Parse the contents of the brackets if found
             j = string.index(")", start=i + 1)
             s = string[i + 1:j]
             i = j
             items.append(self.parse(s, dur))
             index.append(len(items) - 1)
             items.contains_nest = True
             if items[-1].contains_nest:
                 items[-1] = self.expand(items[-1])
         # Look for a '[]'
         elif char == "[":
             j = string.index("]", start=i + 1)
             s = string[i + 1:j]
             i = j
             items.append(self.parse(s, dur / 2.0))
             if items[-1].contains_nest:
                 index.append(len(items) - 1)
                 items.contains_nest = True
         # Look for a '{}'
         elif char == "{":
             j = string.index("}", start=i + 1)
             s = string[i + 1:j]
             i = j
             chars = self.parse(s, dur)
             # If there is a nest,  re-parse using known length / duration
             if chars.contains_nest:
                 chars = self.parse(s, dur / float(len(chars[0])))
             else:
                 for char in chars:
                     char.dur = char.dur / float(len(chars))
             items.append(chars)
             if items[-1].contains_nest:
                 index.append(len(items) - 1)
                 items.contains_nest = True
         # Add single character to list
         elif char not in ")]}":
             items.append(PCHAR(char, dur))
         # Increase iterator
         i += 1
     # If we have no nests, skip this step
     nests = [len(items[i]) for i in index]
     # After conversion, un-nest the values
     if items.contains_nest == True:
         size = LCM(*nests)
         output = PlayString([PlayString([]) for x in range(size)])
         for n in range(size):
             for i in range(len(items)):
                 char = items[i]
                 # Un-nest if index is stored
                 if i in index:
                     output[n].append(modi(char, n))
                 else:
                     output[n].append(char)
         items = output
         items.contains_nest = True
     return items
Ejemplo n.º 7
0
 def parse(self, string, dur=1):
     # Iterate over the string
     string = PlayString(string)
     items = PlayString([])
     index = []
     i = 0
     counter = 0
     while i < len(string):
         char = string[i]
         # Look for a '()'
         if char == "(":
             # Parse the contents of the brackets if found
             j = string.index(")", start=i+1)
             s = string[i+1:j]
             i = j
             items.append(self.parse(s, dur))
             index.append(len(items)-1)
             items.contains_nest = True
             if items[-1].contains_nest:
                 items[-1] = self.expand(items[-1])
         # Look for a '[]'
         elif char == "[":
             j = string.index("]", start=i+1)
             s = string[i+1:j]
             i = j
             items.append(self.parse(s, dur / 2.0))
             if items[-1].contains_nest:
                 index.append(len(items)-1)
                 items.contains_nest = True
         # Look for a '{}'
         elif char == "{":
             j = string.index("}", start=i+1)
             s = string[i+1:j]
             i = j
             chars = self.parse(s, dur)
             # If there is a nest,  re-parse using known length / duration
             if chars.contains_nest:
                 chars = self.parse(s, dur / float(len(chars[0])))
             else:
                 for char in chars:
                     char.dur = char.dur / float(len(chars))
             items.append(chars)
             if items[-1].contains_nest:
                 index.append(len(items)-1)
                 items.contains_nest = True
         # Add single character to list
         elif char not in ")]}":
             items.append( PCHAR(char, dur) )
         # Increase iterator
         i += 1
     # If we have no nests, skip this step
     nests = [len(items[i]) for i in index]
     # After conversion, un-nest the values
     if items.contains_nest == True:
         size = LCM(*nests)
         output = PlayString([PlayString([]) for x in range(size)])
         for n in range(size):
             for i in range(len(items)):
                 char = items[i]
                 # Un-nest if index is stored
                 if i in index:
                     output[n].append(modi(char, n))
                 else:
                     output[n].append(char)
         items = output
         items.contains_nest = True
     return items