Cabbage Logo
Back to Cabbage Site

Sample Player

I would like to build a sample player similar to output ARCADE.

I can drag and drop samples onto a displayed keyboard and play them back via midi. It should be possible to store 64 samples per preset from C0 - Cx.

Editing the samples with built-in effects is not necessary.

Just play them back - in bpm of the DAW
If possible in the key of the DAW

Can you do that with cabbage?
and what is the best way to approach it?

Dragging samples onto the keyboard is possible, but youā€™ll need to check the xy coordinates to see what key the sample was dropped on. I have never done it, but in theory it should work. I can try to create a mock-up for you tomorrow.

Getting the BPM from the DAW is simple. Getting the current key signature is not. I donā€™t think itā€™s possible with any plugin framework that Iā€™m aware of. Thatā€™s not too say you couldnā€™t derive the key yourself from analysing incoming midi notes, but Iā€™m not sure what your looking for as you would need to first play some notes.

If you are just looking to implement a sampler, and you donā€™t really have the need for any effects or further processing, I have to ask, have you looked at HISE? As much as I hate to turn someone away from Cabbage/Csound, HISE is probably worth looking into. Iā€™ve never used it myself, and Iā€™m not sure of its licence, but it might be with investigating.

That sounds good - yes an example/mockup would be fantastic

For example, if you look at the free samplemanager of ADSR or ARCADE then I can choose here with a popup menu in which tone all samples in this preset are played.

Letā€™s say I know the key of the sample i drag on a key and I set this on a selection box.

For example, sample 1 is in A, sample 2 is in G, sample 3 is in F#

In my selection field I enter e.g. C, then sample 1 would have to go down by +2 notes, sample 2 by +4 and so on.

So with key A set, all samples would have to be played in A.

ist this possible?

ā€¦and no HISE is crap :slight_smile:

The first problem I hit when trying this, is that the current mouse position is not broadcast when a file is dropped, because the plugin window is not in focus. Iā€™ll have update the Cabbage source so that the current mouse X/Y position are also broadcast when a file is dropped. Leave it with me.

Note that my idea for this only works if scrolling the keyboard up and down octaves is disabled. Itā€™s easy to prevent this in Cabbage, but it means that what you see is what you get in terms of keys displayed.

Hi Rory,
It doesnā€™t necessarily have to be the keyboard - it is enough if, for example, an 8x8 pad of squares into which you drop the samples. Of course each pad is assigned to a note!

I would play the whole thing with either Maschine Jam or Novation LaunchPad mk3 anyway - both have 64 pads.

Pads would be much easier to organise. Iā€™m just updating Cabbage now. Iā€™ll let you know when Iā€™ve a new build ready for you.

Attached is a simple example that will let you drag samples onto the midi keyboard, and have them then associated with that key. Itā€™s really just a proof of concept. You may need the latest beta which wonā€™t be cooked for about 20 minutes or so. It worked without my latest changes on Windows, but if youā€™re OSX you will probably need the beta.

SamplePlay.csd (1.9 KB)

Hereā€™s the highlights:

instr 1000
    SFile chngetks "LAST_FILE_DROPPED"
    if changed(SFile) == 1 then 
        event "i", 2000, 0, 1
    endif
endin

This instrument is always on and listens for a for a file drop. When a file is dropped, it triggers this instrument:

instr 2000
    SFile chnget "LAST_FILE_DROPPED"
    iX chnget "MOUSE_X"
    iY chnget "MOUSE_Y"
    
    if iY > 228 && iY < 250 then
        if iX > 13 && iX < 30 then
            prints "C1"
            gi1 ftgen 36, 0, 0, 1, SFile, 0, 4, 0
        elseif iX > 30 && iX < 60 then
            prints "D1"
            gi1 ftgen 38, 0, 0, 1, SFile, 0, 4, 0
        elseif iX > 60 && iX < 90 then
            prints "E1"
            gi1 ftgen 40, 0, 0, 1, SFile, 0, 4, 0
        elseif iX > 90 && iX < 120 then
            prints "F1"
            gi1 ftgen 41, 0, 0, 1, SFile, 0, 4, 0
        elseif iX > 120 && iX < 150 then
            prints "G1"
            gi1 ftgen 43, 0, 0, 1, SFile, 0, 4, 0
        elseif iX > 150 && iX < 180 then
            prints "A1"
            gi1 ftgen 45, 0, 0, 1, SFile, 0, 4, 0
        endif
    endif
endin

All this does is check the coordinates of the mouse when the file was dropped, and match it to the key under it. Iā€™d probably make a UDO for this. As you can see, each keyā€™s width is a multiple of 30, so this check could be done more succinctly in a loop. But you get the idea. When we enter an if block we put the sample into a corresponding function table.

