• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python interval.notesToInterval函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中music21.interval.notesToInterval函数的典型用法代码示例。如果您正苦于以下问题:Python notesToInterval函数的具体用法?Python notesToInterval怎么用?Python notesToInterval使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了notesToInterval函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: capuaRuleTwo

def capuaRuleTwo(srcStream):
    """
    See capuaRuleOne for precise instructions.
    
    Applies Capua's second rule to the given srcStream, i.e. if four notes are
    ascending with the pattern M2 m2 M2, the intervals shall be made M2 M2 m2.
    Also changes note.editorial.color for rule 2 (purple purple green purple).
    
    returns the number of times any note was changed
    """
    numChanged = 0

    ssn = srcStream.flat.notesAndRests
    for i in range(0, len(ssn) - 3):
        n1 = ssn[i]
        n2 = ssn[i + 1]
        n3 = ssn[i + 2]
        n4 = ssn[i + 3]

        if n1.isRest or n2.isRest or n3.isRest or n4.isRest:
            continue

        i1 = interval.notesToInterval(n1, n2)
        i2 = interval.notesToInterval(n2, n3)
        i3 = interval.notesToInterval(n3, n4)

        if n1.accidental is not None or n2.accidental is not None or n4.accidental is not None:
            continue

        ### never seems to improve things...
        if n3.step == "A" or n3.step == "D":
            continue

        # e.g., D E F G => D E F# G
        #    or F A Bb C => F A B C
        if i1.directedName == "M2" and i2.directedName == "m2" and i3.directedName == "M2":
            numChanged += 1
            if "capua" in n3.editorial.misc:
                n3.editorial.misc["capua_rule_number"] += RULE_TWO
            else:
                n3.editorial.misc["capua_rule_number"] = RULE_TWO

            if n3.accidental is not None and n3.accidental.name == "flat":
                n3.editorial.misc["saved-accidental"] = n3.accidental
                n3.accidental = None
                n3.editorial.ficta = pitch.Accidental("natural")
                n3.editorial.misc["capua-ficta"] = pitch.Accidental("natural")
                n1.editorial.color = "purple"
                n2.editorial.color = "purple"
                n3.editorial.color = "ForestGreen"
                n4.editorial.color = "purple"
            else:
                n3.editorial.ficta = pitch.Accidental("sharp")
                n3.editorial.misc["capua-ficta"] = pitch.Accidental("sharp")
                n1.editorial.color = "purple"
                n2.editorial.color = "purple"
                n3.editorial.color = "ForestGreen"
                n4.editorial.color = "purple"

    return numChanged
开发者ID:05565,项目名称:music21,代码行数:60,代码来源:capua.py


示例2: capuaRuleFourB

def capuaRuleFourB(srcStream):
    '''
    See capuaRuleOne for precise instructions.
    
    Applies more probable interpretation of Capua's fourth rule to the given
    srcStream, i.e. if a descending minor third is followed by a descending major
    second, the intervals will be changed to a major third followed by a minor
    second. Also copies any relevant accidental to note.editorial.misc under
    "saved-accidental" and changes note.editorial.color for rule 4 (orange
    green orange).
    
    returns the number of times a note was changed.
    '''
    numChanged = 0
    ssn = srcStream.flat.notesAndRests
    for i in range(0, len(ssn)-2):
        n1 = ssn[i]
        n2 = ssn[i+1]
        n3 = ssn[i+2]

        if n1.isRest or \
           n2.isRest or \
           n3.isRest:
            continue

        i1 = interval.notesToInterval(n1,n2)
        i2 = interval.notesToInterval(n2,n3)

        if n1.pitch.accidental is not None or \
           n3.pitch.accidental is not None:
            continue

        ### never seems to improve things...
        if n2.step == "A" or n2.step == "D":
            continue

        # e.g., D F G => D F# G  or G Bb C => G B C
        if i1.directedName  == "m3" and \
           i2.directedName  == "M2":
            numChanged += 1
            if ("capua" in n2.editorial.misc):
                n2.editorial.misc['capua_rule_number'] += RULE_FOUR_B
            else:
                n2.editorial.misc['capua_rule_number'] = RULE_FOUR_B
            if (n2.pitch.accidental is not None and n2.pitch.accidental.name == "flat"):
                n2.editorial.misc["saved-accidental"] = n2.pitch.accidental
                n2.pitch.accidental = None
                n2.editorial.ficta = pitch.Accidental("natural")
                n2.editorial.misc["capua-ficta"] = pitch.Accidental("natural")
                n1.editorial.color = "orange"
                n2.editorial.color = "green"
                n3.editorial.color = "orange"
            else:
                n2.editorial.ficta = pitch.Accidental("sharp")
                n2.editorial.misc["capua-ficta"] = pitch.Accidental("sharp")
                n1.editorial.color = "orange"
                n2.editorial.color = "green"
                n3.editorial.color = "orange"

    return numChanged
