mirror of
https://github.com/cyberboy666/r_e_c_u_r.git
synced 2025-12-06 00:10:07 +01:00
added a extra list of banks to data object and a new index bank_number to be used all over
This commit is contained in:
14
actions.py
14
actions.py
@@ -19,7 +19,7 @@ class Actions(object):
|
||||
is_file, name = self.data.browser_data.extract_file_type_and_name_from_browser_format(
|
||||
self.data.return_browser_list()[self.display.selected_list_index]['name'])
|
||||
if is_file:
|
||||
self.data.create_new_slot_mapping_in_first_open(name)
|
||||
self.data.create_new_slot_mapping_in_first_open(name, self.display.bank_number)
|
||||
else:
|
||||
self.data.browser_data.update_open_folders(name)
|
||||
self.data.rewrite_browser_list()
|
||||
@@ -37,7 +37,7 @@ class Actions(object):
|
||||
getattr(self, action)()
|
||||
|
||||
def clear_all_slots(self):
|
||||
self.data.clear_all_slots()
|
||||
self.data.clear_all_slots(self.display.bank_number)
|
||||
|
||||
def quit_the_program(self):
|
||||
if self.video_driver.has_omx:
|
||||
@@ -45,7 +45,7 @@ class Actions(object):
|
||||
self.tk.destroy()
|
||||
|
||||
def load_this_slot_into_next_player(self, slot):
|
||||
self.data.update_next_slot_number(slot)
|
||||
self.data.update_next_slot_number(self.display.bank_number,slot)
|
||||
self.video_driver.next_player.reload()
|
||||
|
||||
def load_slot_0_into_next_player(self):
|
||||
@@ -109,23 +109,23 @@ class Actions(object):
|
||||
def set_playing_sample_start_to_current_duration(self):
|
||||
current_slot = self.video_driver.current_player.slot_number
|
||||
current_position = self.video_driver.current_player.get_position()
|
||||
self.data.update_slot_start_to_this_time(current_slot, current_position)
|
||||
self.data.update_slot_start_to_this_time(self.display.bank_number, current_slot, current_position)
|
||||
self.load_this_slot_into_next_player(current_slot)
|
||||
|
||||
def clear_playing_sample_start_time(self):
|
||||
current_slot = self.video_driver.current_player.slot_number
|
||||
self.data.update_slot_start_to_this_time(current_slot, -1)
|
||||
self.data.update_slot_start_to_this_time(self.display.bank_number, current_slot, -1)
|
||||
self.load_this_slot_into_next_player(current_slot)
|
||||
|
||||
def set_playing_sample_end_to_current_duration(self):
|
||||
current_slot = self.video_driver.current_player.slot_number
|
||||
current_position = self.video_driver.current_player.get_position()
|
||||
self.data.update_slot_end_to_this_time(current_slot, current_position)
|
||||
self.data.update_slot_end_to_this_time(self.display.bank_number, current_slot, current_position)
|
||||
self.load_this_slot_into_next_player(current_slot)
|
||||
|
||||
def clear_playing_sample_end_time(self):
|
||||
current_slot = self.video_driver.current_player.slot_number
|
||||
self.data.update_slot_end_to_this_time(current_slot, -1)
|
||||
self.data.update_slot_end_to_this_time(self.display.bank_number, current_slot, -1)
|
||||
self.load_this_slot_into_next_player(current_slot)
|
||||
|
||||
def switch_display_to_hdmi(self):
|
||||
|
||||
@@ -27,9 +27,9 @@ class BrowserData(object):
|
||||
for browser_line in self.browser_list:
|
||||
is_file, file_name = self.extract_file_type_and_name_from_browser_format(browser_line['name'])
|
||||
if is_file:
|
||||
is_slotted, slot_number = self._is_file_in_memory_bank(file_name)
|
||||
is_slotted, bankslot_number = self._is_file_in_memory_bank(file_name)
|
||||
if is_slotted:
|
||||
browser_line['slot'] = str(slot_number)
|
||||
browser_line['slot'] = str(bankslot_number)
|
||||
|
||||
return self.browser_list
|
||||
|
||||
@@ -71,9 +71,10 @@ class BrowserData(object):
|
||||
######## used for displaying the mappings in browser view ########
|
||||
if not self.memory_bank:
|
||||
self.memory_bank = data_centre.data.read_json(data_centre.data.BANK_DATA_JSON)
|
||||
for index, slot in enumerate(self.memory_bank):
|
||||
for bank_index, bank in enumerate(self.memory_bank):
|
||||
for slot_index, slot in enumerate(bank):
|
||||
if file_name == slot['name']:
|
||||
return True, index
|
||||
return True, '{}-{}'.format(bank_index,slot_index)
|
||||
return False, ''
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ def get_the_current_dir_path():
|
||||
return os.path.split(current_file_path)[0]
|
||||
|
||||
BANK_DATA_JSON = 'display_data.json'
|
||||
NEXT_SLOT_JSON = 'next_slot_number.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)
|
||||
@@ -51,37 +51,37 @@ class Data(object):
|
||||
def get_screen_size_setting(self):
|
||||
return read_json(SETTINGS_JSON)[0]['options'][0]
|
||||
|
||||
def create_new_slot_mapping_in_first_open(self, file_name):
|
||||
def create_new_slot_mapping_in_first_open(self, file_name, bank_number):
|
||||
######## used for mapping current video to next available slot ########
|
||||
memory_bank = read_json(BANK_DATA_JSON)
|
||||
for index, slot in enumerate(memory_bank):
|
||||
for index, slot in enumerate(memory_bank[bank_number]):
|
||||
if (not slot['name']):
|
||||
self.create_new_slot_mapping(index, file_name)
|
||||
self.create_new_slot_mapping(bank_number, index, file_name)
|
||||
return True
|
||||
return False
|
||||
|
||||
def create_new_slot_mapping(self, slot_number, file_name):
|
||||
def create_new_slot_mapping(self,bank_number, slot_number, file_name):
|
||||
######## used for mapping current video to a specific slot ########
|
||||
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)
|
||||
self._update_a_slots_data(slot_number, new_slot)
|
||||
self._update_a_slots_data(bank_number, slot_number, new_slot)
|
||||
|
||||
@staticmethod
|
||||
def clear_all_slots():
|
||||
def clear_all_slots(bank_number):
|
||||
memory_bank = read_json(BANK_DATA_JSON)
|
||||
for index, slot in enumerate(memory_bank):
|
||||
memory_bank[index] = EMPTY_SLOT
|
||||
for index, slot in enumerate(memory_bank[bank_number]):
|
||||
memory_bank[bank_number][index] = EMPTY_SLOT
|
||||
update_json(BANK_DATA_JSON, memory_bank)
|
||||
|
||||
def update_next_slot_number(self, new_value):
|
||||
def update_next_slot_number(self, bank_number, new_value):
|
||||
memory_bank = read_json(BANK_DATA_JSON)
|
||||
if memory_bank[new_value]['location'] == '':
|
||||
if memory_bank[bank_number][new_value]['location'] == '':
|
||||
print('its empty!')
|
||||
self.message_handler.set_message('INFO', 'the slot you pressed is empty')
|
||||
else:
|
||||
update_json(NEXT_SLOT_JSON, new_value)
|
||||
update_json(NEXT_BANKSLOT_JSON, '{}-{}'.format(bank_number,new_value))
|
||||
|
||||
def add_open_folder(self, folder_name):
|
||||
self.browser_data.update_open_folders(folder_name)
|
||||
@@ -108,6 +108,21 @@ class Data(object):
|
||||
def return_browser_list(self):
|
||||
return self.browser_data.browser_list
|
||||
|
||||
@classmethod
|
||||
def split_bankslot_number(cls, slot_number):
|
||||
split = slot_number.split('-')
|
||||
print(split)
|
||||
is_bank_num_int , converted_bank_number = cls.try_convert_string_to_int(split[0])
|
||||
is_slot_num_int , converted_slot_number = cls.try_convert_string_to_int(split[1])
|
||||
return converted_bank_number, converted_slot_number
|
||||
|
||||
@staticmethod
|
||||
def try_convert_string_to_int(string_input):
|
||||
try:
|
||||
return True , int(string_input)
|
||||
except ValueError:
|
||||
return False , '*'
|
||||
|
||||
@staticmethod
|
||||
def get_settings_data():
|
||||
return read_json(SETTINGS_JSON)
|
||||
@@ -122,30 +137,30 @@ class Data(object):
|
||||
|
||||
def get_next_context(self):
|
||||
######## loads the slot details, uses settings to modify them and then set next slot number ########
|
||||
next_slot_number = read_json(NEXT_SLOT_JSON)
|
||||
next_bankslot_number = read_json(NEXT_BANKSLOT_JSON)
|
||||
memory_bank = read_json(BANK_DATA_JSON)
|
||||
next_slot_details = memory_bank[next_slot_number]
|
||||
bank_num , slot_num = self.split_bankslot_number(next_bankslot_number)
|
||||
next_slot_details = memory_bank[bank_num][slot_num]
|
||||
start_value = next_slot_details['start']
|
||||
end_value = next_slot_details['end']
|
||||
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,
|
||||
slot_number=next_slot_number)
|
||||
slot_number=next_bankslot_number)
|
||||
return context
|
||||
|
||||
def update_slot_start_to_this_time(self, slot_number, position):
|
||||
def update_slot_start_to_this_time(self, bank_number, slot_number, position):
|
||||
memory_bank = read_json(BANK_DATA_JSON)
|
||||
memory_bank[slot_number]['start'] = position
|
||||
memory_bank[bank_number][slot_number]['start'] = position
|
||||
update_json(BANK_DATA_JSON, memory_bank)
|
||||
|
||||
def update_slot_end_to_this_time(self, slot_number, position):
|
||||
def update_slot_end_to_this_time(self,bank_number, slot_number, position):
|
||||
memory_bank = read_json(BANK_DATA_JSON)
|
||||
memory_bank[slot_number]['end'] = position
|
||||
memory_bank[bank_number][slot_number]['end'] = position
|
||||
update_json(BANK_DATA_JSON, memory_bank)
|
||||
|
||||
def _get_length_for_file(self, path):
|
||||
print('getting length for: {}'.format(path))
|
||||
if self.has_omx:
|
||||
temp_player = OMXPlayer(path, args=['--alpha', '0'], dbus_name='t.t')
|
||||
duration = temp_player.duration()
|
||||
@@ -162,10 +177,10 @@ class Data(object):
|
||||
return False, ''
|
||||
|
||||
@staticmethod
|
||||
def _update_a_slots_data(slot_number, slot_info):
|
||||
def _update_a_slots_data(bank_number, slot_number, slot_info):
|
||||
######## overwrite a given slots info with new data ########
|
||||
memory_bank = read_json(BANK_DATA_JSON)
|
||||
memory_bank[slot_number] = slot_info
|
||||
memory_bank[bank_number][slot_number] = slot_info
|
||||
update_json(BANK_DATA_JSON, memory_bank)
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -1 +1 @@
|
||||
[{"name": "colour_pixel_01.mp4", "length": 49.28, "end": -1, "start": -1, "location": "/media/pi/TIM1/videos_to_play/colour_pixel_01.mp4"}, {"name": "colour_pixel_02.mp4", "start": -1, "location": "/media/pi/TIM1/videos_to_play/colour_pixel_02.mp4", "length": 87.04, "end": -1}, {"name": "", "length": -1, "location": "", "start": -1, "end": -1}, {"name": "", "length": -1, "location": "", "start": -1, "end": -1}, {"name": "", "length": -1, "location": "", "start": -1, "end": -1}, {"name": "", "length": -1, "location": "", "start": -1, "end": -1}, {"name": "", "length": -1, "location": "", "start": -1, "end": -1}, {"name": "", "length": -1, "location": "", "start": -1, "end": -1}, {"name": "", "length": -1, "location": "", "start": -1, "end": -1}, {"name": "", "length": -1, "location": "", "start": -1, "end": -1}]
|
||||
[[{"start": -1, "location": "/media/pi/TIM1/videos_to_play/colour_pixel_01.mp4", "length": 49.28, "end": -1, "name": "colour_pixel_01.mp4"}, {"end": -1, "location": "/media/pi/TIM1/videos_to_play/colour_pixel_02.mp4", "length": 87.04, "start": -1, "name": "colour_pixel_02.mp4"}, {"location": "/media/pi/TIM1/teaser1.mp4", "length": 3.114, "end": -1, "start": -1, "name": "teaser1.mp4"}, {"end": -1, "location": "", "length": -1, "start": -1, "name": ""}, {"end": -1, "location": "", "length": -1, "start": -1, "name": ""}, {"end": -1, "location": "", "length": -1, "start": -1, "name": ""}, {"end": -1, "location": "", "length": -1, "start": -1, "name": ""}, {"end": -1, "location": "", "length": -1, "start": -1, "name": ""}, {"end": -1, "location": "", "length": -1, "start": -1, "name": ""}, {"end": -1, "location": "", "length": -1, "start": -1, "name": ""}]]
|
||||
1
data_centre/json_objects/next_bankslot_number.json
Normal file
1
data_centre/json_objects/next_bankslot_number.json
Normal file
@@ -0,0 +1 @@
|
||||
"0-1"
|
||||
@@ -1 +0,0 @@
|
||||
0
|
||||
@@ -18,6 +18,7 @@ class Display(object):
|
||||
|
||||
self.display_mode = "SAMPLER"
|
||||
self.control_mode = 'PLAYER'
|
||||
self.bank_number = 0
|
||||
self.top_menu_index = 0
|
||||
self.selected_list_index = self.top_menu_index
|
||||
self.browser_list = self.data.rewrite_browser_list()
|
||||
@@ -48,7 +49,7 @@ class Display(object):
|
||||
self.display_text.pack()
|
||||
|
||||
def _load_title(self):
|
||||
self.display_text.insert(END, '================== r_e_c_u_r ================== \n')
|
||||
self.display_text.insert(END, '================== r_e_c_u_r:beta ============= \n')
|
||||
self.display_text.tag_add("TITLE", 1.19, 1.28)
|
||||
|
||||
def _load_player(self):
|
||||
@@ -71,20 +72,21 @@ class Display(object):
|
||||
self._highlight_this_row(self.selected_list_index - self.top_menu_index)
|
||||
|
||||
def _load_sampler(self):
|
||||
bank_data = self.data.get_sampler_data()
|
||||
bank_data = self.data.get_sampler_data()[self.bank_number]
|
||||
self.display_text.insert(END, '------------------ <SAMPLER> ------------------ \n')
|
||||
self.display_text.tag_add("DISPLAY_MODE", 4.19, 4.29)
|
||||
self.display_text.insert(END, '{:^4} {:<22} {:<4} {:<4} {:<4} \n'.format(
|
||||
'slot', 'name', 'length', 'start', 'end'))
|
||||
self.display_text.insert(END, '{:^6} {:<20} {:<4} {:<4} {:<4} \n'.format(
|
||||
'{}-slot'.format(self.bank_number), 'name', 'length', 'start', 'end'))
|
||||
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(
|
||||
index, name_without_extension[0:22], self.format_time_value(slot['length']),
|
||||
self.format_time_value(slot['start']), self.format_time_value(slot['end'])))
|
||||
if self.video_driver.current_player.slot_number is '-':
|
||||
self.selected_list_index = 0
|
||||
current_bank , current_slot = self.data.split_bankslot_number(self.video_driver.current_player.slot_number)
|
||||
if current_bank is self.bank_number:
|
||||
self.selected_list_index = current_slot
|
||||
else:
|
||||
self.selected_list_index = self.video_driver.current_player.slot_number
|
||||
self.selected_list_index = 0
|
||||
|
||||
def _load_browser(self):
|
||||
browser_list = self.data.return_browser_list()
|
||||
@@ -155,7 +157,7 @@ class Display(object):
|
||||
time_left = self.format_time_value(end - position)
|
||||
|
||||
return self.VIDEO_DISPLAY_BANNER_TEXT.format(time_been, banner, time_left), \
|
||||
self.VIDEO_DISPLAY_TEXT.format(now_slot, now_status, next_slot, next_status)
|
||||
' NOW [{}] {} NEXT [{}] {}'.format(now_slot, now_status, next_slot, next_status)
|
||||
|
||||
@staticmethod
|
||||
def create_video_display_banner(start, end, crop_length, position):
|
||||
|
||||
@@ -14,7 +14,7 @@ class video_player:
|
||||
self.omx_running = False
|
||||
self.status = 'N/A'
|
||||
self.total_length = 0.0
|
||||
self.slot_number = '-'
|
||||
self.slot_number = '*-*'
|
||||
self.start = -1.0
|
||||
self.end = -1.0
|
||||
self.crop_length = 0.0
|
||||
@@ -55,7 +55,7 @@ class video_player:
|
||||
self.pause_at_start()
|
||||
self.load_attempts = 0
|
||||
return True
|
||||
except:
|
||||
except ValueError:
|
||||
self.message_handler.set_message('ERROR', 'load attempt fail')
|
||||
return False
|
||||
|
||||
@@ -150,7 +150,7 @@ class fake_video_player:
|
||||
self.omx_running = False
|
||||
self.status = 'N/A'
|
||||
self.duration = 0
|
||||
self.slot_number = '-'
|
||||
self.slot_number = '*-*'
|
||||
self.start = -1
|
||||
self.end = -1
|
||||
self.length = 0
|
||||
|
||||
Reference in New Issue
Block a user