示例#1
0
class TrackBuilder(object):
    def __init__(self):
        self.track = Track()
        self.previous = None

    def add_symbol(self, name):
        symbol = Symbol.get_symbol(name)
        self.previous = symbol
        self.accidental = 0
        symbol.action(self)

    def add_note(self, note):
        mnote = mingusNote(note.n)
        self.track.add_notes(mnote, note.duration)

    def add_rest(self, rest):
        self.track.add_notes(None, rest.duration)

    def set_clef(self, clef):
        self.clef = clef

    def add_accidental(self, accidental):
        if accidental.name == 'sharp':
            self.accidental = 1
        elif accidental.name == 'flat':
            self.accidental = -1
        else:
            self.accidental = 0

    def flush(self):
        return self.track
示例#2
0
文件: music.py 项目: sabo/steven
def words_to_track(words):
    """Converts a string to a track, based on the the unicode code point, as
    given by ord()"""
    words_88 = [base88_encode(ord(x)) for x in words]
    notes = [Note().from_int(x) for letter in words_88 for x in letter]
    out_track = Track()
    for i in notes: 
        out_track.add_notes(i)
    return out_track
示例#3
0
文件: music.py 项目: sabo/steven
def screen_to_track(user):
    """Returns a mingus NoteContainer generated from 
    the screenname of a person"""
    user_id = user.idnumber
    id_88 = base88_encode(user_id)
    out_track = Track()
    for i in id_88: 
        out_track.add_notes(Note().from_int(i))
    return out_track
示例#4
0
def words_to_track(words):
    """Converts a string to a track, based on the the unicode code point, as
    given by ord()"""
    words_88 = [base88_encode(ord(x)) for x in words]
    notes = [Note().from_int(x) for letter in words_88 for x in letter]
    out_track = Track()
    for i in notes:
        out_track.add_notes(i)
    return out_track
示例#5
0
def screen_to_track(user):
    """Returns a mingus NoteContainer generated from 
    the screenname of a person"""
    user_id = user.idnumber
    id_88 = base88_encode(user_id)
    out_track = Track()
    for i in id_88:
        out_track.add_notes(Note().from_int(i))
    return out_track
def generate_and_write_music(
        output_file,
        music_length,
        lengths_distribution,
        bpm,
        ):
    import mingus.core.notes as notes
    from mingus.containers.note import Note
    from mingus.containers.track import Track
    from mingus.midi import midi_file_out

    track = Track()

    for note, length in generate_music(music_length, lengths_distribution, note_base=36):
        n = Note()
        n.from_int(note)
        track.add_notes(n, length)

    midi_file_out.write_Track(output_file, track, bpm=bpm)
示例#7
0
    name = note_string[0:1].upper()
    number = name_to_number.NOTES.index(name)
    acc = accidentals(note_string)
    return mod12(number + acc)


name_to_number.NOTES = "C . D . E F . G . A . B".split()

if __name__ == '__main__':
    import argparse
    import random
    # from mingus.containers.bar import Bar
    from mingus.containers.track import Track

    notes = [0]
    for t in range(30):
        note = notes[-1]
        notes.append(note + random.randint(0, 12))

    t = Track()
    notes = map(note_name, notes)
    for n in notes:
        t.add_notes(n)

    parser = argparse.ArgumentParser()
    parser.add_argument('--output', type=str, default='out.mid')
    args = parser.parse_args()

    from mingus.midi import midi_file_out
    midi_file_out.write_Track(args.output, t)