开发者ID:EQ4,项目名称:music21,代码行数:60,代码来源:capua.py


示例3: findPotentialPassingTones

def findPotentialPassingTones(show=True):
    g = corpus.parse("gloria")
    gcn = g.parts["cantus"].measures(1, 126).flat.notesAndRests

    gcn[0].lyric = ""
    gcn[-1].lyric = ""
    for i in range(1, len(gcn) - 1):
        prev = gcn[i - 1]
        cur = gcn[i]
        next = gcn[i + 1]  # @ReservedAssignment

        cur.lyric = ""

        if "Rest" in prev.classes or "Rest" in cur.classes or "Rest" in next.classes:
            continue

        int1 = interval.notesToInterval(prev, cur)
        if int1.isStep is False:
            continue

        int2 = interval.notesToInterval(cur, next)
        if int2.isStep is False:
            continue

        cma = cur.beatStrength
        if cma < 1 and cma <= prev.beatStrength and cma <= next.beatStrength:

            if int1.direction == int2.direction:
                cur.lyric = "pt"  # neighbor tone
            else:
                cur.lyric = "nt"  # passing tone
    if show:
        g.parts["cantus"].show()
开发者ID:05565,项目名称:music21,代码行数:33,代码来源:smt2010.py


示例4: capuaRuleOne

def capuaRuleOne(srcStream):
    '''
    Applies Nicolaus de Capua's first rule to the given srcStream, i.e. if a line descends
    a major second then ascends back to the original note, the major second is
    made into a minor second. Also copies the relevant accidentals into
    `Note.editorial.misc["saved-accidental"]` and changes `Note.style.color`
    for rule 1 (blue green blue).

    The relevant Rule number is also stored in `Note.editorial.misc['capua_rule_number']` which
    can be got out by OR-ing this.

    Returns the number of notes that were changed (not counting notes whose colors were changed).
    '''
    numChanged = 0

    ssn = srcStream.flat.notesAndRests
    for i in range(len(ssn) - 2):
        n1 = ssn[i]
        n2 = ssn[i + 1]
        n3 = ssn[i + 2]

        if (n1.isRest or n2.isRest or n3.isRest):
            continue

        i1 = interval.notesToInterval(n1, n2)
        i2 = interval.notesToInterval(n2, n3)

        if (n1.pitch.accidental is not None
                or n3.pitch.accidental is not None):
            continue

        ### never seems to improve things...
        if n2.step == "A" or n2.step == "D":
            continue

        ## e.g. G, F, G => G, F#, G
        if (i1.directedName == "M-2"
                and i2.directedName == "M2"):
            numChanged += 1
            if ("capua" in n2.editorial.misc):
                n2.editorial.misc['capua_rule_number'] += RULE_ONE
            else:
                n2.editorial.misc['capua_rule_number'] = RULE_ONE
            if (n2.pitch.accidental is not None and n2.pitch.accidental.name == "flat"):
                n2.editorial.misc["saved-accidental"] = n2.pitch.accidental
                n2.pitch.accidental = None
                n2.editorial.ficta = pitch.Accidental("natural")
                n2.editorial.misc["capua-ficta"] = pitch.Accidental("natural")
                n1.style.color = "blue"
                n2.style.color = "forestGreen"
                n3.style.color = "blue"
            else:
                n2.editorial.ficta = pitch.Accidental("sharp")
                n2.editorial.misc["capua-ficta"] = pitch.Accidental("sharp")
                n1.style.color = "blue"
                n2.style.color = "ForestGreen"
                n3.style.color = "blue"

    return numChanged
