Exemplo n.º 1
0
 def cut_fragment(self, e):
     if self.file is not None:
         max = self.start_slider.GetMax()
         left_border = self.start_slider.GetValue()
         right_border = self.end_slider.GetValue()
         if left_border > right_border:
             left_border, right_border = right_border, left_border
         if left_border == 0 and right_border == max:
             self.show_notification("You can't delete all track!",
                                    "Deleting")
             return
         length = len(self.file.channels[0])
         left_index = length // max * left_border
         right_index = length // max * right_border
         if left_border == 0:
             end = fragment.Fragment(
                 self.file.get_fragment(right_index + 1, length))
             self.file.channels = end.channels
         elif right_border == max:
             start = fragment.Fragment(
                 self.file.get_fragment(0, left_index - 1))
             self.file.channels = start.channels
         else:
             start = fragment.Fragment(
                 self.file.get_fragment(0, left_index - 1))
             end = fragment.Fragment(
                 self.file.get_fragment(right_index + 1, length))
             self.file.channels = fragment.concatenate_fragments(
                 [start, end])
         self.file.subchunk2Size = len(
             self.file.channels[0]) * self.file.bitsPerSample // 4
         self.file.chunkSize = self.file.subchunk2Size + 36
         self.draw_track()
 def test_concatenation(self):
     test_file = wave_file.Wave("../Files/01 Bloody Nose.wav")
     fragment1 = fragment.Fragment(test_file.get_fragment(0, 550000))
     fragment2 = fragment.Fragment(test_file.get_fragment(1000000, 1250000))
     temp = fragment.concatenate_fragments((fragment1, fragment2))
     concat = fragment.Fragment(temp)
     self.assertEqual(len(concat.channels), 2)
     self.assertEqual(len(concat.channels[0]), 800000)
     self.assertEqual(len(concat.channels[1]), 800000)
 def test_union_with_different_length(self):
     test_file = wave_file.Wave("../Files/01 Bloody Nose.wav")
     fragment1 = fragment.Fragment(test_file.get_fragment(0, 600000))
     fragment2 = fragment.Fragment(test_file.get_fragment(550000, 900000))
     union = fragment.collect_fragments_to_one((fragment1, fragment2),
                                               test_file.channels[0].dtype)
     union_fragment = fragment.Fragment(union)
     self.assertEqual(len(union_fragment.channels), 2)
     self.assertEqual(len(union_fragment.channels[0]), 600000)
     test_value = fragment1.channels[0][12345] + fragment2.channels[0][
         12345]
     self.assertEqual(union_fragment.channels[0][12345], test_value)
 def test_reverse_fragment(self):
     test_file = wave_file.Wave("../Files/01 Bloody Nose.wav")
     fragment1 = fragment.Fragment(test_file.get_fragment(0, 600000))
     self.assertEqual(len(fragment1.channels[0]), 600000)
     test_value = fragment1.channels[0][12345]
     fragment1.reverse()
     self.assertEqual(
         fragment1.channels[0][len(fragment1.channels[0]) - 12346],
         test_value)
Exemplo n.º 5
0
 def save_fragment(self, e):
     if self.file is not None:
         left_border = self.start_slider.GetValue()
         right_border = self.end_slider.GetValue()
         if left_border > right_border:
             left_border, right_border = right_border, left_border
         length = len(self.file.channels[0])
         left_index = length // self.start_slider.GetMax() * left_border
         right_index = length // self.start_slider.GetMax() * right_border
         fragment_channels = self.file.get_fragment(left_index, right_index)
         self.fragments.append(fragment.Fragment(fragment_channels))
         self.draw_fragments()
Exemplo n.º 6
0
 def reverse_fragment(self, e):
     if self.file is not None:
         max = self.start_slider.GetMax()
         left_border = self.start_slider.GetValue()
         right_border = self.end_slider.GetValue()
         if left_border > right_border:
             left_border, right_border = right_border, left_border
         if left_border == 0 and right_border == max:
             self.show_notification(
                 "For reversing all the track use \"reverse\" button",
                 "Reverse")
             return
         length = len(self.file.channels[0])
         left_index = length // max * left_border
         right_index = length // max * right_border
         if left_border == 0:
             start = fragment.Fragment(
                 self.file.get_fragment(0, right_index))
             start.reverse()
             end = fragment.Fragment(
                 self.file.get_fragment(right_index + 1, length))
             self.file.channels = fragment.concatenate_fragments(
                 [start, end])
         elif right_border == max:
             start = fragment.Fragment(
                 self.file.get_fragment(0, left_index - 1))
             end = fragment.Fragment(
                 self.file.get_fragment(left_index, length))
             end.reverse()
             self.file.channels = fragment.concatenate_fragments(
                 [start, end])
         else:
             start = fragment.Fragment(
                 self.file.get_fragment(0, left_index - 1))
             fr = fragment.Fragment(
                 self.file.get_fragment(left_index, right_index))
             fr.reverse()
             end = fragment.Fragment(
                 self.file.get_fragment(right_index + 1, length))
             self.file.channels = fragment.concatenate_fragments(
                 [start, fr, end])
         self.draw_track()
Exemplo n.º 7
0
 def test_get_fragment(self):
     test_file = wave_file.Wave("../Files/01 Bloody Nose.wav")
     fr = fragment.Fragment(test_file.get_fragment(150000, 1500000))
     for channel in fr.channels:
         self.assertEqual(len(channel), 1350000)