reduced half finished settings code and added options for screen size select

This commit is contained in:
langolierz
2018-01-17 10:04:04 +00:00
parent 9ca3d471e5
commit 8c9692309e
11 changed files with 112 additions and 249 deletions

View File

@@ -43,6 +43,36 @@ class Actions(object):
self.data.update_next_slot_number(slot)
self.video_driver.next_player.reload()
def load_slot_0_into_next_player(self):
load_this_slot_into_next_player(0)
def load_slot_1_into_next_player(self):
load_this_slot_into_next_player(1)
def load_slot_2_into_next_player(self):
load_this_slot_into_next_player(2)
def load_slot_3_into_next_player(self):
load_this_slot_into_next_player(3)
def load_slot_4_into_next_player(self):
load_this_slot_into_next_player(4)
def load_slot_5_into_next_player(self):
load_this_slot_into_next_player(5)
def load_slot_6_into_next_player(self):
load_this_slot_into_next_player(6)
def load_slot_7_into_next_player(self):
load_this_slot_into_next_player(7)
def load_slot_8_into_next_player(self):
load_this_slot_into_next_player(8)
def load_slot_9_into_next_player(self):
load_this_slot_into_next_player(9)
def trigger_next_player(self):
self.video_driver.manual_next = True

View File

@@ -2,6 +2,7 @@ import json
import os
from random import randint
import inspect
from itertools import cycle
try:
from omxplayer.player import OMXPlayer
except:
@@ -17,6 +18,7 @@ def get_the_current_dir_path():
BANK_DATA_JSON = 'display_data.json'
NEXT_SLOT_JSON = 'next_slot_number.json'
SETTINGS_JSON = 'settings.json'
KEYPAD_MAPPING = 'keypad_action_mapping.json'
EMPTY_SLOT = dict(name='', location='', length=-1, start=-1, end=-1)
PATH_TO_DATA_OBJECTS = '{}/json_objects/'.format(get_the_current_dir_path())
@@ -45,8 +47,7 @@ class Data(object):
self.has_omx = self._try_import_omx()
print('has_omx: {}'.format(self.has_omx))
self.DEV_MODE = read_json(SETTINGS_JSON)[6]["value"]
self.screen_size= read_json(SETTINGS_JSON)[0]['options'][0]
def create_new_slot_mapping_in_first_open(self, file_name):
@@ -87,10 +88,14 @@ class Data(object):
def switch_settings(self, setting_index):
######## update the value of selected setting by cycling through valid options ########
settings = read_json(SETTINGS_JSON)
this_setting_option = settings[setting_index]['options']
this_setting_option = this_setting_option[len(this_setting_option)-1:]+this_setting_option[0:1]
settings[setting_index]['options'] = this_setting_option
update_json(SETTINGS_JSON, settings)
for index, setting in enumerate(settings):
if index == setting_index:
self._cycle_setting_value(setting)
#for index, setting in enumerate(settings):
# if index == setting_index:
# self._cycle_setting_value(setting)
update_json(SETTINGS_JSON, settings)
@@ -104,6 +109,10 @@ class Data(object):
def get_settings_data():
return read_json(SETTINGS_JSON)
@staticmethod
def get_keypad_mapping_data():
return read_json(KEYPAD_MAPPING)
@staticmethod
def get_sampler_data():
return read_json(BANK_DATA_JSON)
@@ -117,18 +126,6 @@ class Data(object):
end_value = next_slot_details['end']
length = next_slot_details['length']
use_rand_start, use_sync_length, sync_length, playback_mode = self._get_context_options_from_settings()
if use_rand_start and use_sync_length:
start_value = randint(0, length - sync_length)
end_value = start_value + sync_length
elif use_rand_start and not use_sync_length:
start_value = randint(0, end_value)
elif not use_rand_start and use_sync_length:
end_value = min(length, start_value + sync_length)
self._set_next_slot_number_from_playback_mode(playback_mode, next_slot_number)
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)
@@ -168,74 +165,6 @@ class Data(object):
memory_bank[slot_number] = slot_info
update_json(BANK_DATA_JSON, memory_bank)
@staticmethod
def _cycle_setting_value(setting):
######## contains the valid setting values for each applicable option ########
if setting['name'] == 'PLAYBACK_MODE':
if setting['value'] == 'SAMPLER':
setting['value'] = 'PLAYLIST'
elif setting['value'] == 'PLAYLIST':
setting['value'] = 'RANDOM'
else:
setting['value'] = 'SAMPLER'
elif setting['name'] == 'SYNC_LENGTHS':
if setting['value'] == 'ON':
setting['value'] = 'OFF'
else:
setting['value'] = 'ON'
elif setting['name'] == 'RAND_START':
if setting['value'] == 'ON':
setting['value'] = 'OFF'
else:
setting['value'] = 'ON'
elif setting['name'] == 'VIDEO_OUTPUT':
if setting['value'] == 'HDMI':
setting['value'] = 'COMPOSITE'
else:
setting['value'] = 'HDMI'
elif setting['name'] == 'DEV_MODE':
if setting['value'] == 'ON':
setting['value'] = 'OFF'
else:
setting['value'] = 'ON'
return setting
@staticmethod
def _get_context_options_from_settings():
######## looks up the settings data object and returns states of relevant options ########
settings = read_json(SETTINGS_JSON)
use_sync_length = False
sync_length = 0
use_rand_start = False
playback_mode = ''
for index, setting in enumerate(settings):
if setting['name'] == 'SYNC_LENGTHS' and setting['value'] == 'ON':
use_sync_length = True
elif setting['name'] == 'SYNC_LENGTHS_TO':
sync_length = setting['value']
elif setting['name'] == 'RAND_START' and setting['value'] == 'ON':
use_rand_start = True
elif setting['name'] == 'PLAYBACK_MODE':
playback_mode = setting['value']
return use_rand_start, use_sync_length, sync_length, playback_mode
@staticmethod
def _set_next_slot_number_from_playback_mode(playback_mode, current_slot_number):
######## sets next slot number by using playback mode logic ########
next_slot_number = 0
if playback_mode == 'SAMPLER':
next_slot_number = current_slot_number
elif playback_mode == 'RANDOM':
#TODO: actually find which slots have value and only use those
next_slot_number = randint(0,14)
elif playback_mode == 'PLAYLIST':
#TODO: implement some playlist objects and logic at some point
next_slot_number = current_slot_number
update_json('next_slot_number.json',next_slot_number)
@staticmethod
def _try_import_omx():
try:

