Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
fix: distance was not the distance but a boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
Mouwrice committed Oct 17, 2023
1 parent 47e98c8 commit cb9f124
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
14 changes: 7 additions & 7 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
7 changes: 4 additions & 3 deletions src/marker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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])
3 changes: 2 additions & 1 deletion src/sound.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit cb9f124

Please sign in to comment.