Skip to content
This repository has been archived by the owner on Nov 21, 2020. It is now read-only.

Commit

Permalink
Change from for loop to while loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Huy-Ngo authored and McSinyx committed Apr 7, 2020
1 parent 09f14bf commit b5ab03e
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 8 deletions.
3 changes: 1 addition & 2 deletions examples/palace-event.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

from argparse import ArgumentParser
from datetime import datetime, timedelta
from itertools import count, takewhile
from sys import stderr
from time import sleep
from typing import Iterable, MutableSequence
Expand Down Expand Up @@ -62,7 +61,7 @@ def play(files: Iterable[str], device: str) -> None:
continue
with buffer:
src = buffer.play()
for i in takewhile(lambda i: src.playing, count()):
while src.playing:
print(f' {pretty_time(src.offset_seconds)} /'
f' {pretty_time(buffer.length_seconds)}',
end='\r', flush=True)
Expand Down
3 changes: 1 addition & 2 deletions examples/palace-latency.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
# along with palace. If not, see <https://www.gnu.org/licenses/>.

from argparse import ArgumentParser
from itertools import count, takewhile
from sys import stderr
from time import sleep
from typing import Iterable
Expand All @@ -40,7 +39,7 @@ def play(files: Iterable[str], device: str) -> None:
stderr.write(f'Failed to open file: {filename}\n')
decoder.play(CHUNK_LEN, QUEUE_SIZE, src)
print('Playing: ', filename)
for i in takewhile(lambda i: src.playing, count()):
while src.playing:
print('Offset:', round(src.offset_seconds), 's - Latency:',
src.latency//10**6, 'ms', end='\r', flush=True)
sleep(PERIOD)
Expand Down
3 changes: 1 addition & 2 deletions examples/palace-reverb.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

from argparse import Action, ArgumentParser
from datetime import datetime, timedelta
from itertools import count, takewhile
from sys import stderr
from time import sleep
from typing import Iterable
Expand Down Expand Up @@ -64,7 +63,7 @@ def play(files: Iterable[str], device: str, reverb: str) -> None:
decoder.play(CHUNK_LEN, QUEUE_SIZE, src)
print(f'Playing {filename} ({decoder.sample_type},',
f'{decoder.channel_config}, {decoder.frequency} Hz)')
for i in takewhile(lambda i: src.playing, count()):
while src.playing:
print(f' {pretty_time(src.offset_seconds)} /'
f' {pretty_time(decoder.length_seconds)}',
end='\r', flush=True)
Expand Down
3 changes: 1 addition & 2 deletions examples/palace-stdec.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import wave
from argparse import ArgumentParser
from datetime import datetime, timedelta
from itertools import count, takewhile
from sys import stderr
from time import sleep
from typing import Iterable, Tuple
Expand Down Expand Up @@ -54,7 +53,7 @@ def play(files: Iterable[str], device: str) -> None:
with buffer, buffer.play() as src:
print(f'Playing {filename} ({buffer.sample_type},',
f'{buffer.channel_config}, {buffer.frequency} Hz)')
for i in takewhile(lambda i: src.playing, count()):
while src.playing:
print(f' {pretty_time(src.offset_seconds)} /'
f' {pretty_time(buffer.length_seconds)}',
end='\r', flush=True)
Expand Down

0 comments on commit b5ab03e

Please sign in to comment.