def __init__(self,root,backend): self.root = root self.backend = backend self.configmidi = ConfigMidi(backend) self.configmidi.config_mode() self.midi_running = False self.last_loaded = 'n/a' self.mainframe = tk.Frame(self.root) self.configframe = tk.Frame(self.mainframe) self.deviceframe = tk.Frame(self.mainframe,padx=5) self.deviceselect = DeviceSelect(self) self.configbook = ttk.Notebook(self.configframe) self.configbook.bind_all('<<NotebookTabChanged>>',self.deviceselect.switch_test) self.inputtab = ttk.Frame(self.configbook) input_clip_control_frame = tk.Frame(self.inputtab) input_rec_control_frame = tk.Frame(self.inputtab) input_clip_select_frame = tk.Frame(self.inputtab) input_cue_select_frame = tk.Frame(self.inputtab) input_clip_control_frame.pack(side=tk.TOP) input_rec_control_frame.pack(side=tk.TOP) input_clip_select_frame.pack(side=tk.TOP) input_cue_select_frame.pack(side=tk.TOP) self.input_frames = [input_clip_control_frame, input_rec_control_frame, input_clip_select_frame, input_cue_select_frame] self.inputs = [] self.outputtab = ttk.Frame(self.configbook) self.outputs = [] self.setup_inputs() self.configbook.add(self.inputtab,text='input') self.configbook.add(self.outputtab,text='output') self.configbook.pack(expand=True,fill=tk.BOTH) self.configframe.pack(side=tk.LEFT,expand=True,fill=tk.BOTH) self.deviceframe.pack(side=tk.LEFT,anchor=tk.NE) self.mainframe.pack() self.root.protocol("WM_DELETE_WINDOW",self.stop)
class ConfigGui: """ configure midi controls """ def __init__(self,root,backend): self.root = root self.backend = backend self.configmidi = ConfigMidi(backend) self.configmidi.config_mode() self.midi_running = False self.last_loaded = 'n/a' self.mainframe = tk.Frame(self.root) self.configframe = tk.Frame(self.mainframe) self.deviceframe = tk.Frame(self.mainframe,padx=5) self.deviceselect = DeviceSelect(self) self.configbook = ttk.Notebook(self.configframe) self.configbook.bind_all('<<NotebookTabChanged>>',self.deviceselect.switch_test) self.inputtab = ttk.Frame(self.configbook) input_clip_control_frame = tk.Frame(self.inputtab) input_rec_control_frame = tk.Frame(self.inputtab) input_clip_select_frame = tk.Frame(self.inputtab) input_cue_select_frame = tk.Frame(self.inputtab) input_clip_control_frame.pack(side=tk.TOP) input_rec_control_frame.pack(side=tk.TOP) input_clip_select_frame.pack(side=tk.TOP) input_cue_select_frame.pack(side=tk.TOP) self.input_frames = [input_clip_control_frame, input_rec_control_frame, input_clip_select_frame, input_cue_select_frame] self.inputs = [] self.outputtab = ttk.Frame(self.configbook) self.outputs = [] self.setup_inputs() self.configbook.add(self.inputtab,text='input') self.configbook.add(self.outputtab,text='output') self.configbook.pack(expand=True,fill=tk.BOTH) self.configframe.pack(side=tk.LEFT,expand=True,fill=tk.BOTH) self.deviceframe.pack(side=tk.LEFT,anchor=tk.NE) self.mainframe.pack() self.root.protocol("WM_DELETE_WINDOW",self.stop) def start(self): try: self.configmidi.start() self.midi_running = True except Exception as e: print('midi failed to start',e) self.midi_running = False def stop(self): if self.midi_running: self.configmidi.stop() self.save() self.root.destroy() def setup_inputs(self): # various inputs clip_control_inps = ['clip_play', 'clip_pause', 'clip_reverse', 'clip_random', 'loop_i/o','loop_type','record_pb', 'record_rec', 'pb_speed', 'pb_speed_0', 'ct_speed', 'ct_speed_0'] #rec_control_inps = ['record_playback', 'record_record'] clip_select_inps = ['clip_{}'.format(i) for i in range(C.NO_Q)] + ['clip_clear','col_go_l', 'col_go_r'] cue_select_inps = ['cue_{}'.format(i) for i in range(C.NO_Q)] + ['lp_select', 'qp_delete'] all_inps = [clip_control_inps, clip_select_inps, cue_select_inps] for i,inp in enumerate(all_inps): for x,desc in enumerate(inp): new_inp_b = InputBox(self,self.input_frames[i],desc) r = x // 4 c = x % 4 new_inp_b.topframe.grid(row=r,column=c) self.inputs.append(new_inp_b) # for inp in [str(i) for i in range(8)]: #self.outputs.append(OutputBox(self,self.outputtab,inp)) def save(self): # inputs if self.deviceselect.selected_devices[0][0] == '-': return fname = "./savedata/{}.ini".format(self.deviceselect.selected_devices[0][0].strip()) Config = configparser.RawConfigParser() Config.optionxform = str cfgfile = open(fname,'w') if not Config.has_section('IO'): Config.add_section('IO') Config.set('IO','Input Name',self.deviceselect.selected_devices[0][0]) Config.set('IO','Input ID',self.deviceselect.selected_devices[0][1]) keyname = "Keys" typename = "Type" if not Config.has_section(keyname): Config.add_section(keyname) if not Config.has_section(typename): Config.add_section(typename) for inp in self.inputs: if inp.value.get() != '[-,-]': Config.set(keyname,inp.name,inp.value.get()) if inp.keytype.get() != '----': Config.set(typename,inp.name,inp.keytype.get()) # outputs if self.deviceselect.selected_devices[1][0] != '-': Config.set('IO','Output Name',self.deviceselect.selected_devices[1][0]) Config.set('IO','Output ID',self.deviceselect.selected_devices[1][1]) for outp in self.outputs: out_key = outp.nice_rep() if out_key != [-1,-1]: Config.set("Output Keys", outp.name, out_key) Config.write(cfgfile) cfgfile.close() # last_midi with open('./savedata/last_midi','w') as last_midi: last_midi.write(fname) def load(self,fname=None): if not fname: if self.deviceselect.selected_devices[0][0] == '-': return fname = "./savedata/{}.ini".format(self.deviceselect.selected_devices[0][0]) if os.path.exists(fname): self.last_loaded = os.path.splitext(fname)[0] Config = configparser.RawConfigParser() Config.optionxform = str Config.read(fname) for inp in self.inputs: o = inp.name try: key = Config.get('Keys',o) control_type = Config.get('Type',o) inp.value.set(key) inp.keytype.set(control_type) except: print(o,'failed to load') return int(Config.get('IO','Input ID')) return -1