コード例 #1
0
ファイル: MidiTrack.py プロジェクト: rikinsk/beethoven
    def key_signature_event(self, key="C"):
        """Returns the bytes for a key signature event."""
        val = basic_keys.index(key) - 6
        if val < 0:
            val = 256 + val

        key = a2b_hex("%02x" % val)
        return self.delta_time + META_EVENT + KEY_SIGNATURE + "\x02" + key + "\x00"
コード例 #2
0
    def key_signature_event(self, key='C'):
        """Returns the bytes for a key signature event."""

        val = basic_keys.index(key) - 6
        if val < 0:
            val = 256 + val
        key = a2b_hex('%02x' % val)
        return self.delta_time + META_EVENT + KEY_SIGNATURE + '\x02' + key\
             + '\x00'
コード例 #3
0
ファイル: MusicXML.py プロジェクト: anzev/mingus
def _bar2musicxml(bar):
    doc = Document()
    bar_node = doc.createElement("measure")
    #bar attributes
    attributes = doc.createElement("attributes")
    #calculate divisions by using the LCM
    l=list()
    for nc in bar:
	l.append(int(value.determine(nc[1])[0]))
    lcm = _lcm(terms=l)*4

    divisions  = doc.createElement("divisions")
    divisions.appendChild(doc.createTextNode(str(lcm))) 
    attributes.appendChild(divisions)
    if bar.key.name in basic_keys:
        key = doc.createElement("key")
        fifths = doc.createElement("fifths")
        #now we are going to guess which is the key of the bar
        index = basic_keys.index(bar.key.name)
        if index>13: index -= 12
        fifths.appendChild(doc.createTextNode(str(index-6)))
        mode = doc.createElement("mode")
        mode.appendChild(doc.createTextNode("major")) #does mingus support more modes?
        key.appendChild(fifths)
        key.appendChild(mode)
        attributes.appendChild(key)
    time = doc.createElement("time")
    beats = doc.createElement("beats")
    beattype = doc.createElement("beat-type")
    beats.appendChild(doc.createTextNode(str(bar.meter[0])))
    beattype.appendChild(doc.createTextNode(str(bar.meter[1])))
    time.appendChild(beats)
    time.appendChild(beattype)
    attributes.appendChild(time)
    
    bar_node.appendChild(attributes)
    
    chord=doc.createElement("chord")

    for nc in bar:
        time  = value.determine(nc[1])
	beat = time[0]
        note_cont = nc[2]
        is_chord=False
        if note_cont:
            #is a note_container with 2 or more notes a chord?
            if len(note_cont)>1: is_chord=True
        else: note_cont = [None]
        for n in note_cont:
            note = _note2musicxml(n)
            if is_chord:
                note.appendChild(chord)
            #convert the duration of the note
            duration = doc.createElement("duration")
            duration.appendChild(doc.createTextNode(str(int(lcm*(4.0/beat))))) 
            note.appendChild(duration)
	    #check for dots
	    dot = doc.createElement("dot")
	    for i in range(0,time[1]):
		note.appendChild(dot)
		
	    if beat in value.musicxml.keys():
            	type_node = doc.createElement("type")
            	type_node.appendChild(doc.createTextNode(value.musicxml[beat]))
            	note.appendChild(type_node)
            
	    #check for non-standard ratio
	    if time[2]!=1 and time[3]!=1:
		modification = doc.createElement("time-modification")
		actual = doc.createElement("actual-notes")
		actual.appendChild(doc.createTextNode(str(time[2])))
		normal = doc.createElement("normal-notes")
		normal.appendChild(doc.createTextNode(str(time[3])))
		modification.appendChild(actual)
		modification.appendChild(normal)
		note.appendChild(modification)

            bar_node.appendChild(note)
            

    return bar_node
