Esempio n. 1
0
def main():
    usage= 'usage: %prog [options] infname'
    parser= OptionParser(usage=usage)

    options, args= parser.parse_args(argv[1:])
    if len(args) < 1: parser.error('not enaught args')

    infname= args[0]
    outfname= infname.replace('notes', 'mid')
    assert infname != outfname

    score= Score(480)
    instrument= Instrument()
    instrument.patch=21 
    lines= open(infname).read().split('\n')
    notes= []
    for l in lines:
        if len(l) == 0: continue
        [str_note, start, end, pitch]= l.split()
        start= int(start)
        end= int(end)
        duration= end-start
        pitch= int(pitch)

        score.note_played(instrument, pitch, start, duration, 100)

    writer= writerclass()
    writer.dump(score, outfname)
Esempio n. 2
0
    def parse(self, fname, **kwargs):
        score = Score(480)
        instrument = Instrument()
        lines = open(fname).read().split("\n")
        notes = []
        for l in lines:
            if len(l) == 0:
                continue
            [str_note, start, end, pitch] = l.split()
            start = int(start)
            end = int(end)
            duration = end - start
            pitch = int(pitch)

            score.note_played(instrument, pitch, start, duration, 100)

        return score
Esempio n. 3
0
class MidiToScore(MidiOutStream):
    
    def __init__(self, print_warnings=True):
        MidiOutStream.__init__(self)
        self.actual_instruments= {}
        # diccionario de channel en [*args] de note_on
        self.notes_not_finished= {}
        self.score= None
        self.track_info= {}
        self.print_warnings=print_warnings

    def header(self, format=0, nTracks=1, division=96):
        self.score= Score(division)

    def note_on(self, channel=0, note=0x40, velocity=0x40):
        assert self.score is not None
        notes= self.notes_not_finished.get(channel, {})
        notes[note]= velocity, self.rel_time(), self.abs_time()
        self.notes_not_finished[channel]= notes

    def note_off(self, channel=0, note=0x40, velocity=0x40):
        assert self.score is not None
        notes= self.notes_not_finished.get(channel, {})
        if not note in notes: 
            if self.print_warnings:
                print "WARNING: note_off without note_on ", note
            return
            #import ipdb;ipdb.set_trace()
        #assert note in notes

        starting_vel, starting_reltime, starting_abstime= notes[note]
        if channel not in self.actual_instruments:
            self.actual_instruments[channel]= Instrument(is_drums=channel==9)
        instrument= self.actual_instruments[channel]
        instrument.channel= channel
        #import ipdb;ipdb.set_trace()
        if self.abs_time()-starting_abstime > 0: 
            self.score.note_played(instrument, note, starting_abstime, self.abs_time()-starting_abstime, starting_vel) 

    #def start_of_track(self, n_track=0):

    def patch_change(self, channel, patch):
        assert self.score is not None
        #import ipdb;ipdb.set_trace()
        if channel not in self.actual_instruments:
            self.actual_instruments[channel]= Instrument(is_drums=channel==9)
        instrument= self.actual_instruments[channel]
        instrument.patch= patch
        instrument.channel= channel

    def continuous_controller(self, channel, controller, value):
        #if channel == 3: import ipdb;ipdb.set_trace()
        msg= MidiControllerFactory([controller, value], self.abs_time())
        if channel not in self.actual_instruments:
            self.actual_instruments[channel]= Instrument(is_drums=channel==9)
        instrument= self.actual_instruments[channel]
        instrument.messages.append(msg)

    def end_of_track(self):
        self.actual_instruments= {}

    def smtp_offset(self, *args):
        self.score.append_message(MidiMessage(args, 'smtp_offset')) 

    def time_signature(self, nn, dd, cc, bb):
        self.score.time_signature= (nn,dd)
        if cc != 24 and self.print_warnings: print "WARNING: cc != 24"
        if bb != 8 and self.print_warnings: print "WARNING: bb != 8"
    
    def key_signature(self, sf, mi):
        self.score.key= None
        self.score.mode= None
        if sf <= 7 and sf >= 0:
            self.score.key= sf*7 % 12
            self.score.mode= mi
        elif sf < 0:
            self.score.key= abs(sf)*5 % 12
            self.score.mode= mi
        self.score.key_signature= (sf, mi)

    def tempo(self, tempo):
        self.score.tempo= tempo

    def sysex_event(self, data):
        pass
Esempio n. 4
0
 def header(self, format=0, nTracks=1, division=96):
     self.score= Score(division)