Beispiel #1
0
 def change_volume(change_by: int) -> None:
     factor = 1.41 if change_by >= 0 else (1 / 1.41)
     v = MainLoader.get(ConfigName.drum_volume, 1) * factor
     if v * DrumLoader.max_volume >= SD_MAX:
         return
     if v * DrumLoader.max_volume < 0.01 * SD_MAX:
         return
     MainLoader.set(ConfigName.drum_volume, v)
     MainLoader.save()
     DrumLoader.prepare_all(DrumLoader.length)
Beispiel #2
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))
Beispiel #3
0
    def change_swing(change_by: int) -> None:
        v = MainLoader.get(ConfigName.drum_swing, 0.625)
        v += (0.25 / 4) if change_by >= 0 else (-0.25 / 4)
        if v > 0.80:
            v = 0.50
        elif v < 0.45:
            v = 0.75

        MainLoader.set(ConfigName.drum_swing, v)
        MainLoader.save()
        DrumLoader.prepare_all(DrumLoader.length)
Beispiel #4
0
    def load_drum_type(self) -> None:
        if self.__file_finder.now == self.__file_finder.next:
            return
        self.__file_finder.now = self.__file_finder.next
        tmp = self.__file_finder.get_path_now()

        DrumLoader.load(tmp)
        MainLoader.set(ConfigName.drum_type, self.__file_finder.get_item_now())
        MainLoader.save()

        if not self.is_empty:
            self.prepare_drum(self.length)
Beispiel #5
0
 def __pos_with_swing(step_number, step_len) -> int:
     """shift every even 16th note to make it swing like"""
     if step_number % 2 == 0:
         return round(step_number * step_len)
     else:
         swing_delta = step_len * (MainLoader.get(ConfigName.drum_swing, 0.625) - 0.5)
         return round(step_number * step_len + swing_delta)
Beispiel #6
0
    def __prepare_one(pattern, length: int) -> np.ndarray:
        accents = pattern["accents"]
        ndarr = make_zero_buffer(length)
        drum_volume = MainLoader.get(ConfigName.drum_volume, 1)
        for sound_name in [x for x in DrumLoader.__sounds if x in pattern]:
            notes = pattern[sound_name]
            steps = len(notes)
            if notes.count("!") + notes.count(".") != steps:
                logging.error(f"sound {sound_name} notes {notes} must contain only '.' and '!'")

            step_len = length / steps
            sound, sound_volume = DrumLoader.__sounds[sound_name]
            sound = sound[:length]
            assert sound.ndim == 2 and sound.shape[1] == 2
            assert 0 < sound.shape[0] <= length, f"Must be: 0 < {sound.shape[0]} <= {length}"

            for step_number in range(steps):
                if notes[step_number] != '.':
                    step_accent = int(accents[step_number])
                    step_volume = sound_volume * step_accent * drum_volume / 9.0
                    pos = DrumLoader.__pos_with_swing(step_number, step_len)
                    tmp = (sound * step_volume).astype(SD_TYPE)
                    record_sound_buff(ndarr, tmp, pos)

        return ndarr
Beispiel #7
0
    def __init__(self, s_conn: Connection, in_port):
        super().__init__(s_conn, in_port)
        self.__mapped_notes: Dict[str, int] = MainLoader.get(
            ConfigName.mapped_notes, dict())

        self.__on_count: int = 0
        self.__off_count: int = 0
        self.__past_count_note: int = 0  # mapped for count
        self.__past_note: int = -1  # original MIDI note
        self.__midi_cc_to_note = MidiCcToNote()
Beispiel #8
0
    def __init__(self):
        self.__change_after_samples: int = MAX_32_INT
        self.__sample_counter: int = 0
        self.__i: Intensity = Intensity.SILENT

        self.__file_finder = FileFinder(
            "etc/drums", False, "", MainLoader.get(ConfigName.drum_type,
                                                   "pop"))
        tmp = self.__file_finder.get_path_now()
        DrumLoader.load(tmp)
Beispiel #9
0
 def setvolume(self, vol: int, out: bool):
     if vol > 100 or vol < 0:
         return
     if out:
         self.__vol_out = vol
         MainLoader.set("MIXER_OUT", vol)
     else:
         self.__vol_in = vol
         MainLoader.set("MIXER_IN", vol)
     MainLoader.save()
Beispiel #10
0
class OneLoopCtrl:
    """class with events to control one loop, has playback index"""

    max_late_samples = MainLoader.get(ConfigName.max_late_seconds,
                                      0.1) * SD_RATE

    def __init__(self):
        self._is_rec: bool = False
        self.__drum = RealDrum()
        self.idx: int = 0
        self.__stop_len: int = MAX_32_INT
        self.__stop_event: Event = Event()

    @property
    def is_rec(self) -> bool:
        return self._is_rec

    @property
    def drum(self) -> RealDrum:
        return self.__drum

    def is_stop_len_set(self) -> bool:
        return self.__stop_len < MAX_32_INT

    def get_stop_len(self) -> int:
        return self.__stop_len

    def get_stop_event(self) -> Event:
        return self.__stop_event

    def stop_now(self) -> None:
        self.__stop_event.set()

    def _stop_never(self) -> None:
        self.__stop_len = MAX_32_INT

    def _stop_at_bound(self, bound_value: int) -> None:
        over = self.idx % bound_value
        if over < OneLoopCtrl.max_late_samples:
            self.__stop_event.set()
        else:
            self.__stop_len = self.idx - over + bound_value

    def __str__(self):
        stop = f"stop_len {self.__stop_len}" if self.is_stop_len_set(
        ) else "stop_len=None"
        return f"{self.__class__.__name__} {stop} {self.drum}"
Beispiel #11
0
 def setvolume(self, vol: int, out: bool):
     if vol > 100 or vol < 0:
         return
     if out:
         self.__out.setvolume(vol)
         MainLoader.set("MIXER_OUT", vol)
     else:
         self.__in.setvolume(vol, alsaaudio.MIXER_CHANNEL_ALL,
                             alsaaudio.PCM_CAPTURE)
         MainLoader.set("MIXER_IN", vol)
     MainLoader.save()
Beispiel #12
0
 def test_1(self):
     val = MainLoader.get(ConfigName.drum_swing, -1)
     self.assertTrue(val > 0)
Beispiel #13
0
 def swing(self) -> float:
     return MainLoader.get(ConfigName.drum_swing, 0.75)
Beispiel #14
0
 def volume(self) -> float:
     return MainLoader.get(ConfigName.drum_volume,
                           1) * DrumLoader.max_volume / SD_MAX
Beispiel #15
0
 def __init__(self):
     self.__vol_in: int = MainLoader.get("MIXER_IN", 30)
     self.__vol_out: int = MainLoader.get("MIXER_OUT", 100)