View File

@@ -1 +1 @@
[{"name": "mushroom-dreams.mp4", "location": "/media/pi/TIM1/videos_to_play/mushroom-dreams.mp4", "length": 1132.04, "end": -1, "start": -1}, {"location": "/media/pi/TIM1/samplerloop3s3.mp4", "start": -1, "length": 3.008, "end": -1, "name": "samplerloop3s3.mp4"}, {"name": "", "length": -1, "end": -1, "start": -1, "location": ""}, {"name": "", "length": -1, "end": -1, "start": -1, "location": ""}, {"name": "", "length": -1, "end": -1, "start": -1, "location": ""}, {"name": "", "length": -1, "end": -1, "start": -1, "location": ""}, {"name": "", "length": -1, "end": -1, "start": -1, "location": ""}, {"name": "", "length": -1, "end": -1, "start": -1, "location": ""}, {"name": "", "length": -1, "end": -1, "start": -1, "location": ""}, {"name": "", "length": -1, "end": -1, "start": -1, "location": ""}]
[{"start": 995.839218, "end": 1001.909353, "location": "/media/pi/TIM/videos_to_play/mushroom-dreams.mp4", "length": 1132.04, "name": "mushroom-dreams.mp4"}, {"start": -1, "name": "samplerloop3s3.mp4", "end": -1, "length": 3.008, "location": "/media/pi/TIM/samplerloop3s3.mp4"}, {"start": -1, "end": -1, "location": "", "length": -1, "name": ""}, {"start": -1, "end": -1, "location": "", "length": -1, "name": ""}, {"start": -1, "end": -1, "location": "", "length": -1, "name": ""}, {"start": -1, "end": -1, "location": "", "length": -1, "name": ""}, {"start": -1, "end": -1, "location": "", "length": -1, "name": ""}, {"start": -1, "end": -1, "location": "", "length": -1, "name": ""}, {"start": -1, "end": -1, "location": "", "length": -1, "name": ""}, {"start": -1, "end": -1, "location": "", "length": -1, "name": ""}]

View File

