def test_packet_with_recovery(self): midi_list = [[[128, 10, 0], 1000], [[144, 32, 110], 1000]] recovery_journal_system = RecoveryJournal() seq = 12 #midi session part (sending) packet = OldPacket(seq, midi_list, 0) midi_list_formated, length = MidiCommand().encode_midi_commands( midi_list) header = MidiCommand().header(0, 1, 0, 0, length) #Building Chunk recovery_journal_system.update(packet) recovery_journal = recovery_journal_system.content chunk = header + midi_list_formated + recovery_journal #protocol part packet = RTPPacket(424242, seq, 10, chunk, 96, marker=1) bytes = packet.netbytes() packet = parse_rtppacket(bytes) #midisession part (receiving) marker_b, marker_j, marker_z, marker_p, length = MidiCommand( ).parse_header(packet.data[0]) if marker_p: #silent packet with recovery midi_list = [] else: #normal packet #Extract Midi Note (length en nb notes) print "test 1:", len(packet.data[1:length * 7 + 1]) midi_list = packet.data[1:length * 7 + 1] #Decoding midi commands midi_list = MidiCommand().decode_midi_commands(midi_list, length) #Saving feed history packet_to_save = OldPacket(seq, midi_list, 0) #Extract Midi Recovery Journal if is present in the packet and #the previous packet has been lost if marker_j: print "recovery journal" print len(packet.data[length * 7 + 1:]) journal = packet.data[length * 7 + 1:] #Parse Recovery journal r_journal = recovery_journal_system.parse(journal)
def test_packet_with_recovery(self): midi_list = [[[128, 10, 0], 1000], [[144, 32, 110], 1000]] recovery_journal_system = RecoveryJournal() seq = 12 #midi session part (sending) packet = OldPacket(seq, midi_list, 0) midi_list_formated, length = MidiCommand().encode_midi_commands(midi_list) header = MidiCommand().header(0, 1, 0, 0, length) #Building Chunk recovery_journal_system.update(packet) recovery_journal = recovery_journal_system.content chunk = header + midi_list_formated + recovery_journal #protocol part packet = RTPPacket(424242, seq, 10, chunk, 96, marker=1) bytes = packet.netbytes() packet = parse_rtppacket(bytes) #midisession part (receiving) marker_b, marker_j, marker_z, marker_p, length = MidiCommand().parse_header(packet.data[0]) if marker_p : #silent packet with recovery midi_list = [] else: #normal packet #Extract Midi Note (length en nb notes) print "test 1:", len(packet.data[1:length*7+1]) midi_list = packet.data[1:length*7+1] #Decoding midi commands midi_list = MidiCommand().decode_midi_commands(midi_list, length) #Saving feed history packet_to_save = OldPacket(seq, midi_list, 0) #Extract Midi Recovery Journal if is present in the packet and #the previous packet has been lost if marker_j: print "recovery journal" print len(packet.data[length*7+1:]) journal = packet.data[length*7+1:] #Parse Recovery journal r_journal = recovery_journal_system.parse(journal)
def test_get_packets_1_1(self): """Packet Circ Testing get packet (case: checkpoint > act_seq with wrap around)""" #TestCase 1.1 checkpoint = 8 act_seq = 1 #Adapting list self.packet_circ.flush() #listto test the packet list plist = [[[192, 120, 100],0],[[144, 104, 50],1], [[145, 110, 0],2], \ [[145, 112, 0],3], [[144, 124, 50],4], \ [[145, 114, 0],5], [[145, 12, 0],6]] #Create the gap empty_list = [] for i in range(8): packy = OldPacket(i, [], 0) #Adding packet to list self.packet_circ.to_list(packy) #fulling the list for i in range(10): #modify plist for each packet plist_1 = [ [[plist[j][0][0], plist[j][0][1], plist[j][0][2]], \ plist[j][1] + i] for j in range(len(plist)) ] packy = OldPacket(i, plist_1, 0) #Adding packet to list self.packet_circ.to_list(packy) midi_cmd = self.packet_circ.get_packets(checkpoint, act_seq) #Test len (nb packets) length = 3 assert(len(midi_cmd) == length), \ self.fail("Problem getting the good length from get_packets") #Testing content #iterator iterator = 9 for i in range(len(midi_cmd)): #increment iterator if i != 0: iterator = (iterator + 1) % 10 midi_cmd_notes = midi_cmd[i].packet #Testing content of packet 9, 0, 1 for j in range(len(midi_cmd_notes)): assert(midi_cmd_notes[j][1]== j + iterator), \ self.fail("Problem with midi cmd content")
def test_parse_1(self): """Test simple parsing of recovery journal with note on""" packy = OldPacket(6, self.partition_on, 0) #Creating recovery journal self.recovery_journal.update(packy) recovery_journal = self.recovery_journal.content
def test_update(self): """Test simple recovery journal creation""" #Test for one packet #Creating packet packy = OldPacket(6, self.partition_on, 0) #Creating recovery journal self.recovery_journal.update(packy) recovery_journal = self.recovery_journal.content #Testing type assert ( type(recovery_journal) == str), self.fail("Wrong type returned") recovery_journal_parsed = self.recovery_journal.parse(recovery_journal)
def setUp(self): self.packet_circ = PacketCirc(10) #list to test the packet list plist = [[[192, 120, 100],0],[[144, 104, 50],1], [[145, 110, 0],2], \ [[145, 112, 0],3], [[144, 124, 50],4], \ [[145, 114, 0],5], [[145, 12, 0],6]] #test without wrap around for i in range(10): #modify plist for each packet plist_1 = [ [[plist[j][0][0], plist[j][0][1], plist[j][0][2]], \ plist[j][1] + i] for j in range(len(plist)) ] packy = OldPacket(i, plist_1, 0) #Adding packet to list self.packet_circ.to_list(packy)
def test_parse(self): """Test simple parsing of recovery journal with note on""" #Test for one packet #Creating packet list packy = OldPacket(6, [[[128, 62, 100], 1000]], 0) #Creating recovery journal self.recovery_journal.update(packy) recovery_journal = self.recovery_journal.content print "len of recovery journa for a note off: ", len( self.recovery_journal.content) #Parsing recovery journal recovery_journal_parsed = self.recovery_journal.parse(recovery_journal) #Testing nb notes assert(len(recovery_journal_parsed)==1), \ self.fail("Nb note from recovery journal " + "parsed is not corresponding to the nb of notes put at" + "the creation") decorate = [(t[0][0], t[0][1], t[0][2], t) for t in recovery_journal_parsed] decorate.sort() recovery_journal_parsed = [t[3] for t in decorate] decorated = [(t[0][0], t[0][1], t[0][2], t) for t in self.partition_off] decorated.sort() partition_off = [t[3] for t in decorated] #Testing content print recovery_journal_parsed for i in range(len(recovery_journal_parsed)): assert(recovery_journal_parsed[i][0][0]==partition_off[i][0][0]), \ self.fail("Problem getting right event after parsing") assert(recovery_journal_parsed[i][0][1]==partition_off[i][0][1]), \ self.fail("Problem getting right note number after parsing") #Pb velocity and change from vel 0 to note off assert(recovery_journal_parsed[i][0][2]==partition_off[i][0][2]), \ self.fail("Problem getting right velocity number after" \ + " parsing")
def test_create_recovery_journal(self): """Test with several channels for recovery journla creation""" self.plist_channel_0 = [[[176, 0, 75], 1000], [[176, 32, 110], 1000], [[192, 110, 0], 1000]] #list of notes to test for i in range(128): #note off self.plist_channel_0.append([[128, i, 100], 10 * i]) #controller change (no special) if i > 32 and i < 100: self.plist_channel_0.append([[176, i, 127 - i], 10 * i]) self.plist_channel_1 = [[[177, 0, 75], 1000], [[177, 32, 110], 1000], [[193, 110, 0], 1000]] for i in range(128): #note on if i == 127: self.plist_channel_1.append([[145, i, 1], 10 * i]) else: self.plist_channel_1.append([[145, i, 127 - i], 10 * i]) #controller change (no special) if i > 32 and i < 100: self.plist_channel_0.append([[177, i, 127 - i], 10 * i]) self.plist_channel_0.extend(self.plist_channel_1) packy = OldPacket(6, self.plist_channel_0, 0) #Creating recovery journal self.recovery_journal.update(packy) recovery_journal = self.recovery_journal.content # header + channel_1(header_channel + prog_chapter + note_chapter + control chapter) + channel_2... length_expected = 3 + ( 3 + 3 + (2 + 16) + (1 + 2*67) ) \ + ( 3 + 3 + (2 + 2 * 128) + (1 + 2*67) ) assert ( type(recovery_journal) == str), self.fail("Wrong type returned") assert (len(recovery_journal) == length_expected ), self.fail("Wrong length returned")
#Wheels wheels = [[[224, 120, 1], 1000]] for wheel in wheels: partition_on.append(wheel) partition_off.append(wheel) #Controllers for i in range(128): partition_on.append([[176, i, 100], 1000]) partition_off.append([[176, i, 100], 1000]) #Aftertouch partition_on.append([[208, 1, 100], 1000]) partition_off.append([[208, 1, 100], 1000]) #Poly-aftertouch for i in range(128): partition_on.append([[160, i, 100], 1000]) partition_off.append([[160, i, 100], 1000]) recovery = RecoveryJournal() packy = OldPacket(6, partition_on, 0) ref = time.time() * 1000 recovery.update(packy) print "time update chrono ", str((time.time() * 1000 - ref)) ref = time.time() * 1000 res = recovery.parse(recovery.content) print "time parse chrono ", str((time.time() * 1000 - ref)) print "len cmp// res: ", str(len(res)), " // ref: ", str(len(partition_on))