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

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

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

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 

    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

    // 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


[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/Moiré/Patches/Cs Misc/Sampler/guitar.wav
audio sr = 44100, monaural
opening WAV infile /Volumes/FG APFS/Art/Programming/Projects/Moiré/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?