diff --git a/actions.py b/actions.py index 3d7291f..1799d86 100644 --- a/actions.py +++ b/actions.py @@ -115,9 +115,23 @@ class Actions(object): def update_bank(self, amount): new_bank_number = self.data.update_bank_number(self.display.bank_number, amount) - print ('current number is : {} , new number is {} '.format(self.display.bank_number, new_bank_number)) self.display.bank_number = new_bank_number + def increase_speed(self): + new_rate = self.video_driver.current_player.change_rate(0.5) + current_bank, current_slot = self.data.split_bankslot_number(self.video_driver.current_player.bankslot_number) + self.data.update_slot_rate_to_this(current_bank, current_slot, new_rate) + self.load_this_slot_into_next_player(current_slot) + + def decrease_speed(self): + new_rate = self.video_driver.current_player.change_rate(-0.5) + current_bank, current_slot = self.data.split_bankslot_number(self.video_driver.current_player.bankslot_number) + self.data.update_slot_rate_to_this(current_bank, current_slot, new_rate) + self.load_this_slot_into_next_player(current_slot) + + def print_speed(self): + self.message_handler.set_message('INFO', 'the speed of current video is {}'.format(self.video_driver.current_player.omx_player.rate())) + def set_playing_sample_start_to_current_duration(self): current_bank, current_slot = self.data.split_bankslot_number(self.video_driver.current_player.bankslot_number) current_position = self.video_driver.current_player.get_position() diff --git a/data_centre/data.py b/data_centre/data.py index 5e0b25e..2bb5824 100644 --- a/data_centre/data.py +++ b/data_centre/data.py @@ -19,7 +19,7 @@ BANK_DATA_JSON = 'display_data.json' NEXT_BANKSLOT_JSON = 'next_bankslot_number.json' SETTINGS_JSON = 'settings.json' KEYPAD_MAPPING = 'keypad_action_mapping.json' -EMPTY_SLOT = dict(name='', location='', length=-1, start=-1, end=-1) +EMPTY_SLOT = dict(name='', location='', length=-1, start=-1, end=-1, rate=1) EMPTY_BANK = [EMPTY_SLOT for i in range(10)] PATH_TO_DATA_OBJECTS = '{}/json_objects/'.format(get_the_current_dir_path()) @@ -66,7 +66,7 @@ class Data(object): has_location, location = self._get_path_for_file(file_name) print('file_name:{},has_location:{}, location:{}'.format(file_name,has_location, location)) length = self._get_length_for_file(location) - new_slot = dict(name=file_name, location=location, length=length, start=-1, end=-1) + new_slot = dict(name=file_name, location=location, length=length, start=-1, end=-1, rate=1) self._update_a_slots_data(bank_number, slot_number, new_slot) @staticmethod @@ -154,7 +154,7 @@ class Data(object): length = next_slot_details['length'] context = dict(location=next_slot_details['location'], name=next_slot_details['name'], - length=next_slot_details['length'], start=start_value, end=end_value, + length=next_slot_details['length'], rate=next_slot_details['rate'], start=start_value, end=end_value, bankslot_number=next_bankslot_number) return context @@ -169,6 +169,11 @@ class Data(object): memory_bank[bank_number][slot_number]['end'] = position update_json(BANK_DATA_JSON, memory_bank) + def update_slot_rate_to_this(self,bank_number, slot_number, rate): + memory_bank = read_json(BANK_DATA_JSON) + memory_bank[bank_number][slot_number]['rate'] = rate + update_json(BANK_DATA_JSON, memory_bank) + def _get_length_for_file(self, path): if self.has_omx: temp_player = OMXPlayer(path, args=['--alpha', '0'], dbus_name='t.t') diff --git a/data_centre/json_objects/display_data.json b/data_centre/json_objects/display_data.json index 4cc0b75..ad288fd 100644 --- a/data_centre/json_objects/display_data.json +++ b/data_centre/json_objects/display_data.json @@ -1 +1 @@ -[[{"start": -1, "end": -1, "length": 49.28, "location": "/media/pi/TIM1/videos_to_play/colour_pixel_01.mp4", "name": "colour_pixel_01.mp4"}, {"start": -1, "end": -1, "length": 87.04, "location": "/media/pi/TIM1/videos_to_play/colour_pixel_02.mp4", "name": "colour_pixel_02.mp4"}, {"start": -1, "end": -1, "length": 3.114, "location": "/media/pi/TIM1/teaser1.mp4", "name": "teaser1.mp4"}, {"start": -1, "end": -1, "length": -1, "location": "", "name": ""}, {"start": -1, "end": -1, "length": -1, "location": "", "name": ""}, {"start": -1, "end": -1, "length": -1, "location": "", "name": ""}, {"start": -1, "end": -1, "length": -1, "location": "", "name": ""}, {"start": -1, "end": -1, "length": -1, "location": "", "name": ""}, {"start": -1, "end": -1, "length": -1, "location": "", "name": ""}, {"start": -1, "end": -1, "length": -1, "location": "", "name": ""}], [{"start": -1, "end": -1, "length": -1, "location": "", "name": ""}, {"start": -1, "end": -1, "length": -1, "location": "", "name": ""}, {"start": -1, "end": -1, "length": -1, "location": "", "name": ""}, {"start": -1, "end": -1, "length": -1, "location": "", "name": ""}, {"start": -1, "end": -1, "length": -1, "location": "", "name": ""}, {"start": -1, "end": -1, "length": -1, "location": "", "name": ""}, {"start": -1, "end": -1, "length": -1, "location": "", "name": ""}, {"start": -1, "end": -1, "length": -1, "location": "", "name": ""}, {"start": -1, "end": -1, "length": -1, "location": "", "name": ""}, {"start": -1, "end": -1, "length": -1, "location": "", "name": ""}]] \ No newline at end of file +[[{"rate": 3.5, "location": "/media/pi/TIM1/videos_to_play/colour_pixel_01.mp4", "length": 49.28, "end": -1, "start": -1, "name": "colour_pixel_01.mp4"}, {"rate": 1, "location": "/media/pi/TIM1/videos_to_play/long_spinning.mp4", "length": 804.245, "end": -1, "start": -1, "name": "long_spinning.mp4"}, {"rate": 0.5, "location": "/media/pi/TIM1/Test.mp4", "length": 599.585, "end": -1, "start": -1, "name": "Test.mp4"}, {"rate": 3.0, "location": "/media/pi/TIM1/teaser1.mp4", "length": 3.114, "end": -1, "start": -1, "name": "teaser1.mp4"}, {"rate": 0.5, "start": -1, "length": 3.114, "end": -1, "location": "/media/pi/TIM1/teaser1.mp4", "name": "teaser1.mp4"}, {"rate": 1, "location": "", "length": -1, "end": -1, "start": -1, "name": ""}, {"rate": 1, "location": "", "length": -1, "end": -1, "start": -1, "name": ""}, {"rate": 1, "location": "", "length": -1, "end": -1, "start": -1, "name": ""}, {"rate": 1, "location": "", "length": -1, "end": -1, "start": -1, "name": ""}, {"rate": 1, "location": "", "length": -1, "end": -1, "start": -1, "name": ""}], [{"rate": 1, "location": "", "length": -1, "end": -1, "start": -1, "name": ""}, {"rate": 1, "location": "", "length": -1, "end": -1, "start": -1, "name": ""}, {"rate": 1, "location": "", "length": -1, "end": -1, "start": -1, "name": ""}, {"rate": 1, "location": "", "length": -1, "end": -1, "start": -1, "name": ""}, {"rate": 1, "location": "", "length": -1, "end": -1, "start": -1, "name": ""}, {"rate": 1, "location": "", "length": -1, "end": -1, "start": -1, "name": ""}, {"rate": 1, "location": "", "length": -1, "end": -1, "start": -1, "name": ""}, {"rate": 1, "location": "", "length": -1, "end": -1, "start": -1, "name": ""}, {"rate": 1, "location": "", "length": -1, "end": -1, "start": -1, "name": ""}, {"rate": 1, "location": "", "length": -1, "end": -1, "start": -1, "name": ""}]] \ No newline at end of file diff --git a/data_centre/json_objects/keypad_action_mapping.json b/data_centre/json_objects/keypad_action_mapping.json index bcd8a3d..497820b 100644 --- a/data_centre/json_objects/keypad_action_mapping.json +++ b/data_centre/json_objects/keypad_action_mapping.json @@ -40,13 +40,13 @@ "DEFAULT": ["load_slot_2_into_next_player","clear_all_slots"] }, "m": { - "DEFAULT": ["load_slot_3_into_next_player"] + "DEFAULT": ["load_slot_3_into_next_player","decrease_speed"] }, "n": { - "DEFAULT": ["load_slot_4_into_next_player"] + "DEFAULT": ["load_slot_4_into_next_player","increase_speed"] }, "o": { - "DEFAULT": ["load_slot_5_into_next_player"] + "DEFAULT": ["load_slot_5_into_next_player","print_speed"] }, "p": { "DEFAULT": ["load_slot_6_into_next_player"] diff --git a/data_centre/json_objects/next_bankslot_number.json b/data_centre/json_objects/next_bankslot_number.json index 0a208b6..6d77ead 100644 --- a/data_centre/json_objects/next_bankslot_number.json +++ b/data_centre/json_objects/next_bankslot_number.json @@ -1 +1 @@ -"0-1" \ No newline at end of file +"0-3" \ No newline at end of file diff --git a/display_centre/display.py b/display_centre/display.py index 1c93dba..8dab461 100644 --- a/display_centre/display.py +++ b/display_centre/display.py @@ -75,13 +75,13 @@ class Display(object): bank_data = self.data.get_sampler_data()[self.bank_number] self.display_text.insert(END, '------------------ ------------------ \n') self.display_text.tag_add("DISPLAY_MODE", 4.19, 4.29) - self.display_text.insert(END, '{:^6} {:<20} {:<4} {:<4} {:<4} \n'.format( - '{}-slot'.format(self.bank_number), 'name', 'length', 'start', 'end')) + self.display_text.insert(END, '{:^6} {:<16} {:<4} {:<4} {:<4} {:<4} \n'.format( + '{}-slot'.format(self.bank_number), 'name', 'length', 'start', 'end', 'rate')) for index, slot in enumerate(bank_data): name_without_extension = slot['name'].rsplit('.',1)[0] - self.display_text.insert(END, '{:^4} {:<22} {:<4} {:<4} {:<4} \n'.format( + self.display_text.insert(END, '{:^4} {:<18} {:<4} {:<4} {:<4} {:<4} \n'.format( index, name_without_extension[0:22], self.format_time_value(slot['length']), - self.format_time_value(slot['start']), self.format_time_value(slot['end']))) + self.format_time_value(slot['start']), self.format_time_value(slot['end']), slot['rate'])) current_bank , current_slot = self.data.split_bankslot_number(self.video_driver.current_player.bankslot_number) if current_bank is self.bank_number: self.selected_list_index = current_slot diff --git a/video_centre/video_player.py b/video_centre/video_player.py index 1a0f667..82b656a 100644 --- a/video_centre/video_player.py +++ b/video_centre/video_player.py @@ -17,6 +17,7 @@ class video_player: self.bankslot_number = '*-*' self.start = -1.0 self.end = -1.0 + self.rate = 1 self.crop_length = 0.0 self.location = '' self.load_attempts = 0 @@ -53,6 +54,8 @@ class video_player: if self.start > 0.5: self.set_position(self.start - 0.5) self.pause_at_start() + print('set rate to {}'.format(self.rate)) + self.omx_player.set_rate(self.rate) self.load_attempts = 0 return True except ValueError: @@ -109,6 +112,7 @@ class video_player: self.start = next_context['start'] self.end = next_context['end'] self.bankslot_number = next_context['bankslot_number'] + self.rate = next_context['rate'] def toggle_pause(self): self.omx_player.play_pause() @@ -123,6 +127,17 @@ class video_player: else: self.message_handler.set_message('INFO', 'can not seek outside range') + def change_rate(self, amount): + new_rate = self.rate + amount + if (new_rate > self.omx_player.minimum_rate() and new_rate < self.omx_player.maximum_rate()): + updated_speed = self.omx_player.set_rate(new_rate) + self.rate = new_rate + print('max rate {} , min rate {} '.format(self.omx_player.maximum_rate() ,self.omx_player.minimum_rate())) + return new_rate + else: + self.message_handler.set_message('INFO', 'can not set speed outside of range') + return self.rate + def set_position(self, position): self.omx_player.set_position(position)