开发者ID:sbrother,项目名称:music21,代码行数:59,代码来源:capua.py


示例5: isParallelUnison

 def isParallelUnison(self, note11, note12, note21, note22):
     '''Given four notes, assuming the first pair sounds at the same time and
     the second pair sounds at the same time, returns True if the two
     harmonic intervals are P8 and False otherwise.'''
     interval1 = interval.notesToInterval(note11, note21)
     interval2 = interval.notesToInterval(note12, note22)
     if interval1.name == interval2.name == "P1": return True
     else: return False
开发者ID:knuton,项目名称:music21,代码行数:8,代码来源:counterpoint.py


示例6: capuaRuleOne

def capuaRuleOne(srcStream):
    '''Applies Nicolaus de Capua's first rule to the given srcStream, i.e. if a line descends
    a major second then ascends back to the original note, the major second is
    made into a minor second. Also copies the relevant accidentals into
    note.editorial.misc under "saved-accidental" and changes note.editorial.color
    for rule 1 (blue green blue).
    
    Returns the number of changes.    
    '''
    numChanged = 0
    
    ssn = srcStream.notes
    for i in range(0, len(ssn)-2):
        n1 = ssn[i]
        n2 = ssn[i+1]
        n3 = ssn[i+2]

        if n1.isRest or \
           n2.isRest or \
           n3.isRest:
            continue
        
        i1 = notesToInterval(n1,n2)
        i2 = notesToInterval(n2,n3)

        if n1.accidental is not None or \
           n3.accidental is not None:
            continue

        ### never seems to improve things...
        if n2.step == "A" or n2.step == "D":
            continue

        ## e.g. G, F, G => G, F#, G
        if i1.directedName == "M-2" and \
           i2.directedName == "M2":
            numChanged += 1
            if ("capua" in n2.editorial.misc):
                n2.editorial.misc['capua_rule_number'] += RULE_ONE
            else:
                n2.editorial.misc['capua_rule_number'] = RULE_ONE
            if (n2.accidental is not None and n2.accidental.name == "flat"):
                n2.editorial.misc["saved-accidental"] = n2.accidental
                n2.accidental = None
                n2.editorial.ficta = Accidental("natural")
                n2.editorial.misc["capua-ficta"] = Accidental("natural")
                n1.editorial.color = "blue"
                n2.editorial.color = "forestGreen"
                n3.editorial.color = "blue"
            else:
                n2.editorial.ficta = Accidental("sharp")
                n2.editorial.misc["capua-ficta"] = Accidental("sharp")
                n1.editorial.color = "blue"
                n2.editorial.color = "ForestGreen"
                n3.editorial.color = "blue"

    return numChanged
开发者ID:bewest,项目名称:music21-bewest.clone,代码行数:57,代码来源:capua.py


示例7: capuaRuleFourA

