Soundfiler

Soundfiler will display the contents of a sound file, or a function table containing a sound file (GEN01 tables). This is a fast waveform viewer that allows users to select regions of the waveform. Unlike the table widget, soundfiler can only display one waveform at a time.

soundfiler channel("start", "length"), file("filename"), scrubberPosition(val), showscrubber(val), tableNumber(val), zoom(val), sampleRange(min, max), scrollbars(val), active(val), alpha(val), bounds(x, y, width, height), colour("colour"), identChannel("channel"), rotate(radians, pivotx, pivoty), visible(val), toFront(), widgetArray("chan", number),

Specific Identifiers

channel("start", "length") The soundfiler widget takes two channel parameters which relate to the currently selected region. The first channel will provide the starting position, in samples, of the selected region. The second channel will be the total length of the selected audio in samples.

file("filename") Sets a file for the table to display. Unlike the tableNumber() identifier, which depends on the existence of a valid function table, file() will simply display a file from disk. This can be useful if you are using one of Csound's file reading opcodes. If a full file path is not given, file() will search in the current directory, i.e., the directory that contains the csd file that is open. It is best to keep all files in the same directory as your csd file, but if you wish to keep them in a sperate folder you can pass a full path to the file() identifier.

scrubberPosition(val) Sets the scrubber position where val is an integer value in samples. If you wish to update the scrubberPosition in real time use an identChannel identifier.

showscrubber(val) Sets if the soundfiler scrubber is visible, 1 for visible, 0 for invisible. Defaults to 1.

tableNumber(val) Sets the table/tables to be displayed. If multiple tables are specified the tables will be superimposed on top of each other. If multiple tables are specified with a colon between then the tables will be stacked on top of each other along the Y-axis, e.g., tableNumber(1:2:3:4). Note changing table numbers at runtime will incur a slight performance here. It's simpler to copy the contents of a source table to the table gentable or soundfiler are displaying.

zoom(val) Sets the initial zoom value. Passing a -1 to zoom will cause the zoom buttons to disappear.

sampleRange(min, max) Set the initial range of the samples. For example, sampleRange(0, 255) will cause the gentable widget to display only the first 255 samples from a given table.

scrollbars(val) Enables or disables scrollbars. Enabled by default with soundfiler and keyboard widgets. Disabled by default with texteditor.

Common Identifiers

active(val) Will deactivate a control if 0 is passed. Controls which are deactivate can still be updated from Csound.

alpha(val) A value between 0 and 1 will set the alpha blend value for the entire component. Can be useful if you need to fade widgets in and out.

bounds(x, y, width, height) integer values that set position and size on screen(in pixels).

colour("colour") This sets the main colour. Any CSS or HTML colour string can be passed to this identifier. The colour identifier can also be passed an RBG, or RGBA value. All channel values must be between 0 and 255. For instance colour(0, 0, 255) will create a blue, while colour(0, 255, 0, 255) will create a green with an alpha channel set to full.

identChannel("channel") [!!! DEPRECATED !!!] Although identifier channels still work, they are no longer supported. Please use the new guiMode("queue") system and the cabbageSet opcodes instead. They are far more efficient then identifiers channel.

rotate(radians, pivotx, pivoty) Rotates the widget by a number of radians(2xPI=full rotation). pivotx and pivoty will determine the rotation pivot points, where 0, 0 represents the component's top-left position.

visible(val) A value of 0 will cause the widget to become invisible. Widgets have their visibility set to 1 by default.

toFront() Brings a widget to the front of the z order. This identifier takses no arguments and is only intended for use with identifier channels.

widgetArray("chan", number) [!!! DEPRECATED !!!] Deprecated. Please see the section on Managing large numbers of widgets

Example

<Cabbage>
form caption("Soundfiler Example") size(410, 500), guiMode("queue"), colour(2, 145, 209) pluginId("def1")

texteditor bounds(16, 254, 376, 233) channel("infoText"), readOnly(1), wrap(1), scrollbars(1)

soundfiler bounds(22, 16, 120, 89), channel("soundfiler1"), file("./DoubleBass/1.wav") colour(147, 210, 0), tableBackgroundColour(0, 0, 0, 80)
button bounds(80, 80, 58, 22) corners(5), channel("play1"), text("Play")

