Cabbage Logo
Back to Cabbage Site

Iterate through samples with knob

More like sprintfk, sprintf only runs at i-time, i.e, it’s only ever called once, when an instrument starts.

sprintfk gives me this:

Sdst sprintfk "%s" kTrig #S0

INIT ERROR in instr 1 (opcode sprintfk) line 17: sprintfk: Not string type for %%s

https://csound.com/docs/manual/sprintfk.html

Hi @rorywalsh
I didn’t found a solution with things I tried so far.
What it misses that it takes the strings and give it to diskin2 - similiar to this non working snippet:

instr 1
    SItems[] cabbageGet "GM", "text"
    kQ, kTrig cabbageGetValue "Q"
    cabbageSetValue "GM", kQ
    ;printf "Selected String %s\n", kTrig, SItems[kQ]
    SSample sprintfk "%s" , kQ ; try to get the items from "GM" Channel as string i.e One.wav and give it to next opcode diskin2
    a1 diskin2 SSample
endin

thank you very much!

You should trigger a new instrument that will play the sample whenever a user selects Q. Use the event opcode. I know you can’t pass strings to event’s p-fields, but you can set a channel in instrument 1 to be the current file:

chnset SItems[kQ], "filename"

And then in your diskin2 instrument read:

SFilename chnget "filename"

Btw, is this for a synth or an effect? I mean is instrument 1 been triggered each time you press a note, or is it always on?

Btw, did you see this thread?

1 Like

Hi @rorywalsh

thanks for the links and snippets. I wil go through them now!

ok @rorywalsh what I really try to do is in the following shematic. Maybe it explains better my intention. It would help a lot on load specific samples in a folder with many samples:

image

Another Example would be:

image

With 3 Knobs I can change trough Category, Class and Name.

thanks for you time you already invested here.

That’s what that previous link shows.

So are you trying to sum samples together, and then write them to disk so that diskin can read them back? Seems like a lot of overheard. Why not just play back the summed samples directly?

No, I try to identify a specific sample with this and then load into diskin2.

Samples might have this convention:

Category, Class, Name could lead to the following sample for example:
DRUMS_SNARE_SNARETOP

With this I would go to diskin2.

So we have 3 dimensions which can be called with 3 knobs (for ex. CAT, Class, Name).

Yes, but are you trying to join three samples together, and then play that back with diskin? Or pick a sequence of samples and paly them back one after another?

No, the sample is already on disk with the convention explained.

Like DRUMS_SNARES_SNARELOW.WAV already exists on disk, no further summing needed

So this identified sample will be played back when identified with the help of the 3 dimensions.

Right, I get it now! Sorry, that just wasn’t clicking. So this is basically an exercise in creating the file names and triggering the samples? Do you already have a folder set up with some samples in it? If so can can you zip it and post it? You don’t need to include all the samples, just a handful so I get the picture. I might not be able to get back to you till tomorrow, but I’ll take a look when I get a chance.

Yes! Creating the filenames and then triggering the identified samples.

In the attachment is an example folder. examples.zip (2.9 MB)

Thank you!!!

I can’t open that zip file?

My bad, I got it now…

This simple instrument will let you create a file name based on the current values of the comboboxes. It this what you were looking for?

<Cabbage>
form caption("Untitled") size(400, 300), guiMode("queue"), pluginId("def1")
combobox bounds(10, 18, 80, 20) channel("combo1"), channelType("string"), value("DRUMS") text("DRUMS", "MELODY", "SYNTH", "VOX")
combobox bounds(100, 18, 80, 20) channel("combo2"), channelType("string"), value("FXDRUMS") text("FXDRUMS", "LOWPERC", "SNARE", "TOM")
combobox bounds(190, 18, 80, 20) channel("combo3"), channelType("string"), value("KIKK") text("KIKK", "BAY01", "TOMOH", "SAW1")
button bounds(10, 44, 80, 40) channel("button1"), text("Set sample")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
ksmps = 32
nchnls = 2
0dbfs = 1

;DRUMS_FXDRUMS_KIKK.wav
;DRUMS_LOWPERC_BAY01.wav
;DRUMS_SNARE_TRANSIENTSNARE.wav
;DRUMS_TOMS_TOMOH.wav
;MELODY_HOOKS_MELHOOK01.wav
;MELODY_HOOKS_MELHOOK02.wav
;SYNTH_BASIC_SAW01.wav
;VOX_PHRASES_PHRASE01.wav

;instrument will be triggered by keyboard widget
instr 1

SCombo1, kTrigC1 cabbageGetValue "combo1"
SCombo2, kTrigC2 cabbageGetValue "combo2"
SCombo3, kTrigC3 cabbageGetValue "combo3"

kBut, kSetSampleTrig cabbageGetValue "button1"
printf "%s_%s_%s.wav\n", kSetSampleTrig, SCombo1, SCombo2, SCombo3

endin

</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
i1 0 z
f0 z
</CsScore>
</CsoundSynthesizer>

FANTASTIC!!! @rorywalsh

One question left how to I hand over this string to diskin2 in best way possible?

And as soon as I try to let a knob control the combobox values, it only works if I remove
“channeltype(“strings”)”

kSliderValue cabbageGetValue "knob"
cabbageSetValue "combo1", kSliderValue

thanks so much!

You can use a sprintfk to create the string at run time.

Like so ?

String   sprintfk  "%s_%s_%s.wav", SCombo1, SCombo2, SCombo3
a1 diskin2 String

Maybe I miss something with that but I do get this failure:

INIT ERROR in instr 1 (opcode diskin2) line 37: diskin2: __.wav: failed to open file (No Error.)

thanks for assisting me!

No, this is back to the same problem as before, you can’t change the filename to diskin at runtime. So you either trigger another instrument to play the sample, or use an reinit. I would probably just trigger another instrument to do the playback whenever I change the sample. Write the sample name to a channel, and then pick it up in the playback instrument.