From 5f6973d47fcc7a3f473c0b2448bd8975b9de7e9e Mon Sep 17 00:00:00 2001 From: James Harkins Date: Sat, 19 May 2018 09:13:04 +0800 Subject: [PATCH 1/4] Replace isPIDRunning (old method) with pidRunning --- MP3.sc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MP3.sc b/MP3.sc index 0ce6e3d..1812e94 100644 --- a/MP3.sc +++ b/MP3.sc @@ -152,7 +152,7 @@ MP3 { if(pid.isNil, { ^true; // We can only assume it's still playing - we have no better info! }, { - if(pid.isPIDRunning, { + if(pid.pidRunning, { ^true; }, { playing = false; From 8d71b3d0ac6f054f21c786207a10d681ccbdf744 Mon Sep 17 00:00:00 2001 From: James Harkins Date: Sat, 19 May 2018 09:33:54 +0800 Subject: [PATCH 2/4] Post error if MP3 unixCmd ends with error code --- MP3.sc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/MP3.sc b/MP3.sc index 1812e94..3f4140e 100644 --- a/MP3.sc +++ b/MP3.sc @@ -79,6 +79,10 @@ MP3 { if(sampleRate.isNil){ sampleRate = Server.default.sampleRate; + if(sampleRate.isNil) { + "Sample rate not available, assuming 44100".warn; + sampleRate = 44100; + }; }; khz = sampleRate * 0.001; @@ -121,7 +125,13 @@ MP3 { // ("MP3.start completed (PID"+(pid?"unknown")++")").postln; // playing = true; // }); - pid = cmd.unixCmd; + pid = cmd.unixCmd({ |exit| + if(exit != 0) { + "MP3 subprocess (PID %) terminated with error code %".format(pid, exit).warn; + playing = false; + pid = nil; + }; + }); ("MP3.start completed (PID"+(pid?"unknown")++")").postln; playing = true; } From 86f09c2262dba21d8d0019453a6ba32d8d2865a9 Mon Sep 17 00:00:00 2001 From: James Harkins Date: Sun, 20 May 2018 16:12:13 +0800 Subject: [PATCH 3/4] Clear 'playing' and 'pid' status variables when process quits --- MP3.sc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MP3.sc b/MP3.sc index 3f4140e..875e210 100644 --- a/MP3.sc +++ b/MP3.sc @@ -128,9 +128,9 @@ MP3 { pid = cmd.unixCmd({ |exit| if(exit != 0) { "MP3 subprocess (PID %) terminated with error code %".format(pid, exit).warn; - playing = false; - pid = nil; }; + playing = false; + pid = nil; }); ("MP3.start completed (PID"+(pid?"unknown")++")").postln; playing = true; From 9af839cf40b9f45934ffa4f751b1270c2ba6e452 Mon Sep 17 00:00:00 2001 From: James Harkins Date: Sun, 20 May 2018 16:15:25 +0800 Subject: [PATCH 4/4] Suppress spurious "unable to stop" posting for stopped MP3 object m = MP3(...); m.start; m.stop; m.stop; Second stop posts "MP3.stop - unable to stop automatically, PID not known" -- but it was already stopped! Should check playing status before this. --- MP3.sc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MP3.sc b/MP3.sc index 875e210..2b37a1c 100644 --- a/MP3.sc +++ b/MP3.sc @@ -137,7 +137,7 @@ MP3 { } stop { - if(pid.isNil, { + if(this.playing and: { pid.isNil }, { "MP3.stop - unable to stop automatically, PID not known".warn; }, { ("kill" + pid).systemCmd;