Skip to content

Commit

Permalink
new feature + pedal support
Browse files Browse the repository at this point in the history
  • Loading branch information
onlaj committed Apr 23, 2019
1 parent c6e0b10 commit 017c285
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 19 deletions.
8 changes: 7 additions & 1 deletion menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
<Fading text="Slow"></Fading>
<Fading text="Very slow"></Fading>
</Light_mode>
<Light_mode text="Velocity">
<Velocity text="Fast"></Velocity>
<Velocity text="Medium"></Velocity>
<Velocity text="Slow"></Velocity>
<Velocity text="Very slow"></Velocity>
</Light_mode>
</LED_Strip_Settings>
</menu>
<menu text="Play MIDI">
Expand Down Expand Up @@ -96,4 +102,4 @@
<Other_Settings text="System Info">
</Other_Settings>
</menu>
</data>
</data>
70 changes: 52 additions & 18 deletions visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,14 +386,25 @@ def change_settings(self, choice, location):

if(location == "Fading"):
ledsettings.mode = "Fading"
if(choice == "Fast"):
ledsettings.fadingspeed = 125
elif(choice == "Medium"):
ledsettings.fadingspeed = 100
elif(choice == "Slow"):
ledsettings.fadingspeed = 50
elif(choice == "Very slow"):
ledsettings.fadingspeed = 10

if(location == "Velocity"):
ledsettings.mode = "Velocity"
if(choice == "Fast"):
ledsettings.fadingspeed = 5
elif(choice == "Medium"):
ledsettings.fadingspeed = 3
ledsettings.fadingspeed = 4
elif(choice == "Slow"):
ledsettings.fadingspeed = 3
elif(choice == "Very slow"):
ledsettings.fadingspeed = 2
elif(choice == "Vey slow"):
ledsettings.fadingspeed = 1

if(location == "Light_mode"):
ledsettings.mode = "Normal"
Expand Down Expand Up @@ -632,12 +643,16 @@ def change_port(self, port, portname):
ledsettings = LedSettings()

keylist = [0] * 176
keylist_status = [0] * 176

z = 0
display_cycle = 0
colorWipe(ledstrip.strip, Color(0,0,0), 1)

last_activity = time.time()

last_control_change = 0
pedal_deadzone = 10
while True:
#screensaver
if((time.time() - last_activity) > 600):
Expand Down Expand Up @@ -685,18 +700,25 @@ def change_port(self, port, portname):

red = ledsettings.get_color("Red")
green = ledsettings.get_color("Green")
blue = ledsettings.get_color("Blue")

if(ledsettings.mode == "Fading"):
blue = ledsettings.get_color("Blue")
if(ledsettings.mode == "Fading" or ledsettings.mode == "Velocity"):
n = 0
for note in keylist:
if(int(note) != 101):
for note in keylist:
if(int(note) != 1001):
if(int(note) >= 0):
fading = note / float(100)
fading = (note / float(100)) / 10
ledstrip.strip.setPixelColor((n), Color(int(int(green) * fading), int(int(red) * fading), int(int(blue) * fading)))
if(int(note) == 0):
ledstrip.strip.setPixelColor((0), Color(0, 0, 0))
keylist[n] = keylist[n] - ledsettings.fadingspeed
keylist[n] = keylist[n] - ledsettings.fadingspeed
else:
keylist[n] = 0
if(ledsettings.mode == "Velocity"):
if(int(last_control_change) < pedal_deadzone):
if(int(keylist_status[n]) == 0):
ledstrip.strip.setPixelColor((n), Color(0, 0, 0))
keylist[n] = 0
n += 1
ledstrip.strip.show()

Expand All @@ -707,36 +729,48 @@ def change_port(self, port, portname):
note = find_between(str(msg), "note=", " ")
original_note = note
note = int(note)
velocity = find_between(str(msg), "velocity=", " ")

velocity = find_between(str(msg), "velocity=", " ")
control_change = find_between(str(msg), "value=", " ")
if(control_change != False):
last_control_change = control_change

#changing offset to adjust the distance between the LEDs to the key spacing
if(note > 92):
note_offset = 2
elif(note > 55):
note_offset = 1
else:
note_offset = 0

if(int(velocity) == 0 and int(note) > 0):
keylist_status[(note - 20)*2 - note_offset] = 0
if(ledsettings.mode == "Fading"):
keylist[(note - 20)*2 - note_offset] = 100
keylist[(note - 20)*2 - note_offset] = 1000
elif(ledsettings.mode == "Velocity"):
if(int(last_control_change) < pedal_deadzone):
keylist[(note - 20)*2 - note_offset] = 0
else:
ledstrip.strip.setPixelColor(((note - 20)*2 - note_offset), Color(0, 0, 0))
elapsed_time = time.time() - saving.start_time
if(saving.isrecording == True):
saving.add_track("note_off", original_note, velocity, elapsed_time*1000)
saving.restart_time()
elif(int(velocity) > 0 and int(note) > 0):
brightness = (100 / (float(velocity) / 127 ) )/ 100
brightness = int(brightness)
keylist_status[(note - 20)*2 - note_offset] = 1
if(ledsettings.mode == "Velocity"):
brightness = (100 / (float(velocity) / 127 ) )/ 100
brightness = brightness
else:
brightness = 1
if(ledsettings.mode == "Fading"):
keylist[(note - 20)*2 - note_offset] = 101
keylist[(note - 20)*2 - note_offset] = 1001
if(ledsettings.mode == "Velocity"):
keylist[(note - 20)*2 - note_offset] = 1000/float(brightness)
if(find_between(str(msg), "channel=", " ") == "12"):
ledstrip.strip.setPixelColor(((note - 20)*2 - note_offset), Color(255, 0, 0))
elif(find_between(str(msg), "channel=", " ") == "11"):
ledstrip.strip.setPixelColor(((note - 20)*2 - note_offset), Color(0, 0, 255))
else:
ledstrip.strip.setPixelColor(((note - 20)*2 - note_offset), Color(int(green), int(red), int(blue)))
ledstrip.strip.setPixelColor(((note - 20)*2 - note_offset), Color(int(int(green)/float(brightness)), int(int(red)/float(brightness)), int(int(blue)/float(brightness))))
elapsed_time = time.time() - saving.start_time
if(saving.isrecording == True):
saving.add_track("note_on", original_note, velocity, elapsed_time*1000)
Expand Down

0 comments on commit 017c285

Please sign in to comment.