soundfiler bounds(146, 16, 120, 89), channel("soundfiler2"), file("./DoubleBass/2.wav") colour(147, 210, 0), tableBackgroundColour(0, 0, 0, 80)
button bounds(206, 80, 58, 22) corners(5), channel("play2"), text("Play")

soundfiler bounds(270, 16, 120, 89), channel("soundfiler3"), file("./DoubleBass/3.wav") colour(147, 210, 0), tableBackgroundColour(0, 0, 0, 80)
button bounds(330, 80, 58, 22) corners(5), channel("play3"), text("Play")

soundfiler bounds(22, 116, 120, 89), channel("soundfiler4"), file("./DoubleBass/4.wav") colour(147, 210, 0), tableBackgroundColour(0, 0, 0, 80)
button bounds(80, 180, 58, 22) corners(5), channel("play4"), text("Play")

soundfiler bounds(146, 116, 120, 89), channel("soundfiler5"), file("./DoubleBass/5.wav") colour(147, 210, 0), tableBackgroundColour(0, 0, 0, 80)
button bounds(206, 180, 58, 22) corners(5), channel("play5"), text("Play")

soundfiler bounds(270, 116, 120, 89), channel("soundfiler6"), file("./DoubleBass/6.wav") colour(147, 210, 0), tableBackgroundColour(0, 0, 0, 80)
button bounds(330, 180, 58, 22) corners(5), channel("play6"), text("Play")
button bounds(271, 216, 114, 27) channel("randomPlayback"), corners(5), text("Random Playback", "Stop")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d --midi-key=4 --midi-velocity-amp=5
</CsOptions>e
<CsInstruments>
; Initialize the global variables. 
ksmps = 16
nchnls = 2
0dbfs = 1


; Rory Walsh 2021 
;
; License: CC0 1.0 Universal
; You can copy, modify, and distribute this file, 
; even for commercial purposes, all without asking permission. 


instr GuiControl

    SText  = "A soundfiler widget can be used to display to a sound file; from disk, or from a function table. It does not play back any audio, or produce any signal. All this must be handled using Csound.\n\nIn the example here, 6 samples are loaded from disk. The 'TriggerSamplePlayback' instrument is instantiated 6 times, one for each sample. This saves having to code 6 times.\n\nWhen the 'SamplePlayback' instrument is triggered is plays back the corresponding sample. It also changes the background colour of the soundfiler to give some visual feedback to the user as to when the sample is playing.\n\nFinally, a random button is added which triggers the six different sample to play back at random time intervals." 
    cabbageSet "infoText", "text", SText

    kRandom cabbageGetValue "randomPlayback"
    if kRandom == 1 && metro(1) == 1 then
        event "i", "SamplePlayback", int(random:k(1, 10))*.1, 1, int(random:k(1, 7))
    endif
endin


instr TriggerSamplePlayback 

    STrigButtonChannel sprintf "play%d", p4
    ;trigger playback of sample
    kPlayState, kPlayTrig cabbageGetValue STrigButtonChannel
    if kPlayTrig == 1 then
            event "i", "SamplePlayback", 0, .1, p4
    endif    

endin


instr SamplePlayback

    SFile sprintf "./DoubleBass/%d.wav", p4
    iLen = filelen(SFile)
    p3 = iLen

    SWidgetChannel sprintf "soundfiler%d", p4
    kAlpha expon 180, p3*.3, 80
    cabbageSet metro(20), SWidgetChannel, "tableBackgroundColour", 0, 0, 0, kAlpha     

    a1 diskin2 SFile, 1, 0, 1
    outs a1, a1  

endin


</CsInstruments>
<CsScore>
i"GuiControl" 0 z
i"TriggerSamplePlayback" 0 z 1
i"TriggerSamplePlayback" 0 z 2
i"TriggerSamplePlayback" 0 z 3
i"TriggerSamplePlayback" 0 z 4
i"TriggerSamplePlayback" 0 z 5
i"TriggerSamplePlayback" 0 z 6
</CsScore>
</CsoundSynthesizer>