Example #1
0
 def load(dir_name: Path) -> None:
     assert always_true(f"Loading drum {dir_name}")
     if len(DrumLoader.__sounds) == 0:
         DrumLoader.__load_sounds(dir_name)
     DrumLoader.__load_all_patterns(dir_name, "drum_level1", DrumLoader.__ptn_l1)
     DrumLoader.__load_all_patterns(dir_name, "drum_level2", DrumLoader.__ptn_l2)
     DrumLoader.__load_all_patterns(dir_name, "drum_break", DrumLoader.__ptn_bk)
Example #2
0
def load_all_dics() -> Dict[str, Dict[str, Dict]]:
    dic = dict()
    ff: FileFinder = FileFinder("etc/midi", True, ".json", "")
    for _ in range(ff.items_len):
        ff.iterate_dir(True)
        ff.now = ff.next
        file = ff.get_path_now()
        item = ff.get_item_now()[:-len(ff.get_end_with())]
        assert always_true(f"Loading midi config from {file}")
        loader = JsonDictLoader(file)
        default_dic = loader.get(ConfigName.default_config, dict())
        dic1 = dict()

        for key in [
                x for x in loader.get_keys()
                if x not in [ConfigName.default_config, ConfigName.comment]
        ]:
            value = loader.get(key, None)
            assert type(
                value) == dict, f"Must be dictionary key={key} in file {item}"
            assert len(
                value
            ) > 0, f"Dictionary must be non empty key={key} in file {item}"
            dic1[key] = dict(default_dic, **value)

        dic[item] = dic1

    return dic
Example #3
0
 def start(self) -> None:
     assert always_true("Started MidiController")
     while True:
         msg = self._in_port.receive()
         if msg is None:
             continue
         note = msg.bytes()[1]
         self._translator.translate_and_send(str(note))
Example #4
0
 def __process_command(self, cmd: list) -> None:
     method_name, *params = cmd
     assert always_true(f"Sending command: {cmd}")
     if method_name == ConfigName.change_map:
         MidiConfigLoader.change_map(params[0], params[1])
         update_method = MidiConfigLoader.get(ConfigName.update_method)
         description = MidiConfigLoader.get(ConfigName.description)
         self.__s_conn.send(
             [ConfigName.prepare_redraw, update_method, description])
     else:
         self.__s_conn.send(cmd)
Example #5
0
    def __init__(self):
        super().__init__()

        all_mixers_list = alsaaudio.mixers()
        self.__out = find_mixer(["Master", "PCM", "Speaker"], all_mixers_list)
        self.__out.setvolume(MainLoader.get("MIXER_OUT", 100))

        self.__in = find_mixer(["Mic"], all_mixers_list)
        self.__in.setvolume(MainLoader.get("MIXER_IN", 50))

        assert always_true("Found mixers:", alsaaudio.mixers(), str(self))
Example #6
0
    def _save_song(self) -> None:
        self._stop_song()
        length = self._get_drum_length()
        save_list = []
        for k in self.items:
            save_list.append(k if not k.is_empty else None)

        full_name = self._file_finder.get_path_now()
        assert always_true(f"Saving song file {full_name}")
        with open(full_name, 'wb') as f:
            pickle.dump((length, save_list), f)
Example #7
0
    def play_buffer(self):
        assert always_true(f"======Start {self}")

        # noinspection PyUnusedLocal
        def callback(in_data, out_data, frame_count, time_info, status):

            out_data[:] = 0
            assert len(out_data) == len(in_data) == frame_count
            self.play_samples(out_data, self._ctrl.idx)

            if self._ctrl.is_rec:
                self.record_samples(in_data, self._ctrl.idx)

            self._ctrl.idx += frame_count
            if self._ctrl.idx >= self._ctrl.get_stop_len():
                self._ctrl.stop_now()

        with sd.Stream(callback=callback):
            self._ctrl.get_stop_event().wait()

        if self.is_empty:
            self.trim_buffer(self._ctrl.idx, -1)

        assert always_true(f"======Stop {self}")
Example #8
0
    def _load_song(self) -> None:
        self._stop_song()
        self._file_finder.now = self._file_finder.next
        full_name = self._file_finder.get_path_now()
        assert always_true(f"Loading song file {full_name}")
        with open(full_name, 'rb') as f:
            length, load_list = pickle.load(f)

        self.items.clear()
        ctrl = self._get_control()
        for k in load_list:
            self.items.append(k if k is not None else SongPart(ctrl))

        for a in self.items:
            a._ctrl = ctrl
            for b in a.items:
                b._ctrl = ctrl

        self._set_drum_length(length)