Skip to content

Commit

Permalink
FIX: Not looping leading to TypeError (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
sappelhoff authored Nov 4, 2024
1 parent 6a75c0c commit e8817c0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
## [UNRELEASED] - YYYY-MM-DD
### Fixed
- Expose detected segment (used in dejittering) as `stream["info"]["segments"]` ([#117](https://github.com/xdf-modules/pyxdf/pull/117) by [Robert Guggenberger](https://github.com/agricolab))
- A non-looping playback of an XDF file will no longer lead to a `TypeError` ([#119](https://github.com/xdf-modules/pyxdf/pull/119) by [Stefan Appelhoff](https://github.com/sappelhoff))

### Changed
- Rename `pyxdf.examples` module to `pyxdf.cli` ([#118](https://github.com/xdf-modules/xdf-Python/pull/118) by [Clemens Brunner](https://github.com/cbrnr))
- Reverse logic of `--loop` argument in `pyxdf.examples.playback_lsl.py` to be more in line with standard practice: Supplying `--loop` will loop, whereas ommitting `--loop` will NOT loop ([#119](https://github.com/xdf-modules/pyxdf/pull/119) by [Stefan Appelhoff](https://github.com/sappelhoff))

## [1.16.8] - 2024-07-18
### Fixed
Expand Down
27 changes: 21 additions & 6 deletions pyxdf/cli/playback_lsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def update(self):
# Previous iteration ended at the file boundary; wrap around and reset.
self._prev_file_read_s = 0.0
self._n_loop += 1
overrun = self._n_loop * self._boundary
overrun = self._n_loop * self._boundary if self._boundary else 0
self._file_read_s = _file_read_s - overrun
if self._boundary and self._file_read_s >= self._boundary:
# Previous was below boundary, now above boundary.
Expand Down Expand Up @@ -133,7 +133,7 @@ def sleep(self, duration: Optional[float] = None) -> None:
def main(
fname: str,
playback_speed: float = 1.0,
loop: bool = True,
loop: bool = False,
wait_for_consumer: bool = False,
):
streams, _ = pyxdf.load_xdf(fname)
Expand Down Expand Up @@ -192,10 +192,12 @@ def main(
continue
timer.update()
t_start, t_stop = timer.step_range
all_streams_exhausted = True
for streamer in streamers:
start_idx = read_heads[streamer.name] if t_start > 0 else 0
stop_idx = np.searchsorted(streamer.tvec, t_stop)
if stop_idx > start_idx:
all_streams_exhausted = False
if streamer.srate > 0:
sl = np.s_[start_idx:stop_idx]
push_dat = streams[streamer.stream_ix]["time_series"][sl]
Expand All @@ -210,22 +212,35 @@ def main(
)
# print(f"Pushed sample: {sample}")
read_heads[streamer.name] = stop_idx

if not loop and all_streams_exhausted:
print("Playback finished.")
break
timer.sleep()

except KeyboardInterrupt:
print("TODO: Shutdown outlets")
print("Keyboard interrupt received. Deleting outlets...")
for streamer in streamers:
del streamer.outlet
print("Shutdown complete.")


if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Playback an XDF file over LSL streams."
)
parser.add_argument("filename", type=str, help="Path to the XDF file")
parser.add_argument("filename", type=str, help="Path to the XDF file.")
parser.add_argument(
"--playback_speed", type=float, default=1.0, help="Playback speed multiplier."
)
parser.add_argument("--loop", action="store_false")
parser.add_argument("--wait_for_consumer", action="store_true")
parser.add_argument(
"--loop", action="store_true", help="Loop playback of the file."
)
parser.add_argument(
"--wait_for_consumer",
action="store_true",
help="Wait for consumer before starting playback.",
)
args = parser.parse_args()
main(
args.filename,
Expand Down

0 comments on commit e8817c0

Please sign in to comment.