Logo Search packages:      
Sourcecode: scenic version File versions  Download package

def rtpmidi::engines::midi::recovery_journal::ChannelJournal::dispatch_data (   self,
  data 
)
Build the channel journal of a given channel, 
based on data passed from create_recovery_journal
option standard is for some command standardize to 
designate a special command

Definition at line 113 of file recovery_journal.py.

                                 :
        """Build the channel journal of a given channel, 
        based on data passed from create_recovery_journal
        option standard is for some command standardize to 
        designate a special command"""
        standard = self.follow_standard

        #Chapters list
        controllers = []
        programs = []
        system_p = []
        wheels = []
        notes = []
        extras = []
        afters = []
        poly_afters = []
        
        #witness
        special_consideration = 0
        note_off_presence = 0
        bank_msb = (0, 0)
        bank_lsb = (0, 0)
        reset_all = (0, 0)
        omni_on = (0, 0)
        omni_off = (0, 0)
        poly = (0, 0)
        mono = (0, 0)
        #Order by seqNo and timestamps (only getting last notes if doublon)
        #for each seq (beginning with last one (upper priority))
        
        zap = 0
        
        seq_nums = data.keys()

        for seq in seq_nums:
            #for each midicmd get note type
            for i in range(len(data[seq])):
                command = data[seq][i][0][0]
                pitch = data[seq][i][0][1]
                velocity = data[seq][i][0][2]
                time = data[seq][i][1]
                data[seq][i][1] = seq

                #Note
                if (command&240 == 128 or 
                    command&240 == 144):
                    #if not already in add it
                    if not data[seq][i][0] in notes:
                        notes.append((data[seq][i], seq))
                    else:
                        #replace with a most recent one
                        #deleting old one to conserve order in choice
                        res = notes.index(data[seq][i])
                        del notes[res]
                        notes.append((data[seq][i], seq))

                #program change 0xC (!! si change seulement program change une 
                #note 12 sinon (bank + prog change) 2 note 11 (bank) puis 
                #une note 12 pour le prog 
                elif (command>>4) == 12:
                    if not pitch in programs:
                        #looking for eventual 0xB link to program change
                        if bank_msb != (0, 0):
                            if bank_lsb != (0, 0):
                                #adding lsb
                                programs.append(bank_lsb[0])
                                bank_lsb = (0, 0)
                            #adding msb
                            programs.append(bank_msb[0])
                            
                            if reset_all != (0, 0):
                                if bank_msb[1] < reset_all[1]:
                                    #Passing marker_x to chapter p
                                    programs.append([[0,0,0,0], 0])
                            bank_msb = (0, 0)
                        #adding program
                        programs.append(data[seq][i])
                                    

                #controller change 0xB (!! take care of prog+bank change)
                elif (command>>4) == 11:
                    #Checking specials controllers 
                    #(if standardized, else will not taking care)

                    if not pitch in controllers:
                        
                        #special commands link to chapterP
                        #TODO review MSB LSB
                        if pitch == 0:
                            bank_msb = (data[seq][i], time)
                        elif pitch == 32:
                            bank_lsb = (data[seq][i], time)
                        elif pitch == 121:
                            #Cas du reset all (possible to forget prec
                            #cmds for controllers, but take care if not standardized)
                            reset_all = (data[seq][i], time)
                        #Mutual exculsive by pair(Off/On and Mono/Poly)
                        elif pitch == 124:
                            #Omni Off
                            omni_off = (data[seq][i], time)
                        elif pitch == 125:
                            #Omni On
                            omni_on = (data[seq][i], time)
                        elif pitch == 126:
                            #Mono
                            mono = (data[seq][i], time)
                        elif pitch == 127:
                            #Poly
                            poly = (data[seq][i], time)
                        else:
                            controllers.append((data[seq][i], time))
                        
                        
                #wheel action 0xE 
                elif (command>>4) == 14:
                    wheels_action = [ wheel[0][0][1] for wheel in wheels ]
                    if not pitch in wheels_action:
                        wheels.append((data[seq][i], time))

                    else:
                        res = wheels_action.index(pitch)
                        wheels[res] = (data[seq][i], time)
                
                #channel afther touch 0xD
                elif (command>>4) == 13:
                    afters_action = [ after[0][0][1] for after in afters ]
                    if not pitch in afters_action:
                        afters.append((data[seq][i], time))

                    else:
                        res = afters_action.index(pitch)
                        afters[res] = (data[seq][i], time)

                #note afters 0xA
                elif (command>>4) == 10:
                    poly_afters_action = [ poly_after[0][0][1] 
                                           for poly_after in poly_afters ]
                    if not pitch in poly_afters_action:
                        poly_afters.append((data[seq][i], time))

                    else:
                        res = poly_afters_action.index(pitch)
                        poly[res] = (data[seq][i], time)

                #else log unknown notes
                else:
                    print "Unrecognize command => " + str(command>>4)
    
        #Checking reset all 
        #COnfigurable standard take care ????
        if standard:
            if reset_all != (0,0):
                special_consideration = 1

                wheels = [wheel[0] for wheel in wheels_action 
                      if not reset_all[1] > wheel[1]]

                afters = [after[0] for after in afters 
                      if not reset_all[1] > afters[1]]
                
                poly_afters = [poly_after[0] for poly_after in poly_afters 
                      if not reset_all[1] > poly_afters[1]]

            #Checking if some command haven't been 
            #completed(when msb/lsb not standardize)
            if bank_msb != (0,0):
                controllers.append(bank_msb[0])

            if bank_lsb != (0,0):
                controllers.append(bank_lsb[0])


            #Checking mutual exclusive omniOff omniOn
            if omni_off != (0,0) and omni_on != (0,0):
                if omni_off[1] > omni_on[1]:
                    controllers.append(omni_off[0])
                    #Removing previews notes
                    
                else:
                    controllers.append(omni_on[0])
            else:
                if omni_off !=(0,0):
                #Log special consideration ( we have to rebuild the channel 
                #to be sure )
                    special_consideration = 1
                    controllers.append(omni_off[0])
                    #Removing previews notes

                elif omni_on != (0,0):
                    controllers.append(omni_on[0])
                    #Removing previews notes
                

            #Checking mutual exclusive Mono/Poly
            if poly != (0, 0) and mono != (0, 0):
            #Log special consideration ( we have to rebuild the channel 
            #to be sure )
                special_consideration = 1
                if poly[1] > mono[1]:
                    controllers.append(poly[0])
                else:
                    controllers.append(mono[0])
            else:
                if poly != (0, 0):
                    controllers.append(poly[0])
                elif mono != (0, 0):
                    controllers.append(mono[0])
            
        
        else:
            wheels = [wheel[0] for wheel in wheels]
            afters = [after[0] for after in afters]  
            poly_afters = [poly_after[0] for poly_after in poly_afters]
            notes = [note[0] for note in notes]
            
            controllers = [controller[0] for controller in controllers]

            if reset_all != (0,0):
                controllers.append(reset_all[0])

            if poly != (0, 0):
                controllers.append(poly[0])

            if mono != (0, 0):
                controllers.append(mono[0])

            if omni_off != (0, 0):
                controllers.append(omni_off[0])

            if omni_on != (0, 0):
                controllers.append(omni_on[0])

            if bank_msb != (0, 0):
                controllers.append(bank_msb[0])

            if bank_lsb != (0, 0):
                controllers.append(bank_lsb[0])

        return (special_consideration, controllers, programs, system_p, 
                wheels, notes, extras, afters, poly_afters)



Generated by  Doxygen 1.6.0   Back to index