示例#1
0
class TonePoemApp(App):
    midi_in = ObjectProperty(None)
    setting_panel = ObjectProperty(None)
    use_kivy_settings = DEBUG

    def __init__(self, *args, **kw):
        self.profile = None
        self.config = None
        super(TonePoemApp, self).__init__(*args, **kw)

    def on_start(self):
        if DEBUG:
            self.profile = cProfile.Profile()
            self.profile.enable()

    def on_stop(self):
        if DEBUG:
            self.profile.disable()
            self.profile.dump_stats('tone_poem.profile')

    def get_application_config(self):
        return super(TonePoemApp, self).get_application_config(
            os.path.join(self.user_data_dir, CONFIG_INI))

    def build_config(self, config):
        config.setdefaults('MIDI', {
            'Input device': '',
        })
        config.add_callback(lambda section, key, value: self.midi_in.open_port(value),
                            section='MIDI', key='Input Device')

    def build_settings(self, settings):
        with open(os.path.join(ROOT_DIR, SETTINGS_JSON), 'r') as json_file:
            setting_base = json.load(json_file)

        # Dynamically fill in available MIDI ports.
        for setting in setting_base:
            if setting['title'] == 'Input Device':
                setting['options'] = list(self.midi_in.available_ports().values())

        settings.add_json_panel('Tone Poem', self.config, data=json.dumps(setting_base))

    def build(self):
        fluidsynth.init(os.path.join(ROOT_DIR, 'sounds', 'FluidR3_GM.sf2'))
        self.midi_in = MidiInputDispatcher()
        midi_device = self.config.get('MIDI', 'Input device')
        if midi_device:
            self.midi_in.open_port(midi_device)

        self.setting_panel = Settings()

        party = PlayerParty()
        sm = TonePoemGame(OrderedDict([
            ('area', AreaScreen(name='area')),
            ('encounter', EncounterScreen(name='encounter', party=party))
        ]), app=self)
        return sm
示例#2
0
    def build(self):
        fluidsynth.init(os.path.join(ROOT_DIR, 'sounds', 'FluidR3_GM.sf2'))
        self.midi_in = MidiInputDispatcher()
        midi_device = self.config.get('MIDI', 'Input device')
        if midi_device:
            self.midi_in.open_port(midi_device)

        self.setting_panel = Settings()

        party = PlayerParty()
        sm = TonePoemGame(OrderedDict([
            ('area', AreaScreen(name='area')),
            ('encounter', EncounterScreen(name='encounter', party=party))
        ]), app=self)
        return sm