def capuaRuleFourA(srcStream):
    '''
    See capuaRuleOne for precise instructions.

    Applies one interpretation of Capua's fourth rule to the given srcStream,
    i.e. if a descending minor third is followed by a descending major second,
    the intervals will be changed to a major third followed by a minor second.
    Also changes note.editorial.color for rule 4 (orange green orange).
    
    returns the number of notes that were changed

    This rule is a less likely interpretation of the ambiguous rule 4, thus
    applyCapuaToStream uses capuaRuleFourB instead.
    '''
    numChanged = 0

    ssn = srcStream.flat.notesAndRests
    for i in range(0, len(ssn)-2):
        n1 = ssn[i]
        n2 = ssn[i+1]
        n3 = ssn[i+2]

        if n1.isRest or \
           n2.isRest or \
           n3.isRest:
            continue
        
        i1 = interval.notesToInterval(n1,n2)
        i2 = interval.notesToInterval(n2,n3)

        if n1.pitch.accidental is not None or \
           n2.pitch.accidental is not None or \
           n3.pitch.accidental is not None:
            continue

        ### never seems to improve things...
        if n2.step == "A" or n2.step == "D":
            continue

        # e.g., D B A => D Bb A
        if i1.directedName  == "m-3" and \
           i2.directedName  == "M-2":
            numChanged += 1
            if ("capua" in n2.editorial.misc):
                n2.editorial.misc['capua_rule_number'] += RULE_FOUR_A
            else:
                n2.editorial.misc['capua_rule_number'] = RULE_FOUR_A
            n2.editorial.ficta = pitch.Accidental("flat")
            n2.editorial.misc["capua-ficta"] = pitch.Accidental("flat")
            n1.editorial.color = "orange"
            n2.editorial.color = "ForestGreen"
            n3.editorial.color = "orange"

    return numChanged
开发者ID:EQ4,项目名称:music21,代码行数:54,代码来源:capua.py


示例8: capuaRuleThree

def capuaRuleThree(srcStream):
    '''
    See capuaRuleOne for precise instructions.
    
    Applies Capua's third rule to the given srcStream, i.e. if there is a
    descending major third followed by an ascending major second, the second
    note will be made a half-step higher so that there is a descending minor
    third followed by an ascending minor second. Also changes
    note.editorial.color for rule 3 (pink green pink).
    
    returns the number of times a note was changed
    '''
    numChanged = 0
    
    ssn = srcStream.flat.notesAndRests
    for i in range(0, len(ssn)-2):
        n1 = ssn[i]
        n2 = ssn[i+1]
        n3 = ssn[i+2]

        if n1.isRest or \
           n2.isRest or \
           n3.isRest:
            continue
        
        i1 = interval.notesToInterval(n1,n2)
        i2 = interval.notesToInterval(n2,n3)

        if n1.pitch.accidental is not None or \
           n2.pitch.accidental is not None or \
           n3.pitch.accidental is not None:
            continue

        ### never seems to improve things...
        if n2.step == "A" or n2.step == "D":
            continue

        # e.g., E C D => E C# D
        if i1.directedName  == "M-3" and \
           i2.directedName  == "M2":
            numChanged += 1
            if ("capua" in n2.editorial.misc):
                n2.editorial.misc['capua_rule_number'] += RULE_THREE
            else:
                n2.editorial.misc['capua_rule_number'] = RULE_THREE
            n2.editorial.ficta = pitch.Accidental("sharp")
            n2.editorial.misc["capua-ficta"] = pitch.Accidental("sharp")
            n1.editorial.color = "DeepPink"
            n2.editorial.color = "ForestGreen"
            n3.editorial.color = "DeepPink"

    return numChanged
开发者ID:EQ4,项目名称:music21,代码行数:52,代码来源:capua.py


示例9: resolves

def resolves(voice, resolve_interval):
    """Given a voice starting with the note that must resolve, checks whether it resolves according to the provided resolveInterval integer

    >>> from music21 import note, stream
    >>> voice = stream.Part()
    >>> for current_note in map(note.Note, ['f4', 'e4', 'f4']):
    ...     voice.append(current_note)
    >>> resolves(voice, -2)
    True
    >>> resolves(voice, 2)
    False
    """
    if len(voice) < 2:
        return True

    first_note = voice[0]
    for note in voice[1:]:
        current_interval = interval.notesToInterval(first_note, note)
        if current_interval.generic.directed == resolve_interval:
            return True
        # returns false if the resolve interval is wrong or there a chromatic step in the wrong direction
        if current_interval.generic.directed != 1 or resolve_interval * current_interval.chromatic.directed < 0:
            return

    return True
开发者ID:pschafhalter,项目名称:Johann,代码行数:25,代码来源:helpers.py


示例10: getDominant

 def getDominant(self):
     interval1to5 = interval.notesToInterval(self.tonic, self.pitchFromScaleDegree(5))
     if interval1to5.specificName != "Perfect":
         print(interval1to5.diatonicType)
         raise ScaleException("This scale has no Dominant (Locrian perhaps?)")
     else:
         return self.pitchFromScaleDegree(5)