@@ -12,7 +12,7 @@
"c": {
"BROWSER": ["enter_on_browser_selection"],
"SAMPLER": ["toggle_pause_on_player"],
"SETTINGS": ["enter_on_setting_selection"]
"SETTINGS": ["enter_on_settings_selection"]
},
"d": {
"DEFAULT": ["trigger_next_player"]
@@ -31,33 +31,33 @@
"DEFAULT": ["toggle_function"]
},
"j": {
"DEFAULT": ["load_this_slot_into_next_player"]
"DEFAULT": ["load_slot_0_into_next_player"]
},
"k": {
"DEFAULT": ["load_this_slot_into_next_player"]
"DEFAULT": ["load_slot_1_into_next_player"]
},
"l": {
"DEFAULT": ["load_this_slot_into_next_player"]
"DEFAULT": ["load_slot_2_into_next_player"]
},
"m": {
"DEFAULT": ["load_this_slot_into_next_player"]
"DEFAULT": ["load_slot_3_into_next_player"]
},
"n": {
"DEFAULT": ["load_this_slot_into_next_player"]
"DEFAULT": ["load_slot_4_into_next_player"]
},
"o": {
"DEFAULT": ["load_this_slot_into_next_player"]
"DEFAULT": ["load_slot_5_into_next_player"]
},
"p": {
"DEFAULT": ["load_this_slot_into_next_player"]
"DEFAULT": ["load_slot_6_into_next_player"]
},
"q": {
"DEFAULT": ["load_this_slot_into_next_player"]
"DEFAULT": ["load_slot_7_into_next_player"]
},
"r": {
"DEFAULT": ["load_this_slot_into_next_player"]
"DEFAULT": ["load_slot_8_into_next_player"]
},
"s": {
"DEFAULT": ["load_this_slot_into_next_player"]
"DEFAULT": ["load_slot_9_into_next_player","quit_the_program"]
}
}

View File

@@ -1 +1 @@
[{"value": "PLAYLIST", "name": "PLAYBACK_MODE"}, {"value": "[1,1,1,4,1,2,1,4]", "name": "PLAYLIST"}, {"value": "OFF", "name": "SYNC_LENGTHS"}, {"value": "00:08", "name": "SYNC_LENGTHS_TO"}, {"value": "OFF", "name": "RAND_START"}, {"value": "COMPOSITE", "name": "VIDEO_OUTPUT"}, {"value": "ON", "name": "DEV_MODE"}]
[{"name": "SCREEN_SIZE", "options": ["dev_mode","XGA","composite"]}]

View File

@@ -115,7 +115,7 @@ class Display(object):
break
if index >= self.top_menu_index:
setting = settings_list[index]
self.display_text.insert(END, '{:>23} {:<22} \n'.format(setting['name'], setting['value'][0:20]))
self.display_text.insert(END, '{:>23} {:<22} \n'.format(setting['name'], setting['options'][0][0:20]))
line_count = line_count + 1
for index in range(self.MENU_HEIGHT - number_of_settings_items):

View File

@@ -3,7 +3,7 @@
# navigate to home, to recur, run python then back
#export DISPLAY=:0.0
#sleep 2
sleep 2
xmodmap ~/r_e_c_u_r/dotfiles/.remap
python3 ~/r_e_c_u_r/r_e_c_u_r.py

View File

@@ -31,7 +31,7 @@ display = Display(tk, video_driver, message_handler, data)
# setup the actions
actions = Actions(tk, message_handler, data, video_driver, display)
numpad_input = NumpadInput(message_handler, display, actions)
numpad_input = NumpadInput(message_handler, display, actions, data)
frame.pack()
tk.attributes("-fullscreen", True)

View File

