Skip to content

Commit

Permalink
✨ Add a safeStartPlaying method that only calls start_playing whe…
Browse files Browse the repository at this point in the history
…n Live is currently stopped
  • Loading branch information
leolabs committed Nov 11, 2023
1 parent a14f37a commit 46e1354
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
7 changes: 7 additions & 0 deletions midi-script/Song.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
20 changes: 19 additions & 1 deletion src/ns/song.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> {
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<boolean> {
return this.sendCommand("safe_stop_playing");
}

Expand Down

0 comments on commit 46e1354

Please sign in to comment.