mirror of
https://github.com/cyberboy666/r_e_c_u_r.git
synced 2025-12-13 11:50:12 +01:00
added new sampler modes incl random start and fixed length
This commit is contained in:
12
actions.py
12
actions.py
@@ -114,35 +114,35 @@ class Actions(object):
|
||||
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.data.update_slot_rate_to_this(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.data.update_slot_rate_to_this(current_slot, new_rate)
|
||||
self._load_this_slot_into_next_player(current_slot)
|
||||
|
||||
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 = round(self.video_driver.current_player.get_position(),3)
|
||||
self.data.update_slot_start_to_this_time(current_bank, current_slot, current_position)
|
||||
self.data.update_slot_start_to_this_time(current_slot, current_position)
|
||||
self._load_this_slot_into_next_player(current_slot)
|
||||
|
||||
def clear_playing_sample_start_time(self):
|
||||
current_bank, current_slot = self.data.split_bankslot_number(self.video_driver.current_player.bankslot_number)
|
||||
self.data.update_slot_start_to_this_time(current_bank, current_slot, -1)
|
||||
self.data.update_slot_start_to_this_time(current_slot, -1)
|
||||
self._load_this_slot_into_next_player(current_slot)
|
||||
|
||||
def set_playing_sample_end_to_current_duration(self):
|
||||
current_bank, current_slot = self.data.split_bankslot_number(self.video_driver.current_player.bankslot_number)
|
||||
current_position = round(self.video_driver.current_player.get_position(),0)
|
||||
self.data.update_slot_end_to_this_time(current_bank, current_slot, current_position)
|
||||
self.data.update_slot_end_to_this_time(current_slot, current_position)
|
||||
self._load_this_slot_into_next_player(current_slot)
|
||||
|
||||
def clear_playing_sample_end_time(self):
|
||||
current_bank, current_slot = self.data.split_bankslot_number(self.video_driver.current_player.bankslot_number)
|
||||
self.data.update_slot_end_to_this_time(current_bank, current_slot, -1)
|
||||
self.data.update_slot_end_to_this_time(current_slot, -1)
|
||||
self._load_this_slot_into_next_player(current_slot)
|
||||
|
||||
def toggle_capture_preview(self):
|
||||
|
||||
@@ -88,7 +88,6 @@ class Data(object):
|
||||
|
||||
def update_next_slot_number(self, new_value):
|
||||
if self.bank_data[self.bank_number][new_value]['location'] == '':
|
||||
print('its empty!')
|
||||
self.message_handler.set_message('INFO', 'the slot you pressed is empty')
|
||||
elif self.is_this_path_broken(self.bank_data[self.bank_number][new_value]['location']):
|
||||
self.message_handler.set_message('INFO', 'no device found for this slot')
|
||||
@@ -123,11 +122,71 @@ class Data(object):
|
||||
end_value = next_slot_details['end']
|
||||
length = next_slot_details['length']
|
||||
|
||||
start_value, end_value = self._overwrite_values_with_sampler_settings(start_value, end_value, length)
|
||||
|
||||
context = dict(location=next_slot_details['location'], name=next_slot_details['name'],
|
||||
length=next_slot_details['length'], rate=next_slot_details['rate'], start=start_value, end=end_value,
|
||||
bankslot_number=self.next_bankslot)
|
||||
|
||||
self._update_next_bankslot_value(slot_num)
|
||||
return context
|
||||
|
||||
def _overwrite_values_with_sampler_settings(self, start, end, length):
|
||||
use_rand_start = self.settings['sampler']['RAND_START_MODE']['value'] == 'on'
|
||||
use_fixed_length = self.settings['sampler']['FIXED_LENGTH_MODE']['value'] == 'on'
|
||||
fixed_length_value = self.settings['sampler']['FIXED_LENGTH']['value']
|
||||
if start == -1:
|
||||
start = 0
|
||||
if end == -1:
|
||||
end = length
|
||||
new_end = end
|
||||
new_start = start
|
||||
|
||||
if use_fixed_length and use_rand_start:
|
||||
max_increase = int(max(end - start - max(fixed_length_value, 4),0))
|
||||
print('max increase is {} '.format(max_increase))
|
||||
random_increase = randint(0,max_increase)
|
||||
new_start = start + random_increase
|
||||
new_end = min(new_start + fixed_length_value, end)
|
||||
elif use_fixed_length and not use_rand_start:
|
||||
new_end = min(new_start + fixed_length_value, end)
|
||||
elif not use_fixed_length and use_rand_start:
|
||||
max_increase = int(max(end - start - 4,0))
|
||||
print('max increase is {} '.format(max_increase))
|
||||
random_increase = randint(0,max_increase)
|
||||
new_start = start + random_increase
|
||||
|
||||
print('new start: {}, new end: {} '.format(new_start, new_end))
|
||||
return new_start, new_end
|
||||
|
||||
def _update_next_bankslot_value(self, slot_num):
|
||||
next_setting = self.settings['sampler']['LOAD_NEXT']['value']
|
||||
loaded_slots = self._get_list_of_loaded_slots_in_current_bank()
|
||||
if loaded_slots:
|
||||
if next_setting == 'random':
|
||||
next_slot = loaded_slots[randint(0,len(loaded_slots)-1)]
|
||||
elif next_setting == 'consecutive':
|
||||
next_slot = self.get_next_loaded_slot(slot_num, loaded_slots)
|
||||
else:
|
||||
next_slot = slot_num
|
||||
|
||||
self.next_bankslot = '{}-{}'.format(self.bank_number,next_slot)
|
||||
self._update_json(self.NEXT_BANKSLOT_JSON,self.next_bankslot)
|
||||
|
||||
def _get_list_of_loaded_slots_in_current_bank(self):
|
||||
list_of_loaded_slots = []
|
||||
for index, slot in enumerate(self.bank_data[self.bank_number]):
|
||||
if slot['location'] != '' and not self.is_this_path_broken(slot['location']):
|
||||
list_of_loaded_slots.append(index)
|
||||
return list_of_loaded_slots
|
||||
|
||||
@staticmethod
|
||||
def get_next_loaded_slot(current_slot, loaded_slots):
|
||||
i = ( current_slot + 1 ) % len(loaded_slots)
|
||||
while(i not in loaded_slots):
|
||||
i = ( i + 1 ) % len(loaded_slots)
|
||||
return i
|
||||
|
||||
def update_slot_start_to_this_time(self, slot_number, position):
|
||||
self.bank_data[self.bank_number][slot_number]['start'] = position
|
||||
self._update_json(self.BANK_DATA_JSON, self.bank_data)
|
||||
@@ -152,7 +211,6 @@ class Data(object):
|
||||
return None
|
||||
|
||||
|
||||
|
||||
def _get_path_for_file(self, file_name):
|
||||
######## returns full path for a given file name ########
|
||||
for path in self.PATHS_TO_BROWSER:
|
||||
@@ -188,87 +246,5 @@ class Data(object):
|
||||
return ''
|
||||
else:
|
||||
return input
|
||||
"""
|
||||
## methods from old BROWSERDATA class
|
||||
|
||||
def update_open_folders(self, folder_name):
|
||||
if folder_name not in self.open_folders:
|
||||
self.open_folders.append(folder_name)
|
||||
else:
|
||||
self.open_folders.remove(folder_name)
|
||||
|
||||
def update_open_folders_for_settings(self, folder_name):
|
||||
if folder_name not in self.settings_open_folders:
|
||||
self.settings_open_folders.append(folder_name)
|
||||
else:
|
||||
self.settings_open_folders.remove(folder_name)
|
||||
|
||||
def generate_browser_list(self):
|
||||
######## starts the recursive process of listing all folders and video files to display ########
|
||||
self.browser_list = []
|
||||
for path in self.PATHS_TO_BROWSER:
|
||||
self._add_folder_to_browser_list(path, 0)
|
||||
|
||||
for browser_line in self.browser_list:
|
||||
is_file, name = self.extract_file_type_and_name_from_browser_format(browser_line['name'])
|
||||
if is_file:
|
||||
is_slotted, bankslot_number = self._is_file_in_memory_bank(name)
|
||||
if is_slotted:
|
||||
browser_line['slot'] = bankslot_number
|
||||
|
||||
def generate_settings_list(self, open_folders):
|
||||
self.settings_list = []
|
||||
for sub_setting in self.settings.keys():
|
||||
if sub_setting in open_folders:
|
||||
self.settings_list.append(dict(name=sub_setting + '/', value=''))
|
||||
for setting in self.settings[sub_setting]:
|
||||
setting_value = self.make_empty_if_none(self.settings[sub_setting][setting]['value'])
|
||||
self.settings_list.append(dict(name=' ' + setting, value=setting_value))
|
||||
else:
|
||||
self.settings_list.append(dict(name=sub_setting + '|', value=''))
|
||||
|
||||
|
||||
|
||||
@staticmethod
|
||||
def extract_file_type_and_name_from_browser_format(dir_name):
|
||||
# removes whitespace and folder state from display item ########
|
||||
if dir_name.endswith('|') or dir_name.endswith('/'):
|
||||
return False, dir_name.lstrip()[:-1]
|
||||
else:
|
||||
return True, dir_name.lstrip()
|
||||
|
||||
def _add_folder_to_browser_list(self, current_path, current_level):
|
||||
######## adds the folders and mp4 files at the current level to the results list. recursively recalls at deeper level if folder is open ########
|
||||
# TODO make note of / investigate what happens with multiple folders of same name
|
||||
root, dirs, files = next(os.walk(current_path))
|
||||
|
||||
indent = ' ' * 4 * (current_level)
|
||||
for folder in dirs:
|
||||
is_open, char = self._check_folder_state(folder)
|
||||
self.browser_list.append(dict(name='{}{}{}'.format(indent, folder, char), slot='x'))
|
||||
if (is_open):
|
||||
next_path = '{}/{}'.format(root, folder)
|
||||
next_level = current_level + 1
|
||||
self._add_folder_to_browser_list(next_path, next_level)
|
||||
|
||||
for f in files:
|
||||
split_name = os.path.splitext(f)
|
||||
if (split_name[1] in ['.mp4', '.mkv', '.avi', '.mov']):
|
||||
self.browser_list.append(dict(name='{}{}'.format(indent, f), slot='-'))
|
||||
|
||||
def _check_folder_state(self, folder_name):
|
||||
######## used for displaying folders as open or closed ########
|
||||
if folder_name in self.open_folders:
|
||||
return True, '/'
|
||||
else:
|
||||
return False, '|'
|
||||
|
||||
def _is_file_in_memory_bank(self, file_name):
|
||||
######## used for displaying the mappings in browser view ########
|
||||
for bank_index, bank in enumerate(self.bank_data):
|
||||
for slot_index, slot in enumerate(bank):
|
||||
if file_name == slot['name']:
|
||||
return True, '{}-{}'.format(bank_index,slot_index)
|
||||
return False, ''
|
||||
"""
|
||||
|
||||
|
||||
@@ -2,9 +2,25 @@
|
||||
[
|
||||
{
|
||||
"end": -1,
|
||||
"length": 804.245,
|
||||
"location": "/media/pi/5EB5-664C/recur test videos/long_spinning.mp4",
|
||||
"name": "long_spinning.mp4",
|
||||
"length": 49.28,
|
||||
"location": "/media/pi/5EB5-664C/recur test videos/colour_pixal_01.mp4",
|
||||
"name": "colour_pixal_01.mp4",
|
||||
"rate": 1,
|
||||
"start": 3.979
|
||||
},
|
||||
{
|
||||
"end": -1,
|
||||
"length": 87.04,
|
||||
"location": "/media/pi/5EB5-664C/recur test videos/colour_pixal_02.mp4",
|
||||
"name": "colour_pixal_02.mp4",
|
||||
"rate": 1,
|
||||
"start": 4.49
|
||||
},
|
||||
{
|
||||
"end": -1,
|
||||
"length": 52.757,
|
||||
"location": "/media/pi/5EB5-664C/recur test videos/colour_pixal_03.mp4",
|
||||
"name": "colour_pixal_03.mp4",
|
||||
"rate": 1,
|
||||
"start": -1
|
||||
},
|
||||
@@ -16,22 +32,6 @@
|
||||
"rate": 1,
|
||||
"start": -1
|
||||
},
|
||||
{
|
||||
"end": -1,
|
||||
"length": 5838.04,
|
||||
"location": "/media/pi/5EB5-664C/MST3K_0310_Fugitive_Alien_xvid.avi",
|
||||
"name": "MST3K_0310_Fugitive_Alien_xvid.avi",
|
||||
"rate": 1,
|
||||
"start": -1
|
||||
},
|
||||
{
|
||||
"end": -1,
|
||||
"length": -1,
|
||||
"location": "",
|
||||
"name": "",
|
||||
"rate": 1,
|
||||
"start": -1
|
||||
},
|
||||
{
|
||||
"end": -1,
|
||||
"length": -1,
|
||||
|
||||
@@ -113,7 +113,7 @@
|
||||
"FIXED_LENGTH": {
|
||||
"action": "set_fixed_length",
|
||||
"options": [],
|
||||
"value": ""
|
||||
"value": 5
|
||||
},
|
||||
"FIXED_LENGTH_MODE": {
|
||||
"action": "update_video_settings",
|
||||
@@ -128,7 +128,7 @@
|
||||
"options": [
|
||||
"now",
|
||||
"random",
|
||||
"playlist"
|
||||
"consecutive"
|
||||
],
|
||||
"value": "now"
|
||||
},
|
||||
|
||||
@@ -156,7 +156,6 @@ class SettingsMenu(Menu):
|
||||
if setting_folder_key in self.open_folders:
|
||||
self.menu_list.append(dict(name='{}/'.format(setting_folder_key), value=''))
|
||||
order_list_name = '{}_ORDER'.format(setting_folder_key.upper())
|
||||
print(order_list_name)
|
||||
ordered_value = self.order_keys_from_list(setting_folder_item, getattr(self,order_list_name))
|
||||
for (setting_details_key, setting_details_item) in ordered_value:
|
||||
self.menu_list.append(dict(name=' {}'.format(setting_details_key), value=self.data.make_empty_if_none(setting_details_item['value'])))
|
||||
|
||||
@@ -59,7 +59,8 @@ class VideoPlayer:
|
||||
#self.omx_player.set_rate(self.rate)
|
||||
#self.load_attempts = 0
|
||||
return True
|
||||
except (ValueError, SystemError):
|
||||
except (ValueError, SystemError) as e:
|
||||
print(e)
|
||||
#self.message_handler.set_message('ERROR', 'load attempt fail')
|
||||
return False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user