Skip to content

Commit

Permalink
Metronome is on whenever BPM is set
Browse files Browse the repository at this point in the history
Fixes #212
  • Loading branch information
jeffkaufman committed Feb 6, 2021
1 parent f2ea1f3 commit 68e075f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
1 change: 1 addition & 0 deletions html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ <h1 id=instanceName>Bucket Brigade</h1>
<h4>Best to leave these alone, since they do affect everyone</h4>

Beats per Minute: <input type=text id=bpm></input>
(<i>Enables metronome, set to 0 to disable</i>)
<p>
Repeats (for rounds): <input type=text id=repeats></input>
<p>
Expand Down
21 changes: 6 additions & 15 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ def reset(self):

self.leader = None

self.metronome_on = False
self.backing_track: Any = np.zeros(0)
self.backing_track_index = 0

Expand Down Expand Up @@ -305,14 +304,11 @@ def cleanup_(self):

events: Dict[str, str] = {}

METRONOME = "metronome -- set BPM under Advanced Settings"

tracks = []
def populate_tracks() -> None:
for track in sorted(os.listdir(util.AUDIO_DIR)):
if track != "README":
tracks.append(track)
tracks.append(METRONOME)

populate_tracks()

Expand Down Expand Up @@ -461,10 +457,7 @@ def wrap_assign(queue, start, vals) -> None:
queue[0:second_section_size] = vals[first_section_size:]

def run_backing_track() -> None:
if state.requested_track == METRONOME:
state.metronome_on = True
backfill_metronome()
elif state.requested_track in tracks:
if state.requested_track in tracks:
with wave.open(os.path.join(util.AUDIO_DIR, state.requested_track)) as inf:
if inf.getnchannels() != 1:
raise Exception(
Expand Down Expand Up @@ -718,7 +711,7 @@ def fix_volume(data, backing_data, n_people, user_backing_volume=1.0):
data *= ((1 + N_PHANTOM_PEOPLE) / (n_people + N_PHANTOM_PEOPLE)) ** 0.5
data += (
backing_data *
(state.backing_volume * (1 if state.metronome_on else 0.2)) *
(state.backing_volume * (1 if state.bpm > 0 else 0.2)) *
user_backing_volume
)
data *= state.global_volume
Expand Down Expand Up @@ -828,10 +821,9 @@ def handle_special(query_params, server_clock, user=None, client_read_clock=None
state.song_start_clock = server_clock
state.song_end_clock = 0

state.metronome_on = False
if state.bpm and state.bpr and state.repeats:
state.requested_track = METRONOME
if state.requested_track:
if state.bpm > 0:
backfill_metronome()
elif state.requested_track:
run_backing_track()
# These must be separate from song_start/end_clock, because they
# are used for video sync and must be EXACTLY at the moment the
Expand All @@ -843,7 +835,6 @@ def handle_special(query_params, server_clock, user=None, client_read_clock=None
if query_params.get("mark_stop_singing", None):
# stop the backing track from playing, if it's still going
state.backing_track_index = len(state.backing_track)
state.metronome_on = False

if user is not None:
if user.userid == state.leader:
Expand Down Expand Up @@ -993,7 +984,7 @@ def handle_post(in_json, in_data) -> Tuple[Any, str]:
state.leader = None

if clear_samples > 0:
if state.metronome_on:
if state.bpm > 0:
write_metronome(clear_index, clear_samples)
else:
wrap_assign(
Expand Down

0 comments on commit 68e075f

Please sign in to comment.