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("chan"), 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"), channel("chan"), displayType("type"), identChannel("channel"), rotate(radians, pivotx, pivoty), parent(val), visible(val), toFront(), moveBehind("widgetName"), widgetArray("chan", number),
Specific Identifiers
channel("chan")
or
channel("chan1", "chan2")
in the case of widgets that accept two channels such as xypad, soundfiler and range widgets. channel()
accepts a string/s that names the channel/s that
Cabbage will communicate with Csound on. The current value of this widget can be retrieved in Csound using a chnget
, or a
cabbageGetValue
opcode. Its value can be set using the cabbageSet
, or cabbageSetValue
opcodes.
hrange
, vrange
, xypad
, and soundfiler
all take two channels:
hrange, vrange : channel("min", "max")
- min and max values
xypad : channel("x", "y")
- x and y values
soundfiler : channel("start", "length")
- start time and length of user selection, in samples
Channels named should start with a letter and cannot have any white spaces. Note that all widgets should have a unique channel name.
file("filename")
This identifier is used across a number of widgets.
combobox
and listbox
- will load lines from a file as selectable items.gentable
and soundfiler
- will load a sound file to displayimage
- will
load an iamge to display (PNG/JPG/SVG)
infobutton
- sets the file to display when the button is clicked This can be a local html file, or a URL.texteditor
- sets the file to load, should be a text file.
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. If you wish to keep
them in a separate folder use relative paths, i.e, ../../folder
.
Avoid absolute path at all costs. Failure to do so will most likely problems with your instruments as soon as you share them.
displayType("type")
Sets the the type of display. Must be 'spectrogram' or 'spectroscope', 'waveform' or 'lissajous'. Set to 'spectroscope by default. This identifier can
also be used for the soundfiler widget to display a mixed down stereo to mono view. To enable this behaviour, set the diplay type to mono.
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 the cabbageSet opcodes.
gentable can also take an optional parameter, tableNum
which determine which table the scrubber will be placed on, if you are using multiple table.
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)
Sets whether the widget will show scrollbars or not.
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.
channel("chan")
or
channel("chan1", "chan2")
in the case of widgets that accept two channels such as xypad, soundfiler and range widgets. channel()
accepts a string/s that names the channel/s that
Cabbage will communicate with Csound on. The current value of this widget can be retrieved in Csound using a chnget
, or a
cabbageGetValue
opcode. Its value can be set using the cabbageSet
, or cabbageSetValue
opcodes.
hrange
, vrange
, xypad
, and soundfiler
all take two channels:
hrange, vrange : channel("min", "max")
- min and max values
xypad : channel("x", "y")
- x and y values
soundfiler : channel("start", "length")
- start time and length of user selection, in samples
Channels named should start with a letter and cannot have any white spaces. Note that all widgets should have a unique channel name.
identChannel("channel") [!!! DEPRECATED !!!]
Although identifier channels still work, they are no longer supported. Please use the new guiMode("queue") system and the
cabbageGet
and 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.
parent(val)
This identifier is can be to set a widget's parent. It should only be used when creating widgets dynamically using the cabbageCreate
opcode. See
plants for more details.
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 takes no arguments and is only intended for use within the Csound orchestra. it makes no sense to call it when declaring the widget.
moveBehind("widgetName")
Moves a widget directly behind another. This identifier should only ever be called from your Csound orchestra using a
cabbageSet
opcode.
This only works with widgets or plants that have the same parent.
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>