supercollider / sc3-plugins

Community plugins for SuperCollider
https://supercollider.github.io/sc3-plugins/
GNU General Public License v2.0
449 stars 122 forks source link

new Stk wrapping #33

Closed sonoro1234 closed 8 years ago

sonoro1234 commented 9 years ago

Hello,

Stk is a library devoted to physical modeling

https://ccrma.stanford.edu/software/stk/index.html

As StkUgens are quite buggy I did another stk wraping for myself: Is is based on StkInstrumnt so that with only one UGen (StkInst) it is possible to talk to all stk instruments and specific parameter are accesed by number.

for example stk::Bowed has https://ccrma.stanford.edu/software/stk/classstk_1_1Bowed.html

Bow Pressure = 2
Bow Position = 4
Vibrato Frequency = 11
Vibrato Gain = 1
Bow Velocity = 100
Frequency = 101
Volume = 128

( SynthDef(\helpStkbowed,{arg out=0,freq=220,gate=1,amp=1,bowpressure = 64, bowposition = 17, vibfreq=50, vibgain=1, loudness=128;     var sig,env;     env = EnvGen.kr(Env.asr(0,1,0.1),gate,doneAction:2);     sig = StkInst.ar(Stk.at("Bowed"),freq, gate, amp, 0.5,[2,bowpressure,4,bowposition,11,vibfreq,1,vibgain,128,loudness])*env;     Out.ar(out, sig.dup); }).add; )

It can be found on: https://github.com/sonoro1234/StkInst

Works for me but I would like somebody to use it before doing a pull request for sc3-plugins Also need some advise about copying audio stk files (where, how...)

Best victor bombi

sonoro1234 commented 9 years ago

Instruments using sound files where noisy. Now fixed with LITTLE_ENDIAN checking Everything works, only left to know where to install rawwavefiles in sc3 distribution

danstowell commented 8 years ago

I don't use STK I'm afraid, so I can't test. I agree that the standard wrappings are buggy. Can anyone try out this proposal?

@sonoro1234 this proposal changes the API, so it's not clear who it would "hurt" to make this change. Any comment on that?

sonoro1234 commented 8 years ago

I think the same instruments are wrapped. Yes, the api changes a little but it would be the "price" for something to work. 372 lines of new code where easier for me that chasing bugs in 1589 lines.

danstowell commented 8 years ago

@sonoro1234 if I understand right, the old and new ugens can both coexist, so there's NO reason not to do a pull request. The sc3-plugins repository is deliberately not as closely guarded as the main sc repository. Please could you do a PR? That way, if anyone decides to do a new release (!) they can be included for testing right away

sonoro1234 commented 8 years ago

@danstowell Still dont know what should be done with sample files needed by Stk. Where should they be placed at installation?

danstowell commented 8 years ago

I don't know. This has been dealt with before in some of Nick Collins' ugens - see the extra Qitch files here - however I don't see any special install commands going along with those.

sonoro1234 commented 8 years ago

Yes, I see that everyting in sc folder is copied

# install help and sc specific files that are found in 'PLUGIN_NAME/sc' folder
foreach (DIR ${PLUGIN_DIRS};${PLUGIN_DIRS_EXTRA})
    install(DIRECTORY "${DIR}/sc/" DESTINATION "${INSTALL_DESTINATION_DISTRO}/${DIR}"
            PATTERN "*")
endforeach(DIR)

But I cant find how to reference that location on sclang

danstowell commented 8 years ago

example:

   LFSaw.filenameSymbol

(Note that if the synth is on a different machine than the lang, this might not give the needed answer. But you probably have to live with that.)

sonoro1234 commented 8 years ago

Platform.userExtensionDir would be better? Does it work in all systems?

sonoro1234 commented 8 years ago
Platform.userExtensionDir ++"/SC3Plugins/StkInst/rawwaves"

is this ok for all platforms?

sonoro1234 commented 8 years ago

@danstowell also: I would like to set rawwaves path with

{StkGlobals.ar(1,1,Platform.userExtensionDir ++"/SC3Plugins/StkInst/rawwaves")}.play;

But this Synth sould be auto free after StkGlobals_Ctor (where it sets the rawwavepath for the library) Any example on how to do that?

danstowell commented 8 years ago

Yes Platform.userExtensionDir might be a good way, BUT you can't guarantee that the user has placed the file where you expect it! Maybe they put it in a subfolder called weird_new_plugins

In order to set the rawwavepath, look at SuperCollider's rarely-used /u_cmd message. Nick Collins used it in his FeatureSave class (in SCMIRugens). You might like to use the same design pattern as he did. (Look at the FeatureSave helpfile example for a start.)