@@ -1,146 +1,42 @@
import string
class NumpadInput(object):
def __init__(self, message_handler, display, actions):
def __init__(self, message_handler, display, actions, data):
self.message_handler = message_handler
self.display = display
self.actions = actions
self.key_mappings = data.get_keypad_mapping_data()
self.bind_actions()
def bind_actions(self):
self.display.display_text.bind("<Key>", self.on_key_press)
self.display.display_text.bind("<BackSpace>", self.on_backspace_press)
def on_key_press(self, event):
if event.char == '-':
self.on_minus_press()
elif event.char == '+':
self.on_plus_press()
elif event.char == '\r':
self.on_enter_press()
elif event.char == '*':
self.on_star_press()
elif event.char == '/':
self.on_slash_press()
elif event.char == '.':
self.on_dot_press()
elif event.char == '0':
self.on_0_press()
elif event.char == '1':
self.on_1_press()
elif event.char == '2':
self.on_2_press()
elif event.char == '3':
self.on_3_press()
elif event.char == '4':
self.on_4_press()
elif event.char == '5':
self.on_5_press()
elif event.char == '6':
self.on_6_press()
elif event.char == '7':
self.on_7_press()
elif event.char == '8':
self.on_8_press()
elif event.char == '9':
self.on_9_press()
if event.char is not '.':
self.display.refresh_display()
def on_backspace_press(self, event):
if self.display.display_mode == 'BROWSER':
self.actions.enter_on_browser_selection()
elif self.display.display_mode == 'SAMPLER':
self.actions.toggle_pause_on_player()
elif self.display.display_mode == 'SETTINGS':
self.actions.enter_on_settings_selection()
self.display.refresh_display()
def on_minus_press(self):
if self.display.display_mode == 'BROWSER':
self.actions.move_browser_selection_up()
elif self.display.display_mode == 'SAMPLER':
self.actions.seek_back_on_player()
elif self.display.display_mode == 'SETTINGS':
self.actions.move_settings_selection_up()
def on_plus_press(self):
if self.display.display_mode == 'BROWSER':
self.actions.move_browser_selection_down()
elif self.display.display_mode == 'SAMPLER':
self.actions.seek_forward_on_player()
elif self.display.display_mode == 'SETTINGS':
self.actions.move_settings_selection_down()
def on_enter_press(self):
self.actions.trigger_next_player()
def on_star_press(self):
self.actions.cycle_display_mode()
def on_slash_press(self):
self.actions.toggle_function()
def on_dot_press(self):
numpad = list(string.ascii_lowercase[0:19])
if event.char is '.':
self.actions.quit_the_program()
elif event.char in numpad:
print('the event key pressed is {}'.format(event.char))
print('the corrosponding mapping is {}'.format(self.key_mappings[event.char]))
this_mapping = self.key_mappings[event.char]
print('the current display mode is {}'.format(self.display.display_mode))
if self.display.display_mode in this_mapping:
mode = self.display.display_mode
elif 'DEFAULT' in this_mapping:
mode = 'DEFAULT'
print('the mode is set to {}'.format(mode))
def on_0_press(self):
if self.message_handler.function_on:
pass
if self.message_handler.function_on and len(this_mapping[mode]) > 1:
print('the action being called is {}'.format(this_mapping[mode][1]))
getattr(self.actions, this_mapping[mode][1])()
else:
self.actions.load_this_slot_into_next_player(0)
print('the action being called is {}'.format(this_mapping[mode][0]))
getattr(self.actions, this_mapping[mode][0])()
def on_1_press(self):
if self.message_handler.function_on:
self.actions.set_playing_sample_start_to_current_duration()
self.display.refresh_display()
else:
self.actions.load_this_slot_into_next_player(1)
print('{} is not in keypad map'.format(event.char))
def on_2_press(self):
if self.message_handler.function_on:
self.actions.clear_playing_sample_start_time()
else:
self.actions.load_this_slot_into_next_player(2)
def on_3_press(self):
if self.message_handler.function_on:
self.actions.clear_all_slots()
else:
self.actions.load_this_slot_into_next_player(3)
def on_4_press(self):
if self.message_handler.function_on:
self.actions.set_playing_sample_end_to_current_duration()
else:
self.actions.load_this_slot_into_next_player(4)
def on_5_press(self):
if self.message_handler.function_on:
self.actions.clear_playing_sample_end_time()
else:
self.actions.load_this_slot_into_next_player(5)
def on_6_press(self):
if self.message_handler.function_on:
pass
else:
self.actions.load_this_slot_into_next_player(6)
def on_7_press(self):
if self.message_handler.function_on:
pass
else:
self.actions.load_this_slot_into_next_player(7)
def on_8_press(self):
if self.message_handler.function_on:
pass
else:
self.actions.load_this_slot_into_next_player(8)
def on_9_press(self):
if self.message_handler.function_on:
pass
else:
self.actions.load_this_slot_into_next_player(9)

View File

@@ -6,7 +6,7 @@ class VideoDriver(object):
self.root = root
self.message_handler = message_handler
self.data = data
self.delay = 5
self.delay = 50
self.has_omx = self.data.has_omx
print(self.has_omx)
if self.has_omx:
@@ -32,6 +32,7 @@ class VideoDriver(object):
self.wait_for_first_load()
def wait_for_first_load(self):
if self.current_player.is_loaded():
self.play_video()
else:

View File

@@ -25,9 +25,11 @@ class video_player:
self.arguments = ['--no-osd', '--win', self.screen_size, '--alpha', '0']
def load(self):
try:
self.get_context_for_player()
self.status = 'LOADING'
print('the location is {}'.format(self.location))
self.omx_player = OMXPlayer(self.location, args=self.arguments, dbus_name=self.name)
self.omx_running = True
self.total_length = self.omx_player.duration() # <-- uneeded once self.duration stores float
@@ -40,6 +42,9 @@ class video_player:
if self.start > 0.5:
self.set_position(self.start - 0.5)
self.pause_at_start()
except:
self.message_handler.set_message('ERROR', 'first load error')
self.root.after(100, self.load)
def pause_at_start(self):
position = self.get_position()
@@ -117,10 +122,12 @@ class video_player:
pass
def set_screen_size(self):
if self.data.DEV_MODE == 'ON':
if self.data.screen_size == 'dev_mode':
return '50,350,550,750'
else:
elif self.data.screen_size == 'composite':
return '45,15,970,760'
elif self.data.screen_size == 'XGA':
return '0,0,1024,768'
class fake_video_player: