| blc2 - Python library and frontend for running theatrical lighting and SFX. Written for the English 2041F fall 2019 theatre production of "The Cenci".
git clone https://benconnors.ca/git-repos/blc2 |
audioview.py (2934B) - raw
1 import curses 2 import threading 3 4 from .globals import CURSES_LOCK 5 6 def format_time(t): 7 t = int(t/1000 + 0.5) 8 h = (t // 3600) 9 m = t % 3600 10 11 s = m % 60 12 m = m // 60 13 14 if not m and not h: 15 return "%2ds" % s 16 elif not h: 17 return "%2dm%2ds" % (m, s) 18 return "%dh%2dm%2ds" % (h, m, s) 19 20 class AudioView: 21 def set_dim(self, height, width): 22 with CURSES_LOCK, self._lock: 23 if (height, width) != (self._height, self._width): 24 self.win.erase() 25 self.win.refresh() 26 27 self.win.resize(height, width) 28 self.win.redrawwin() 29 30 self._height = height 31 self._width = width 32 self._refresh() 33 self.win.refresh() 34 35 def set_pos(self, y, x): 36 with self._lock: 37 if (y, x) != (self._y, self._x): 38 with CURSES_LOCK: 39 self.win.mvwin(y, x) 40 self._put_title() 41 self.win.refresh() 42 43 @property 44 def audio(self): 45 return self._audio 46 47 @audio.setter 48 def audio(self, v): 49 with self._lock: 50 self._audio = v 51 self._refresh() 52 53 @property 54 def title(self): 55 return self._title 56 57 @title.setter 58 def title(self, value): 59 with self._lock: 60 self._title = value 61 self._put_title() 62 self.win.refresh() 63 64 @property 65 def highlight(self): 66 return self._highlight 67 68 @highlight.setter 69 def highlight(self, value): 70 with self._lock: 71 self._highlight = value 72 self._put_title() 73 self.win.refresh() 74 75 def _put_title(self): 76 self.win.border() 77 pos = min(self._width-2-len(self._title), (3*self._width)//4 - (len(self._title) // 2)) 78 self.win.addstr(self._height-1, pos, self._title, curses.A_REVERSE if self._highlight else 0) 79 80 def _refresh(self): 81 with CURSES_LOCK: 82 self.win.erase() 83 84 if self._audio is not None: 85 self.win.addstr(1, 1, "Filename: "+str(self._audio.filename)) 86 self.win.addstr(2, 1, " Fade in: "+str(self._audio.fade_in)+"ms") 87 self.win.addstr(3, 1, "Duration: "+str(format_time(self._audio.duration))) 88 self.win.addstr(4, 1, "Fade out: "+str(self._audio.fade_out)+"ms") 89 90 self._put_title() 91 self.win.refresh() 92 93 def __init__(self, y, x, height, width): 94 with CURSES_LOCK: 95 self.win = curses.newwin(height, width, y, x) 96 self.win.leaveok(True) 97 self.win.keypad(True) 98 99 self._lock = threading.RLock() 100 self._highlight = False 101 self._title = "Audio" 102 self._height = height 103 self._width = width 104 self._y = -1 105 self._x = -1 106 107 self._audio = None 108 109 self.set_pos(y, x) 110 self.set_dim(height, width)