It's easy for a synth to free itself. Look at the source code to the FreeSelf ugen (in TriggerUGens.cpp).

sonoro1234 commented 8 years ago

Have found

unit->mDone = true;
DoneAction(2, unit);

Can this be used on Ctor?

sonoro1234 commented 8 years ago

Is this the same as?

NodeEnd(&unit->mParent->mNode);
danstowell commented 8 years ago

Yes - look at Unit_DoneAction() in SC_Node.cpp to see the connection - but you don't need to use DoneAction because you don't need the indirection, nor the option to perform other doneactions. simply do NodeEnd

sonoro1234 commented 8 years ago

It seems that StkInst is not ready. I am getting an SIGSEV at scsynth quit:

Program received signal SIGSEGV, Segmentation fault.
0x672586b1 in World_Free (inWorld=0x1c2cbc0, inPtr=0x27a22a0)
    at C:\SupercolliderRepos\scfork\supercollider\server\scsynth\SC_World.cpp:807
807             inWorld->hw->mAllocPool->Free(inPtr);
(gdb) thread apply all bt

Thread 1 (Thread 3284.0xb38):
#0  0x672586b1 in World_Free (inWorld=0x1c2cbc0, inPtr=0x27a22a0)
    at C:\SupercolliderRepos\scfork\supercollider\server\scsynth\SC_World.cpp:807
#1  0x6d581bab in operator delete (ptr=0x27a22a0) at C:\SupercolliderRepos\Mios\StkInst\StkInst.cpp:42
#2  0x6d5f8ee4 in deallocate (this=0x6d6fd234 <stk::Stk::alertList_>, __p=<optimized out>)
    at c:/mingw32-4.8.2-posix-dwarf/i686-w64-mingw32/include/c++/ext/new_allocator.h:110
#3  _M_deallocate (this=0x6d6fd234 <stk::Stk::alertList_>, __n=<optimized out>, __p=<optimized out>)
    at c:/mingw32-4.8.2-posix-dwarf/i686-w64-mingw32/include/c++/bits/stl_vector.h:174
#4  ~_Vector_base (this=0x6d6fd234 <stk::Stk::alertList_>, __in_chrg=<optimized out>)
    at c:/mingw32-4.8.2-posix-dwarf/i686-w64-mingw32/include/c++/bits/stl_vector.h:160
#5  ~vector (this=0x6d6fd234 <stk::Stk::alertList_>, __in_chrg=<optimized out>)
    at c:/mingw32-4.8.2-posix-dwarf/i686-w64-mingw32/include/c++/bits/stl_vector.h:416
#6  __tcf_2 () at C:\SupercolliderRepos\Mios\StkInst\stk\src\Stk.cpp:68
#7  0x6d5811a4 in _CRT_INIT@12 () from C:\SupercolliderRepos\Mios\ugens\StkInst.scx
#8  0x6d58139d in __DllMainCRTStartup () from C:\SupercolliderRepos\Mios\ugens\StkInst.scx
#9  0x6d581443 in DllMainCRTStartup@12 () from C:\SupercolliderRepos\Mios\ugens\StkInst.scx
#10 0x77871288 in ntdll!RtlQueryInformationActivationContext () from C:\Windows\system32\ntdll.dll
#11 0x6d580000 in ?? ()
#12 0x7786b16c in ntdll!RtlExitUserProcess () from C:\Windows\system32\ntdll.dll
#13 0x7786b0ee in ntdll!RtlExitUserProcess () from C:\Windows\system32\ntdll.dll
#14 0x761744d1 in KERNEL32!ExitProcess () from C:\Windows\system32\kernel32.dll
#15 0x00000000 in ?? ()

It seems realted to Stk using stl_vector and my redefinition of operator delete as

void operator delete(void* ptr) noexcept
{
    RTFree(gWorld, ptr);
}
sonoro1234 commented 8 years ago

Perhaps a stl custom allocator should be used. It is a bit too much complicated for me. Perhaps @timblechmann has any clues on that?

sonoro1234 commented 8 years ago

@danstowell Solved the SIGSEV issue in my repo https://github.com/sonoro1234/StkInst

trying to incorporate in sc3-plugins breaks StkUGens compilation because there is only a CMake file for all plugins and include_directories from both projects get mixed. Solutions : rework all CMAKE building of plugins!! or discard StkUGens!! Any thoughts?

sonoro1234 commented 8 years ago

solved in PR #47