From 46e13549f0c33ef6d82d20c42df30fb8c539af32 Mon Sep 17 00:00:00 2001 From: Leo Bernard Date: Sat, 11 Nov 2023 16:50:01 +0100 Subject: [PATCH] :sparkles: Add a `safeStartPlaying` method that only calls `start_playing` when Live is currently stopped --- midi-script/Song.py | 7 +++++++ src/ns/song.ts | 20 +++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/midi-script/Song.py b/midi-script/Song.py index bfd2e42..0a9b5d2 100755 --- a/midi-script/Song.py +++ b/midi-script/Song.py @@ -103,6 +103,13 @@ def set_midi_recording_quantization(self, ns, name): quantization = REC_QUANTIZATIONS.get(str(name), REC_QUANTIZATIONS['rec_q_no_q']) ns.midi_recording_quantization = quantization + def safe_start_playing(self, ns): + if not self.song.is_playing: + self.song.start_playing() + return True + + return False + def safe_stop_playing(self, ns): if self.song.is_playing: self.song.stop_playing() diff --git a/src/ns/song.ts b/src/ns/song.ts index e6ce265..f80aa28 100644 --- a/src/ns/song.ts +++ b/src/ns/song.ts @@ -332,7 +332,25 @@ export class Song extends Namespace< return this.sendCommand("stop_playing"); } - public async safeStopPlaying() { + /** + * Only starts playing when Live is currently not playing + * to prevent Live from jumping back to the start when it's + * already playing. + * + * @returns a boolean indicating whether the command was executed + */ + public async safeStartPlaying(): Promise { + return this.sendCommand("safe_start_playing"); + } + + /** + * Only stops playback when Live is currently playing to prevent + * Live jumping back to the beginning of the arrangement when it's + * already stopped. + * + * @returns a boolean indicating whether the command was executed + */ + public async safeStopPlaying(): Promise { return this.sendCommand("safe_stop_playing"); }