Skip to content

Commit

Permalink
Pass midi timestamp to color_mode
Browse files Browse the repository at this point in the history
  • Loading branch information
stephen322 committed Oct 15, 2023
1 parent 8f7382f commit ab4bd6e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions lib/color_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def LoadSettings(self, ledsettings):
"""Called whenever settings change"""
pass

def NoteOn(self, midi_event, midi_state, note_position):
def NoteOn(self, midi_event, midi_time, midi_state, note_position):
"""Primary high-level function for ColorMode
Called on midi note-on
Expand Down Expand Up @@ -74,7 +74,7 @@ def LoadSettings(self, ledsettings):
self.green = ledsettings.get_color("Green")
self.blue = ledsettings.get_color("Blue")

def NoteOn(self, midi_event: mido.Message, midi_state, note_position):
def NoteOn(self, midi_event: mido.Message, midi_time, midi_state, note_position):
return (self.red, self.green, self.blue)


Expand All @@ -85,7 +85,7 @@ def LoadSettings(self, ledsettings):
self.multicolor_index = 0
self.multicolor_iteration = ledsettings.multicolor_iteration

def NoteOn(self, midi_event: mido.Message, midi_state, note_position):
def NoteOn(self, midi_event: mido.Message, midi_time, midi_state, note_position):
chosen_color = self.get_random_multicolor_in_range(midi_event.note)
return chosen_color

Expand Down Expand Up @@ -141,7 +141,7 @@ def LoadSettings(self, ledsettings):
self.timeshift = int(ledsettings.rainbow_timeshift)
self.timeshift_start = time.time()

def NoteOn(self, midi_event: mido.Message, midi_state, note_position):
def NoteOn(self, midi_event: mido.Message, midi_time, midi_state, note_position):
shift = (time.time() - self.timeshift_start) * self.timeshift
return self.calculate_rainbow_colors(note_position, shift)

Expand All @@ -165,7 +165,7 @@ def LoadSettings(self, ledsettings):
self.speed_period_in_seconds = ledsettings.speed_period_in_seconds
self.speed_max_notes = ledsettings.speed_max_notes

def NoteOn(self, midi_event: mido.Message, midi_state, note_position):
def NoteOn(self, midi_event: mido.Message, midi_time, midi_state, note_position):
current_time = time.time()
self.notes_in_last_period.append(current_time)
return self.speed_get_colors()
Expand Down Expand Up @@ -204,7 +204,7 @@ def LoadSettings(self, ledsettings):
"green": int(ledsettings.usersettings.get_setting_value("gradient_end_green")),
"blue": int(ledsettings.usersettings.get_setting_value("gradient_end_blue"))}

def NoteOn(self, midi_event: mido.Message, midi_state, note_position):
def NoteOn(self, midi_event: mido.Message, midi_time, midi_state, note_position):
return self.gradient_get_colors(note_position)

def gradient_get_colors(self, position):
Expand All @@ -224,7 +224,7 @@ def LoadSettings(self, ledsettings):
self.key_in_scale = ledsettings.key_in_scale
self.key_not_in_scale = ledsettings.key_not_in_scale

def NoteOn(self, midi_event: mido.Message, midi_state, note_position):
def NoteOn(self, midi_event: mido.Message, midi_time, midi_state, note_position):
scale_colors = get_scale_color(self.scale_key, midi_event.note, self.key_in_scale, self.key_not_in_scale)
return scale_colors

Expand All @@ -235,7 +235,7 @@ def LoadSettings(self, ledsettings):
self.scale = int(ledsettings.velocityrainbow_scale)
self.curve = int(ledsettings.velocityrainbow_curve)

def NoteOn(self, midi_event: mido.Message, midi_state, note_position=None):
def NoteOn(self, midi_event: mido.Message, midi_time, midi_state, note_position):
x = int(((255 * powercurve(midi_event.velocity / 127, self.curve / 100)
* (self.scale / 100) % 256) + self.offset) % 256)
x2 = colorsys.hsv_to_rgb(x / 255, 1, (midi_event.velocity / 127) * 0.3 + 0.7)
Expand Down
2 changes: 1 addition & 1 deletion visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ def start_webserver():
if note_position >= ledstrip.led_number or note_position < 0:
continue

color = color_mode.NoteOn(msg, None, note_position)
color = color_mode.NoteOn(msg, msg_timestamp, None, note_position)
if color is not None:
red, green, blue = color
else:
Expand Down

0 comments on commit ab4bd6e

Please sign in to comment.