musikinformatik / SuperDirt

Tidal Audio Engine
GNU General Public License v2.0
519 stars 75 forks source link

sclang: Fading a pattern with Pdef has issues #226

Closed jkbd closed 3 years ago

jkbd commented 3 years ago

I'm running scsynth version 3.11.2 on Arch Linux and the Quarks.gui tells, the latest version of SuperDirt is installed. I tried the sclang-dirt.scd hack, but unfortunately I managed to crash something.

A minimal example to reproduce. Everything set up, so this plays the bass drum sample as expected:

(type:\dirt, orbit:0, s: \bd).play; 

Let's play a pattern:

(
Pdef(\x,
    Pbind(
        \type, \dirt,
        \s, \bd,
        \n, Pseq([1, 0, 0, 0], inf),  // four on the floor
        \dur, 0.5
    )
).play
)

If I set a fadeTime for the Pdef ...

Pdef(\x).fadeTime=8

...then it will crash as soon as a new pattern is evaluated:

(
Pdef(\x,
    Pbind(
        \type, \dirt,
        \s, \hh,  // hi-hats
        \dur, 0.25
    )
).play
)

The error is ERROR: Message 'dbamp' not understood. but the rest of the dump does not give me a clue what is going on. And Pdef(\x) will only play SuperDirt again, after I restarted both interpreter and server. Can somebody please help?

telephon commented 3 years ago

Thanks! Quick fix:

Event.addEventType(\dirt, {
            var keys, values;
            var dirt = ~dirt ? SuperDirt.default;
            if(dirt.isNil) {
                Error("dirt event: no dirt instance found.\n\n// You could try:\nSuperDirt.default = ~dirt;").throw;
            };
            ~delta = ~delta ?? { ~stretch.value * ~dur.value };
            ~amp = ~amp.value;
            ~latency = ~latency ?? { dirt.server.latency };
            if(~n.isArray) {
                keys = currentEnvironment.keys.asArray;
                values = keys.collect(_.envirGet).flop;
                values.do { |each|
                    var e = Event(parent: currentEnvironment);
                    keys.do { |key, i| e.put(key, each.at(i)) };
                    dirt.orbits.wrapAt(e[\orbit] ? 0).value(e)
                }
            } {
                dirt.orbits.wrapAt(~orbit ? 0).value(currentEnvironment)
            }
        });

I'll add it to the next release.

jkbd commented 3 years ago

This fixes the crash. But it does not sound right. While fading, I hear poppy transients instead of a smooth cross-fade. After the fadeTime passed, the new pattern plays normal.

jkbd commented 3 years ago

Pdef(\x) will only play SuperDirt again, after I restarted both interpreter and server.

This is another unrelated problem, I noticed. And it may be me doing wrong. I played using a TempoClock, like

t = TempoClock.new;

(
Pdef(\x,
    Pbind(
        \note, Pseq([1, 2, 3], inf),
        \dur, 0.5
    )
).play(t)
)

After CmdPeriod.run, the clock is gone.

Pdef(\x).play(t);   // -> ERROR: clock is not running.
t = TempoClock.new;
Pdef(\x).play(t);   // no error, no sound

Somehow, without the Pdef the last line produces sound again:

Pbind(\note, Pseq([1, 2, 3], inf), \dur, 0.5).play(t)
CmdPeriod.run
t = TempoClock.new
Pbind(\note, Pseq([1, 2, 3], inf), \dur, 0.5).play(t)

Any suggestions? Should I create an issue at SuperCollider?

jkbd commented 3 years ago

For the clock I can use t = TempoClock.new.permanent_(true) and it will survive CmdPeriod.run. Then I can play the Pdef(\x) again without errors. Awesome!

jkbd commented 3 years ago

Probably you got me wrong. I apologize for discussing two problems in one issue. But the fading between the two patterns, as in the top example, still sounds wrong and the issue is not solved. What is solved, is that your patch and the correct usage of TempoClock keeps SuperCollider from crashing and and the Pdef from silently slipping in some unfunctional state.

I recorded the output of SuperCollider of the top example (with your patch applied). The second pattern was evaluated roughly at the fifth beat with .fadeTime = 8. This is the waveform visualized:

fading-patterns

I would expect the Hi-Hat to move in gradually and the Bass Drum to fade-out.

telephon commented 3 years ago

Thanks! Maybe something else different in our libraries. Can you check with the freshly released version? I can't reproduce this behaviour anymore with the new version.

jkbd commented 3 years ago

In deed! With SuperDirt 7abb62e89649daa1232b9cbd6427241868abd30e it fades as expected. Thank you very much! Now the issue is solved.