Пример #1
0
    def coreInsert(self,
                   offset: Union[float, Fraction],
                   element: Music21Object,
                   *,
                   ignoreSort=False,
                   setActiveSite=True):
        '''
        N.B. -- a "core" method, not to be used by general users.  Run .insert() instead.

        A faster way of inserting elements that does no checks,
        just insertion.

        Only be used in contexts that we know we have a proper, single Music21Object.
        Best for usage when taking objects in a known Stream and creating a new Stream

        When using this method, the caller is responsible for calling Stream.coreElementsChanged
        after all operations are completed.

        Do not mix coreInsert with coreAppend operations.

        Returns boolean if the Stream is now sorted.
        '''
        # environLocal.printDebug(['coreInsert', 'self', self,
        #    'offset', offset, 'element', element])
        # need to compare highest time before inserting the element in
        # the elements list
        storeSorted = False
        if not ignoreSort:
            # # if sorted and our insertion is > the highest time, then
            # # are still inserted
            # if self.isSorted is True and self.highestTime <= offset:
            #     storeSorted = True
            if self.isSorted is True:
                ht = self.highestTime
                if ht < offset:
                    storeSorted = True
                elif ht == offset:
                    if not self._elements:
                        storeSorted = True
                    else:
                        highestSortTuple = self._elements[-1].sortTuple()
                        thisSortTuple = list(element.sortTuple())
                        thisSortTuple[1] = offset
                        thisSortTuple = tuple(thisSortTuple)

                        if highestSortTuple < thisSortTuple:
                            storeSorted = True

        self.setElementOffset(
            element,
            float(offset),  # why is this not opFrac?
            addElement=True,
            setActiveSite=setActiveSite)
        element.sites.add(self)
        # need to explicitly set the activeSite of the element
        # will be sorted later if necessary
        self._elements.append(element)
        # self._elementTree.insert(float(offset), element)
        return storeSorted
Пример #2
0
 def test_reprInternal(self):
     from music21.base import Music21Object
     b = Music21Object()
     b.id = 'hello'
     r = repr(b)
     self.assertEqual(r, '<music21.base.Music21Object id=hello>')