コード例 #4
0
def _bar2musicxml(bar):
    doc = Document()
    bar_node = doc.createElement("measure")
    #bar attributes
    attributes = doc.createElement("attributes")
    #calculate divisions by using the LCM
    l=list()
    for nc in bar:
        l.append(int(value.determine(nc[1])[0]))
    lcm = _lcm(terms=l)*4

    divisions  = doc.createElement("divisions")
    divisions.appendChild(doc.createTextNode(str(lcm))) 
    attributes.appendChild(divisions)
    if bar.key.name in basic_keys:
        key = doc.createElement("key")
        fifths = doc.createElement("fifths")
        #now we are going to guess which is the key of the bar
        index = basic_keys.index(bar.key.name)
        if index>13: index -= 12
        fifths.appendChild(doc.createTextNode(str(index-6)))
        mode = doc.createElement("mode")
        mode.appendChild(doc.createTextNode("major")) #does mingus support more modes?
        key.appendChild(fifths)
        key.appendChild(mode)
        attributes.appendChild(key)
    time = doc.createElement("time")
    beats = doc.createElement("beats")
    beattype = doc.createElement("beat-type")
    beats.appendChild(doc.createTextNode(str(bar.meter[0])))
    beattype.appendChild(doc.createTextNode(str(bar.meter[1])))
    time.appendChild(beats)
    time.appendChild(beattype)
    attributes.appendChild(time)
    
    bar_node.appendChild(attributes)
    
    global isTied #must last over barlines
    
    for nc in bar:
        time  = value.determine(nc[1])
        beat = time[0]
        note_cont = nc[2]
        is_first_of_group=True
        
        prevTied = isTied
        isTied = note_cont.tied
        
        if not note_cont: note_cont = [None]
        for n in note_cont:
            note = _note2musicxml(n, isChord=not is_first_of_group)
            is_first_of_group = False
            #all but the last have a <chord/> element.

            #convert the duration of the note
            duration = doc.createElement("duration")
            duration.appendChild(doc.createTextNode(str(int(lcm*(4.0/beat))))) 
            note.appendChild(duration)
            
            #add tie if necessary.
            if prevTied:
                tied=doc.createElement("tie")
                tied.setAttribute("type","stop")
                note.appendChild(tied)
            if isTied:
                tied=doc.createElement("tie")
                tied.setAttribute("type","start")
                note.appendChild(tied)
            
            #check for dots
            dot = doc.createElement("dot")
            for i in range(0,time[1]):
                note.appendChild(dot)

            if beat in value.musicxml.keys():
                type_node = doc.createElement("type")
                type_node.appendChild(doc.createTextNode(value.musicxml[beat]))
                note.appendChild(type_node)
            
            #check for non-standard ratio
            if time[2]!=1 and time[3]!=1:
                modification = doc.createElement("time-modification")
                actual = doc.createElement("actual-notes")
                actual.appendChild(doc.createTextNode(str(time[2])))
                normal = doc.createElement("normal-notes")
                normal.appendChild(doc.createTextNode(str(time[3])))
                modification.appendChild(actual)
                modification.appendChild(normal)
                note.appendChild(modification)

            bar_node.appendChild(note)
            

    return bar_node
コード例 #5
0
ファイル: MusicXML.py プロジェクト: valrus/mingus3
def _bar2musicxml(bar):
    doc = Document()
    bar_node = doc.createElement('measure')

    # bar attributes

    attributes = doc.createElement('attributes')

    # calculate divisions by using the LCM

    l = list()
    for nc in bar:
        l.append(int(value.determine(nc[1])[0]))
    lcm = _lcm(terms=l) * 4
    divisions = doc.createElement('divisions')
    divisions.appendChild(doc.createTextNode(str(lcm)))
    attributes.appendChild(divisions)
    if bar.key.name in basic_keys:
        key = doc.createElement('key')
        fifths = doc.createElement('fifths')

        # now we are going to guess which is the key of the bar

        index = basic_keys.index(bar.key.name)
        if index > 13:
            index -= 12
        fifths.appendChild(doc.createTextNode(str(index - 6)))
        mode = doc.createElement('mode')
        mode.appendChild(doc.createTextNode('major'))  # does mingus support
        # more modes?
        key.appendChild(fifths)
        key.appendChild(mode)
        attributes.appendChild(key)
    time = doc.createElement('time')
    beats = doc.createElement('beats')
    beattype = doc.createElement('beat-type')
    beats.appendChild(doc.createTextNode(str(bar.meter[0])))
    beattype.appendChild(doc.createTextNode(str(bar.meter[1])))
    time.appendChild(beats)
    time.appendChild(beattype)
    attributes.appendChild(time)
    bar_node.appendChild(attributes)
    chord = doc.createElement('chord')
    for nc in bar:
        time = value.determine(nc[1])
        beat = time[0]
        note_cont = nc[2]
        is_chord = False
        if note_cont:

            # is a note_container with 2 or more notes a chord?

            if len(note_cont) > 1:
                is_chord = True
        else:
            note_cont = [None]
        for n in note_cont:
            note = _note2musicxml(n)
            if is_chord:
                note.appendChild(chord)

            # convert the duration of the note

            duration = doc.createElement('duration')
            duration.appendChild(
                doc.createTextNode(str(int(lcm * (4.0 / beat)))))
            note.appendChild(duration)

            # check for dots

            dot = doc.createElement('dot')
            for i in range(0, time[1]):
                note.appendChild(dot)
            if beat in list(value.musicxml.keys()):
                type_node = doc.createElement('type')
                type_node.appendChild(doc.createTextNode(value.musicxml[beat]))
                note.appendChild(type_node)

        # check for non-standard ratio

            if time[2] != 1 and time[3] != 1:
                modification = doc.createElement('time-modification')
                actual = doc.createElement('actual-notes')
                actual.appendChild(doc.createTextNode(str(time[2])))
                normal = doc.createElement('normal-notes')
                normal.appendChild(doc.createTextNode(str(time[3])))
                modification.appendChild(actual)
                modification.appendChild(normal)
                note.appendChild(modification)
            bar_node.appendChild(note)
    return bar_node