开发者ID:knuton,项目名称:music21,代码行数:7,代码来源:scale.py


示例11: searchForIntervals

def searchForIntervals(notesStr):
    '''
    notesStr is the same as above.  Now however we check to see
    if the generic intervals are the same, rather than the note names.
    Useful if the clef is missing.
    '''
    notesArr = notesStr.split()
    noteObjArr = []
    for tN in notesArr:
        tNObj = note.Note()
        tNObj.name = tN[0]
        tNObj.octave = int(tN[1])
        noteObjArr.append(tNObj)

    interObjArr = []
    for i in range(len(noteObjArr) - 1):
        int1 = interval.notesToInterval(noteObjArr[i], noteObjArr[i + 1])
        interObjArr.append(int1)
    #print interObjArr

    searcher1 = IntervalSearcher(interObjArr)
    ballataObj  = cadencebook.BallataSheet()

    streamOpus = stream.Opus()

    for thisWork in ballataObj:
        print(thisWork.title)
        for thisCadence in thisWork.snippets:
            if thisCadence is None:
                continue
            for i in range(len(thisCadence.parts)):
                colorFound(searcher1, thisCadence, streamOpus, thisWork, i)

    if any(streamOpus):
        streamOpus.show('lily.png')
开发者ID:ahankinson,项目名称:music21,代码行数:35,代码来源:findTrecentoFragments.py


示例12: isHiddenFifth

 def isHiddenFifth(self, note11, note12, note21, note22):
     '''Given four notes, assuming the first pair sounds at the same time and
     the second pair sounds at the same time, returns True if there is a
     hidden fifth and false otherwise.'''
     interval1 = interval.notesToInterval(note11, note21)
     interval2 = interval.notesToInterval(note12, note22)
     interval3 = interval.notesToInterval(note11, note12)
     interval4 = interval.notesToInterval(note21, note22)
     if interval3.direction > 0 and interval4.direction > 0:
         if interval2.name == "P5" and not interval1.name == "P5": return True
         else: return False
     elif interval3.direction < 0 and interval4.direction < 0:
         if interval2.name == "P5" and not interval1.name == "P5": return True
         else: return False
     elif interval3.direction == interval4.direction == 0: return False
     return False
开发者ID:knuton,项目名称:music21,代码行数:16,代码来源:counterpoint.py


示例13: generateFirstSpecies

 def generateFirstSpecies(self, stream1, minorScale):
     '''Given a stream (the cantus firmus) and the stream's key in the
     form of a MinorScale object, generates a stream of first species
     counterpoint that follows the rules of 21M.301.'''
     # DOES NOT YET CHECK FOR TOO MANY THIRDS/SIXTHS IN A ROW,
     # DOES NOT YET RAISE LEADING TONES, AND DOES NOT CHECK FOR NOODLING.
     stream2 = Stream([])
     firstNote = stream1.notes[0]
     choices = [interval.transposeNote(firstNote, "P1"),\
                interval.transposeNote(firstNote, "P5"),\
                interval.transposeNote(firstNote, "P8")]
     note1 = random.choice(choices)
     note1.duration = firstNote.duration
     stream2.append(note1)
     afterLeap = False
     for i in range(1, len(stream1.notes)):
         prevFirmus = stream1.notes[i-1]
         currFirmus = stream1.notes[i]
         prevNote = stream2.notes[i-1]
         choices = self.generateValidNotes(prevFirmus, currFirmus, prevNote, afterLeap, minorScale)
         if len(choices) == 0:
             raise ModalCounterpointException("Sorry, please try again")
         newNote = random.choice(choices)
         newNote.duration = currFirmus.duration
         stream2.append(newNote)
         int = interval.notesToInterval(prevNote, newNote)
         if int.generic.undirected > 3: afterLeap = True
         else: afterLeap = False
     return stream2
开发者ID:knuton,项目名称:music21,代码行数:29,代码来源:counterpoint.py


