diff --git a/src/main.py b/src/main.py index 059a5c9..bb8d62f 100644 --- a/src/main.py +++ b/src/main.py @@ -9,13 +9,13 @@ class Tracker: def __init__(self): - snare_drum = Sound("./DrumSamples/Snare/CKV1_Snare Loud.wav", (-100, 0, 600)) - hi_hat = Sound("./DrumSamples/HiHat/CKV1_HH Closed Loud.wav", (-220, -200, 800)) - kick_drum = Sound("./DrumSamples/Kick/CKV1_Kick Loud.wav", (-475, 200, 30)) - hi_hat_foot = Sound("./DrumSamples/HiHat/CKV1_HH Foot.wav", (-420, -350, 30)) - tom1 = Sound("./DrumSamples/Perc/Tom1.wav", (-320, 0, 800)) - tom2 = Sound("./DrumSamples/Perc/Tom2.wav", (-320, 100, 850)) - cymbal = Sound("./DrumSamples/cymbals/Hop_Crs.wav", (-50, 500, 925)) + snare_drum = Sound("Snare Drum", "./DrumSamples/Snare/CKV1_Snare Loud.wav", (-100, 0, 600)) + hi_hat = Sound("High Hat", "./DrumSamples/HiHat/CKV1_HH Closed Loud.wav", (-220, -200, 800)) + kick_drum = Sound("Kick Drum", "./DrumSamples/Kick/CKV1_Kick Loud.wav", (-475, 200, 30)) + hi_hat_foot = Sound("High Hat Foot", "./DrumSamples/HiHat/CKV1_HH Foot.wav", (-420, -350, 30)) + tom1 = Sound("Tom 1", "./DrumSamples/Perc/Tom1.wav", (-350, 0, 700)) + tom2 = Sound("Tom 2", "./DrumSamples/Perc/Tom2.wav", (-350, 100, 750)) + cymbal = Sound("Tom 3", "./DrumSamples/cymbals/Hop_Crs.wav", (-50, 500, 925)) self.markers: list[Marker] = [ Marker("WristOut_L", 14, [snare_drum, hi_hat, tom1, tom2, cymbal], downward_trend=-3, upward_trend=0.5), diff --git a/src/marker.py b/src/marker.py index 27a5959..34e3969 100644 --- a/src/marker.py +++ b/src/marker.py @@ -49,8 +49,6 @@ def update(self, position: tuple[float, float, float]): if self.is_hit(): self.time_until_next_hit = self.memory - print("Hit detected: {}".format(self)) - # print("Velocity: {} {}".format(self.velocities, mean(self.velocities[:-self.look_ahead]))) self.find_and_play_sound(self.positions[-self.look_ahead]) def get_velocity(self) -> float: @@ -84,13 +82,16 @@ def find_and_play_sound(self, position: tuple[float, float, float]): closest_sound = None closest_distance = float("inf") for sound in self.sounds: - if distance := sound.is_hit(position) is not None: + if (distance := sound.is_hit(position)) is not None: if distance < closest_distance: closest_sound = sound closest_distance = distance if closest_sound is not None: closest_sound.hit(position) + print("{}: {} with distance {}".format(self.label, closest_sound.name, closest_distance)) + else: + print("{}: No sound found for position {}".format(self.label, position)) def __str__(self): return "{}: \n{} {}".format(self.label, self.positions[-1], self.velocities[-1]) diff --git a/src/sound.py b/src/sound.py index f7d0fdd..f4b7b5c 100644 --- a/src/sound.py +++ b/src/sound.py @@ -9,7 +9,8 @@ class Sound: closest one to hit impact. """ - def __init__(self, path: str, position: tuple[float, float, float]): + def __init__(self, name: str, path: str, position: tuple[float, float, float]): + self.name = name self.sound = pygame.mixer.Sound(path) self.position = np.array(position)