Skip to content

Commit

Permalink
Added SOUND_STOP (#58)
Browse files Browse the repository at this point in the history
* Added SOUND_STOP

* Updated README with SOUND_STOP command

* missed comma added

* added newline
  • Loading branch information
ErikSkinnari authored Aug 21, 2020
1 parent f9d2915 commit 28bfa6a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ Commands follow the format: `COMMAND arg1 arg2 ...`. Scripts are just a text fil
* Supports `.wav`, `.flac`, and `.ogg` only.
* If (argument 2) supplied, set volume to (argument 2).
* Range is 0 to 100
* `SOUND_STOP`
* Stops all sounds currently playing.
* If (argument 1) supplied, fading for (argument 1) milliseconds and then stops the sounds.
* `WAIT_UNPRESSED`
* Waits until the button the script is bound to is unpressed. (no arguments)
* `WEB`
Expand Down
13 changes: 11 additions & 2 deletions scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import files

VALID_COMMANDS = ["@ASYNC", "@SIMPLE", "@LOAD_LAYOUT", "STRING", "DELAY", "TAP", "PRESS", "RELEASE", "WEB", "WEB_NEW", "CODE", "SOUND", "WAIT_UNPRESSED", "M_MOVE", "M_SET", "M_SCROLL", "M_LINE", "M_LINE_MOVE", "M_LINE_SET", "LABEL", "IF_PRESSED_GOTO_LABEL", "IF_UNPRESSED_GOTO_LABEL", "GOTO_LABEL", "REPEAT_LABEL", "IF_PRESSED_REPEAT_LABEL", "IF_UNPRESSED_REPEAT_LABEL", "M_STORE", "M_RECALL", "M_RECALL_LINE", "OPEN", "RELEASE_ALL", "RESET_REPEATS"]
VALID_COMMANDS = ["@ASYNC", "@SIMPLE", "@LOAD_LAYOUT", "STRING", "DELAY", "TAP", "PRESS", "RELEASE", "WEB", "WEB_NEW", "CODE", "SOUND", "SOUND_STOP", "WAIT_UNPRESSED", "M_MOVE", "M_SET", "M_SCROLL", "M_LINE", "M_LINE_MOVE", "M_LINE_SET", "LABEL", "IF_PRESSED_GOTO_LABEL", "IF_UNPRESSED_GOTO_LABEL", "GOTO_LABEL", "REPEAT_LABEL", "IF_PRESSED_REPEAT_LABEL", "IF_UNPRESSED_REPEAT_LABEL", "M_STORE", "M_RECALL", "M_RECALL_LINE", "OPEN", "RELEASE_ALL", "RESET_REPEATS"]
ASYNC_HEADERS = ["@ASYNC", "@SIMPLE"]

threads = [[None for y in range(9)] for x in range(9)]
Expand Down Expand Up @@ -231,6 +231,15 @@ def main_logic(idx):
else:
print("[scripts] " + coords + " Play sound file " + split_line[1])
sound.play(split_line[1])
elif split_line[0] == "SOUND_STOP":
if len(split_line) > 1:
delay = split_line[1]
print("[scripts] " + coords +
" Stopping sounds with " + delay + " milliseconds fadeout time")
sound.fadeout(int(delay))
else:
print("[scripts] " + coords + " Stopping sounds")
sound.stop()
elif split_line[0] == "WAIT_UNPRESSED":
print("[scripts] " + coords + " Wait for script key to be unpressed")
while lp_events.pressed[x][y]:
Expand Down Expand Up @@ -651,7 +660,7 @@ def validate_script(script_str):
if split_line[0] in ["WAIT_UNPRESSED", "RELEASE_ALL", "RESET_REPEATS"]:
if len(split_line) > 1:
return ("Too many arguments for command '" + split_line[0] + "'.", line)
if split_line[0] in ["DELAY", "WEB", "WEB_NEW", "PRESS", "RELEASE"]:
if split_line[0] in ["DELAY", "WEB", "WEB_NEW", "PRESS", "RELEASE", "SOUND_STOP"]:
if len(split_line) > 2:
return ("Too many arguments for command '" + split_line[0] + "'.", line)
if split_line[0] in ["SOUND", "M_MOVE", "M_SCROLL", "M_SET"]:
Expand Down
15 changes: 15 additions & 0 deletions sound.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,18 @@ def play(filename, volume=100.0):
sound.play()
except:
print("[sound] Could not play sound " + final_name)


def stop():
try:
m.stop()
except:
print("Could not stop sounds")


def fadeout(delay):
try:
m.fadeout(delay)
except:
print("Could not fade out sound")

0 comments on commit 28bfa6a

Please sign in to comment.