示例14: countMelodicIntervals

    def countMelodicIntervals(self, sStream, found=None, ignoreDirection=True, 
        ignoreUnison=True):
        '''
        Find all unique melodic intervals in this Stream. 

        If `found` is provided as a dictionary, this dictionary will be used to store Intervals, and counts of Intervals already found will be incremented.
        '''
        # note that Stream.findConsecutiveNotes() and Stream.melodicIntervals()
        # offer similar approaches, but return Streams and manage offsets and durations, components not needed here
    
        if found == None:
            found = {}

        # if this has parts, need to move through each at a time
        if sStream.hasPartLikeStreams():
            procList = [s for s in sStream.getElementsByClass('Stream')]
        else: # assume a single list of notes
            procList = [sStream]

        for p in procList:
            # get only Notes for now, skipping rests and chords
            noteStream = p.stripTies(inPlace=False).getElementsByClass('Note')
            #noteStream.show()
            for i, n in enumerate(noteStream):
                if i <= len(noteStream) - 2:
                    nNext = noteStream[i+1]
                else:
                    nNext = None

                if nNext is not None:
                    #environLocal.printDebug(['creating interval from notes:', n, nNext, i])
                    i = interval.notesToInterval(n, nNext)
                    if ignoreUnison: # will apply to enharmonic eq unisons
                        if i.chromatic.semitones == 0:
                            continue
                    if ignoreDirection:
                        if i.chromatic.semitones < 0:
                            i = i.reverse()
                    # must use directed name for cases where ignoreDirection
                    # is false
                    if i.directedName not in found.keys():
                        found[i.directedName] = [i, 1]
                    else:
                        found[i.directedName][1] += 1 # increment counter
                        
#         def compare(x, y):
#             return abs(x.chromatic.semitones) - abs(y.chromatic.semitones)
#         found.sort(cmp=compare)

        return found
开发者ID:bewest,项目名称:music21-bewest.clone,代码行数:50,代码来源:discrete.py


示例15: findPotentialPassingTones

def findPotentialPassingTones(show=True):
    g = corpus.parse('gloria')
    gcn = g.parts['cantus'].measures(1,126).flat.notesAndRests

    gcn[0].lyric = ""
    gcn[-1].lyric = ""
    for i in range(1, len(gcn) - 1):
        prev = gcn[i-1]
        cur  = gcn[i]
        nextN = gcn[i+1]  
        
        cur.lyric = ""
        
        if ("Rest" in prev.classes or 
            "Rest" in cur.classes or 
            "Rest" in nextN.classes):
            continue
        
        int1 = interval.notesToInterval(prev, cur)
        if int1.isStep is False:
            continue
        
        int2 = interval.notesToInterval(cur, nextN)
        if int2.isStep is False:
            continue
            
        cma = cur.beatStrength 
        if (cma < 1 and 
            cma <= prev.beatStrength and
            cma <= nextN.beatStrength): 

            if int1.direction == int2.direction:
                cur.lyric = 'pt' # neighbor tone
            else:
                cur.lyric = 'nt' # passing tone
    if show:   
        g.parts['cantus'].show()
开发者ID:00gavin,项目名称:music21,代码行数:37,代码来源:smt2010.py


示例16: ch1_writing_II_A

def ch1_writing_II_A(show=True, *arguments, **keywords):
    '''p. 7

    Compose a melody using whole and half steps in any musical style.

    This technique uses a random walk of whole or half steps with direction 
    choices determined by whether the present note is above or below the 
    target end.
    '''
    import random
    from music21 import stream, expressions, pitch

    dirWeight = [-1, 1] # start with an even distribution
    s = stream.Stream()

    nStart = note.Note('g4')
    n = copy.deepcopy(nStart)

    while True:
