I’m interested in alternate tunings, and I found a UDO code to read a Scala file and create a table that Csound can use to produce the scales.
So, I got it loaded in Cabbage (the code’s author provided a test for the UDO), and each time I run it, I seem to get a different result. The first time, it doesn’t play at all, until I click the play button in Cabbage again, at which time it plays fine. So, to test it again, I choose another scale file to read, and it does the same thing, the first click on play doesn’t seem to do anything, but it doesn’t give an error either. But again, the second click plays the file. Then I go back to the first scale, and it runs the first time without a problem.
So, suffice it to say, sometimes it runs, and some times it doesn’t (without any error), and occasionally, it will lock up Cabbage, and all I can do is force quit…
So, it seems the code is functional, and works, because the program will occasionally run, and it seems to load the alternate tuning files. I’ve successfully run the program using at least 5 different files. It just seems that Cabbage (or something) doesn’t like multiple runnings, because after about 5 times of loading, it just locks up.
<Cabbage>
form caption("Untitled") size(400, 300), colour(58, 110, 182), pluginId("def1")
keyboard bounds(8, 158, 381, 95)
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-odac --nchnls=2 --0dbfs=1 --nodisplays --sample-rate=48000 --ksmps=10
</CsOptions>
<CsVersion>
After 6.09
</CsVersion>
<CsInstruments>
;Creates a table by reading a scala scale file (.scl).
;Scale values are converted to decimal format useable by the cpstun(i) opcode.
;ibasefreq defaults to Csounds A4 value.
;ibasekey defaults to 69.
;ifn specifies the table number. Defaults to zero for a Csound generated number.
;Returns the table number, or zero if the scale file is not found.
;The scala file format is documented at http://www.huygens-fokker.org/scala/scl_format.html
;Example usage:
;giscale scltun "/home/user/scl/bohlen-p.scl"
opcode sclft, i, Sjjo
ScalaFile, ibasefreq, ibasekey, ifn xin
cigoto (filevalid(ScalaFile) == 0), NOTFOUND
iline init 0
inoncommentline init 0
inumgrades init 0
ipitwrites init 0
ibasefreq = (ibasefreq == -1 ? A4 : ibasefreq)
ibasekey = (ibasekey == -1 ? 69 : ibasekey)
while iline != -1 do
Sline, iline readfi ScalaFile
istrlen strlen Sline
if strchar:i(Sline) == 33 then
;;ignore commentlines
elseif inoncommentline == 0 then
;;; first non comment line is description
inoncommentline += 1
elseif inoncommentline == 1 then
;;; second non comment line is numnotes
inumgrades strtod strsub(Sline, 0, istrlen - 1)
ipitstore[] init inumgrades
inoncommentline += 1
else
;;; cents or ratio's from here
ipos init 0
istartslice init -1
iendslice init -1
icentformat init 0
while ipos < istrlen do
ichr strchar Sline, ipos
if (ichr >= 45 && ichr < 58) then
if (istartslice == -1) then
istartslice = ipos
endif
if (ichr == 46) then
icentformat = 1
endif
elseif (istartslice >= 0 && iendslice == -1) then
iendslice = ipos
igoto breakout
endif
ipos += 1
od
breakout:
if (istartslice != -1) then
Ssegment strsub Sline, istartslice, iendslice
ipitval = evalstr(strcat("return ", Ssegment))
ipitval = (icentformat == 1 ? (2 ^ (ipitval/1200)) : ipitval)
ipitstore[ipitwrites] = ipitval
ipitwrites += 1
endif
endif
od
idummy_ ftgen ifn, 0, -(ipitwrites + 5), -2, inumgrades, ipitval, ibasefreq, ibasekey, 1
iarrstep init 0
while iarrstep < inumgrades do
tableiw ipitstore[iarrstep], iarrstep + 5, idummy_
iarrstep += 1
od
igoto EXITOPCODE
NOTFOUND:
prints "scl2tun didn't work. File not found\n"
idummy_ = 0
EXITOPCODE:
xout idummy_
endop
;;;;;;EXAMPLE
;change this to where your scale file is
giScale sclft "/Users/mjmogo/Downloads/scl/carlos_gamma.scl"
instr 1
ihz = cpstuni(p5, giScale)
kfilt expseg 8000, p3*0.2, ihz*2, p3*0.8, ihz*8
ares vco2 p4, ihz
ares mvclpf2 ares, kfilt, 0.1;xres[,istor]
ares *= linseg(0,0.01,1,p3-0.1,1,0.05,0) ;declick
ares *= lineto(expcurve((1/active:k(p1)),0.11), 0.01) ;amp control
outs ares, ares
endin
</CsInstruments>
<CsScore>
i1 0 [4-0] 0.8 50
i . ^+0.5 [4-0.5] 0.8 55
i . ^+0.4 [4-0.9] . 59
i . ^+0.35 [4-1.25] . 65
i . ^+0.35 [4-1.6] . 70
i . ^+0.4 [4-2] . 74
i . ^+2.2 [4-0] . 73
i . ^+0.2 [4-0.2] . 69
i . ^+0.2 [4-0.4] . 65
i . ^+0.2 [4-0.6] . 61
i . ^+0.2 [4-0.8] . 57
i . ^+0.2 [4-1] . 53
i . ^+3 [7-0] . 62
i . ^+0.1 [7-0.1] . 67
i . ^+0.1 [7-0.2] . 71
i . ^+0.2 [7-0.4] . 40
i . ^+0.4 [7-0.8] . 31
e
</CsScore>
</CsoundSynthesizer>
I got the UDO from here ( http://csound.1045644.n5.nabble.com/Csnd-Scala-udo-td5761154.html ). It seems other had some issues, but I wasn’t able to see a resolution. You can find the scala tuning files here ( http://www.huygens-fokker.org/docs/scales.zip ).