For simplicity, Iā€™ve numbered each function table to match the corresponding MIDI note number. Itā€™s clear why I did this in the next instrument, the one that gets triggered when you press a note:

instr 1
    iFreq = sr/ftlen(p4)
    aPhs phasor iFreq
    aTab tab aPhs, p4, 1
    outs aTab, aTab
endin

p4 is the current MIDI note, which is also the number of the corresponding table. Youā€™ll see that I create some dummy function tables in the score. This just stops Csound from giving out if you play a note before you have loaded a samples.

Some things to note:

  • this only works for the first few notes, youā€™ll need to add hook for the rest
  • it would probably be simpler to use images/pads to drop samples on, at least you would be working with a larger landing space.
  • Iā€™ve attached below another file that uses a UDO to check if the mouse is over a pad. It might be handy for you.

DragPad.csd (1.7 KB)

Hi, Rory,

how do I get these two examples SamplePlay.csd and DragPad.csd together into one instrument? I donā€™t get it.

You donā€™t. The fact that a plugin wonā€™t have focus until you drop a file means the drag pad approach wonā€™t work. But the first instrument works fine for me.

Sorry - I donā€™t understand - you wrote that it would be better to create pads to store the samples because the area would be bigger here?

Is it possible to put the sample on an area that looks like a pad?

Yes sorry, itā€™s just that the hover-over feature of the drum pads instrument I included wonā€™t work. But you can certain drag samples to them if you wish. Just do it in the same way it is done for the example with the keyboard, i.e., check the mouse coordinates when you drop a file and see if they are within the constraints of a pad.

Thanks for this Rory,

I was able to get the ā€œLAST_FILE_DROPPEDā€ to update my ftable (gen01), but for some reason, I canā€™t get it to update a sounfiler widget (so as to have some visual feedback)?

// cabbage    
soundfiler bounds(20, 20, 166, 100), channel("wave1"), colour(147, 210, 0), tableBackgroundColour(0, 0, 0, 80), file("guitar.wav")

// instruments
    instr 1000    
        SFile1 chngetks "LAST_FILE_DROPPED"
        if changed(SFile1) == 1 then 
            event "i", 2000, 0, 1 
        endif
    endin

    instr 2000
        SFile chnget "LAST_FILE_DROPPED"
        SWave sprintf "colour(%d, 210, 100), file(%s)", 0, SFile
        cabbageSet "wave1", SWave
        
        iX chnget "MOUSE_X"
        iY chnget "MOUSE_Y"
        
        gi1 ftgen 1, 0, 0, 1, SFile, 0, 0, 0
    endin

    // score
    i 1000 0 z
    f 1 0 0 1 "guitar.wav" 0 0 0

Seems to work fine here?

Mm, so strangeā€¦Ok, will try to re-write the csd file from scratch and see what happens (but first will try the latest beta hehe)! Thx, will let you know.

dndTest.csd (984 Bytes)

Thatā€™s the file I used.

1 Like

Thanks!

[UPDATE] Ok, I think I discovered what the problem is: I restarted the computer after installing the latest beta 2.8.113, and afterwards, as predicted, I was asked to give Cabbage permission to access say my Desktop and my Documents folder, but it didnā€™t ask me for access permission to my external hard drive (nor I think it gave it any, or thoroughly). I was able to open your csd file and load samples from the local folders but not ifā€¦

  • I opened the csd file from the external volume and then tried to load a sample from that same external location.
  • I opened the csd file from a local folder (e.g. Desktop) and load a sample from the external volume.
    However, I think this applied only to the soundfiler, for the ftable seems to have been updated (the following what was returned from the Cabbage Console)ā€¦

ftable 1:
deferred alloc for /Users/flaviogaete/Documents/My Documents/Csound/Sampler/beats.wav
audio sr = 44100, monaural
opening WAV infile /Users/flaviogaete/Documents/My Documents/Csound/Sampler/beats.wav
defer length 88200
rtevent: T 14.200 TT 14.200 M: 0.00000 0.00000
ftable 1:
deferred alloc for /Volumes/FG APFS/Art/Programming/Projects/MoireĢ/Patches/Cs Misc/Sampler/guitar.wav
audio sr = 44100, monaural
opening WAV infile /Volumes/FG APFS/Art/Programming/Projects/MoireĢ/Patches/Cs Misc/Sampler/guitar.wav
defer length 351998
WARNING: replacing previous ftable 1
WARNING: ftable 1 relocating due to size change
currently active instruments may find this disturbing

How would this work when it comes to exporting a VST/AU plugin, does it follow permissions given to the DAW instead?