#        n.quarterLength = random.choice([.25, .5, 1])
        n.duration.type = random.choice(['16th', 'eighth', 'quarter'])
        s.append(n)
        # if we have written more than fifteen notes 
        # and the last notes matches the first pitch class, then end.
        if len(s) > 4 and n.pitch.pitchClass == nStart.pitch.pitchClass:
            n.expressions.append(expressions.Fermata())
            break
        if len(s) > 30: # emergency break in case the piece is too long
            break
        direction = random.choice(dirWeight)
        if direction == 1:
            i = random.choice(['w', 'h'])
        else:
            i = random.choice(['w-', 'h-'])
        try:
            n = n.transpose(i)
        except pitch.AccidentalException:
            break # end b/c our transposition have exceeded accidental range
        
        iSpread = interval.notesToInterval(nStart, n)
        if iSpread.direction == -1: # we are below our target, favor upward
            dirWeight = [-1, 1, 1]
        if iSpread.direction == 1: # we are above our target, favor down
            dirWeight = [-1, -1, 1]

    if show:
        s.show()
    else:
        unused_post = musicxml.m21ToString.fromMusic21Object(s)
开发者ID:05565,项目名称:music21,代码行数:49,代码来源:mgtaPart1.py


示例17: generateTripletBlues

def generateTripletBlues(blRealization=None, numRepeats=5):  # 12/8
    """
    Turns whole notes in twelve bar blues bass line to triplet blues bass line. Takes
    in numRepeats, which is the number of times to repeat the bass line. Also, takes in a 
    realization of :meth:`~music21.figuredBass.examples.twelveBarBlues`. If none is provided, 
    a default realization with :attr:`~music21.figuredBass.rules.Rules.forbidVoiceOverlap`
    set to False and :attr:`~music21.figuredBass.rules.Rules.partMovementLimits` set to
    [(1,4),(2,12),(3,12)] is used.

    >>> from music21.figuredBass import examples
    >>> #_DOCS_SHOW examples.generateTripletBlues(numRepeats = 1).show()

    .. image:: images/figuredBass/fbExamples_tripletBlues.*
        :width: 700   
    """
    from music21 import tinyNotation, stream, interval, meter

    if blRealization == None:
        bluesLine = twelveBarBlues()
        fbRules = rules.Rules()
        fbRules.partMovementLimits = [(1, 4), (2, 12), (3, 12)]
        fbRules.forbidVoiceOverlap = False
        blRealization = bluesLine.realize(fbRules)
        sampleScore = blRealization.generateRandomRealizations(numRepeats)

    tripletBassLine = tinyNotation.TinyNotationStream("BB-4 BB-8 D4 D8 F4 F8 A-8 G8 F8")

    newBassLine = stream.Part()
    for n in sampleScore[1].notes:
        i = interval.notesToInterval(tripletBassLine[0], n)
        tp = tripletBassLine.transpose(i)
        for lyr in n.lyrics:
            tp.notes[0].addLyric(lyr.text)
        for m in tp.notes:
            newBassLine.append(m)

    newTopLine = stream.Part()
    for sampleChord in sampleScore[0].notes:
        sampleChordCopy = copy.deepcopy(sampleChord)
        sampleChordCopy.quarterLength = 6.0
        newTopLine.append(sampleChordCopy)

    newScore = stream.Score()
    newScore.append(meter.TimeSignature("12/8"))  # Time signature
    newScore.append(sampleScore[1][1])  # Key signature
    newScore.insert(0, newTopLine)
    newScore.insert(0, newBassLine)
    return newScore
开发者ID:JoeCodeswell,项目名称:music21,代码行数:48,代码来源:examples.py


示例18: searchForIntervals

def searchForIntervals(notesStr):
    '''
    notesStr is the same as above.  Now however we check to see
    if the generic intervals are the same, rather than the note names.
    Useful if the clef is missing.
    '''
    notesArr = notesStr.split()
    noteObjArr = []
    for tN in notesArr:
        tNObj = note.Note()
        tNObj.name = tN[0]
        tNObj.octave = int(tN[1])
        noteObjArr.append(tNObj)
    
    interObjArr = []
    for i in range(len(noteObjArr) - 1):
        int1 = interval.notesToInterval(noteObjArr[i], noteObjArr[i+1])
        interObjArr.append(int1)
    #print interObjArr

    searcher1 = IntervalSearcher(interObjArr) 
    ballataObj  = cadencebook.BallataSheet()

    streamOpus = stream.Opus()

    for thisWork in ballataObj:
        print(thisWork.title)
        for thisCadence in thisWork.snippets:
            if thisCadence is None:
                continue
            for i in range(len(thisCadence.parts)):
                if searcher1.compareToStream(thisCadence.parts[i].flat) is True:
                    notesStr = ""
                    for thisNote in thisCadence.parts[i].flat.notesAndRests:
                        #thisNote.editorial.color = "blue"
                        if thisNote.isRest is False:
                            notesStr += thisNote.nameWithOctave + " "
                        else:
                            notesStr += "r "
                    streamOpus.insert(0, thisCadence)
