Cabbage Logo
Back to Cabbage Site

Total noobie questions wrtting txt or xml files and iterating through and setting widget array data

Hello everyone

I am working on a 32 step sequencer. I have been working on the ui over the past few days and I feel like I am coming to a standstill I have knowledge of other programming languages but since I am new to csound I have little to know clue on the proper syntax to be using when it comes to the basic like reading and writting to txt or xml files. Or even changing the nth index in a widget array such as a file location for soundfiler. Also adding or removing nth line to a listbox could help.

I was able to go through the tutorials provided on the cabbage audio website but I noticed they dont really cover setting and getting information from multipule widgets such as soundfiler. So far I have been able to load only 1 file location and successfully display the waveform inside the soundfiler display Im having trouble iterating through and setting all 64 file locations.

I followed the basic instructions on creating multiple objects using widgets So now I have 64 soundfiler objects overlapping each other in my patch.

How would I make only the selected index visible programmatically not by manually selecting the visibility check box in the properties.

Again I don’t know how to set the nth index of the soundfiler filename depending on which index is selected if that makes sense.

Any help is much appreciated

Hi @RetroMaximus, welcome to the forum. It might be best to break this down into different parts. To read and write text to disk, you can use one of the file IO opcodes in Csound. Writing to xml of JSON is not supported so you might have to take some care in how you format your data.

64 soundfiler objects :see_no_evil: All in a widget array. That’s certainly one way to try it. It might be easier however to simply create one soundfiler, and dynamically load what samples you want to it. For example, here I step through each sample in a directory and update the soundfiler widget every second.


soundfileTest.csd (762 Bytes)

For an example of how to do it with 64 different widgets, from an array, look at the WidgetArrays.csd example. This positions each widget from the array on instrument startup. In your case, if you absolutely need 64 soundfilers, you can either toggle their visibility, or move them off-screen.

As I mentioned before, I think the best thing is to break this own into more focused tasks. I’m not really sure where to start in terms of assistance, as there are so many elements to it. Obviously, I’m more than happy to help.

This is not currently possible without some hackery. The issue is a listbox is registered by a host as having a particular range. Neither the VST2 or VST3 SDK allow dynamic remapping of parameter ranges.But if you really need to do it, I’m sure we can find way :wink:

1 Like

Awesome this is exactly what i needed to know. So just by my playing around over the past few days I was able to get things working correctly. what you have in your example is a much more refined version of what i had going so this is good news to me. i was able to cycle through and update what is displayed but i had 16 “load” buttons at first and wasnt sure if i was going about it the right way for future things like possibly playing all sounds at once if the sequence called for it thats why i figured a widget array was the way to go. But I wasnt able to get any playback should the sound be playing when it is loaded? im not sure how to trigger any audio output

So there might be a few ways I can solve this if i was to use 64 soundfilers it would make for a lot more backend prep but in the long run will make things more efficient in terms of editing or playing back a programmed sequence. The example you provided brings clarity for me the only thing i am worried about is triggering all sounds to playback at once if at all needed.

I am slowly working on the sample browser which is why there is a random listbox with 2 lines which hold sample directories. The idea is when a favorite directory is selected the corresponding index will be selected in the listbox2 to get the string “the sample directory” then populate("*.wav",“c:\filelocation”) with the wav in said directory for the sample browser listbox. Thats a bit convoluted sorry. :slight_smile:

In conjunction with the sample browser I would need a archive manager displayed in the second screen shot to handle adding and removing favorite sample directories.

learning a new language is stressful. I hope this community is active. :slight_smile:

Below is a screen shot of my sampler sequencer.

OverBlast Standalone

Archive Manager

Sound will only play back when you instruct Csound to do so.

You know that soundfilers merely display sound files, they don’t play back and sound. This all has to be done with Csound. Check out the SampleLoadAndPlayback example from this Examples->Misc menu, that shows just one way to playback audio samples. Of course there are many ways to do it in Csound.

This is no issue, so long as you keep a record of what files have been opened in your Csound code.

Am I right in assuming most of this is GUI development for now?

Sure is :wink:

Yes this is generally the gui at the moment nothing is working other then the creation arguments for the listboxes to populate wavs from a directory.

I was unaware that soundfiler was for displaying waveforms for some reason I had it in my head that it would store the wave data for playing at a later time. And I will be looking at the SampleLoadAndPlayback example right now Thx for the info.

Since Ive posted this original question I was able to get the first few buttons of the Archive Manager working i have this bit of code based on this fprints example.

http://www.csounds.com/manual/html/fprints.html

It seams to be working if i change SText or SDir to a temp string like “temp text” for example. But the next time the button is pushed all of the text is over written and not appended to the end. Also with my code nothing gets written but with a temp string it works. SText chnget and SDir chnget dosent seam to work.

instr 1
SFile chnget “directoryBtn”
if changed(SFile) == 1 then
SIdentString sprintfk “text(”%s")", SFile
chnset SIdentString, “dirTextIdent”
endif

kBut chnget “addBtn”

if changed:k(kBut) == 1 then
       
    SText chnget "titleText"
    
        fprints "favoritedirs.txt", SText
            
    SDir chnget "dirText"
   
        fprints "favoritedirs-locations.txt", SDir
                  
endif

endin

I should mention later I will have to get a line of text based on a int i don’t know how to do that yet either. :confused:

Yeah, the plugin GUI is merely an abstraction of data contained in the Csound code. It’s helpful to keep this mind as you develop your instrument further.

I’m not sure fprints can append a file. And I’m not sure if the current set of Csound opcodes allow reading a string from a file. I wrote some simple opcodes for doing this that you can access here. Here is a simple code example that takes the sound files that have been loaded to the soundfiler and saves them to disk. I’m currently on Windows, so I simple downloaded the opcodes, and placed them into the same directory as I’m working in. Note the --opcode-lib in the CsOptions section.
gSFilename init “”

(...)
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d --opcode-lib=strtofile.dll
</CsOptions>
(...)

instr 1
    kIndex init 1
    if metro(1) == 1 then
        gSFilename sprintfk "file(\"./Drums1/%02d.wav\")", kIndex
        kIndex +=1
        chnsetks gSFilename, "soundfiler1"
        event "i", "WRITE_DATA", 0, 0
    endif 
endin

instr WRITE_DATA
    SFilename strcat  "\n", gSFilename
    iRes strToFile SFilename, "quickTest.txt", 1
endin

I have to spawn the writing of the data to another instrument as the opcode only works at i-rate. You’re new to Csound yeah? Have fun getting your head around i-time and k-time opcodes :rofl:

soundfileTest.csd (1.0 KB)

If you want to go full power , CSOUND is a great audio programming language but not much as a programming language. Something like Python is much better option , especially if you like to save to JSON or XML files. For JSON I can vouch for CPython that works outside the box , the good news is that CSOUND seems to have a very good integration with Python, allowing through opcodes to inline python code, to send data from CSOUND to Python and from Python to CSOUND.

http://floss.booktype.pro/csound/b-python-inside-csound/

I plan to start using python too for my own project cause nothing can beats its power in terms of flexibility and most importantly a massive amount of third party libraries.