Switch case logic stop audio in file

Hi I’m trying to create a switch case program that opens a file and runs the code in the file.
When the day ends, it should stop the file and go over to the next file.

The sound cannot overlap each other.

In the code I have now, I have a case logic for 1 minute to test the cases.
I want the cases to stop on the end of the day, so when it’s 11:59pm it should close the file and sound and start the new case file at 00.01pm the next day.

This is the current code I have.


(
s.waitForBoot {
    // Wacht tot de server start
    s.sync;

    // Dynamisch basispad bepalen
    ~basePath = PathName(thisProcess.nowExecutingPath).parentPath ++ "cases/";

    // Log het berekende pad (voor debuggen)
    "Gevonden basePath: ".post; ~basePath.postln;

	// Dynamisch bepalen van het pad naar DataManager.scd

   ~utilsPath = PathName(thisProcess.nowExecutingPath).parentPath ++ "/utils/DataManager.scd";

	// Controleer of het bestand bestaat
	if (File.exists(~utilsPath)) {
    ~utilsPath.postln; // Log het pad voor debugging
    thisProcess.interpreter.executeFile(~utilsPath);
	} {
    ("DataManager.scd niet gevonden in: " + ~utilsPath).postln;
	};



    // Case-lader functie
    ~loadCase = { |index|
        var filePath = ~basePath ++ "case" ++ index ++ ".scd";
        if (File.exists(filePath)) {
            ("Laden: " + filePath).postln;
            thisProcess.interpreter.executeFile(filePath);
        } {
            ("Case file niet gevonden: " + filePath).postln;
        };
    };

 ~currentScheduler = nil;

~scheduler = Routine {
    ~caseIndex = 15;
    ~dayLength = 1; // Length of a day in minutes (for testing)
    while {
        ~caseIndex < 30; // For up to 15 cases
    } {
        ~loadCase.(~caseIndex);
        (~dayLength * 60).wait; // Wait for the day length in seconds
        ~caseIndex = ~caseIndex + 1;
    };
    "Alle cases geladen.".postln;
};

// Start the scheduler
~startScheduler = {
    if (~currentScheduler.notNil and: { ~currentScheduler.isPlaying }) {
        ~currentScheduler.stop; // Stop the existing scheduler
        "Scheduler gestopt.".postln;
    };
    ~currentScheduler = ~scheduler.play;
    "Scheduler gestart.".postln;
};

// Stop the scheduler
~stopScheduler = {
    if (~currentScheduler.notNil and: { ~currentScheduler.isPlaying }) {
        ~currentScheduler.stop;
        ~currentScheduler = nil;
        "Scheduler gestopt.".postln;
    } {
        "Geen actieve scheduler om te stoppen.".postln;
    };
};
};
)

This is the sound code I have.

(
~barmul = 2**3;

Ppar([
    Pbind(*[
        instrument: \kick,
        amp: -20.dbamp,
        degree: Pseq([\rest, \rest, 0],inf),
        legato: Pn(Penv([0.05,0.7,0.05], [1,1] * ~barmul, 'exp')),
        dur: Pseq([4],inf) / 4
    ]),
    Pbind(*[
        instrument: \hh,
        amp: (Pn(Penv([-90,-70,-90], [3,1] * ~barmul, 'exp'))).dbamp,
        legato: 1/16,
        dur: 1/2
    ]),
    Pbind(*[
        instrument: \pureping,
        amp: -20.dbamp,
        legato: 1/4,
        degree: Pseq([\rest, \rest], inf) - 7,
        dur: 1
    ])
]).play(TempoClock(60 / 60));
)

Have a look at the DayTimer quark. It’s really good in my experience for exactly this sort of thing.

How do I make sure that the code stops in the case file itself.
I can switch the days but the sound file doesn’t know it has to quit when the main file changes to the next case file.

thanks for the link fyi!

You have to build the code so that it’s stoppable, there’s no such thing as automatically stopping the sound from one particular scd file. So if you’re playing a pattern,

~player = ~pattern.play;

And then to stop it,

~player.stop;

You might want to figure out a system where each file has a corresponding “stop” file which frees resources and stops the sound.