def db(): initialize(':memory:')
def start(args): prctl.set_proctitle('mg-main') prctl.set_name('mg-main') if args.config: settings.load(args.config) if args.debug: settings.log_level = 'debug' configure_logging(settings) settings.create_dirs() from mg.fluidsynth.api import FluidSynth from mg.state import State from mg.controller import SynthController, SystemController, MIDIController state = State(settings) menu, input_manager, event_handler = start_ui(state, settings, args.debug) fluid = FluidSynth(settings.sound_dir) synth_ctrl = SynthController(fluid, state) synth_ctrl.start_listening() system_ctrl = SystemController(state, settings) system_ctrl.start_listening() system_ctrl.set_string_led(0, False) system_ctrl.set_string_led(1, False) system_ctrl.set_string_led(2, False) system_ctrl.update_udc_configuration() midi_ctrl = MIDIController(input_manager) midi_ctrl.start_listening() menu.message('Starting synthesizer') start_fluidsynth( fluid, dump_midi=args.dump_midi, debug=args.debug_fs) menu.message('Starting core') from mg.mglib import mgcore mgcore.start() mgcore.add_fluid_output(fluid.synth) mgcore.enable_fluid_output() menu.message('Opening database') from mg import db import logging log = logging.getLogger() db_path = os.path.join(settings.data_dir, 'mg.db') try: db.initialize(db_path) except Exception: log.exception('Unable to initialize database!') db.migrate(db_path) # restore key calibration from mg.input import calibration key_calib = calibration.load_keys() calibration.commit_keys(key_calib) # restore mapping ranges for name in mgcore.get_mapping_configs().keys(): ranges = db.load_mapping_ranges(name) if ranges: mgcore.set_mapping_ranges(name, ranges) # set default global settings state.main_volume = 120 state.reverb_volume = 25 state.preset.keynoise[0].volume = 25 state.coarse_tune = 0 state.fine_tune = 0 state.ui.brightness = 80 state.synth.gain = 50 state.pitchbend_range = 100 # restore misc config misc = db.load_misc_config() if misc: state.from_misc_dict(misc) try: preset = db.Preset.get() # noqa menu.message(f'Loading preset {preset.number}...') with state.lock(): state.load_preset(preset.id) except db.Preset.DoesNotExist: pass menu.message('Starting server') start_server(state, menu) menu.goto('home') input_manager.start() event_handler.mainloop()