play music with beep
This commit is contained in:
parent
93ae03e5a2
commit
1b85648bab
36
terminis/music.sh
Executable file
36
terminis/music.sh
Executable file
@ -0,0 +1,36 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
C0=-f16; Db0=-f17; D0=-f18; Eb0=-f19; E0=-f20; F0=-f21; Gb0=-f23; G0=-f24; Ab0=-f25; A0=-f27; Bb0=-f29; B0=-f30
|
||||||
|
C1=-f32; Db1=-f34; D1=-f36; Eb1=-f38; E1=-f41; F1=-f43; Gb1=-f46; G1=-f49; Ab1=-f51; A1=-f55; Bb1=-f58; B1=-f61
|
||||||
|
C2=-f65; Db2=-f69; D2=-f73; Eb2=-f77; E2=-f82; F2=-f87; Gb2=-f92; G2=-f98; Ab2=-f103; A2=-f110; Bb2=-f116; B2=-f123
|
||||||
|
C3=-f130; Db3=-f138; D3=-f146; Eb3=-f155; E3=-f164; F3=-f174; Gb3=-f185; G3=-f196; Ab3=-f207; A3=-f220; Bb3=-f233; B3=-f246
|
||||||
|
C4=-f261; Db4=-f277; D4=-f293; Eb4=-f311; E4=-f329; F4=-f349; Gb4=-f369; G4=-f392; Ab4=-f415; A4=-f440; Bb4=-f466; B4=-f493
|
||||||
|
C5=-f523; Db5=-f554; D5=-f587; Eb5=-f622; E5=-f659; F5=-f698; Gb5=-f739; G5=-f783; Ab5=-f830; A5=-f880; Bb5=-f932; B5=-f987
|
||||||
|
C6=-f1046; Db6=-f1108; D6=-f1174; Eb6=-f1244; E6=-f1318; F6=-f1396; Gb6=-f1479; G6=-f1567; Ab6=-f1661; A6=-f1760; Bb6=-f1864; B6=-f1975
|
||||||
|
C7=-f2093; Db7=-f2217; D7=-f2349; Eb7=-f2489; E7=-f2637; F7=-f2793; Gb7=-f2959; G7=-f3135; Ab7=-f3322; A7=-f3520; Bb7=-f3729; B7=-f3951
|
||||||
|
C8=-f4186; Db8=-f4434; D8=-f4698; Eb8=-f4978; E8=-f5274; F8=-f5587; Gb8=-f5919; G8=-f6271; Ab8=-f6644; A8=-f7040; Bb8=-f7458; B8=-f7902
|
||||||
|
|
||||||
|
dc=-l100; dcp=-l150; c=-l200; cp=-l300; n=-l400; np=-l600; b=-l800; bp=-l1200; r=-l1600
|
||||||
|
|
||||||
|
if command -v beep > /dev/null; then
|
||||||
|
while true; do
|
||||||
|
beep $n $E5 -n $c $B4 -n $c $C5 -n $c $D5 -n $dc $E5 -n $dc $D5 -n $c $C5 -n $c $B4 \
|
||||||
|
-n $n $A4 -n $c $A4 -n $c $C5 -n $n $E5 -n $c $D5 -n $c $C5 \
|
||||||
|
-n $c $B4 -n $c $E4 -n $c $Ab4 -n $c $C5 -n $n $D5 -n $n $E5 \
|
||||||
|
-n $n $C5 -n $n $A4 -n $n $A4 -n $c $B3 -n $c $C4 \
|
||||||
|
-n $np $D5 -n $c $F5 -n $c $A5 -n $dc $A5 -n $dc $A5 -n $c $G5 -n $c $F5 \
|
||||||
|
-n $n $E5 -n $c $E5 -n $c $C5 -n $c $E5 -n $dc $F5 -n $dc $E5 -n $c $D5 -n $c $C5 \
|
||||||
|
-n $c $B4 -n $c $E4 -n $c $Ab4 -n $c $C5 -n $n $D5 -n $n $E5 \
|
||||||
|
-n $n $C5 -n $n $A4 -n $b $A4 \
|
||||||
|
-n $n $E5 -n $c $B4 -n $c $C5 -n $c $D5 -n $dc $E5 -n $dc $D5 -n $c $C5 -n $c $B4 \
|
||||||
|
-n $n $A4 -n $c $A4 -n $c $C5 -n $n $E5 -n $c $D5 -n $c $C5 \
|
||||||
|
-n $c $B4 -n $c $E4 -n $c $Ab4 -n $c $C5 -n $n $D5 -n $n $E5 \
|
||||||
|
-n $n $C5 -n $n $A4 -n $n $A4 -n $c $B3 -n $c $C4 \
|
||||||
|
-n $np $D5 -n $c $F5 -n $c $A5 -n $dc $A5 -n $dc $A5 -n $c $G5 -n $c $F5 \
|
||||||
|
-n $n $E5 -n $c $E5 -n $c $C5 -n $c $E5 -n $dc $F5 -n $dc $E5 -n $c $D5 -n $c $C5 \
|
||||||
|
-n $c $B4 -n $c $E4 -n $c $Ab4 -n $c $C5 -n $n $D5 -n $n $E5 \
|
||||||
|
-n $n $C5 -n $n $A4 -n $b $A4 \
|
||||||
|
-n $b $E5 -n $b $C5 -n $b $D5 -n $b $B4 -n $b $C5 -n $b $A4 -n $b $Ab4 -n $c $B4 -n $c $E4 -n $c $Ab4 -n $c $B4 \
|
||||||
|
-n $b $E5 -n $b $C5 -n $b $D5 -n $b $B4 -n $n $C5 -n $n $E5 -n $n $A5 -n $n $A5 -n $r $Ab5
|
||||||
|
done
|
||||||
|
fi
|
@ -1,6 +1,9 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
import psutil
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import curses
|
import curses
|
||||||
@ -21,9 +24,9 @@ import locale
|
|||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import configparser
|
from configparser import ConfigParser
|
||||||
except ImportError: # Python2
|
except ImportError: # Python2
|
||||||
import ConfigParser as configparser
|
from ConfigParser import SafeConfigParser as ConfigParser
|
||||||
|
|
||||||
|
|
||||||
DIR_NAME = "Terminis"
|
DIR_NAME = "Terminis"
|
||||||
@ -31,10 +34,10 @@ HELP_MSG = """terminis [options]
|
|||||||
|
|
||||||
Tetris clone for terminal
|
Tetris clone for terminal
|
||||||
|
|
||||||
--help\tshow command usage (this message)
|
--help\t-h\tshow command usage (this message)
|
||||||
--edit\tedit controls in text editor
|
--edit\t-e\tedit controls in text editor
|
||||||
--reset\treset to default controls settings
|
--reset\t-r\treset to default controls settings
|
||||||
--level=n\tstart at level n (integer between 1 and 15)"""
|
--level=n\t\tstart at level n (integer between 1 and 15)"""
|
||||||
|
|
||||||
|
|
||||||
class Rotation:
|
class Rotation:
|
||||||
@ -492,7 +495,7 @@ class Stats(Window):
|
|||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
|
|
||||||
class ControlsParser(configparser.SafeConfigParser):
|
class ControlsParser(ConfigParser):
|
||||||
FILE_NAME = "config.cfg"
|
FILE_NAME = "config.cfg"
|
||||||
if sys.platform == "win32":
|
if sys.platform == "win32":
|
||||||
DIR_PATH = os.environ.get("appdata", os.path.expanduser("~\Appdata\Roaming"))
|
DIR_PATH = os.environ.get("appdata", os.path.expanduser("~\Appdata\Roaming"))
|
||||||
@ -522,7 +525,7 @@ class ControlsParser(configparser.SafeConfigParser):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
configparser.SafeConfigParser.__init__(self)
|
ConfigParser.__init__(self)
|
||||||
self.optionxform = str
|
self.optionxform = str
|
||||||
self.add_section(self.SECTION)
|
self.add_section(self.SECTION)
|
||||||
for action, key in self.DEFAULTS.items():
|
for action, key in self.DEFAULTS.items():
|
||||||
@ -581,6 +584,23 @@ class ControlsWindow(Window, ControlsParser):
|
|||||||
self.window.refresh()
|
self.window.refresh()
|
||||||
|
|
||||||
|
|
||||||
|
class Music:
|
||||||
|
PATH = "music.sh"
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.process = None
|
||||||
|
|
||||||
|
def play(self):
|
||||||
|
self.process = subprocess.Popen(["sh", self.PATH])
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
if self.process:
|
||||||
|
for proc in psutil.Process(self.process.pid).children(recursive=True):
|
||||||
|
proc.terminate()
|
||||||
|
self.process.terminate()
|
||||||
|
self.process = None
|
||||||
|
|
||||||
|
|
||||||
class Game:
|
class Game:
|
||||||
WIDTH = 80
|
WIDTH = 80
|
||||||
HEIGHT = Matrix.HEIGHT
|
HEIGHT = Matrix.HEIGHT
|
||||||
@ -618,6 +638,7 @@ class Game:
|
|||||||
self.next = Next(side_width, right_x, top_y)
|
self.next = Next(side_width, right_x, top_y)
|
||||||
self.stats = Stats(self, side_width, side_height, left_x, bottom_y)
|
self.stats = Stats(self, side_width, side_height, left_x, bottom_y)
|
||||||
self.controls = ControlsWindow(side_width, side_height, right_x, bottom_y)
|
self.controls = ControlsWindow(side_width, side_height, right_x, bottom_y)
|
||||||
|
self.music = Music()
|
||||||
|
|
||||||
self.actions = {
|
self.actions = {
|
||||||
self.controls["QUIT"]: self.quit,
|
self.controls["QUIT"]: self.quit,
|
||||||
@ -637,6 +658,7 @@ class Game:
|
|||||||
self.new_piece()
|
self.new_piece()
|
||||||
scheduler.repeat("time", 1, self.stats.refresh_time)
|
scheduler.repeat("time", 1, self.stats.refresh_time)
|
||||||
scheduler.repeat("input", self.AUTOREPEAT_DELAY, self.process_input)
|
scheduler.repeat("input", self.AUTOREPEAT_DELAY, self.process_input)
|
||||||
|
self.music.play()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
scheduler.run()
|
scheduler.run()
|
||||||
@ -676,6 +698,7 @@ class Game:
|
|||||||
self.matrix.refresh(paused=True)
|
self.matrix.refresh(paused=True)
|
||||||
self.next.refresh(paused=True)
|
self.next.refresh(paused=True)
|
||||||
self.scr.timeout(-1)
|
self.scr.timeout(-1)
|
||||||
|
self.music.stop()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
key = self.scr.getkey()
|
key = self.scr.getkey()
|
||||||
@ -683,12 +706,14 @@ class Game:
|
|||||||
self.quit()
|
self.quit()
|
||||||
break
|
break
|
||||||
elif key == self.controls["PAUSE"]:
|
elif key == self.controls["PAUSE"]:
|
||||||
|
break
|
||||||
|
|
||||||
self.scr.timeout(0)
|
self.scr.timeout(0)
|
||||||
self.hold.refresh()
|
self.hold.refresh()
|
||||||
self.matrix.refresh()
|
self.matrix.refresh()
|
||||||
self.next.refresh()
|
self.next.refresh()
|
||||||
self.stats.time = time.time() - self.stats.time
|
self.stats.time = time.time() - self.stats.time
|
||||||
break
|
self.music.play()
|
||||||
|
|
||||||
def swap(self):
|
def swap(self):
|
||||||
if self.matrix.piece.hold_enabled:
|
if self.matrix.piece.hold_enabled:
|
||||||
@ -726,6 +751,7 @@ class Game:
|
|||||||
def quit(self):
|
def quit(self):
|
||||||
self.stats.save()
|
self.stats.save()
|
||||||
t = time.localtime(time.time() - self.stats.time)
|
t = time.localtime(time.time() - self.stats.time)
|
||||||
|
self.music.stop()
|
||||||
sys.exit(
|
sys.exit(
|
||||||
"SCORE\t{:n}\n".format(self.stats.score) +
|
"SCORE\t{:n}\n".format(self.stats.score) +
|
||||||
"HIGH\t{:n}\n".format(self.stats.high_score) +
|
"HIGH\t{:n}\n".format(self.stats.high_score) +
|
||||||
@ -736,14 +762,14 @@ class Game:
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if "--help" in sys.argv[1:] or "/?" in sys.argv[1:]:
|
if "--help" in sys.argv[1:] or "-h" in sys.argv[1:] or "/?" in sys.argv[1:]:
|
||||||
print(HELP_MSG)
|
print(HELP_MSG)
|
||||||
else:
|
else:
|
||||||
if "--reset" in sys.argv[1:]:
|
if "--reset" in sys.argv[1:] or "-r" in sys.argv[1:]:
|
||||||
controls = ControlsParser()
|
controls = ControlsParser()
|
||||||
controls.reset()
|
controls.reset()
|
||||||
controls.edit()
|
controls.edit()
|
||||||
elif "--edit" in sys.argv[1:]:
|
elif "--edit" in sys.argv[1:] or "-e" in sys.argv[1:]:
|
||||||
ControlsParser().edit()
|
ControlsParser().edit()
|
||||||
|
|
||||||
locale.setlocale(locale.LC_ALL, '')
|
locale.setlocale(locale.LC_ALL, '')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user