added midi support and a arbitury map for testing

This commit is contained in:
langolierz
2018-04-18 23:32:32 +00:00
parent c913ed4e22
commit f824a37a2c
9 changed files with 155 additions and 5 deletions

View File

@@ -19,6 +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'
MIDI_MAPPING = 'midi_action_mapping.json'
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())
@@ -133,6 +134,10 @@ class Data(object):
def get_keypad_mapping_data():
return read_json(KEYPAD_MAPPING)
@staticmethod
def get_midi_mapping_data():
return read_json(MIDI_MAPPING)
@staticmethod
def get_sampler_data():
return read_json(BANK_DATA_JSON)

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,63 @@
{
"note_on 71": {
"NAV_BROWSER": ["move_browser_selection_up"],
"PLAYER": ["seek_back_on_player"],
"NAV_SETTINGS": ["move_settings_selection_up"]
},
"note_on 72": {
"NAV_BROWSER": ["move_browser_selection_down"],
"PLAYER": ["seek_forward_on_player"],
"NAV_SETTINGS": ["move_settings_selection_down"]
},
"note_on 73": {
"NAV_BROWSER": ["enter_on_browser_selection"],
"PLAYER": ["toggle_pause_on_player"],
"NAV_SETTINGS": ["enter_on_settings_selection"]
},
"note_on 74": {
"DEFAULT": ["trigger_next_player"]
},
"note_on 75": {
"DEFAULT": ["set_playing_sample_start_to_current_duration", "clear_playing_sample_start_time"]
},
"note_on 76": {
"DEFAULT": ["set_playing_sample_end_to_current_duration", "clear_playing_sample_end_time"]
},
"note_on 77": {},
"note_on 78": {
"DEFAULT": ["cycle_display_mode"]
},
"note_on 79": {
"DEFAULT": ["toggle_function"]
},
"note_on 80": {
"DEFAULT": ["load_slot_0_into_next_player","previous_bank"]
},
"note_on 81": {
"DEFAULT": ["load_slot_1_into_next_player","next_bank"]
},
"note_on 82": {
"DEFAULT": ["load_slot_2_into_next_player","clear_all_slots"]
},
"note_on 83": {
"DEFAULT": ["load_slot_3_into_next_player","decrease_speed"]
},
"note_on 84": {
"DEFAULT": ["load_slot_4_into_next_player","increase_speed"]
},
"note_on 85": {
"DEFAULT": ["load_slot_5_into_next_player","print_speed"]
},
"note_on 86": {
"DEFAULT": ["load_slot_6_into_next_player"]
},
"note_on 87": {
"DEFAULT": ["load_slot_7_into_next_player"]
},
"note_on 88": {
"DEFAULT": ["load_slot_8_into_next_player"]
},
"note_on 89": {
"DEFAULT": ["load_slot_9_into_next_player","quit_the_program"]
}
}

View File

@@ -1 +1 @@
"0-4"
"0-1"

View File

@@ -1 +1 @@
[{"name": "SCREEN_SIZE", "options": ["dev_mode", "auto"]}, {"name": "quit_the_program", "options": ["run_action"]}, {"name": "switch_display_to_hdmi", "options": ["run_action"]}, {"name": "switch_display_to_lcd", "options": ["run_action"]}, {"name": "set_composite_to_pal", "options": ["run_action"]}, {"name": "set_composite_to_ntsc", "options": ["run_action"]}]
[{"options": ["dev_mode", "auto"], "name": "SCREEN_SIZE"}, {"options": ["run_action"], "name": "quit_the_program"}, {"options": ["run_action"], "name": "switch_display_to_hdmi"}, {"options": ["run_action"], "name": "switch_display_to_lcd"}, {"options": ["run_action"], "name": "set_composite_to_pal"}, {"options": ["run_action"], "name": "set_composite_to_ntsc"}]

View File

@@ -7,6 +7,7 @@ from data_centre.data import Data
from display_centre.display import Display
from display_centre.messages import MessageHandler
from user_input.numpad_input import NumpadInput
from user_input.midi_input import MidiInput
from video_centre.video_driver import VideoDriver
import data_centre
@@ -23,7 +24,8 @@ message_handler = MessageHandler()
data = Data(message_handler)
# setup the video driver
video_driver = VideoDriver(frame, message_handler, data)
video_driver = VideoDriver(tk, message_handler, data)
#capture = Capture()
# setup the display
display = Display(tk, video_driver, message_handler, data)
@@ -32,6 +34,7 @@ display = Display(tk, video_driver, message_handler, data)
actions = Actions(tk, message_handler, data, video_driver, display)
numpad_input = NumpadInput(tk, message_handler, display, actions, data)
midi_input = MidiInput(tk, message_handler, display, actions, data)
frame.pack()
tk.attributes("-fullscreen", True)

72
user_input/midi_input.py Normal file
View File

@@ -0,0 +1,72 @@
import string
import datetime
import mido
class MidiInput(object):
def __init__(self, root, message_handler, display, actions, data):
self.root = root
self.message_handler = message_handler
self.display = display
self.actions = actions
self.midi_mappings = data.get_midi_mapping_data()
self.midi_device = None
self.midi_delay = 1
#self.midi_mappings = data.get_midi_mapping_data()
self.open_port()
def poll_midi_input(self):
for message in self.midi_device.iter_pending():
if not message.dict()['type'] == 'clock':
print(message)
try:
pass#print('{} {} {}'.format(message.dict()['type'],message.dict()['note'],message.dict()['velocity']))
except:
pass
self.on_midi_message(message)
self.root.after(self.midi_delay, self.poll_midi_input)
def open_port(self):
print('gonna try open this port!')
midi_ports = mido.get_input_names()
midi_device_on_port_20 = [s for s in midi_ports if '20:0' in s]
if midi_device_on_port_20:
self.midi_device = mido.open_input(midi_device_on_port_20[0])
self.message_handler.set_message('INFO', 'listening to midi device {}'.format(self.midi_device.name))
self.poll_midi_input()
def on_midi_message(self, message):
message_dict = message.dict()
if message_dict['type'] == 'note_on' and message_dict['velocity'] == 0:
print('!!!!!')
message_dict['type'] = 'note_off'
mapped_message_name = message_dict['type']
if 'note' in message_dict:
mapped_message_name = '{} {}'.format(mapped_message_name,message_dict['note'])
#print(mapped_message_name)
if mapped_message_name in self.midi_mappings.keys():
self.run_action_for_mapped_message(mapped_message_name)
else:
pass#print('{} is not in midi map'.format(mapped_message_name))
def run_action_for_mapped_message(self, message_name):
this_mapping = self.midi_mappings[message_name]
if self.display.control_mode in this_mapping:
mode = self.display.control_mode
elif 'DEFAULT' in this_mapping:
mode = 'DEFAULT'
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:
print('the action being called is {}'.format(this_mapping[mode][0]))
getattr(self.actions, this_mapping[mode][0])()
self.display.refresh_display()

7
video_centre/capture.py Normal file
View File

@@ -0,0 +1,7 @@
class Capture(object):
def __init__(self, root, message_handler, data):
self.root = root
self.message_handler = message_handler
self.data = data

View File

@@ -16,7 +16,7 @@ class VideoDriver(object):
self.last_player = video_player(self.root, self.message_handler, self.data, 'a.a')
self.current_player = video_player(self.root,self.message_handler, self.data, 'b.b')
self.next_player = video_player(self.root, self.message_handler, self.data, 'c.c')
self.print_status()
#self.print_status()
self.root.after(self.delay, self.begin_playing)
else:
self.last_player = fake_video_player()