コード例 #1
0
ファイル: sites.py プロジェクト: pierrebateau/music21
    def getSitesByClass(self, className):
        '''
        Return a list of unwrapped site from siteDict.site [SiteRef.site] (generally a Stream) 
        that matches the provided class.

        Input can be either a Class object or a string

            >>> import music21
            >>> from music21 import stream
            >>> class Mock(music21.Music21Object):
            ...     pass
            ...
            >>> aObj = Mock()
            >>> bObj = Mock()
            >>> cObj = stream.Stream()
            >>> aSites = music21.Sites()
            >>> aSites.add(aObj, 234)
            >>> aSites.add(bObj, 3000)
            >>> aSites.add(cObj, 200)
            >>> aSites.getSitesByClass(Mock) == [aObj, bObj]
            True

        ::

            >>> aSites.getSitesByClass('Stream') == [cObj]
            True

        '''
        found = []
        if not isinstance(className, str):
            className = common.classToClassStr(className)

        for idKey in self._locationKeys:
            siteRef = self.siteDict[idKey]
            if siteRef.isDead:
                continue
            classStr = siteRef.classString
            if classStr == className:
                objRef = siteRef.site
                if not WEAKREF_ACTIVE:  # leave None alone
                    obj = objRef
                else:
                    obj = common.unwrapWeakref(objRef)
                found.append(obj)
        return found
コード例 #2
0
ファイル: sites.py プロジェクト: ifitz/music21
    def getSitesByClass(self, className):
        """
        Return a list of unwrapped site from siteDict.site [SiteRef.site] (generally a Stream) 
        that matches the provided class.

        Input can be either a Class object or a string

            >>> import music21
            >>> from music21 import stream
            >>> class Mock(music21.Music21Object):
            ...     pass
            ...
            >>> aObj = Mock()
            >>> bObj = Mock()
            >>> cObj = stream.Stream()
            >>> aSites = music21.Sites()
            >>> aSites.add(aObj, 234)
            >>> aSites.add(bObj, 3000)
            >>> aSites.add(cObj, 200)
            >>> aSites.getSitesByClass(Mock) == [aObj, bObj]
            True

        ::

            >>> aSites.getSitesByClass('Stream') == [cObj]
            True

        """
        found = []
        if not isinstance(className, str):
            className = common.classToClassStr(className)

        for idKey in self._locationKeys:
            siteRef = self.siteDict[idKey]
            if siteRef.isDead:
                continue
            classStr = siteRef.classString
            if classStr == className:
                objRef = siteRef.site
                if not WEAKREF_ACTIVE:  # leave None alone
                    obj = objRef
                else:
                    obj = common.unwrapWeakref(objRef)
                found.append(obj)
        return found
コード例 #3
0
    def getSitesByClass(self, className):
        '''
        Return a list of unwrapped site from siteDict.site [SiteRef.site] (generally a Stream) 
        that matches the provided class.

        Input can be either a Class object or a string

        >>> class Mock(base.Music21Object):
        ...     pass
        ...
        >>> aObj = Mock()
        >>> bObj = Mock()
        >>> cObj = stream.Stream()
        >>> aSites = sites.Sites()

        >>> aSites.add(aObj)
        >>> aSites.add(bObj)
        >>> aSites.add(cObj)

        >>> aSites.getSitesByClass(Mock) == [aObj, bObj]
        True

        >>> aSites.getSitesByClass('Stream') == [cObj]
        True
        '''
        found = []
        if not isinstance(className, str):
            className = common.classToClassStr(className)

        for siteRef in self.siteDict.values():
            if siteRef.isDead:
                continue
            classStr = siteRef.classString
            if classStr == className:
                objRef = siteRef.site
                found.append(objRef)
        return found
コード例 #4
0
ファイル: sites.py プロジェクト: spyamine/music21
    def getSitesByClass(self, className):
        '''
        Return a list of unwrapped site from siteDict.site [SiteRef.site] (generally a Stream) 
        that matches the provided class.

        Input can be either a Class object or a string

        >>> class Mock(base.Music21Object):
        ...     pass
        ...
        >>> aObj = Mock()
        >>> bObj = Mock()
        >>> cObj = stream.Stream()
        >>> aSites = sites.Sites()

        >>> aSites.add(aObj)
        >>> aSites.add(bObj)
        >>> aSites.add(cObj)

        >>> aSites.getSitesByClass(Mock) == [aObj, bObj]
        True

        >>> aSites.getSitesByClass('Stream') == [cObj]
        True
        '''
        found = []
        if not isinstance(className, str):
            className = common.classToClassStr(className)

        for siteRef in self.siteDict.values():
            if siteRef.isDead:
                continue
            classStr = siteRef.classString
            if classStr == className:
                objRef = siteRef.site
                found.append(objRef)
        return found
コード例 #5
0
ファイル: clef.py プロジェクト: ELVIS-Project/music21
 def __repr__(self):
     # get just the clef name of this instance
     return '<music21.clef.%s>' % common.classToClassStr(self.__class__)
コード例 #6
0
 def __repr__(self):
     # get just the clef name of this instance
     return "<music21.clef.%s>" % common.classToClassStr(self.__class__)