#                    streamLily += "\\score {" + \
#                            "<< \\time " + str(thisCadence.timeSig) + \
#                            "\n \\new Staff {" + str(thisCadence.parts[i].lily) + "} >>" + \
#                            thisCadence.header() + "\n}\n"
                    print(u"In piece %r found in stream %d: %s" % (thisWork.title, i, notesStr))
    if len(streamOpus) > 0:
        streamOpus.show('lily.png')
开发者ID:dorienh,项目名称:music21,代码行数:47,代码来源:findTrecentoFragments.py


示例19: ch1_basic_I_B

def ch1_basic_I_B(show=True, *arguments, **keywords):
    """
    p2.
    given 2 pitches, mark on a keyboard their positions and mark 
    intervals as W for whole step and H for half step, otherwise N
    """
    pitches = [("a#", "b"), ("b-", "c#"), ("g-", "a"), ("d-", "c##"), ("f", "e"), ("f#", "e")]
    for i, j in pitches:
        n1 = note.Note(i)
        n2 = note.Note(j)
        i1 = interval.notesToInterval(n1, n2)
        if i1.intervalClass == 1:  # by interval class
            unused_mark = "H"
        elif i1.intervalClass == 2:
            unused_mark = "W"
        else:
            unused_mark = "N"
开发者ID:jamesdoherty,项目名称:music21,代码行数:17,代码来源:mgtaPart1.py


示例20: corpusFindMelodicSevenths

def corpusFindMelodicSevenths(show = True):
    # find and display melodic sevenths
    import os
    from music21.analysis import discrete

    mid = discrete.MelodicIntervalDiversity()
    groupEast = corpus.search('shanxi', field='locale')
    groupWest = corpus.search('niederlande', field='locale') 

    found = []
    for unused_name, group in [('shanxi', groupEast), ('niederlande', groupWest)]:
        for fp, n in group:
            s = converter.parse(fp, number=n)
            intervalDict = mid.countMelodicIntervals(s)
        
            for key in sorted(intervalDict.keys()):
                if key in ['m7', 'M7']:
                    found.append([fp, n, s])
                   
    results = stream.Stream()
    for fp, num, s in found: 
        environLocal.printDebug(['working with found', fp, num])
        # this assumes these are all monophonic
        noteStream = s.flat.getElementsByClass('Note')
        for i, n in enumerate(noteStream):
            if i <= len(noteStream) - 2:
                nNext = noteStream[i+1]
            else:
                nNext = None

            if nNext is not None:
                #environLocal.printDebug(['creating interval from notes:', n, nNext, i])
                i = interval.notesToInterval(n, nNext)
                environLocal.printDebug(['got interval', i.name])
                if i.name in ['m7', 'M7']:
                    #n.addLyric(s.metadata.title)
                    junk, fn = os.path.split(fp)
                    n.addLyric('%s: %s' % (fn, num))

                    m = noteStream.extractContext(n, 1, 2, forceOutputClass=stream.Measure)
                    m.makeAccidentals()
                    m.timeSignature = m.bestTimeSignature()
                    results.append(m)
    if show == True:
        results.show()
开发者ID:matyastr,项目名称:msps,代码行数:45,代码来源:smt2010.py



注:本文中的music21.interval.notesToInterval函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.extractUuid函数代码示例发布时间:2022-05-27
下一篇:
Python realizer.figuredBassFromStream函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap