Esempio n. 1
0
class BackingTrackPlayerApp(App):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.mc = MidiControl()

    def build(self):
        self.title = 'Backing Track Player V1.0'
        self.use_kivy_settings = False
        Window.bind(on_dropfile=self._dropfile_action)
        return Builder.load_string(kv)

    def _dropfile_action(self, window, path):
        self.root.set_backing_track(path.decode())

    def on_start(self):
        names = self.mc.get_midi_ports()
        self.root.ids.midi_devices.values = names
        m_input = self.config.getdefault('MIDI', 'input', 'None')
        ch = self.config.get('MIDI', 'channel')
        song = self.config.get('Track', 'song')
        if m_input in names:
            self.root.set_backing_track(
                song
            )  # before set midi ports - so errors can show in track area
            self.mc.set_midi_port(m_input)
            self.mc.midi_channel = int(ch)
            self.root.ids.midi_devices.text = m_input
            self.root.ids.midi_ch.text = str(int(ch) + 1)
        Clock.schedule_interval(self.mc.read_midi_callback, .1)

    def open_settings(self, *largs):  # kivy control panel will not open
        pass

    def build_config(self, config):
        config.setdefaults('MIDI', {'input': 'None', 'channel': 'None'})
        config.setdefaults('Track', {'song': 'None'})

    def get_application_config(self, defaultpath='%(appdir)s/%(appname)s.ini'):
        if platform == 'macosx':  # mac will not write into app folder
            s = '~/.%(appname)s.ini'
        else:
            s = defaultpath
        return super().get_application_config(defaultpath=s)

    def on_stop(self):
        if self.mc.midi_in_port and self.mc.midi_channel is not None and self.root.track_path:
            self.config.set('MIDI', 'input', self.mc.midi_in_port.name)
            self.config.set('MIDI', 'channel', self.mc.midi_channel)
            self.config.set('Track', 'song', self.root.track_path)
            self.config.write()
Esempio n. 2
0
class BackingTrackPlayerApp(App):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.mc = MidiControl()

    def build(self):
        self.title = 'Backing Track Player V1.01'
        self.use_kivy_settings = False
        Window.minimum_width = window_width
        Window.minimum_height = window_height
        # Window.size = 800, 375
        Window.bind(on_dropfile=self._dropfile_action)
        Window.bind(on_request_close=self.window_request_close)
        return Builder.load_string(kv)

    def _dropfile_action(self, _, path):
        self.root.ids.sm.get_screen('play_screen').set_backing_track(
            path.decode())

    def on_start(self):
        names = self.mc.get_midi_ports()
        self.root.ids.midi_devices.values = names
        m_input = self.config.getdefault('MIDI', 'input', 'None')
        ch = self.config.get('MIDI', 'channel')
        song = self.config.get('Track', 'song')
        if not Path(song).exists(
        ):  # if track that was in config file was no longer exists...
            song = 'None'
        self.root.ids.sm.get_screen('play_screen').set_backing_track(song)
        # before set midi ports - so errors can show in track area
        if m_input in names:
            self.mc.set_midi_port(m_input)
            self.mc.midi_channel = int(ch)
            self.root.ids.midi_devices.text = m_input
            self.root.ids.midi_ch.text = str(int(ch) + 1)
        Clock.schedule_interval(self.mc.read_midi_callback, .1)

    def open_settings(self, *largs):  # kivy control panel will not open
        pass

    def build_config(self, config):
        config.setdefaults('MIDI', {'input': 'None', 'channel': 'None'})
        config.setdefaults('Track', {'song': 'None'})
        config.setdefaults(
            'Window', {
                'width': window_width,
                'height': window_height,
                'top': window_top,
                'left': window_left
            })

    def get_application_config(self, defaultpath='%(appdir)s/%(appname)s.ini'):
        if platform == 'win' or platform == 'macosx':  # mac will not write into app folder
            s = self.user_data_dir + '/%(appname)s.ini'  # puts ini in AppData on Windows
        else:
            s = defaultpath
        return super().get_application_config(defaultpath=s)

    def window_request_close(self, _):
        # Window.size is automatically adjusted for density, must divide by density when saving size
        config = self.config
        config.set('Window', 'width', int(Window.size[0] / Metrics.density))
        config.set('Window', 'height', int(Window.size[1] / Metrics.density))
        config.set('Window', 'top', Window.top)
        config.set('Window', 'left', Window.left)
        self.config.write()
        return False

    def on_stop(self):
        p = self.root.ids.sm.get_screen('play_screen').track_path
        if p:
            self.config.set('Track', 'song', p)
            self.config.write()
        if self.mc.midi_in_port and self.mc.midi_channel is not None:
            self.config.set('MIDI', 'input', self.mc.midi_in_port.name)
            self.config.set('MIDI', 'channel', self.mc.midi_channel)
            self.config.write()